Example usage for org.apache.commons.math3.stat.descriptive.moment StandardDeviation incrementAll

List of usage examples for org.apache.commons.math3.stat.descriptive.moment StandardDeviation incrementAll

Introduction

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

Prototype

public void incrementAll(double[] values) throws MathIllegalArgumentException 

Source Link

Document

This default implementation just calls #increment in a loop over the input array.

Usage

From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java

@Test
public void testInformationNumericFeature() {
    ExampleSet exampleSet = examplesForFeaturesValues(new float[] { 0.0f, 1.0f, 2.0f, 4.0f },
            new float[] { 1.0f, 1.5f, 2.0f, 5.0f });
    List<Decision> decisions = Decision.decisionsFromExamples(exampleSet, 0, 100);
    assertEquals(3, decisions.size());//from w  w  w .j a v a2  s . c  om
    assertEquals(3.0f, ((NumericDecision) decisions.get(0)).getThreshold());
    assertEquals(1.5f, ((NumericDecision) decisions.get(1)).getThreshold());
    assertEquals(0.5f, ((NumericDecision) decisions.get(2)).getThreshold());
    Pair<Decision, Double> best = NumericalInformation.bestGain(decisions, exampleSet);
    assertEquals(1.5f, ((NumericDecision) best.getFirst()).getThreshold());

    StandardDeviation all = new StandardDeviation();
    all.incrementAll(new double[] { 1.0, 1.5, 2.0, 5.0 });
    StandardDeviation positive = new StandardDeviation();
    positive.incrementAll(new double[] { 1.0, 1.5 });
    StandardDeviation negative = new StandardDeviation();
    negative.incrementAll(new double[] { 2.0, 5.0 });

    assertEquals(differentialEntropy(all) - (2.0 / 4.0) * differentialEntropy(positive)
            - (2.0 / 4.0) * differentialEntropy(negative), best.getValue().doubleValue());
}

From source file:com.cloudera.oryx.rdf.common.information.NumericInformationTest.java

@Test
public void testInformationCategoricalFeature() {
    ExampleSet exampleSet = examplesForValuesForCategories(new float[][] { new float[] { 1.0f, 1.5f },
            new float[] { 5.5f, 7.0f }, new float[] { 2.0f, 5.0f }, });
    List<Decision> decisions = Decision.decisionsFromExamples(exampleSet, 0, 100);
    assertEquals(2, decisions.size());//  ww w. ja  va 2  s .c  o  m
    BitSet categories0 = ((CategoricalDecision) decisions.get(0)).getCategoryIDs();
    BitSet categories1 = ((CategoricalDecision) decisions.get(1)).getCategoryIDs();
    assertEquals(1, categories0.cardinality());
    assertTrue(categories0.get(0));
    assertEquals(2, categories1.cardinality());
    assertTrue(categories1.get(0));
    assertTrue(categories1.get(2));

    Pair<Decision, Double> best = NumericalInformation.bestGain(decisions, exampleSet);
    assertEquals(categories0, ((CategoricalDecision) best.getFirst()).getCategoryIDs());

    StandardDeviation all = new StandardDeviation();
    all.incrementAll(new double[] { 1.0, 1.5, 5.5, 7.0, 2.0, 5.0 });
    StandardDeviation positive = new StandardDeviation();
    positive.incrementAll(new double[] { 1.0, 1.5 });
    StandardDeviation negative = new StandardDeviation();
    negative.incrementAll(new double[] { 5.5, 7.0, 2.0, 5.0 });

    assertEquals(differentialEntropy(all) - (2.0 / 6.0) * differentialEntropy(positive)
            - (4.0 / 6.0) * differentialEntropy(negative), best.getValue().doubleValue());
}