Example usage for org.apache.commons.math.stat.descriptive.moment StandardDeviation evaluate

List of usage examples for org.apache.commons.math.stat.descriptive.moment StandardDeviation evaluate

Introduction

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

Prototype

public double evaluate(final double[] values, final double mean) 

Source Link

Document

Returns the Standard Deviation of the entries in the input array, using the precomputed mean value.

Usage

From source file:net.sf.jdmf.util.MathCalculator.java

/**
 * Calculates the standard deviation of all attribute values.
 * // w  ww .  j  a  v  a 2  s  .  co  m
 * @param attributeValues attribute values
 * @return the standard deviation
 */
public Double calculateStandardDeviation(Comparable[] attributeValues, Double mean) {
    StandardDeviation standardDeviation = new StandardDeviation();

    Double evaluatedStdDev = standardDeviation.evaluate(convertToPrimitives(attributeValues), mean);

    log.debug("standardDeviation( " + mean + " ) = " + evaluatedStdDev);

    return evaluatedStdDev;
}

From source file:musite.prediction.feature.disorder.DisorderTest.java

@Test
public void extractMean() throws IOException {
    //         String xml = "testData/musite-test.xml";
    String xml = "data/Uniprot/uniprot_sprot.201009.ptm.musite.with.disorder.xml";

    ProteinsXMLReader reader = DisorderUtil.getDisorderXMLReader();
    Proteins proteins = MusiteIOUtil.read(reader, xml);

    TTest ttest = new TTestImpl();
    StandardDeviation std = new StandardDeviation();

    Map<AminoAcid, double[]> mapAAScores = new EnumMap<AminoAcid, double[]>(AminoAcid.class);
    for (AminoAcid aa : AminoAcid.values()) {
        List<Double> scores = new ArrayList<Double>();
        Iterator<Protein> it = proteins.proteinIterator();
        while (it.hasNext()) {
            Protein protein = it.next();
            List<Double> dis = DisorderUtil.extractDisorder(protein, aa);
            if (dis != null)
                scores.addAll(dis);// w  w  w  .jav a  2 s  . c  om
        }
        mapAAScores.put(aa, list2array(scores));
        //            System.out.print(aa.toString()+":");
        //            System.out.println(""+average(scores)+"("+scores.size()+")");
    }

    Map<String, AminoAcid> mapKeyAA = getMapKeywordAminoAcid();

    for (PTM ptm : PTM.values()) {
        Set<String> keywords = ptm.getUniprotKeywords();
        for (String keyword : keywords) {
            AnnotationFilter filter = ResidueAnnotationUtil.createAnnotationFilter("keyword",
                    Collections.singleton(keyword), true);

            double[] scores;
            {
                List<Double> list = new ArrayList<Double>();
                Iterator<Protein> it = proteins.proteinIterator();
                while (it.hasNext()) {
                    Protein protein = it.next();
                    List<Double> dis = DisorderUtil.extractDisorder(protein, ptm, filter);
                    if (dis != null)
                        list.addAll(dis);
                }
                scores = list2array(list);
            }

            System.out.print(ptm.toString());
            System.out.print("\t" + keyword);
            if (scores.length == 0)
                System.out.println("\tno_site");
            else {
                System.out.print("\t" + scores.length);
                double mean = StatUtils.mean(scores);
                System.out.print("\t" + mean);
                System.out.print("\t" + std.evaluate(scores, mean));

                AminoAcid aa = mapKeyAA.get(keyword);
                double[] bg = mapAAScores.get(aa);
                System.out.print("\t" + aa.toString());
                System.out.print("\t" + bg.length);
                mean = StatUtils.mean(bg);
                System.out.print("\t" + mean);
                System.out.print("\t" + std.evaluate(bg, mean));

                double pvalue = -1.0;
                try {
                    pvalue = ttest.tTest(scores, bg);
                } catch (Exception e) {
                    //                        e.printStackTrace();
                }

                if (pvalue != -1.0)
                    System.out.print("\t" + pvalue);

                System.out.println();
            }
        }
    }
}