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


Java NormalDistribution.sample方法代码示例

本文整理汇总了Java中org.apache.commons.math3.distribution.NormalDistribution.sample方法的典型用法代码示例。如果您正苦于以下问题:Java NormalDistribution.sample方法的具体用法?Java NormalDistribution.sample怎么用?Java NormalDistribution.sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.distribution.NormalDistribution的用法示例。


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

示例1: testRandomDataNormalDistribution

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
@Test
public void testRandomDataNormalDistribution() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        RealMatrix s = checkAEqualPTPt(m);
        checkSchurForm(s);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:SchurTransformerTest.java

示例2: testRandomDataNormalDistribution

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
@Test
public void testRandomDataNormalDistribution() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        RealMatrix h = checkAEqualPHPt(m);
        checkHessenbergForm(h);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:HessenbergTransformerTest.java

示例3: testNormalDistributionUnsymmetricMatrix

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
@Test
@Ignore
public void testNormalDistributionUnsymmetricMatrix() {
    for (int run = 0; run < 100; run++) {
        Random r = new Random(System.currentTimeMillis());
        NormalDistribution dist = new NormalDistribution(0.0, r.nextDouble() * 5);

        // matrix size
        int size = r.nextInt(20) + 4;

        double[][] data = new double[size][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                data[i][j] = dist.sample();
            }
        }

        RealMatrix m = MatrixUtils.createRealMatrix(data);
        checkUnsymmetricMatrix(m);
    }
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:22,代码来源:EigenDecompositionTest.java

示例4: gaussianMixture

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
public  RegDataSet gaussianMixture(){

        NormalDistribution leftGaussian = new NormalDistribution(0.2,0.01);

        NormalDistribution rightGaussian = new NormalDistribution(0.7,0.1);

        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;
            if (featureValue>0.5){
                label = leftGaussian.sample();
            } else {
                label = rightGaussian.sample();
            }
            dataSet.setFeatureValue(i,0,featureValue);
            dataSet.setLabel(i,label);
        }
        return dataSet;
    }
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:26,代码来源:RegressionSynthesizer.java

示例5: calculateNormalDistributedValue

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
/**
 * 'Computes' a random float with the given mean and standard deviation as normal distribution.
 *
 */
private void calculateNormalDistributedValue() {
	//		https://commons.apache.org/proper/commons-math/javadocs/api-3.2/org/apache/commons/math3/distribution/NormalDistribution.html
	String userInput = this.getInputOrDefault();
	double mean = Double.parseDouble(userInput.split(";")[0]);
	double standardDeviation = Double.parseDouble(userInput.split(";")[1]);
	NormalDistribution normalDistribution = new NormalDistribution(mean, standardDeviation);
	this.value = (float) normalDistribution.sample();
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:13,代码来源:FloatAttributeInput.java

示例6: getMinMaxSupplier

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
private MinMaxSupplier getMinMaxSupplier(int min, int max, int mean, int sd) {
    final NormalDistribution distribution = new NormalDistribution(mean, sd);
    return new MinMaxSupplier(new DoubleFunction0() {
        @Override
        public double value() {
            return distribution.sample();
        }
    }, min, max);
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:10,代码来源:SchemaGenerator.java

示例7: delegateGetBucketForDouble

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
/**
 * Test to check the Bucket Distribution for the double values
 *
 * @throws IndexParseFieldException
 */
public static RunStats delegateGetBucketForDouble(int buckets) throws Exception
{
    Long startTime = System.currentTimeMillis();
    PrimaryIndexBucketGeneratorImpl ibg = new PrimaryIndexBucketGeneratorImpl(FieldDataType.DOUBLE, buckets);
    PrimaryIndexBucketLocatorImpl locator = new PrimaryIndexBucketLocatorImpl(null, null, ibg.generateBuckets(), null, null, null, null, null, null);
    logger.debug("test to getBucket for the bucket distribution on Double values");
    HashMap<Long, List<Object>> hm = new HashMap<>();
    SummaryStatistics stats = new SummaryStatistics();
    NormalDistribution dist = new NormalDistribution(0, 6);
    Random r = new Random();
    for (int i = 0; i < 20000; i++)
    {
        //double randomDouble = (-1) * Double.MIN_NORMAL + r.nextDouble() * Double.MAX_VALUE * Double.MAX_VALUE;
        double normalRandom = dist.sample();
        //randomly scale a bit more:
        double scaleRandom = Math.random();
        if (scaleRandom < .25)
        {
            normalRandom = normalRandom * 10;
        } else if (scaleRandom < .5)
        {
            normalRandom = normalRandom * 500;
        } else if (scaleRandom < .75)
        {
            normalRandom = normalRandom * 125000;
        } else
        {
            normalRandom = normalRandom * 1250000;
        }
        Long bucketId = locator.getBucket(normalRandom, FieldDataType.DOUBLE);
        calculate(hm, stats, bucketId, normalRandom);
    }
    Long runTime = System.currentTimeMillis() - startTime;
    RunStats runStats = new RunStats("BucketForDouble", FieldDataType.DOUBLE, runTime, stats, hm);
    logger.debug(runStats.toString());
    return runStats;
}
 
开发者ID:PearsonEducation,项目名称:Docussandra,代码行数:43,代码来源:BucketCSV.java

示例8: makeBlobs

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd,
                                       double min, double max, boolean shuffle, RandomGenerator random) {

    NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9);

    double range = max - min;
    Vector2D[] centerPoints = new Vector2D[centers];
    for (int i = 0; i < centers; i++) {
        double x = random.nextDouble() * range + min;
        double y = random.nextDouble() * range + min;
        centerPoints[i] = new Vector2D(x, y);
    }
    
    int[] nSamplesPerCenter = new int[centers];
    int count = samples / centers;
    Arrays.fill(nSamplesPerCenter, count);
    
    for (int i = 0; i < samples % centers; i++) {
        nSamplesPerCenter[i]++;
    }
    
    List<Vector2D> points = new ArrayList<Vector2D>();
    for (int i = 0; i < centers; i++) {
        for (int j = 0; j < nSamplesPerCenter[i]; j++) {
            Vector2D point = new Vector2D(dist.sample(), dist.sample());
            points.add(point.add(centerPoints[i]));
        }
    }
    
    if (shuffle) {
        Collections.shuffle(points, new RandomAdaptor(random));
    }

    return points;
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:36,代码来源:ClusterAlgorithmComparison.java

示例9: nextNormal

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
/**
 * Generates a random value for the normal distribution with the mean equal to {@code mu} and standard deviation
 * equal to {@code sigma}.
 *
 * @param mu    the mean of the distribution
 * @param sigma the standard deviation of the distribution
 * @return a random value for the given normal distribution
 */
public static double nextNormal(final RandomGenerator rng, final double mu, final double sigma) {
    final NormalDistribution normalDistribution =
            new NormalDistribution(rng, mu, sigma, NormalDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
    while (true) {
        final double sample = normalDistribution.sample();
        if (!Doubles.isFinite(sample)) {
            logger.warn("Discarding non finite sample from normal distribution (mu={}, sigma={}): {}",
                    mu, sigma, sample);
            continue;
        }
        return sample;
    }
}
 
开发者ID:asoem,项目名称:greyfish,代码行数:22,代码来源:RandomGenerators.java

示例10: retrieveGaussianMixtureModelForFilteredTargets

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
/** <p>Produces a Gaussian mixture model based on the difference between targets and segment means.</p>
 * <p>Filters targets to populations where more than the minProportion lie in a single segment.</p>
 * <p>Returns null if no pass filtering.  Please note that in these cases,
 * in the rest of this class, we use this to assume that a GMM is not a good model.</p>
 *
 * @param segments  -- segments with segment mean in log2 copy ratio space
 * @param targets -- targets with a log2 copy ratio estimate
 * @param minProportion -- minimum proportion of all targets that a given segment must have in order to be used
 *                      in the evaluation
 * @param numComponents -- number of components to use in the GMM.  Usually, this is 2.
 * @return  never {@code null}.  Fitting result with indications whether it converged or was even attempted.
 */
private MixtureMultivariateNormalFitResult retrieveGaussianMixtureModelForFilteredTargets(final List<ModeledSegment> segments,
                                                                                          final TargetCollection<ReadCountRecord.SingleSampleRecord> targets, double minProportion, int numComponents){

    // For each target in a segment that contains enough targets, normalize the difference against the segment mean
    //  and collapse the filtered targets into the copy ratio estimates.
    final List<Double> filteredTargetsSegDiff = getNumProbeFilteredTargetList(segments, targets, minProportion);

    if (filteredTargetsSegDiff.size() < numComponents) {
        return new MixtureMultivariateNormalFitResult(null, false, false);
    }

    // Assume that Apache Commons wants data points in the first dimension.
    // Note that second dimension of length 2 (instead of 1) is to wrok around funny Apache commons API.
    final double[][] filteredTargetsSegDiff2d = new double[filteredTargetsSegDiff.size()][2];

    // Convert the filtered targets into 2d array (even if second dimension is length 1).  The second dimension is
    //  uncorrelated Gaussian.  This is only to get around funny API in Apache Commons, which will throw an
    //  exception if the length of the second dimension is < 2
    final RandomGenerator rng = RandomGeneratorFactory.createRandomGenerator(new Random(RANDOM_SEED));
    final NormalDistribution nd = new NormalDistribution(rng, 0, .1);
    for (int i = 0; i < filteredTargetsSegDiff.size(); i++) {
        filteredTargetsSegDiff2d[i][0] = filteredTargetsSegDiff.get(i);
        filteredTargetsSegDiff2d[i][1] = nd.sample();
    }

    final MixtureMultivariateNormalDistribution estimateEM0 = MultivariateNormalMixtureExpectationMaximization.estimate(filteredTargetsSegDiff2d, numComponents);
    final MultivariateNormalMixtureExpectationMaximization multivariateNormalMixtureExpectationMaximization = new MultivariateNormalMixtureExpectationMaximization(filteredTargetsSegDiff2d);

    try {
        multivariateNormalMixtureExpectationMaximization.fit(estimateEM0);
    } catch (final MaxCountExceededException | ConvergenceException | SingularMatrixException e) {
        // We are done, we cannot make a fitting.  We should return a result that we attempted a fitting, but it
        //  did not converge.  Include the model as it was when the exception was thrown.
        return new MixtureMultivariateNormalFitResult(multivariateNormalMixtureExpectationMaximization.getFittedModel(), false, true);
    }
    return new MixtureMultivariateNormalFitResult(multivariateNormalMixtureExpectationMaximization.getFittedModel(), true, true);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:50,代码来源:CoverageDropoutDetector.java

示例11: getUnivariateGaussianTargetsWithDropout

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
private Object[][] getUnivariateGaussianTargetsWithDropout(final double sigma, final double dropoutRate) {
    Random rng = new Random(337);
    final RandomGenerator randomGenerator = RandomGeneratorFactory.createRandomGenerator(rng);
    NormalDistribution n = new NormalDistribution(randomGenerator, 1, sigma);
    final int numDataPoints = 10000;
    final int numEventPoints = 2000;

    // Randomly select dropoutRate of targets and reduce by 25%-75% (uniformly distributed)
    UniformRealDistribution uniformRealDistribution = new UniformRealDistribution(randomGenerator, 0, 1.0);
    final List<ReadCountRecord.SingleSampleRecord> targetList = new ArrayList<>();
    for (int i = 0; i < numDataPoints; i++){
        double coverage = n.sample() + (i < (numDataPoints - numEventPoints) ? 0.0 : 0.5);
        if (uniformRealDistribution.sample() < dropoutRate) {
            double multiplier = .25 + uniformRealDistribution.sample()/2;
            coverage = coverage * multiplier;
        }
        targetList.add(new ReadCountRecord.SingleSampleRecord(new Target("arbitrary_name", new SimpleInterval("chr1", 100 + 2*i, 101 + 2 * i)), coverage));
    }

    HashedListTargetCollection<ReadCountRecord.SingleSampleRecord> targets = new HashedListTargetCollection<>(targetList);

    List<ModeledSegment> segments = new ArrayList<>();
    segments.add(new ModeledSegment(new SimpleInterval("chr1", 100, 16050), 8000, 1));
    segments.add(new ModeledSegment(new SimpleInterval("chr1", 16100, 20200), 2000, 1.5));

    return new Object [] []{ {targets, segments}};
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:28,代码来源:CoverageDropoutDetectorTest.java

示例12: fillExpectedValueArrayRecursive

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
private double fillExpectedValueArrayRecursive(double[] array, int currentNode, TObjectDoubleMap<String>[] strategyP1, TObjectDoubleMap<String>[] strategyP2, boolean negateValues, ZeroBranchOption zeroBranchOption, boolean inZeroBranch, NormalDistribution distribution) {
	Node node = nodes[currentNode];
	//biggestPayoff = 0;
	//smallestPayoff = 0;
	if (node.isLeaf()) {
		if (inZeroBranch) {
			//array[currentNode] = 0;
			array[currentNode] = negateValues ? -node.getValue() + biggestPayoff: node.getValue() - smallestPayoff;
		}
		else {
			array[currentNode] = negateValues ? -node.getValue() + biggestPayoff: node.getValue() - smallestPayoff;
		}
		return array[currentNode];
	}

	
	array[currentNode] = 0;
	for(Action action : node.actions) {
		double probability = 0;
		if (node.getPlayer() == 0) {
			probability = action.getProbability();
		} else if (node.getPlayer() == 1){
			probability = strategyP1[node.getInformationSet()].get(action.getName());
		} else {
			probability = strategyP2[node.getInformationSet()].get(action.getName());
		}
		
		if (null == distribution) {
			probability = inZeroBranch ? 0 : probability;
			array[currentNode] += probability * (fillExpectedValueArrayRecursive(array, action.childId, strategyP1, strategyP2, negateValues, zeroBranchOption, probability == 0, distribution));
		} else {
			array[currentNode] += probability * fillExpectedValueArrayRecursive(array, action.childId, strategyP1, strategyP2, negateValues, zeroBranchOption, probability == 0, distribution) + distribution.sample();
		}
	}
	return array[currentNode];
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:37,代码来源:Game.java

示例13: testEquilibriumEvalutationKuhnNoise

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
@Test
public void testEquilibriumEvalutationKuhnNoise() {
	Game kuhnGame = new Game();
	kuhnGame.createGameFromFileZerosumPackageFormat(TestConfiguration.zerosumGamesFolder + "kuhn.txt");

	SequenceFormLPSolver solverP1 = new SequenceFormLPSolver(kuhnGame, 1);
	SequenceFormLPSolver solverP2 = new SequenceFormLPSolver(kuhnGame, 2);
	
	solverP1.solveGame();
	solverP2.solveGame();
	
	TObjectDoubleMap<String>[] strategyP1 = solverP1.getInformationSetActionProbabilities();
	TObjectDoubleMap<String>[] strategyP2 = solverP2.getInformationSetActionProbabilities();
	
	// get negated expected values
	double[] nodeEvaluationTable = kuhnGame.getExpectedValuesForNodes(strategyP1, strategyP2, true);
	for (double noise = 0.1; noise < 1; noise += 0.1) {
	// Add Gaussian noise to evaluations
	NormalDistribution distribution = new NormalDistribution(0, noise);
	for (int iteration = 0; iteration < 100; iteration++) {
		for (int i = 0; i < nodeEvaluationTable.length; i++) {
			nodeEvaluationTable[i] += distribution.sample();
		}

		// Compute the best strategy to commit to when the limited look-ahead player knows how much can be achieved from a node in (some) equilibrium
		LimitedLookAheadOpponentSolver solver = new LimitedLookAheadOpponentSolver(kuhnGame, 1, nodeEvaluationTable, 1);
		//solver.writeModelToFile(TestConfiguration.lpModelsFolder + "kuhnp1-limited-look-ahead.lp");
		solver.writeModelToFile(TestConfiguration.lpModelsFolder + "equilibrium-kuhn-limited-look-ahead.lp");
		solver.solveGame();
		assertTrue(solverP1.getValueOfGame() <= solver.getValueOfGame());
	}}
}
 
开发者ID:ChrKroer,项目名称:ExtensiveFormGames,代码行数:33,代码来源:TestLimitedLookAheadOpponentSolver.java

示例14: getNormalVector

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
/**
 * @return	Vector of iid normally distributed random variables
 */
public static double [] getNormalVector(int D) {
    RandomGenerator rng = new Well44497b(Prng.nextLong()); 
	double [] ret = new double[D];
	NormalDistribution N = new NormalDistribution(rng, 0, 1, 1e-6);
	for(int i=0; i<D; i++) {
		ret[i] = N.sample();
	}
	return ret;
}
 
开发者ID:mgormley,项目名称:optimize,代码行数:13,代码来源:Stats.java

示例15: generateNoiseVector

import org.apache.commons.math3.distribution.NormalDistribution; //导入方法依赖的package包/类
public static Vector2D generateNoiseVector(NormalDistribution distribution) {
    return new Vector2D(distribution.sample(), distribution.sample());
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:4,代码来源:ClusterAlgorithmComparison.java


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