Example usage for org.apache.commons.math3.stat.descriptive.rank Median evaluate

List of usage examples for org.apache.commons.math3.stat.descriptive.rank Median evaluate

Introduction

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

Prototype

public double evaluate(final double p) throws MathIllegalArgumentException 

Source Link

Document

Returns the result of evaluating the statistic over the stored data.

Usage

From source file:com.left8.evs.edmodule.edcow.EDCoWThreshold.java

public double theta1(double[] autoCorrelationValues, double gama) {
    Median m = new Median();
    return (m.evaluate(autoCorrelationValues) + (gama * mad(autoCorrelationValues)));
}

From source file:com.left8.evs.edmodule.edcow.EDCoWThreshold.java

public double theta2(double[][] crossCorrelationValues, double gama) {
    double[] vecCrossCorrelation = transformMatrix(crossCorrelationValues);
    Median m = new Median();
    return (m.evaluate(vecCrossCorrelation) + (gama * mad(vecCrossCorrelation)));
}

From source file:com.left8.evs.edmodule.edcow.EDCoWThreshold.java

public double mad(double[] autoCorrelationValues) {
    double[] tempTable = new double[autoCorrelationValues.length];
    Median m = new Median();
    double medianValue = m.evaluate(autoCorrelationValues);
    for (int i = 0; i < autoCorrelationValues.length; i++) {
        tempTable[i] = Math.abs(autoCorrelationValues[i] - medianValue);
    }/* w ww. j a  v  a2s.co m*/
    return m.evaluate(tempTable); //return the median of tempTable, the equation (13) in the paper
}

From source file:eu.crisis_economics.abm.algorithms.portfolio.returns.MedianOverHistoryStockReturnExpectationFunction.java

private double medianOfSeries(final double[] series) {
    Median median = new Median();
    median.setData(series);//from ww w .j  av  a  2  s. co  m
    return median.evaluate(50);
}

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

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

    Median median = new Median();

    RealMatrix matrix0 = MatrixUtils.createRealMatrix(input[0]);
    RealMatrix matrix1 = MatrixUtils.createRealMatrix(input[1]);

    return Math.abs(median.evaluate(matrix0.getColumn(0)) - median.evaluate(matrix1.getColumn(0)));

}

From source file:io.github.msdk.featdet.chromatogrambuilder.BuildingChromatogram.java

@Nonnull
Double calculateMz() {/*from ww w  .j a  va  2 s .  c  o  m*/
    if (mzValues.isEmpty())
        throw new MSDKRuntimeException("Cannot calculate the m/z value of an empty chromatogram");

    // Convert the m/z values to an array
    double mzDoubleValues[] = Doubles.toArray(mzValues);

    // Calculate the final m/z value as a median of all m/z values
    Median median = new Median();
    double medianValue = median.evaluate(mzDoubleValues);

    return medianValue;

}

From source file:edu.uci.imbs.actor.VariablePopulationProtectionStatistics.java

private void calculateMedianPeasantProtectionProportion() {
    double[] proportions = buildSortedArrayOfProtectionProportions();
    Median median = new Median();
    medianPeasantProtectionProportion = median.evaluate(proportions);
}

From source file:edu.uci.imbs.actor.VariablePopulationProtectionStatistics.java

private void calculateMedianBanditNumberPeasantsToPreyUpon() {
    Median median = new Median();
    medianBanditNumberPeasantsToPreyUpon = median.evaluate(numbersOfPeasantsToPreyUponDoubles);
}

From source file:de.biomedical_imaging.ij.nanotrackj.Track.java

/**
 * @return The median hue of the track// w ww  .  ja  va2  s.  c  om
 */
public float getMedianHUE() {
    Median median = new Median();
    double[] hues = new double[this.size()];
    for (int i = 0; i < this.size(); i++) {
        hues[i] = ((CenterBlob) this.get(i).getBlob()).getHUE();
    }
    return (float) median.evaluate(hues);
}

From source file:com.github.lindenb.jvarkit.tools.redon.CopyNumber01.java

private void normalizeCoverage() {
    final Median medianOp = new Median();
    final Mean meanOp = new Mean();

    if (medianOp.evaluate(new double[] { 20, 1000, 19 }) != 20) {
        throw new RuntimeException("boum");
    }//from ww  w. j a  v  a 2 s. com

    int autosome_count = 0;
    Collections.sort(this.interval2row, CopyNumber01.sortOnXY);

    for (int j = 0; j < this.interval2row.size(); ++j) {
        GCAndDepth r = this.interval2row.get(j);
        if (isSexualChrom(r.getChrom()))
            continue;
        autosome_count++;
    }

    double x[] = new double[autosome_count];
    double y[] = new double[autosome_count];

    int i = 0;
    for (int j = 0; j < this.interval2row.size(); ++j) {
        GCAndDepth r = this.interval2row.get(j);
        if (isSexualChrom(r.getChrom()))
            continue;
        x[i] = r.getX();
        y[i] = r.getY();
        ++i;
    }

    final double min_x = x[0];
    final double max_x = x[x.length - 1];

    /* merge adjacent x having same values */
    i = 0;
    int k = 0;
    while (i < x.length) {
        int j = i + 1;

        while (j < x.length && Double.compare(x[i], x[j]) == 0) {
            ++j;
        }
        x[k] = x[i];
        y[k] = meanOp.evaluate(y, i, j - i);
        ++k;
        i = j;
    }

    /* reduce size of x et y */
    if (k != x.length) {
        info("Compacting X from " + x.length + " to " + k);
        x = Arrays.copyOf(x, k);
        y = Arrays.copyOf(y, k);
    }

    //min depth cal
    double min_depth = Double.MAX_VALUE;

    UnivariateInterpolator interpolator = createInterpolator();
    UnivariateFunction spline = interpolator.interpolate(x, y);
    int points_removed = 0;
    i = 0;
    while (i < this.interval2row.size()) {
        GCAndDepth r = this.interval2row.get(i);
        if (r.getX() < min_x || r.getX() > max_x) {
            this.interval2row.remove(i);
            ++points_removed;
        } else {
            double norm = spline.value(r.getX());
            if (Double.isNaN(norm) || Double.isInfinite(norm)) {
                info("NAN " + r);
                this.interval2row.remove(i);
                ++points_removed;
                continue;
            }
            r.depth -= norm;
            min_depth = Math.min(min_depth, r.depth);
            ++i;
        }
    }
    info("Removed " + points_removed + " because GC% is too small (Sexual chrom)");
    spline = null;

    //fit to min, fill new y for median calculation
    info("min:" + min_depth);

    y = new double[this.interval2row.size()];
    for (i = 0; i < this.interval2row.size(); ++i) {
        GCAndDepth gc = this.interval2row.get(i);
        gc.depth -= min_depth;
        y[i] = gc.depth;
    }

    //normalize on median
    double median_depth = medianOp.evaluate(y, 0, y.length);
    info("median:" + median_depth);
    for (i = 0; i < this.interval2row.size(); ++i) {
        GCAndDepth gc = this.interval2row.get(i);
        gc.depth /= median_depth;
    }

    //restore genomic order
    Collections.sort(this.interval2row, CopyNumber01.sortOnPosition);

    /**  smoothing values with neighbours */
    final int SMOOTH_WINDOW = 5;
    y = new double[this.interval2row.size()];
    for (i = 0; i < this.interval2row.size(); ++i) {
        y[i] = this.interval2row.get(i).getY();
    }
    for (i = 0; i < this.interval2row.size(); ++i) {
        GCAndDepth gc = this.interval2row.get(i);
        int left = i;
        int right = i;
        while (left > 0 && i - left < SMOOTH_WINDOW && this.interval2row.get(left - 1).tid == gc.tid) {
            left--;
        }
        while (right + 1 < this.interval2row.size() && right - i < SMOOTH_WINDOW
                && this.interval2row.get(right + 1).tid == gc.tid) {
            right++;
        }
        gc.depth = medianOp.evaluate(y, left, (right - left) + 1);
    }

}