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


Java MultivariateNormalDistribution.sample方法代码示例

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


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

示例1: GenerateInitCentroids

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
private void GenerateInitCentroids() {
    centroids = loadCentroids();
    Random random = new Random(12397238947287L);
    List<Point> initCentroids = new ArrayList<>();
    RandomGenerator point_random = new JDKRandomGenerator();

    for (Point centroid : centroids) {
        MultivariateNormalDistribution distribution = new MultivariateNormalDistribution(point_random, means, covariances);

        double[] point = distribution.sample();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < dimension - 1; i++) {
            point[i] += centroid.location[i];
            sb.append(point[i]).append(", ");
        }
        point[dimension - 1] += centroid.location[dimension - 1];
        sb.append(point[dimension - 1]);

        System.out.println(sb.toString());
    }
}
 
开发者ID:wangyangjun,项目名称:StreamBench,代码行数:22,代码来源:KMeansPoints.java

示例2: consume

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
@Override
public void consume(List<Datum> records) throws Exception {
    if (!hasConsumed) {
        n = records.get(0).metrics().getDimension();
        mean = new ArrayRealVector(n);
        covV = new ArrayRealVector(n, 1d/n);
        covM = new DiagonalMatrix(covV.toArray());
        mnd = new MultivariateNormalDistribution(mean.toArray(), covM.getData());
        mnd.reseedRandomGenerator(randomSeed);
        randomProjectionMatrix = new BlockRealMatrix(mnd.sample(k));
        hasConsumed = true;
    }
    for (Datum d: records){
        metricVector = d.metrics();
        transformedVector = randomProjectionMatrix.operate(metricVector);
        output.add(new Datum(d,transformedVector));
    }
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:19,代码来源:RandomProjection.java

示例3: testGaussian

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
private double testGaussian(double scale) {
    double[] means = new double[]{0,0};
    double[][] covariances = new double[][]{
        {scale, 0}, {0, scale}
    };
    MultivariateNormalDistribution uniform = new MultivariateNormalDistribution(means, covariances);
    DescriptiveStatistics stats = new DescriptiveStatistics(NORMAL_SAMPLES);
    for (int i=0; i<NORMAL_SAMPLES; i++) {
        double[] xy = uniform.sample();
        final double x = xy[0];
        final double y = xy[1];
        stats.addValue(Math.sqrt(x*x + y*y));
    }

    return stats.getPercentile(90);
}
 
开发者ID:MASPlanes,项目名称:MASPlanes,代码行数:17,代码来源:InverseWishartDistributionTest.java

示例4: GaussianRandomFeatures

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
public GaussianRandomFeatures(int D, int n, double gammak, boolean sine) {
	_D = D;
	_n = n;
	_gammak = gammak;
	_sine = sine;
	
	// Initialize mnd
	// The value for the variances are taken from: http://www.eecs.berkeley.edu/~brecht/papers/07.rah.rec.nips.pdf
	_cov = new double[_n][_n];
	_mu = new double[_n];
	for(int i = 0; i < _n; i++) {
		_mu[i] = 0;
		for(int j = 0; j < _n; j++)
			_cov[i][j] = (i == j) ? 2*_gammak : 0;
	}
	_mnd = new MultivariateNormalDistribution(_mu, _cov);
	_ws = new double[_D][];
	for (int i = 0; i < _D; i ++)
		_ws[i] = _mnd.sample();
	
	// Initialize urd
	_lb = 0;
	_ub = 2*Math.PI;
	_urd = new UniformRealDistribution (_lb, _ub);
	_bs = new double[_D];
	for (int i = 0; i < _D; i ++)
		_bs[i] = _urd.sample();
}
 
开发者ID:dpinney,项目名称:essence,代码行数:29,代码来源:GaussianRandomFeatures.java

示例5: generate

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
public void generate(int sleep_frequency) throws InterruptedException {
//        GenerateCentroids();
        centroids = loadCentroids();
        long time = System.currentTimeMillis();
        ThroughputLog throughput = new ThroughputLog(this.getClass().getSimpleName());
        Random centroid_random = new Random(2342342170123L);
        RandomGenerator point_random = new JDKRandomGenerator();
        point_random.setSeed(8624214);

        for (long generated_points = 0; generated_points < POINT_NUM; generated_points++) {

            int centroid_index = centroid_random.nextInt(centroids.size());
            MultivariateNormalDistribution distribution = new MultivariateNormalDistribution(point_random, means, covariances);

            double[] point = distribution.sample();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dimension - 1; i++) {
                point[i] += centroids.get(centroid_index).location[i];
                sb.append(point[i]).append("\t");
            }
            point[dimension - 1] += centroids.get(centroid_index).location[dimension - 1];
            sb.append(point[dimension - 1]).append(Constant.TimeSeparator).append(System.currentTimeMillis());

            throughput.execute();
            ProducerRecord<String, String> newRecord = new ProducerRecord<>(TOPIC, sb.toString());
            producer.send(newRecord);
//            System.out.println(sb.toString());
            // control data generate speed
            if (sleep_frequency > 0 && generated_points % sleep_frequency == 0) {
                Thread.sleep(1);
            }
        }

        producer.close();
        logger.info("LatencyLog: " + String.valueOf(System.currentTimeMillis() - time));
    }
 
开发者ID:wangyangjun,项目名称:StreamBench,代码行数:37,代码来源:KMeansPoints.java

示例6: testMahalanobis

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
@Test
public void testMahalanobis() {
    MultivariateNormalDistribution mvNormal = getSample3dNormal();
    Gaussian gaussian = new Gaussian(mvNormal.getMeans(), mvNormal.getCovariances());

    int N = 100000;
    int k = 3;
    double[][] testData = new double[N][k];
    for (int i = 0; i < N; i++) {
        testData[i] = mvNormal.sample();
    }

    double[] mScores = new double[N];
    long startTime = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
        mScores[i] = gaussian.mahalanobis(testData[i]);
    }
    long endTime = System.currentTimeMillis();
    log.debug("Mahalobis distance on {} in {}", N, endTime-startTime);

    double[] dScores = new double[N];
    startTime = System.currentTimeMillis();
    for (int i = 0; i < N; i++) {
        dScores[i] = -Math.log(mvNormal.density(testData[i]));
    }
    endTime = System.currentTimeMillis();
    log.debug("LogPDF on {} in {}", N, endTime-startTime);

    // Check that mahalonbis distance has same relative magnitude as -log(pdf)
    for (int i = 1; i < N; i++) {
        assertEquals(mScores[i] > mScores[i-1], dScores[i] > dScores[i-1]);
    }
}
 
开发者ID:stanford-futuredata,项目名称:macrobase,代码行数:34,代码来源:GaussianTest.java

示例7: gaussianNoise

import org.apache.commons.math3.distribution.MultivariateNormalDistribution; //导入方法依赖的package包/类
/**
 * 2 labels, 3 features, multi-variate gaussian noise
 * y0: w=(0,1,0)
 * y1: w=(1,0,0)
 * y2: w=(0,0,1)
 * @return
 */
public static MultiLabelClfDataSet gaussianNoise(int numData){
    int numClass = 3;
    int numFeature = 3;

    MultiLabelClfDataSet dataSet = MLClfDataSetBuilder.getBuilder().numFeatures(numFeature)
            .numClasses(numClass)
            .numDataPoints(numData)
            .build();

    // generate weights
    Vector[] weights = new Vector[numClass];
    for (int k=0;k<numClass;k++){
        Vector vector = new DenseVector(numFeature);
        weights[k] = vector;
    }


    weights[0].set(1,1);

    weights[1].set(0, 1);


    weights[2].set(2, 1);



    // generate features
    for (int i=0;i<numData;i++){
        for (int j=0;j<numFeature;j++){
            dataSet.setFeatureValue(i,j,Sampling.doubleUniform(-1, 1));
        }
    }

    double[] means = new double[numClass];
    double[][] covars = new double[numClass][numClass];
    covars[0][0]=0.5;
    covars[0][1]=0.02;         covars[1][0]=0.02;
    covars[0][2]=-0.03;         covars[2][0]=-0.03;

    covars[1][1]=0.2;
    covars[1][2]=-0.03;         covars[2][1]=-0.03;



    covars[2][2]=0.3;

    MultivariateNormalDistribution distribution = new MultivariateNormalDistribution(means,covars);

    // assign labels
    int numFlipped = 0;
    for (int i=0;i<numData;i++){
        double[] noises = distribution.sample();
        for (int k=0;k<numClass;k++){
            double dot = weights[k].dot(dataSet.getRow(i));
            double score = dot + noises[k];
            if (score>=0){
                dataSet.addLabel(i,k);
            }
            if (dot*score<0){
                numFlipped += 1;
            }
        }
    }

    System.out.println("number of flipped bits = "+numFlipped);
    return dataSet;
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:75,代码来源:MultiLabelSynthesizer.java


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