Example usage for org.apache.commons.math3.distribution TDistribution TDistribution

List of usage examples for org.apache.commons.math3.distribution TDistribution TDistribution

Introduction

In this page you can find the example usage for org.apache.commons.math3.distribution TDistribution TDistribution.

Prototype

public TDistribution(double degreesOfFreedom, double inverseCumAccuracy) throws NotStrictlyPositiveException 

Source Link

Document

Create a t distribution using the given degrees of freedom and the specified inverse cumulative probability absolute accuracy.

Usage

From source file:adams.data.distribution.T.java

/**
 * Returns the configured distribution.//  w w w . j ava2 s  .  c  o m
 *
 * @return      the distribution
 */
@Override
public RealDistribution getRealDistribution() {
    return new TDistribution(m_DegreesOfFreedom, m_InverseCumAccuracy);
}

From source file:edu.cmu.tetrad.util.RandomUtil.java

/**
 * Returns the next random number drawn from the Student T distribution with the given degrees of freedom.
 *
 * @param df The degrees of freedom. See any stats book.
 * @return Ibid.//w w w.j a v  a2  s.co m
 */
public double nextT(double df) {
    return new TDistribution(randomGenerator, df).sample();
}

From source file:io.coala.random.impl.RandomDistributionFactoryImpl.java

@Override
public RandomNumberDistribution<Double> getT(final RandomNumberStream rng, final Number degreesOfFreedom) {
    final RealDistribution dist = new TDistribution(RandomNumberStream.Util.asCommonsRandomGenerator(rng),
            degreesOfFreedom.doubleValue());
    return new RandomNumberDistribution<Double>() {
        @Override//from   w  w  w . j a  va  2 s .c o m
        public Double draw() {
            return dist.sample();
        }
    };
}

From source file:org.apache.metron.statistics.outlier.MedianAbsoluteDeviationTest.java

@Test
public void testLongTailed() {

    TDistribution generator = new TDistribution(new MersenneTwister(0L), 100);
    DescriptiveStatistics stats = new DescriptiveStatistics();
    List<MedianAbsoluteDeviationFunctions.State> states = new ArrayList<>();
    MedianAbsoluteDeviationFunctions.State currentState = null;
    //initialize the state
    currentState = (MedianAbsoluteDeviationFunctions.State) run("OUTLIER_MAD_STATE_MERGE(states, NULL)",
            ImmutableMap.of("states", states));
    for (int i = 0, j = 0; i < 10000; ++i, ++j) {
        Double d = generator.sample();
        stats.addValue(d);// w  w w.  j  a  v  a2 s .  c om
        run("OUTLIER_MAD_ADD(currentState, data)", ImmutableMap.of("currentState", currentState, "data", d));
        if (j >= 1000) {
            j = 0;
            List<MedianAbsoluteDeviationFunctions.State> stateWindow = new ArrayList<>();
            for (int stateIndex = Math.max(0, states.size() - 5); stateIndex < states.size(); ++stateIndex) {
                stateWindow.add(states.get(stateIndex));
            }
            currentState = (MedianAbsoluteDeviationFunctions.State) run(
                    "OUTLIER_MAD_STATE_MERGE(states, currentState)",
                    ImmutableMap.of("states", stateWindow, "currentState", currentState));
        }
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)",
                ImmutableMap.of("currentState", currentState, "value", stats.getMin()));
        Assert.assertTrue("Score: " + score + " is not an outlier despite being a minimum.", score > 3.5);
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)",
                ImmutableMap.of("currentState", currentState, "value", stats.getMax()));
        Assert.assertTrue("Score: " + score + " is not an outlier despite being a maximum", score > 3.5);
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState",
                currentState, "value", stats.getMean() + 4 * stats.getStandardDeviation()));
        Assert.assertTrue(
                "Score: " + score + " is not an outlier despite being 4 std deviations away from the mean",
                score > 3.5);
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState",
                currentState, "value", stats.getMean() - 4 * stats.getStandardDeviation()));
        Assert.assertTrue(
                "Score: " + score + " is not an outlier despite being 4 std deviations away from the mean",
                score > 3.5);
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)",
                ImmutableMap.of("currentState", currentState, "value", stats.getMean()));
        Assert.assertFalse("Score: " + score + " is an outlier despite being the mean", score > 3.5);
    }
}