List of usage examples for org.apache.commons.math.distribution BetaDistributionImpl BetaDistributionImpl
public BetaDistributionImpl(double alpha, double beta)
From source file:change_point_detection.CusumElement.java
public CusumElement(double alphaPreChange, double betaPreChange, double alphaPostChange, double betaPostChange, double preChangeMean, double cusumScore) { this.preChangeDist = new BetaDistributionImpl(alphaPreChange, betaPreChange); this.postChangeDist = new BetaDistributionImpl(alphaPostChange, betaPostChange); this.preChangeMean = preChangeMean; this.cusumScore = cusumScore; }
From source file:com.opengamma.analytics.financial.credit.recoveryratemodel.RecoveryRateModelStochastic.java
public RecoveryRateModelStochastic(final double a, final double b, final double x) { super(0.0);/*from w ww . j a va 2 s .com*/ _a = a; _b = b; _x = x; BetaDistributionImpl betaDistribution = new BetaDistributionImpl(_a, _b); // FIXME : Fix this _recoveryRate = 0.0; //betaDistribution.inverseCumulativeProbability(_x); _recoveryRateType = RecoveryRateType.STOCHASTIC; // ---------------------------------------------------------------------------------------------------------------------------------------- }
From source file:change_point_detection.BetaDistributionChangePoint.java
public int/*estimated change point*/ detectChange() throws Exception { int estimatedChangePoint = -1; int N = this.dynamicWindow.size(); this.cushion = Math.max(100, (int) Math.floor(Math.pow(N, gamma))); //mean conf. should not fall below 0.3 if (N > (2 * this.cushion) && calculateMean(0, N - 1) <= 0.3) return N - 1; double threshold = -Math.log(this.sensitivity); double w = 0; int kAtMaxW = -1; for (int k = this.cushion; k <= N - this.cushion; k++) { if (calculateMean(k, N - 1) <= 0.95 * calculateMean(0, k - 1)) { double skn = 0; /* estimate pre and post change parameters */ double alphaPreChange = calcBetaDistAlpha(0, k - 1); double betaPreChange = calculateBetaDistBeta(alphaPreChange, 0, k - 1); double alphaPostChange = calcBetaDistAlpha(k, N - 1); double betaPostChange = calculateBetaDistBeta(alphaPostChange, k, N - 1); BetaDistributionImpl preBetaDist = new BetaDistributionImpl(alphaPreChange, betaPreChange); BetaDistributionImpl postBetaDist = new BetaDistributionImpl(alphaPostChange, betaPostChange); for (int i = k; i < N; i++) { try { skn += Math.log(postBetaDist.density(this.dynamicWindow.get(i).doubleValue()) / preBetaDist.density(this.dynamicWindow.get(i).doubleValue())); } catch (Exception e) { e.printStackTrace(); System.out.println("continuing..."); skn = 0;/* w w w. j av a2 s . c o m*/ break; } } if (skn > w) { w = skn; kAtMaxW = k; } } } if (w >= threshold && kAtMaxW != -1) { System.out.println("\nChangePoint Found!"); estimatedChangePoint = kAtMaxW; System.out.println("Estimated change point is " + estimatedChangePoint); } //force change point if confidence falls down terribly if (estimatedChangePoint == -1 && N >= 100 && calculateMean(0, N - 1) < 0.3) estimatedChangePoint = N - 1; return estimatedChangePoint; }
From source file:edu.utexas.cs.tactex.servercustomers.factoredcustomer.ProbabilityDistribution.java
ProbabilityDistribution(FactoredCustomerService service, Element xml) { if (null == randomSeedRepo) randomSeedRepo = (RandomSeedRepo) SpringApplicationContext.getBean("randomSeedRepo"); type = Enum.valueOf(DistType.class, xml.getAttribute("distribution")); switch (type) { case POINTMASS: case DEGENERATE: param1 = Double.parseDouble(xml.getAttribute("value")); sampler = new DegenerateSampler(param1); break;/*from ww w.j ava 2s . com*/ case UNIFORM: param1 = Double.parseDouble(xml.getAttribute("low")); param2 = Double.parseDouble(xml.getAttribute("high")); sampler = new UniformSampler(param1, param2); break; case INTERVAL: param1 = Double.parseDouble(xml.getAttribute("mean")); param2 = Double.parseDouble(xml.getAttribute("stdDev")); param3 = Double.parseDouble(xml.getAttribute("low")); param4 = Double.parseDouble(xml.getAttribute("high")); sampler = new IntervalSampler(param1, param2, param3, param4); break; case NORMAL: case GAUSSIAN: param1 = Double.parseDouble(xml.getAttribute("mean")); param2 = Double.parseDouble(xml.getAttribute("stdDev")); sampler = new ContinuousSampler(new NormalDistributionImpl(param1, param2)); break; case STDNORMAL: param1 = 0; param2 = 1; sampler = new ContinuousSampler(new NormalDistributionImpl(param1, param2)); break; case LOGNORMAL: param1 = Double.parseDouble(xml.getAttribute("expMean")); param2 = Double.parseDouble(xml.getAttribute("expStdDev")); sampler = new LogNormalSampler(param1, param2); break; case CAUCHY: param1 = Double.parseDouble(xml.getAttribute("median")); param2 = Double.parseDouble(xml.getAttribute("scale")); sampler = new ContinuousSampler(new CauchyDistributionImpl(param1, param2)); break; case BETA: param1 = Double.parseDouble(xml.getAttribute("alpha")); param2 = Double.parseDouble(xml.getAttribute("beta")); sampler = new ContinuousSampler(new BetaDistributionImpl(param1, param2)); break; case BINOMIAL: param1 = Double.parseDouble(xml.getAttribute("trials")); param2 = Double.parseDouble(xml.getAttribute("success")); sampler = new DiscreteSampler(new BinomialDistributionImpl((int) param1, param2)); break; case POISSON: param1 = Double.parseDouble(xml.getAttribute("lambda")); sampler = new DiscreteSampler(new PoissonDistributionImpl(param1)); break; case CHISQUARED: param1 = Double.parseDouble(xml.getAttribute("dof")); sampler = new ContinuousSampler(new ChiSquaredDistributionImpl(param1)); break; case EXPONENTIAL: param1 = Double.parseDouble(xml.getAttribute("mean")); sampler = new ContinuousSampler(new ExponentialDistributionImpl(param1)); break; case GAMMA: param1 = Double.parseDouble(xml.getAttribute("alpha")); param2 = Double.parseDouble(xml.getAttribute("beta")); sampler = new ContinuousSampler(new GammaDistributionImpl(param1, param2)); break; case WEIBULL: param1 = Double.parseDouble(xml.getAttribute("alpha")); param2 = Double.parseDouble(xml.getAttribute("beta")); sampler = new ContinuousSampler(new WeibullDistributionImpl(param1, param2)); break; case STUDENT: param1 = Double.parseDouble(xml.getAttribute("dof")); sampler = new ContinuousSampler(new TDistributionImpl(param1)); break; case SNEDECOR: param1 = Double.parseDouble(xml.getAttribute("d1")); param2 = Double.parseDouble(xml.getAttribute("d2")); sampler = new ContinuousSampler(new FDistributionImpl(param1, param2)); break; default: throw new Error("Invalid probability distribution type!"); } sampler.reseedRandomGenerator(service.getRandomSeedRepo() .getRandomSeed("factoredcustomer.ProbabilityDistribution", SeedIdGenerator.getId(), "Sampler") .getValue()); }
From source file:change_point_detection.CpdDP.java
public int/*estimated change point*/ detectChange() throws Exception { int estimatedChangePoint = -1; int N = this.dynamicWindow.size(); this.cushion = Math.max(100, (int) Math.floor(Math.pow(N, gamma))); //mean conf. should not fall below 0.3 double preChangeMean, postChangeMean, wholeMean; wholeMean = calculateMean(0, N - 1); if ((N > (2 * this.cushion) && wholeMean <= 0.3) || this.dynamicWindow.size() > this.dim) return N - 1; double threshold = -Math.log(this.sensitivity); double w = 0; int kAtMaxW = -1; for (int k = this.cushion; k <= N - this.cushion; k++) { double skn = 0; int prevN = this.trackN[k]; preChangeMean = prevN == -1 ? calculateMean(0, k - 1) : this.cusumElementArr[prevN][k].getPreChangeMean(); postChangeMean = calculateMean(k, N - 1); if (postChangeMean <= (1 - this.secAlgMarSlack) * preChangeMean) {//signal from secondary if (prevN == -1) { //calculate from scratch /* estimate pre and post change parameters */ double alphaPreChange = calcBetaDistAlpha(0, k - 1, preChangeMean); double betaPreChange = calculateBetaDistBeta(alphaPreChange, 0, k - 1, preChangeMean); double alphaPostChange = calcBetaDistAlpha(k, N - 1, postChangeMean); double betaPostChange = calculateBetaDistBeta(alphaPostChange, k, N - 1, postChangeMean); BetaDistributionImpl preBetaDist = new BetaDistributionImpl(alphaPreChange, betaPreChange); BetaDistributionImpl postBetaDist = new BetaDistributionImpl(alphaPostChange, betaPostChange); for (int i = k; i < N; i++) { try { skn += Math.log(postBetaDist.density(this.dynamicWindow.get(i).doubleValue()) / preBetaDist.density(this.dynamicWindow.get(i).doubleValue())); } catch (Exception e) { e.printStackTrace(); System.out.println("continuing..."); skn = 0;// w w w . j a va 2 s. co m break; } } this.cusumElementArr[N - 1][k] = new CusumElement(preBetaDist, postBetaDist, preChangeMean, skn); } else {//warning and calculate recursively double alphaPostChange2 = calcBetaDistAlpha(k, N - 1, postChangeMean); double betaPostChange2 = calculateBetaDistBeta(alphaPostChange2, k, N - 1, postChangeMean); BetaDistributionImpl postBetaDist2 = new BetaDistributionImpl(alphaPostChange2, betaPostChange2); skn += this.cusumElementArr[prevN][k].getCusumScore(); for (int i = prevN + 1; i < N; i++) { try { skn += Math.log(postBetaDist2.density(this.dynamicWindow.get(i).doubleValue()) / this.cusumElementArr[prevN][k].getPreChangeDist() .density(this.dynamicWindow.get(i).doubleValue())); } catch (Exception e) { e.printStackTrace(); System.out.println("continuing..."); skn = 0; break; } } this.cusumElementArr[N - 1][k] = new CusumElement( this.cusumElementArr[prevN][k].getPreChangeDist(), postBetaDist2, preChangeMean, skn); } this.trackN[k] = N - 1; } if (skn > w) { w = skn; kAtMaxW = k; } } if (w >= threshold && kAtMaxW != -1) { System.out.println("\nChangePoint Found!"); estimatedChangePoint = kAtMaxW; System.out.println("Estimated change point is " + estimatedChangePoint + ", detected at point: " + N); } //force change point if confidence falls down terribly if (estimatedChangePoint == -1 && N >= 100 && wholeMean < 0.3) estimatedChangePoint = N - 1; return estimatedChangePoint; }
From source file:org.renjin.Distributions.java
public static double dbeta(final double x, final double shape1, final double shape2, boolean log) { return d(new BetaDistributionImpl(shape1, shape2), x, log); }
From source file:org.renjin.Distributions.java
public static double pbeta(final double q, final double shape1, final double shape2, boolean lowerTail, boolean logP) { return p(new BetaDistributionImpl(shape1, shape2), q, lowerTail, logP); }
From source file:org.renjin.Distributions.java
public static double qbeta(final double p, final double shape1, final double shape2, boolean lowerTail, boolean logP) { return q(new BetaDistributionImpl(shape1, shape2), p, lowerTail, logP); }
From source file:org.renjin.primitives.random.Distributions.java
public static double dbeta(@Recycle double x, @Recycle double shape1, @Recycle double shape2, boolean log) { return d(new BetaDistributionImpl(shape1, shape2), x, log); }
From source file:org.renjin.primitives.random.Distributions.java
public static double pbeta(@Recycle double q, @Recycle double shape1, @Recycle double shape2, boolean lowerTail, boolean logP) { return p(new BetaDistributionImpl(shape1, shape2), q, lowerTail, logP); }