当前位置: 首页>>代码示例>>Java>>正文


Java BetaDistribution类代码示例

本文整理汇总了Java中org.apache.commons.math3.distribution.BetaDistribution的典型用法代码示例。如果您正苦于以下问题:Java BetaDistribution类的具体用法?Java BetaDistribution怎么用?Java BetaDistribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BetaDistribution类属于org.apache.commons.math3.distribution包,在下文中一共展示了BetaDistribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mainTest

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
public static void mainTest() throws Exception{
	int maxIterations=10000;

	List<List<Double>> sample_sep=EMUtils.getSimulatedScores(new int[]{1000,2000},Arrays.asList(new RealDistribution[]{
			new BetaDistribution(2,2),
			new BetaDistribution(5,1)
	}));

	//		List<List<Double>> sample_sep=EMUtils.getSimulatedScores(new int[]{1000,2000},Arrays.asList(new RealDistribution[]{
	//				new GammaDistribution(2,2),
	//				new GammaDistribution(7.5,1)
	//		}));
	List<Double> values=new ArrayList<Double>();
	List<InterfaceMLDistribution> distributions=new ArrayList<InterfaceMLDistribution>();
	for(List<Double> s:sample_sep){
		values.addAll(s);			
		distributions.add(new MLBetaDistribution(false, 0));
		//			distributions.add(new MLGammaDistribution(false, 0));
	}

	Sample sample=new Sample(values, null, null);
	//		EM em=new EM(sample, distributions, maxIterations, minChangeLikelihood);
	EM em=new EM(sample, distributions, maxIterations, Double.NEGATIVE_INFINITY);
	EMResult r=em.doEM(true);
	System.out.println(r.likelihood);
}
 
开发者ID:boecker-lab,项目名称:passatuto,代码行数:27,代码来源:EMMain.java

示例2: MixModel

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
public MixModel(MethyModel tumor, MethyModel normal, RealVector thetas, int nBetas, int MYTHREADS) throws InterruptedException {
	int nFeatures=tumor.getNaRatio().getDimension();
	this.nBetas = nBetas;
	RealVector betas = new ArrayRealVector(nBetas);
	for (int i=0; i<nBetas; i++) {
		betas.setEntry(i,i/(nBetas-1.0));
	}
	mixDens = new RealMatrix[nFeatures];
	ExecutorService executor = Executors.newFixedThreadPool(MYTHREADS);

	for(int i = 0; i < nFeatures; i++) {
		double tumorAlpha = tumor.getAlpha().getEntry(i);
		double tumorBeta = tumor.getBeta().getEntry(i);
		BetaDistribution tumorDist = new BetaDistribution(tumorAlpha,tumorBeta);
		double normalAlpha = normal.getAlpha().getEntry(i);
		double normalBeta = normal.getBeta().getEntry(i);
		BetaDistribution normalDist = new BetaDistribution(normalAlpha,normalBeta);
		Runnable worker = new CalMixDens(tumorDist,normalDist,thetas,betas,nPoints,i,mixDens);
		executor.execute(worker);
	}
	executor.shutdown();
	while (!executor.isTerminated()) {
		Thread.sleep(10000);
	}
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:26,代码来源:MixModel.java

示例3: testGoodnessOfFitByTwoLevelTesting

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Theory
public void testGoodnessOfFitByTwoLevelTesting(
        @FromDataPoints("N") final int N,
        @FromDataPoints("K") final int K,
        final BetaDistParam parameters,
        final BetaRNG betaRNG) {

    final double alpha = parameters.alpha;
    final double beta = parameters.beta;

    System.out.printf("%s: alpha = %.2f, beta = %.2f%n", betaRNG.getClass().getSimpleName(), alpha, beta);

    TwoLevelTester tester = new TwoLevelTester(N, K);
    tester.test(
            random -> betaRNG.generate(random, alpha, beta),
            new BetaDistribution(alpha, beta, 1e-15));
    System.out.println(betaRNG);
}
 
开发者ID:komiya-atsushi,项目名称:fast-rng-java,代码行数:19,代码来源:BetaRNGTest.java

示例4: prior

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
protected void prior() {
	// TODO Auto-generated method stub	
	double e = Math.exp(-this.distance*Constants._con_base_r);
	double alpha = Math.max(Constants._mu_J_e*(1-e), Constants.eps);
	double beta = Math.max(Constants._mu_J_e*e, Constants.eps);
	this.exp = new BetaDistribution(Constants.rg, alpha, beta).sample();
	// TODO should be a smaller number?
	this.exp = Math.max(this.exp, 1e-3);
	int z = Constants._haplotype_z/2;
	this.alpha = new double[2][z];
	//Dirichlet diri = new Dirichlet(distz(z), Constants._mu_alpha_e);
	for(int i=0; i<2; i++)
		//this.alpha[i] = ArrayUtils.toPrimitive(diri.sample());
		Arrays.fill(this.alpha[i], 1.0/z);
	return;
}
 
开发者ID:c-zhou,项目名称:polyGembler,代码行数:17,代码来源:HiddenMarkovModel.java

示例5: testNextInversionDeviate

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    RandomGenerator rg = new Well19937c(100);
    RandomDataGenerator rdg = new RandomDataGenerator(rg);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = rdg.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    rg.setSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(rg, 2, 4,
                                                             BetaDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = betaDistribution.sample();
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:RandomDataGeneratorTest.java

示例6: testSliceSamplingOfMonotonicBetaDistribution

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
/**
 * Test slice sampling of a monotonic beta distribution as an example of sampling of a bounded random variable.
 * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%,
 * respectively.
 */
@Test
public void testSliceSamplingOfMonotonicBetaDistribution() {
    rng.setSeed(RANDOM_SEED);

    final double alpha = 10.;
    final double beta = 1.;
    final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
    final Function<Double, Double> betaLogPDF = betaDistribution::logDensity;

    final double xInitial = 0.5;
    final double xMin = 0.;
    final double xMax = 1.;
    final double width = 0.1;
    final int numSamples = 10000;
    final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width);
    final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples));

    final double mean = betaDistribution.getNumericalMean();
    final double variance = betaDistribution.getNumericalVariance();
    final double sampleMean = new Mean().evaluate(samples);
    final double sampleVariance = new Variance().evaluate(samples);
    Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
    Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:30,代码来源:SliceSamplerUnitTest.java

示例7: testSliceSamplingOfPeakedBetaDistribution

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
/**
 * Test slice sampling of a peaked beta distribution as an example of sampling of a bounded random variable.
 * Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%,
 * respectively.
 */
@Test
public void testSliceSamplingOfPeakedBetaDistribution() {
    rng.setSeed(RANDOM_SEED);

    final double alpha = 10.;
    final double beta = 4.;
    final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
    final Function<Double, Double> betaLogPDF = betaDistribution::logDensity;

    final double xInitial = 0.5;
    final double xMin = 0.;
    final double xMax = 1.;
    final double width = 0.1;
    final int numSamples = 10000;
    final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width);
    final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples));

    final double mean = betaDistribution.getNumericalMean();
    final double variance = betaDistribution.getNumericalVariance();
    final double sampleMean = new Mean().evaluate(samples);
    final double sampleVariance = new Variance().evaluate(samples);
    Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
    Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:30,代码来源:SliceSamplerUnitTest.java

示例8: testDirichletNormalization

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Test
public void testDirichletNormalization() {
    // a Dirichlet with two parameters is a Beta
    final double a = 11;
    final double b = 36;
    final double[] params1 = new double[] {a, b};
    final double normalization = Math.pow(10, SomaticLikelihoodsEngine.log10DirichletNormalization(params1));
    final BetaDistribution bd = new BetaDistribution(a,b);
    for (final double x : new double[] {0.1, 0.3, 0.6}) {
        Assert.assertEquals(bd.density(x), normalization * Math.pow(x, a - 1) * Math.pow(1-x, b-1), 1e-6);
    }

    // a Dirichlet with parameters equal to 1 is flat, so the normalization is 1/the hypervolume of the simplex
    // which is d! where d is the dimension

    final double[] params2 = new double[] {1, 1, 1, 1};
    final double normalization2 = Math.pow(10, SomaticLikelihoodsEngine.log10DirichletNormalization(params2));
    Assert.assertEquals(normalization2, 6, 1e-6);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:20,代码来源:SomaticLikelihoodsEngineUnitTest.java

示例9: getBeta

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Override
public RandomNumberDistribution<Double> getBeta(
		final RandomNumberStream rng, final Number alpha, final Number beta)
{
	final RealDistribution dist = new BetaDistribution(
			RandomNumberStream.Util.asCommonsRandomGenerator(rng),
			alpha.doubleValue(), beta.doubleValue());
	return new RandomNumberDistribution<Double>()
	{
		@Override
		public Double draw()
		{
			return dist.sample();
		}
	};
}
 
开发者ID:krevelen,项目名称:coala,代码行数:17,代码来源:RandomDistributionFactoryImpl.java

示例10: testNextInversionDeviate

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Test
public void testNextInversionDeviate() {
    // Set the seed for the default random generator
    randomData.reSeed(100);
    double[] quantiles = new double[10];
    for (int i = 0; i < 10; i++) {
        quantiles[i] = randomData.nextUniform(0, 1);
    }
    // Reseed again so the inversion generator gets the same sequence
    randomData.reSeed(100);
    BetaDistribution betaDistribution = new BetaDistribution(2, 4);
    /*
     *  Generate a sequence of deviates using inversion - the distribution function
     *  evaluated at the random value from the distribution should match the uniform
     *  random value used to generate it, which is stored in the quantiles[] array.
     */
    for (int i = 0; i < 10; i++) {
        double value = randomData.nextInversionDeviate(betaDistribution);
        Assert.assertEquals(betaDistribution.cumulativeProbability(value), quantiles[i], 10E-9);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:RandomDataTest.java

示例11: univarBeta

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
public  RegDataSet univarBeta(){


        BetaDistribution betaDistribution = new BetaDistribution(2,5);

        RegDataSet dataSet = RegDataSetBuilder.getBuilder()
                .numDataPoints(numDataPoints)
                .numFeatures(1)
                .dense(true)
                .missingValue(false)
                .build();
        for (int i=0;i<numDataPoints;i++){
            double featureValue = Sampling.doubleUniform(0,1);
            double label;
            label =  betaDistribution.density(featureValue);
            label += noise.sample();
            dataSet.setFeatureValue(i,0,featureValue);
            dataSet.setLabel(i,label);
        }
        return dataSet;
    }
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:22,代码来源:RegressionSynthesizer.java

示例12: getSeatProbs

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
public double[] getSeatProbs(int trials) {
	double delta = 1.0/(double)trials;
	double[] seatProbs = new double[district_betas.size()+1];
	for( int i = 0; i < trials; i++) {
		int seats = 0;
		for(BetaDistribution bd : district_betas) {
			double r = FastMath.random();
			if( r <= bd.cumulativeProbability(0.5)) {
				seats++;
			}
		}
		seatProbs[seats] += delta;
	}
	
	return seatProbs;
}
 
开发者ID:happyjack27,项目名称:autoredistrict,代码行数:17,代码来源:Metrics.java

示例13: CalMixDens

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
CalMixDens(BetaDistribution tumorDist, BetaDistribution normalDist, RealVector thetas, RealVector betas,
		   int nPoints, int featureIdx, RealMatrix[] mixDens) {
	this.tumorDist = tumorDist;
	this.normalDist = normalDist;
	this.thetas = thetas;
	this.nThetas = thetas.getDimension();
	this.betas = betas;
	this.nBetas = betas.getDimension();
	this.nPoints = nPoints;
	this.featureIdx = featureIdx;
	this.mixDens = mixDens;
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:13,代码来源:MixModel.java

示例14: setUp

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Setup
public void setUp() {
    String[] items = parameters.split(":");
    alpha = Double.valueOf(items[0]);
    beta = Double.valueOf(items[1]);
    commonsMath = new BetaDistribution(alpha, beta);
}
 
开发者ID:komiya-atsushi,项目名称:fast-rng-java,代码行数:8,代码来源:BetaBenchmark.java

示例15: testNextBeta

import org.apache.commons.math3.distribution.BetaDistribution; //导入依赖的package包/类
@Test
public void testNextBeta() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new BetaDistribution(2,5));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextBeta(2, 5);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:12,代码来源:RandomDataGeneratorTest.java


注:本文中的org.apache.commons.math3.distribution.BetaDistribution类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。