本文整理了Java中org.apache.commons.math3.stat.descriptive.moment.Mean
类的一些代码示例,展示了Mean
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mean
类的具体详情如下:
包路径:org.apache.commons.math3.stat.descriptive.moment.Mean
类名称:Mean
[英]Computes the arithmetic mean of a set of values. Uses the definitional formula:
mean = sum(x_i) / n
where n
is the number of observations.
When #increment(double) is used to add data incrementally from a stream of (unstored) values, the value of the statistic that #getResult() returns is computed using the following recursive updating algorithm:
m =
the first valuem = m + (new value - m) / (number of observations)
If #evaluate(double[]) is used to compute the mean of an array of stored values, a two-pass, corrected algorithm is used, starting with the definitional formula computed using the array of stored values and then correcting this by adding the mean deviation of the data values from the arithmetic mean. See, e.g. "Comparison of Several Algorithms for Computing Sample Means and Variances," Robert F. Ling, Journal of the American Statistical Association, Vol. 69, No. 348 (Dec., 1974), pp. 859-866.
Returns Double.NaN
if the dataset is empty. Note that Double.NaN may also be returned if the input includes NaN and / or infinite values.
Note that this implementation is not synchronized. If multiple threads access an instance of this class concurrently, and at least one of the threads invokes the increment()
or clear()
method, it must be synchronized externally.
[中]计算一组值的算术平均值。使用定义公式:
平均值=总和(x_i)/n
其中n
是观察次数。
当使用#increment(double)从(未存储的)值流中增量添加数据时,#getResult()返回的统计值使用以下递归更新算法计算:
1.初始化m =
第一个值
1.对于每个附加值,使用m = m + (new value - m) / (number of observations)
如果使用#evaluate(double[])来计算存储值数组的平均值,则使用两次通过的校正算法,从使用存储值数组计算的定义公式开始,然后通过将数据值与算术平均值的平均偏差相加来校正。例如,见《计算样本均值和方差的几种算法的比较》,罗伯特·F·林,《美国统计协会杂志》,第69卷,第348号(1974年12月),第859-866页。
如果数据集为空,则返回Double.NaN
。请注意这一点。如果输入包含NaN和/或无限值,也可能返回NaN。
请注意,此实现是不同步的。如果多个线程同时访问该类的一个实例,并且至少有一个线程调用increment()
或clear()
方法,则必须在外部对其进行同步。
代码示例来源:origin: org.apache.commons/commons-math3
/**
* This method calculates {@link SemiVariance} for the entire array against the mean, using
* the current value of the biasCorrection instance property.
*
* @param values the input array
* @param direction the {@link Direction} of the semivariance
* @return the SemiVariance
* @throws MathIllegalArgumentException if values is null
*
*/
public double evaluate(final double[] values, Direction direction)
throws MathIllegalArgumentException {
double m = (new Mean()).evaluate(values);
return evaluate (values, m, direction, biasCorrected, 0, values.length);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Get the mean vector.
* @return mean vector
*/
public double[] getResult() {
double[] result = new double[means.length];
for (int i = 0; i < result.length; ++i) {
result[i] = means[i].getResult();
}
return result;
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Add a new vector to the sample.
* @param v vector to add
* @throws DimensionMismatchException if the vector does not have the right dimension
*/
public void increment(double[] v) throws DimensionMismatchException {
if (v.length != means.length) {
throw new DimensionMismatchException(v.length, means.length);
}
for (int i = 0; i < v.length; ++i) {
means[i].increment(v[i]);
}
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* {@inheritDoc}
*/
@Override
public Mean copy() {
Mean result = new Mean();
// No try-catch or advertised exception because args are guaranteed non-null
copy(this, result);
return result;
}
代码示例来源:origin: OryxProject/oryx
@Test
public void testRecommendLoad() throws Exception {
AtomicLong count = new AtomicLong();
Mean meanReqTimeNanos = new Mean();
long start = System.nanoTime();
int workers = LoadTestALSModelFactory.WORKERS;
ExecUtils.doInParallel(workers, workers, true, i -> {
RandomGenerator random = RandomManager.getRandom(Integer.toString(i).hashCode() ^ System.nanoTime());
for (int j = 0; j < LoadTestALSModelFactory.REQS_PER_WORKER; j++) {
String userID = "U" + random.nextInt(LoadTestALSModelFactory.USERS);
long callStart = System.nanoTime();
target("/recommend/" + userID).request()
.accept(MediaType.APPLICATION_JSON_TYPE).get(LIST_ID_VALUE_TYPE);
long timeNanos = System.nanoTime() - callStart;
if (j > 0) {
// Ignore first iteration's time as 'burn in'
synchronized (meanReqTimeNanos) {
meanReqTimeNanos.increment(timeNanos);
}
}
long currentCount = count.incrementAndGet();
if (currentCount % 100 == 0) {
log(currentCount, meanReqTimeNanos, start);
}
}
});
int totalRequests = workers * LoadTestALSModelFactory.REQS_PER_WORKER;
log(totalRequests, meanReqTimeNanos, start);
}
代码示例来源:origin: ICOnator/ICOnator-backend
private BigDecimal getMean(List<Double> data) {
Mean mean = new Mean();
data.stream().forEach((value) -> mean.increment(value));
return BigDecimal.valueOf(mean.getResult());
}
代码示例来源:origin: OryxProject/oryx
Mean meanMatchLength = new Mean();
for (int user = 0; user < userItemCount; user++) {
String userID = "U" + user;
i++;
meanMatchLength.increment(i);
log.info("Mean matching prefix: {}", meanMatchLength.getResult());
assertGreaterOrEqual(meanMatchLength.getResult(), 4.0);
meanMatchLength.clear();
for (int item = 0; item < userItemCount; item++) {
String itemID = "I" + item;
i++;
meanMatchLength.increment(i);
log.info("Mean matching prefix: {}", meanMatchLength.getResult());
assertGreaterOrEqual(meanMatchLength.getResult(), 5.0);
代码示例来源:origin: org.apache.commons/commons-math3
/** Constructs a VectorialMean.
* @param dimension vectors dimension
*/
public VectorialMean(int dimension) {
means = new Mean[dimension];
for (int i = 0; i < dimension; ++i) {
means[i] = new Mean();
}
}
代码示例来源:origin: myrrix/myrrix-recommender
final Multimap<Long,RecommendedItem> testData) throws TasteException {
final Mean precision = new Mean();
final Mean recall = new Mean();
final Mean ndcg = new Mean();
final Mean meanAveragePrecision = new Mean();
if (precision.getN() > 0) {
result = new IRStatisticsImpl(precision.getResult(),
recall.getResult(),
ndcg.getResult(),
meanAveragePrecision.getResult());
} else {
result = null;
代码示例来源:origin: us.ihmc/valkyrie
sideDependentFingerPositionMeans.get(robotSide).get(jointEnum).clear();
continue;
fingerPositionMeans.get(jointEnum).increment(fingerJoints.get(jointEnum).getQ());
double offset = motorBasedFingerJointPositions.get(jointName).getValue() - mean.getResult();
biases.get(jointName).sub(offset);
mean.clear();
代码示例来源:origin: meyerjp3/psychometrics
public String toString(String title){
StringBuilder sb = new StringBuilder();
Formatter f = new Formatter(sb);
f.format("%-50s", title);f.format("%n");
f.format("%30s", "==============================");f.format("%n");
f.format("%-10s", "Statistic");f.format("%5s", "");
f.format("%10s", "Value");f.format("%5s", "");f.format("%n");
f.format("%30s", "------------------------------");f.format("%n");
f.format("%-10s", "N");f.format("%5s", "");
f.format("%10.4f", (double)m.getN());f.format("%5s", "");f.format("%n");
f.format("%-10s", "Min");f.format("%5s", "");
f.format("%10.4f", min.getResult());f.format("%5s", "");f.format("%n");
f.format("%-10s", "Max");f.format("%5s", "");
f.format("%10.4f", max.getResult());f.format("%5s", "");f.format("%n");
f.format("%-10s", "Mean");f.format("%5s", "");
f.format("%10.4f", m.getResult());f.format("%5s", "");f.format("%n");
f.format("%-10s", "St. Dev.");f.format("%5s", "");
f.format("%10.4f", sd.getResult());f.format("%5s", "");f.format("%n");
f.format("%-10s", "Skewness");f.format("%5s", "");
f.format("%10.4f", skew.getResult());f.format("%5s", "");f.format("%n");
f.format("%-10s", "Kurtosis");f.format("%5s", "");
f.format("%10.4f", kurt.getResult());f.format("%5s", "");f.format("%n");
f.format("%30s", "==============================");f.format("%n");
return f.toString();
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Returns the weighted arithmetic mean of the entries in the input array.
* <p>
* Throws <code>MathIllegalArgumentException</code> if either array is null.</p>
* <p>
* See {@link Mean} for details on the computing algorithm. The two-pass algorithm
* described above is used here, with weights applied in computing both the original
* estimate and the correction factor.</p>
* <p>
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
* <ul><li>the values array is null</li>
* <li>the weights array is null</li>
* <li>the weights array does not have the same length as the values array</li>
* <li>the weights array contains one or more infinite values</li>
* <li>the weights array contains one or more NaN values</li>
* <li>the weights array contains negative values</li>
* </ul></p>
*
* @param values the input array
* @param weights the weights array
* @return the mean of the values or Double.NaN if length = 0
* @throws MathIllegalArgumentException if the parameters are not valid
* @since 2.1
*/
public double evaluate(final double[] values, final double[] weights)
throws MathIllegalArgumentException {
return evaluate(values, weights, 0, values.length);
}
代码示例来源:origin: org.apache.commons/commons-math3
/**
* Get the number of vectors in the sample.
* @return number of vectors in the sample
*/
public long getN() {
return (means.length == 0) ? 0 : means[0].getN();
}
代码示例来源:origin: apache/accumulo
public void clear() {
min = Long.MAX_VALUE;
max = Long.MIN_VALUE;
sum = 0;
mean.clear();
}
代码示例来源:origin: jpmml/jpmml-evaluator
static
private Double evaluate(Collection<?> values){
Mean statistic = new Mean();
for(Object value : values){
Number number = (Number)TypeUtil.parseOrCast(DataType.DOUBLE, value);
statistic.increment(number.doubleValue());
}
return statistic.getResult();
}
}
代码示例来源:origin: meyerjp3/psychometrics
Mean personGrandMean = new Mean();
StandardDeviation personGrandSd = new StandardDeviation();
double iProx = 0.0;
mPerson[j] = new Mean();
sdPerson[j] = new StandardDeviation();
mItem[l] = new Mean();
sdItem[l] = new StandardDeviation();
mItem[l].increment(irm[j].getDifficulty());
sdItem[l].increment(irm[j].getDifficulty());
mPerson[j].increment(theta[l]);
sdPerson[j].increment(theta[l]);
Si[j] += resp;
iProx = mPerson[j].getResult()-Math.sqrt(1.0+pSd/2.9)*logit;
irm[j].setDifficulty(iProx);
iMean += iProx;
personGrandMean.clear();
personGrandSd.clear();
Pair<Double, Double> personScores = null;
pProx = mItem[l].getResult() + Math.sqrt(1.0+sdItem[l].getResult()/2.9)*logit;
maxChange = Math.max(maxChange, Math.abs(theta[l]-pProx));
theta[l] = pProx;
代码示例来源:origin: OryxProject/oryx
protected Endpoint(String path, double relativeProb) {
Preconditions.checkArgument(relativeProb > 0.0);
this.path = path;
this.relativeProb = relativeProb;
meanTimeNanos = new Mean();
stdevTimeNanos = new StandardDeviation();
}
代码示例来源:origin: org.apache.commons/commons-math3
dest.meanImpl = new Mean(dest.secondMoment);
} else {
dest.meanImpl = source.meanImpl.copy();
dest.mean = (Mean) dest.meanImpl;
} else {
Mean.copy(source.mean, dest.mean);
代码示例来源:origin: geogebra/geogebra
/**
* Returns the weighted arithmetic mean of the entries in the input array.
* <p>
* Throws <code>MathIllegalArgumentException</code> if either array is null.</p>
* <p>
* See {@link Mean} for details on the computing algorithm. The two-pass algorithm
* described above is used here, with weights applied in computing both the original
* estimate and the correction factor.</p>
* <p>
* Throws <code>MathIllegalArgumentException</code> if any of the following are true:
* <ul><li>the values array is null</li>
* <li>the weights array is null</li>
* <li>the weights array does not have the same length as the values array</li>
* <li>the weights array contains one or more infinite values</li>
* <li>the weights array contains one or more NaN values</li>
* <li>the weights array contains negative values</li>
* </ul></p>
*
* @param values the input array
* @param weights the weights array
* @return the mean of the values or Double.NaN if length = 0
* @throws MathIllegalArgumentException if the parameters are not valid
* @since 2.1
*/
public double evaluate(final double[] values, final double[] weights)
throws MathIllegalArgumentException {
return evaluate(values, weights, 0, values.length);
}
代码示例来源:origin: apache/accumulo
@Override
public long num() {
return mean.getN();
}
内容来源于网络,如有侵权,请联系作者删除!