/** * 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); }
/** * 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; }
/** * 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]); } }
@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); }
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);
/** 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(); } }
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;
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();
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(); }
/** * 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); }
/** * 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(); }
public void clear() { min = Long.MAX_VALUE; max = Long.MIN_VALUE; sum = 0; mean.clear(); }
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;
protected Endpoint(String path, double relativeProb) { Preconditions.checkArgument(relativeProb > 0.0); this.path = path; this.relativeProb = relativeProb; meanTimeNanos = new Mean(); stdevTimeNanos = new StandardDeviation(); }
/** * 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); }
@Override public long num() { return mean.getN(); }