Calculate the mean measurements for the given parameter value.

@param numEntriesPerPreview
@param numParamValues
@param paramValue
@return List of mean measurement arrays
333246
private List<double[]> calculateMeanMeasurementsForParam(
            int numEntriesPerPreview,
            int numParamValues,
            int paramValue) 
    {
        List<double[]> paramMeasurementsSum  = 
                new ArrayList<double[]>(numEntriesPerPreview);
        List<double[]> meanParamMeasurements = 
                new ArrayList<double[]>(numEntriesPerPreview);
        
        int numCompleteFolds = 0;
        
        // sum up measurement values
        for (PreviewCollection<Preview> foldPreview : 
             this.origMultiRunPreviews.subPreviews) 
        {
            // check if there is a preview for each parameter value
            if (foldPreview.getPreviews().size() == numParamValues) {
                numCompleteFolds++;
                
                Preview foldParamPreview = 
                        foldPreview.getPreviews().get(paramValue);
                
                // add this Preview's measurements to the overall sum
                this.addPreviewMeasurementsToSum(
                        paramMeasurementsSum, 
                        foldParamPreview, 
                        numEntriesPerPreview);
            }
        }
        
        // divide sum by number of folds
        for (int entryIdx = 0; entryIdx < numEntriesPerPreview; entryIdx++) {
            double[] sumEntry  = paramMeasurementsSum.get(entryIdx);
            double[] meanEntry = new double[sumEntry.length];
            
            // first measurement is used for indexing -> simply copy
            meanEntry[0] = sumEntry[0];
            
            // calculate mean for remaining measurements
            for (int m = 1; m < sumEntry.length; m++) {
                meanEntry[m] = sumEntry[m] / numCompleteFolds;
            }
            
            meanParamMeasurements.add(meanEntry);
        }
        
        return meanParamMeasurements;
    }
25485
@Override
	public Map<String, Object> getValues(double evaluationTime, MonteCarloSimulationModel model) throws CalculationException
	{
		RandomVariable values = getValue(evaluationTime, model);

		if(values == null) {
			return null;
		}

		// Sum up values on path
		double value = values.getAverage();
		double error = values.getStandardError();

		Map<String, Object> results = new HashMap<>();
		results.put("value", value);
		results.put("error", error);

		return results;
	}
717184
public static double moment(FlatDataCollection flatDataCollection, int r, double mean) {
        int n = 0;
        double moment=0.0;
        
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            Double v = it.next();
            if(v != null) {
                ++n;
                moment+=Math.pow(v-mean, r);
            }
        }

        if(n<=1) {
            throw new IllegalArgumentException("The provided collection must have more than 1 elements.");
        }
        
        moment/=n;
        
        return moment;
    }
970368
public void generateValues(double newMean) {
        double meanWithOffset = newMean + offset;
        for (int i = 0; i < data.length; i++) {
            data[i] = meanWithOffset * proportional_dev[i] - offset;
        }
        mean = newMean;
    }
1304564
public static double[] eval(int[] context, double[] prior, EvalParameters model)
    {
        Context[] params = model.getParams();
        int numfeats[] = new int[model.getNumOutcomes()];
        int[] activeOutcomes;
        double[] activeParameters;
        double value = 1;
        for (int ci = 0; ci < context.length; ci++)
        {
            if (context[ci] >= 0)
            {
                Context predParams = params[context[ci]];
                activeOutcomes = predParams.getOutcomes();
                activeParameters = predParams.getParameters();
                for (int ai = 0; ai < activeOutcomes.length; ai++)
                {
                    int oid = activeOutcomes[ai];
                    numfeats[oid]++;
                    prior[oid] += activeParameters[ai] * value;
                }
            }
        }

        double normal = 0.0;
        for (int oid = 0; oid < model.getNumOutcomes(); oid++)
        {
            if (model.getCorrectionParam() != 0)
            {
                prior[oid] = Math
                        .exp(prior[oid]
                                     * model.getConstantInverse()
                                     + ((1.0 - ((double) numfeats[oid] / model
                                .getCorrectionConstant())) * model.getCorrectionParam()));
            }
            else
            {
                prior[oid] = Math.exp(prior[oid] * model.getConstantInverse());
            }
            normal += prior[oid];
        }

        for (int oid = 0; oid < model.getNumOutcomes(); oid++)
        {
            prior[oid] /= normal;
        }
        return prior;
    }
626881
private Stream<Numeric> runComputeMean(GraqlCompute.Statistics.Value query) {
        Map<String, Double> meanPair = runComputeStatistics(query);
        if (meanPair == null) return Stream.empty();

        Double mean = meanPair.get(MeanMapReduce.SUM) / meanPair.get(MeanMapReduce.COUNT);
        return Stream.of(new Numeric(mean));
    }
1060230
@Override
    protected Measurement[] getModelMeasurementsImpl() {
        Measurement[] measurements = new Measurement[this.maxStoredCount];

        for (int m = 0; m < this.maxMemberCount; m++) {
            measurements[m] = new Measurement("Member weight " + (m + 1), -1);
        }

        for (int s = this.maxMemberCount; s < this.maxStoredCount; s++) {
            measurements[s] = new Measurement("Stored member weight " + (s + 1), -1);
        }

        if (this.storedWeights != null) {
            int storeSize = this.storedWeights.length;

            for (int i = 0; i < storeSize; i++) {
                if (i < this.ensemble.length) {
                    measurements[i] = new Measurement("Member weight " + (i + 1), this.storedWeights[storeSize - i - 1][0]);
                } else {
                    measurements[i] = new Measurement("Stored member weight " + (i + 1), this.storedWeights[storeSize - i - 1][0]);
                }
            }
        }
        return measurements;
    }
76466
public static double standardDeviation(double[] x, double mean) {
        if (x.length == 0) {
            return Double.NaN;
        }
        if (x.length == 1) {
            return 0.0;
        }
        return Math.sqrt(variance(x, mean));
    }
1213610
public static double mean(TransposeDataCollection sampleDataCollection) {
        double mean = 0.0;
        
        int totalSampleN = 0;
        for(Map.Entry<Object, FlatDataCollection> entry : sampleDataCollection.entrySet()) {
            mean += Descriptives.sum(entry.getValue());
            
            totalSampleN += entry.getValue().size();
        }
        
        mean/=totalSampleN;
        
        return mean;
    }
328592
public void calc(int numLabels){
		//计算最大阶
		int numTemplets = size();
		this.orders = new int[numTemplets];
		for(int j=0; j<numTemplets; j++) {
			Templet t = get(j);
			this.orders[j] = t.getOrder();
			if (orders[j] > maxOrder)
				maxOrder = orders[j];
		}
		
		base = new int[maxOrder+2];
		base[0]=1;
		for(int i=1; i<base.length; i++) {
			base[i]=base[i-1]*numLabels;
		}
		this.numStates = base[maxOrder+1];
		offset = new int[numTemplets][numStates];
		
		for(int t=0; t<numTemplets; t++) {
			Templet tpl =  this.get(t);
			int[] vars = tpl.getVars();
			/**
			 * 记录每一阶的状态
			 */
			int[] bits = new int[maxOrder+1];
			int v;
			for(int s=0; s<numStates; s++) {
				int d = s;
				//对于一个n阶状态组合，计算每个成员状态
				for(int i=0; i<maxOrder+1; i++) {
					bits[i] = d%numLabels;
					d = d/numLabels;
				}
				//对于一个n阶状态组合，记录一个特征模板映射到特征空间中到基地址的偏移
				//TODO 是否可以和上面合并简化
				v = 0;						
				for(int i=0; i<vars.length; i++) {
					v = v*numLabels + bits[-vars[i]];
				}
				offset[t][s] = v;
			}
		}
	}
1127780
public void setMeanValue(float v) {
    if (Measure_Type.featOkTst && ((Measure_Type)jcasType).casFeat_meanValue == null)
      jcasType.jcas.throwFeatMissing("meanValue", "ch.epfl.bbp.uima.types.Measure");
    jcasType.ll_cas.ll_setFloatValue(addr, ((Measure_Type)jcasType).casFeatCode_meanValue, v);}
425181
public static void doubleCenterSymmetric(double[][] m) {
    final int size = m.length;
    // Storage for mean values - initially all 0.
    double[] means = new double[size];
    for(int x = 0; x < m.length; x++) {
      final double[] rowx = m[x];
      // We already added "x" values in previous iterations.
      // Fake-add 0: mean + (0 - mean) / (x + 1)
      double rmean = means[x] - means[x] / (x + 1);
      for(int y = x + 1; y < rowx.length; y++) {
        final double nv = rowx[y];
        final double dx = nv - rmean, dy = nv - means[y];
        // For x < y, this is the yth entry.
        rmean += dx / (y + 1);
        // For y > x, this is the xth entry
        means[y] += dy / (x + 1);
      }
      means[x] = rmean;
    }
    // Compute total mean by averaging column means.
    double mean = means[0];
    for(int x = 1; x < size; x++) {
      double dm = means[x] - mean;
      mean += dm / (x + 1);
    }
    // Row and column center; also make symmetric.
    for(int x = 0; x < size; x++) {
      m[x][x] = -2. * means[x] + mean;
      for(int y = x + 1; y < size; y++) {
        final double nv = m[x][y] - means[x] - means[y] + mean;
        m[x][y] = nv;
        m[y][x] = nv;
      }
    }
  }
428521
@Override
    public void eval(INDArray labels, INDArray predictions, INDArray mask, final List<? extends Serializable> recordMetaData) {

        Triple<INDArray,INDArray, INDArray> p = BaseEvaluation.reshapeAndExtractNotMasked(labels, predictions, mask, axis);
        if(p == null){
            //All values masked out; no-op
            return;
        }

        INDArray labels2d = p.getFirst();
        INDArray predictions2d = p.getSecond();
        INDArray maskArray = p.getThird();
        Preconditions.checkState(maskArray == null, "Per-output masking for ROCMultiClass is not supported");


        if(labels2d.dataType() != predictions2d.dataType())
            labels2d = labels2d.castTo(predictions2d.dataType());

        // FIXME: int cast
        int n = (int) labels2d.size(1);
        if (underlying == null) {
            underlying = new ROC[n];
            for (int i = 0; i < n; i++) {
                underlying[i] = new ROC(thresholdSteps, rocRemoveRedundantPts);
            }
        }

        if (underlying.length != labels2d.size(1)) {
            throw new IllegalArgumentException(
                            "Cannot evaluate data: number of label classes does not match previous call. " + "Got "
                                            + labels2d.size(1) + " labels (from array shape "
                                            + Arrays.toString(labels2d.shape()) + ")"
                                            + " vs. expected number of label classes = " + underlying.length);
        }

        for (int i = 0; i < n; i++) {
            INDArray prob = predictions2d.getColumn(i, true); //Probability of class i
            INDArray label = labels2d.getColumn(i, true);
            //Workaround for: https://github.com/deeplearning4j/deeplearning4j/issues/7305
            if(prob.rank() == 0)
                prob = prob.reshape(1,1);
            if(label.rank() == 0)
                label = label.reshape(1,1);
            underlying[i].eval(label, prob);
        }
    }
247081
def calc_average_parameters(parameter_layers):
        
        mean_layers = [numpy.mean(x) if x[0] else 0 for x in parameter_layers]
        overall_mean = numpy.mean([x for x in mean_layers if x])
        return mean_layers, overall_mean
254190
private String parseParamsForStatistics(ParameterSet params, JSONObject obj) throws Exception
    {
        if ((params.toArray().length < 1) || (params.toArray().length > 2)) {
            return "Incorrect number of arguments to @Statistics (expects 2, received " +
                    params.toArray().length + ")";
        }
        Object first = params.toArray()[0];
        if (!(first instanceof String)) {
            return "First argument to @Statistics must be a valid STRING selector, instead was " +
                    first;
        }
        String subselector = (String)first;
        try {
            StatsSelector s = StatsSelector.valueOf(subselector.toUpperCase());
            subselector = s.name();
        }
        catch (Exception e) {
            return "First argument to @Statistics must be a valid STRING selector, instead was " +
                    first;
        }

        boolean interval = false;
        if (params.toArray().length == 2) {
            interval = ((Number)(params.toArray()[1])).longValue() == 1L;
        }
        obj.put("subselector", subselector);
        obj.put("interval", interval);

        return null;
    }
160981
public static <A> double[] samLMR(A sorted, NumberArrayAdapter<?, A> adapter, int nmom) {
    final int n = adapter.size(sorted);
    final double[] sum = new double[nmom];
    nmom = n < nmom ? n : nmom;
    // Estimate probability weighted moments (unbiased)
    for(int i = 0; i < n; i++) {
      double term = adapter.getDouble(sorted, i);
      // Robustness: skip bad values
      if(Double.isInfinite(term) || Double.isNaN(term)) {
        continue;
      }
      sum[0] += term;
      for(int j = 1, z = i; j < nmom; j++, z--) {
        term *= z;
        sum[j] += term;
      }
    }
    // Normalize by "n choose (j + 1)"
    sum[0] /= n;
    double z = n;
    for(int j = 1; j < nmom; j++) {
      z *= n - j;
      sum[j] /= z;
    }
    normalizeLMR(sum, nmom);
    // Handle case when lambda2 == 0, by setting tau3...tauN = 0:
    if(sum[1] == 0) {
      for(int i = 2; i < nmom; i++) {
        sum[i] = 0.; // tau3...tauN = 0.
      }
      return sum;
    }
    // Map lambda3...lambdaN to tau3...tauN
    for(int i = 2; i < nmom; i++) {
      sum[i] /= sum[1];
    }
    return sum;
  }
112945
public static double mean(FlatDataCollection flatDataCollection) {
        int n = 0;
        double mean = 0.0;
        Iterator<Double> it = flatDataCollection.iteratorDouble();
        while(it.hasNext()) {
            Double value = it.next();
            if(value != null) {
                ++n;
                mean += value;
            }
        }

        if(n==0) {
            throw new IllegalArgumentException("No not null values where found in the collection.");
        }
        mean /= n;
        
        return mean;
    }