cern.jet.random.Normal类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中cern.jet.random.Normal类的一些代码示例,展示了Normal类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Normal类的具体详情如下:
包路径:cern.jet.random.Normal
类名称:Normal

Normal介绍

[英]Normal (aka Gaussian) distribution; See the math definition and [animated definition](http://www.statsoft.com/textbook/glosn.html#Normal Distribution).

1                       2 
pdf(x) = ---------    exp( - (x-mean) / 2v )  
sqrt(2pi*v) 
x 
- 
1        | |                 2 
cdf(x) = ---------    |    exp( - (t-mean) / 2v ) dt 
sqrt(2pi*v)| | 
- 
-inf.

where v = variance = standardDeviation^2.

Instance methods operate on a user supplied uniform random number generator; they are unsynchronized. Static methods operate on a default uniform random number generator; they are synchronized.

Implementation: Polar Box-Muller transformation. See G.E.P. Box, M.E. Muller (1958): A note on the generation of random normal deviates, Annals Math. Statist. 29, 610-611.
[中]正态(又名高斯)分布;请参见{$0$}和{$1$}

1                       2 
pdf(x) = ---------    exp( - (x-mean) / 2v )  
sqrt(2pi*v) 
x 
- 
1        | |                 2 
cdf(x) = ---------    |    exp( - (t-mean) / 2v ) dt 
sqrt(2pi*v)| | 
- 
-inf.

其中v=方差=标准偏差^2。
实例方法在用户提供的统一随机数生成器上运行;它们是不同步的。静态方法在默认的统一随机数生成器上运行;它们是同步的。
实现:极盒穆勒变换。参见G.E.P.Box,M.E.Muller(1958):关于随机正态偏差产生的注释,数学年鉴。统计学家。29, 610-611.

代码示例

代码示例来源:origin: addthis/stream-lib

RandomEngine r = new MersenneTwister64(0);
Normal[] dists = new Normal[]{
    new Normal(100, 50, r),
    new Normal(150, 20, r),
    new Normal(500, 300, r),
    new Normal(10000, 10000, r),
    new Normal(1200, 300, r),
};
for (int numSamples : new int[]{1, 10, 100, 1000, 10000}) {
    samples[i] = new long[numSamples];
    for (int j = 0; j < samples[i].length; ++j) {
      samples[i][j] = (long) Math.max(0, dists[i].nextDouble());

代码示例来源:origin: org.jwall/streams-core

/**
 * @param variance
 *            the variance to set
 */
public void setVariance(Double variance) {
  this.variance = variance;
  this.rnd.setState(mean, variance);
}

代码示例来源:origin: org.jwall/streams-core

/**
 * @see stream.generator.DistributionFunction#p(java.lang.Double)
 */
@Override
public Double p(Double x) {
  return this.rnd.pdf(x);
}

代码示例来源:origin: blazegraph/database

/**
 * Constructs a normal (gauss) distribution.
 * Example: mean=0.0, standardDeviation=1.0.
 */
public Normal(double mean, double standardDeviation, RandomEngine randomGenerator) {
  setRandomGenerator(randomGenerator);
  setState(mean,standardDeviation);
}
/**

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) {
  Normal normal = new Normal();
  normal.name = null;
  String name = normal.name;
  System.out.println( "My name is : " + name );
}

代码示例来源:origin: broadgsa/gatk

@Test
public void testNormalDistribution() {
  final double requiredPrecision = 1E-10;
  final Normal n = new Normal(0.0, 1.0, null);
  for( final double mu : new double[]{-5.0, -3.2, -1.5, 0.0, 1.2, 3.0, 5.8977} ) {
    for( final double sigma : new double[]{1.2, 3.0, 5.8977} ) {
      for( final double x : new double[]{-5.0, -3.2, -1.5, 0.0, 1.2, 3.0, 5.8977} ) {
        n.setState(mu, sigma);
        Assert.assertEquals(n.pdf(x), MathUtils.normalDistribution(mu, sigma, x), requiredPrecision);
        Assert.assertEquals(Math.log10(n.pdf(x)), MathUtils.normalDistributionLog10(mu, sigma, x), requiredPrecision);
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

RandomEngine engine = new DRand();
Poisson poisson = new Poisson(lambda, engine);
int poissonObs = poisson.nextInt();

Normal normal = new Normal(mean, variance, engine);
double normalObs = normal.nextDouble();

代码示例来源:origin: uk.ac.ebi.pride.spectracluster/spectra-cluster

public double assessSimilarityAsPValue(IPeakMatches peakMatches) {
  // if there are no shared peaks, return 1 to indicate that it's random
  if (peakMatches.getNumberOfSharedPeaks() < 1)
    return 1;
  // only use the intensities
  double[] intensitiesSpec1 = extractPeakIntensities(peakMatches.getSharedPeaksFromSpectrumOne());
  double[] intensitiesSpec2 = extractPeakIntensities(peakMatches.getSharedPeaksFromSpectrumTwo());
  double correlation = kendallsCorrelation.correlation(intensitiesSpec1, intensitiesSpec2);
  // if the correlation cannot be calculated, assume that there is none
  if (Double.isNaN(correlation)) {
    return 1;
  }
  // convert correlation into probability using the distribution used in Peptidome
  // Normal Distribution with mean = 0 and SD^2 = 2(2k + 5)/9k(k − 1)
  double k = (double) peakMatches.getNumberOfSharedPeaks();
  // this cannot be calculated for only 1 shared peak
  if (k == 1)
    return 1;
  double sdSquare = (2 * (2 * k + 5)) / (9 * k * (k - 1) );
  double sd = Math.sqrt(sdSquare);
  Normal normal = new Normal(0, sd, randomEngine);
  double probability = normal.cdf(correlation);
  return 1 - probability;
}

代码示例来源:origin: cmu-phil/tetrad

double cdfResult = n.cdf(mid);

代码示例来源:origin: stackoverflow.com

public static void main(String args[]) {
  Normal normal = new Normal();
  normal.name = "suhail gupta";
  System.out.println( "My name is : " + normal.name );    
}

代码示例来源:origin: blazegraph/database

/**
 * Returns a random number from the distribution.
 */
public double nextDouble() {
  return nextDouble(this.mean,this.standardDeviation);
}
/**

代码示例来源:origin: com.blazegraph/colt

/**
 * Constructs a normal (gauss) distribution.
 * Example: mean=0.0, standardDeviation=1.0.
 */
public Normal(double mean, double standardDeviation, RandomEngine randomGenerator) {
  setRandomGenerator(randomGenerator);
  setState(mean,standardDeviation);
}
/**

代码示例来源:origin: cmu-phil/tetrad

double idealValue = idealDistribution.cdf(x);

代码示例来源:origin: openimaj/openimaj

Function(int ndims, MersenneTwister rng) {
  super(rng);
  final Normal normal = new Normal(0, 1, rng);
  r = new double[ndims];
  double sumSq = 0;
  
  for (int i=0; i<ndims; i++) {
    r[i] = normal.nextDouble();
    sumSq += (r[i] * r[i]);
  }
  
  double norm = 1.0 / Math.sqrt(sumSq);
  for (int i=0; i<ndims; i++) {
    r[i] *= norm;
  }
}

代码示例来源:origin: stackoverflow.com

var obj = {
 note: "I'm the one object Singleton always returns"
};
function Singleton() {
 this.note = "This object is thrown away, so you never see this object";
 return obj;
}
function Normal() {
 this.note = "This object isn't thrown away";
}

var o1 = Singleton();
console.log("o1", o1);
var o2 = new Singleton();
console.log("o1 === o2? ",  o1 === o2);  // true
console.log("o1 === obj?", o1 === obj); // true
var n1 = new Normal();
console.log("n1", n1);
var n2 = new Normal();
console.log("n1 === n2?", n1 === n2);   // false

代码示例来源:origin: blazegraph/database

/**
 * Returns a random number from the distribution with the given mean and standard deviation.
 */
public static double staticNextDouble(double mean, double standardDeviation) {
  synchronized (shared) {
    return shared.nextDouble(mean,standardDeviation);
  }
}
/**

代码示例来源:origin: de.sfb876/streams-core

/**
 * @param mean
 *            the mean to set
 */
public void setMean(Double mean) {
  this.mean = mean;
  this.rnd.setState(mean, variance);
}

代码示例来源:origin: de.sfb876/streams-core

/**
 * @see stream.generator.DistributionFunction#p(java.lang.Double)
 */
@Override
public Double p(Double x) {
  return this.rnd.pdf(x);
}

代码示例来源:origin: cmu-phil/tetrad

/**
 * Calculates the Cramer-von-Mises statistic for a variable
 *
 * @param dataSet relevant data set
 * @param variable continuous variable whose normality is in question
 *
 * @return Cramer-von-Mises statistic
 */
public static double cramerVonMises(DataSet dataSet, ContinuousVariable variable)
{
  int n = dataSet.getNumRows();
  int columnIndex = dataSet.getColumn(variable);
  Normal idealDistribution = getNormal(dataSet, variable);
  double cvmStatistic = 0.0;
  for (int i = 1; i <= n; i++)
  {
    double summedTerm = (((2 * i) - 1) / (2 * n)) - idealDistribution.cdf(dataSet.getDouble(i - 1, columnIndex));
    summedTerm *= summedTerm;
    cvmStatistic += summedTerm;
  }
  cvmStatistic += 1 / (12 * n);
  cvmStatistic /= n;
  return cvmStatistic;
}

代码示例来源:origin: openimaj/openimaj

Function(int ndims, MersenneTwister rng) {
  super(rng);
  final Normal normal = new Normal(0, 1, rng);
  r = new double[ndims];
  double sumSq = 0;
  
  for (int i=0; i<ndims; i++) {
    r[i] = normal.nextDouble();
    sumSq += (r[i] * r[i]);
  }
  
  double norm = 1.0 / Math.sqrt(sumSq);
  for (int i=0; i<ndims; i++) {
    r[i] *= norm;
  }
}

相关文章

微信公众号

最新文章

更多