Example usage for org.apache.commons.math3.stat.descriptive.moment Variance evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.moment Variance evaluate

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive.moment Variance evaluate.

Prototype

@Override
public double evaluate(final double[] values) throws MathIllegalArgumentException 

Source Link

Document

Returns the variance of the entries in the input array, or Double.NaN if the array is empty.

Usage

From source file:cz.cuni.mff.d3s.spl.utils.StatisticsUtils.java

/** Compute variance of given data with bias correction.
 * //from w  w  w  . j  av a2  s.c  o  m
 * @param values Array of values to compute the variance from.
 * @return Varince of the provided values.
 */
public static double variance(double... values) {
    Variance var = new Variance();
    return var.evaluate(values);
}

From source file:cz.cuni.mff.d3s.spl.utils.StatisticsUtils.java

/** Compute variance of given data without bias correction.
 * // w w  w .  j av  a 2s  .c  o m
 * @param values Array of values to compute the variance from.
 * @return Varince of the provided values.
 */
public static double varianceN(double... values) {
    Variance var = new Variance(false);
    return var.evaluate(values);
}

From source file:hyperheuristics.algorithm.moeadfrrmab.UCBSelectorVariance.java

protected double calcVariance(double[] values) {
    Variance variancia = new Variance();
    return variancia.evaluate(values);
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleVarianceAggregation.java

@Override
public Number getExpectedValue(int start, int length) {
    if (length < 2) {
        return null;
    }//from  w w  w.  j  a va2 s.  c o  m

    double[] values = new double[length];
    for (int i = 0; i < length; i++) {
        values[i] = start + i;
    }

    Variance variance = new Variance();
    return variance.evaluate(values);
}

From source file:com.facebook.presto.operator.aggregation.TestDoubleVariancePopAggregation.java

@Override
public Number getExpectedValue(int start, int length) {
    if (length == 0) {
        return null;
    }/* w w w. j  a v a  2s  .c  o  m*/

    double[] values = new double[length];
    for (int i = 0; i < length; i++) {
        values[i] = start + i;
    }

    Variance variance = new Variance(false);
    return variance.evaluate(values);
}

From source file:cz.cuni.mff.d3s.spl.data.BenchmarkRunSummary.java

/** Compute variance of the samples.
 * /* w  w w .  j av  a2 s .  c  o  m*/
 * @return Variance of the data in the original benchmark run.
 */
public synchronized double getVariance() {
    if (cacheVariance == null) {
        Variance mean = new Variance();
        cacheVariance = mean.evaluate(data);
    }
    return cacheVariance;
}

From source file:aml.filter.InteractiveSelector.java

private boolean disagreement(int sourceId, int targetId) {
    double[] signatureVector = new double[aligns.size()];
    int index = 0;
    for (Alignment a : aligns)
        signatureVector[index++] = a.getSimilarity(sourceId, targetId);

    Variance v = new Variance();
    double variance = v.evaluate(signatureVector);

    if (variance < 0.041) {
        previousAgreement = false;/*from  w w w. j  a v a  2s.  c  om*/
        previousFeedback = 0;
        previousSignatureVector = signatureVector;
        return false;
    } else if (previousAgreement == true && previousFeedback == -1
            && previousSignatureVector == signatureVector)
    //vectorsMatch(previousSignatureVector,signatureVector))
    {
        previousAgreement = true;
        previousFeedback = -1;
        previousSignatureVector = signatureVector;
        return false;
    } else {
        previousAgreement = true;
        previousSignatureVector = signatureVector;
        return true;
    }
}

From source file:br.unicamp.ic.recod.gpsi.measures.gpsiNormalBhattacharyyaDistanceScore.java

@Override
public double score(double[][][] input) {

    Mean mean = new Mean();
    Variance var = new Variance();

    double mu0, sigs0, mu1, sigs1;
    double dist[][] = new double[2][];

    dist[0] = MatrixUtils.createRealMatrix(input[0]).getColumn(0);
    dist[1] = MatrixUtils.createRealMatrix(input[1]).getColumn(0);

    mu0 = mean.evaluate(dist[0]);/*from   ww w .  j a v  a2s  . c  o  m*/
    sigs0 = var.evaluate(dist[0]) + Double.MIN_VALUE;
    mu1 = mean.evaluate(dist[1]);
    sigs1 = var.evaluate(dist[1]) + Double.MIN_VALUE;

    double distance = (Math.log((sigs0 / sigs1 + sigs1 / sigs0 + 2) / 4)
            + (Math.pow(mu1 - mu0, 2.0) / (sigs0 + sigs1))) / 4;

    return distance == Double.POSITIVE_INFINITY ? 0 : distance;

}

From source file:com.std.Index.java

@Override
public void calculate_beta(YStockQuote sp500, int timeFrame) {
    double[] sp500Col = Arrays.copyOfRange(sp500.get_historical_rate_of_return(), 0, timeFrame);
    calculate_historical_rate_of_return(timeFrame);
    sp500Col = Arrays.copyOfRange(sp500.get_historical_rate_of_return(), 0,
            this.historical_rate_of_return.length);
    Covariance covarianceObj = new Covariance();
    Variance varianceObj = new Variance(false);
    double covariance = covarianceObj.covariance(historical_rate_of_return, sp500Col);
    double variance = varianceObj.evaluate(sp500Col);

    this.Beta = String.valueOf(Math.round((covariance / variance) * 100.0) / 100.0);
}

From source file:nl.systemsgenetics.eqtlinteractionanalyser.eqtlinteractionanalyser.TestEQTLDatasetForInteractions.java

private void correctExpressionDataForInteractions(String[] covsToCorrect, ExpressionDataset datasetCovariates,
        ExpressionDataset datasetGenotypes, int nrSamples, ExpressionDataset datasetExpression,
        OLSMultipleLinearRegression regression, HashMultimap<String, String> qtlProbeSnpMultiMap)
        throws MathIllegalArgumentException, Exception {

    System.out.println("Correcting expression data for predefined gene environment interaction effects: "
            + Arrays.toString(covsToCorrect));
    int[] covsToCorrectIndex = new int[covsToCorrect.length];
    for (int c = 0; c < covsToCorrect.length; c++) {
        covsToCorrectIndex[c] = ((Integer) datasetCovariates.hashProbes.get(covsToCorrect[c])).intValue();

    }//from ww  w.j a va  2 s .c om

    HashMap<String, Integer> snpMap = new HashMap<String, Integer>(datasetGenotypes.nrProbes);
    for (Map.Entry<String, Integer> snpEntry : datasetGenotypes.hashProbes.entrySet()) {
        try {
            snpMap.put(snpEntry.getKey().substring(0, snpEntry.getKey().indexOf('_')), snpEntry.getValue());
        } catch (Exception e) {
            System.out.println(snpEntry.getKey());
            throw e;
        }
    }

    Variance v = new Variance();

    for (int p = 0; p < datasetExpression.nrProbes; p++) {

        String probe = datasetExpression.probeNames[p].substring(0,
                datasetExpression.probeNames[p].lastIndexOf('_'));
        Set<String> probeQtls = qtlProbeSnpMultiMap.get(probe);

        if (probeQtls.isEmpty()) {
            throw new Exception("No eQTLs found for: " + probe);
        }

        int snpsInData = 0;
        HashSet<String> excludedSnps = new HashSet<String>();
        for (String snp : probeQtls) {

            Integer s = snpMap.get(snp);
            if (s != null) {

                if (v.evaluate(datasetGenotypes.rawData[s]) > 0) {
                    ++snpsInData;
                } else {
                    excludedSnps.add(snp);
                }

            }

        }

        //boolean foundPisS = false;
        double[][] valsX = new double[nrSamples][snpsInData + covsToCorrect.length * 2]; //store genotypes, covariates, interactions
        int k = 0;
        for (String snp : probeQtls) {

            if (excludedSnps.contains(snp)) {
                continue;
            }

            Integer s = snpMap.get(snp);
            if (s == null) {
                //throw new Exception("Snp " + snp + " not found");
                continue;
            }
            //            if(s.intValue() == p){
            //               foundPisS = true;
            //            }
            double[] snpData = datasetGenotypes.rawData[s];
            for (int i = 0; i < datasetGenotypes.nrSamples; ++i) {
                valsX[i][k] = snpData[i];
            }

            k++;
        }
        //         if(!foundPisS){
        //            
        //            System.out.println("Expected snp: " + datasetGenotypes.probeNames[p] + " at index: " + p);
        //            
        //            for(String qtlSnp : probeQtls = qtlProbeSnpMultiMap.get(probe)){
        //               System.out.println("QTL snp: " + qtlSnp + " found at index: " + snpMap.get(qtlSnp));
        //            }
        //            
        //            throw new Exception("Error 2");
        //         }
        for (int c = 0; c < covsToCorrect.length; c++) {
            double[] covData = datasetCovariates.rawData[covsToCorrectIndex[c]];
            double[] snpData = datasetGenotypes.rawData[p];

            for (int s = 0; s < nrSamples; s++) {
                valsX[s][c * 2 + snpsInData] = covData[s]; //covariate
                valsX[s][c * 2 + snpsInData + 1] = snpData[s] * covData[s]; //interction
            }
        }
        double[] valsY = datasetExpression.rawData[p];
        regression.newSampleData(valsY, valsX);
        try {
            datasetExpression.rawData[p] = regression.estimateResiduals();
        } catch (Exception up) {
            System.err.println(
                    "Error correcting for interactions: " + probe + " - " + datasetGenotypes.probeNames[p]);
        }
    }
}