Example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation

List of usage examples for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.descriptive DescriptiveStatistics getStandardDeviation.

Prototype

public double getStandardDeviation() 

Source Link

Document

Returns the standard deviation of the available values.

Usage

From source file:com.github.jessemull.microflex.stat.statbigdecimal.StandardDeviationBigDecimalTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *///from   w  ww . ja  v a 2  s . c o  m
@Test
public void testAggregatedSetIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.setsAggregated(plate.dataSet(), begin, end - begin, mc);

        for (WellBigDecimal well : plate) {
            resultList.addAll(well.data().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.StandardDeviationTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *///from   w w  w.j  a  va 2s .  c  o m
@Test
public void testAggregatedPlateIndices() {

    for (Plate plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.platesAggregated(plate, begin, end - begin, mc);

        for (Well well : plate) {
            resultList.addAll(well.data().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.StandardDeviationTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//* ww  w  .  j a v a  2 s .c o  m*/
@Test
public void testAggregatedSetIndices() {

    for (Plate plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.setsAggregated(plate.dataSet(), begin, end - begin, mc);

        for (Well well : plate) {
            resultList.addAll(well.data().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.StandardDeviationTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//*from   w ww.j  a v a 2  s  . c  om*/
@Test
public void testAggregatedPlateIndices() {

    for (Plate plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.platesAggregated(plate, begin, end - begin, mc);

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflexbiginteger.stat.StandardDeviationTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//*from   w  w  w.j a va2s . c o m*/
@Test
public void testAggregatedSetIndices() {

    for (Plate plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.setsAggregated(plate.dataSet(), begin, end - begin, mc);

        for (Well well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.StandardDeviationBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *//*  www . j av  a  2 s.  co m*/
@Test
public void testAggregatedPlateIndices() {

    for (PlateBigInteger plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.platesAggregated(plate, begin, end - begin, mc);

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:com.github.jessemull.microflex.stat.statbiginteger.StandardDeviationBigIntegerTest.java

/**
 * Tests the aggregated plate statistics method using the values between the indices.
 *///from w ww  .j  av  a2 s .  c o  m
@Test
public void testAggregatedSetIndices() {

    for (PlateBigInteger plate : arrayIndices) {

        int size = arrayIndices[0].first().size();
        int begin = random.nextInt(size - 5);
        int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

        List<BigDecimal> resultList = new ArrayList<BigDecimal>();
        BigDecimal aggregatedReturned = deviation.setsAggregated(plate.dataSet(), begin, end - begin, mc);

        for (WellBigInteger well : plate) {
            resultList.addAll(well.toBigDecimal().subList(begin, end));
        }

        double[] inputAggregated = new double[resultList.size()];

        for (int i = 0; i < resultList.size(); i++) {
            inputAggregated[i] = resultList.get(i).doubleValue();
        }

        DescriptiveStatistics statAggregated = new DescriptiveStatistics(inputAggregated);
        double resultAggregatedDouble = statAggregated.getStandardDeviation();

        BigDecimal aggregatedResult = new BigDecimal(resultAggregatedDouble);

        BigDecimal[] corrected = correctRoundingErrors(aggregatedResult, aggregatedReturned);
        assertEquals(corrected[0], corrected[1]);
    }
}

From source file:fr.inria.eventcloud.benchmarks.load_balancing.LoadBalancingBenchmark.java

public StatsRecorder execute() {
    this.logParameterValues();

    // creates and runs micro benchmark
    MicroBenchmark microBenchmark = new MicroBenchmark(this.nbRuns, new MicroBenchmarkService() {

        private EventCloudsRegistry registry;

        private BenchmarkStatsCollector collector;

        private String collectorURL;

        private NodeProvider nodeProvider;

        private EventCloudDeployer deployer;

        private CustomPublishProxy publishProxies;

        private Event[] events;

        @Override//from w ww .  j  av  a 2  s.  co  m
        public void setup() throws Exception {
            LOG.info("Loading events from {}", LoadBalancingBenchmark.this.inputFile);
            this.events = LoadBalancingBenchmark.this.loadEvents(LoadBalancingBenchmark.this.inputFile);

            LOG.info("{} compound events loaded", this.events.length);

            this.collector = PAActiveObject.newActive(BenchmarkStatsCollector.class,
                    new Object[] { LoadBalancingBenchmark.this.nbPeers - 1 });
            this.collectorURL = PAActiveObject.registerByName(this.collector, BENCHMARK_STATS_COLLECTOR_NAME);

            this.nodeProvider = LoadBalancingBenchmark.this.createNodeProvider();

            LoadBalancingBenchmark.this.componentsManager = EventCloudComponentsManagerFactory
                    .newComponentsManager(this.nodeProvider, 1, LoadBalancingBenchmark.this.nbPeers, 1, 1, 0);

            LoadBalancingBenchmark.this.componentsManager.start();

            EventCloudDeploymentDescriptor descriptor = this.createDeploymentDescriptor(this.nodeProvider,
                    this.collectorURL);

            this.deployer = new EventCloudDeployer(new EventCloudDescription(), descriptor,
                    LoadBalancingBenchmark.this.componentsManager);
            this.deployer.deploy(1, 1);

            this.registry = LoadBalancingBenchmark.this.deployRegistry(this.deployer, this.nodeProvider);

            String registryURL = null;
            try {
                registryURL = this.registry.register("registry");
            } catch (ProActiveException e) {
                throw new IllegalStateException(e);
            }

            EventCloudId eventCloudId = this.deployer.getEventCloudDescription().getId();

            this.publishProxies = LoadBalancingBenchmark.this.createPublishProxies(this.nodeProvider,
                    registryURL, eventCloudId);
        }

        private EventCloudDeploymentDescriptor createDeploymentDescriptor(NodeProvider nodeProvider,
                String benchmarkStatsCollectorURL) {
            Criterion[] criteria = new Criterion[1];
            criteria[0] = new QuadrupleCountCriterion();

            LoadBalancingConfiguration configuration = null;

            if (LoadBalancingBenchmark.this.strategy != null) {
                configuration = new LoadBalancingConfiguration(criteria,
                        LoadBalancingBenchmark.this.componentsManager, LoadBalancingBenchmark.this.strategy);
            }

            EventCloudDeploymentDescriptor descriptor = new EventCloudDeploymentDescriptor(
                    new CustomSemanticOverlayProvider(configuration, this.collectorURL,
                            LoadBalancingBenchmark.this.nbQuadruplesPublished,
                            LoadBalancingBenchmark.this.inMemoryDatastore));

            return descriptor;
        }

        @Override
        public void run(StatsRecorder recorder) throws TimeoutException {
            LOG.info("Assigning events");
            this.publishProxies.assignEvents(this.events);

            LOG.info("Publishing events to trigger load balancing");
            this.publishProxies.publish();

            this.collector.waitCondition(3600000);

            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            LOG.info("Distribution on peers is:");

            Map<OverlayId, Integer> results = new HashMap<OverlayId, Integer>();

            for (Peer peer : this.collector.getPeers()) {
                @SuppressWarnings("unchecked")
                GenericResponseOperation<Integer> result = (GenericResponseOperation<Integer>) PAFuture
                        .getFutureValue(peer.receive(new CountQuadruplesOperation(false)));

                results.put(peer.getId(), result.getValue());
            }

            // Proxy proxy =
            // org.objectweb.proactive.extensions.p2p.structured.factories.ProxyFactory.newProxy(this.deployer.getTrackers());
            // CountQuadrupleResponse response =
            // (CountQuadrupleResponse)
            // PAFuture.getFutureValue(proxy.send(new
            // CountQuadrupleRequest()));
            //
            // Map<OverlayId, Long> results = response.getResult();

            DescriptiveStatistics stats = new DescriptiveStatistics();

            int count = 0;
            for (Entry<OverlayId, Integer> entry : results.entrySet()) {
                LOG.info("{}  {}", entry.getKey(), entry.getValue());
                count += entry.getValue();
                stats.addValue(entry.getValue());
            }

            LOG.info(
                    "{} peers manage a total of {} quadruples, standard deviation is {}, variability (stddev/average * 100) is {}%",
                    results.size(), count, stats.getStandardDeviation(),
                    (stats.getStandardDeviation() / stats.getMean()) * 100);

            System.exit(1);
        }

        @Override
        public void clear() throws Exception {
            LOG.info("Clearing previously recorded information before to start benchmark");

            List<ResponseOperation> futures = new ArrayList<ResponseOperation>();

            for (Peer p : this.deployer.getRandomTracker().getPeers()) {
                futures.add(p.receive(new ClearOperation()));
            }

            PAFuture.waitForAll(futures);

            this.collector.clear();
        }

        @Override
        public void teardown() throws Exception {
            LoadBalancingBenchmark.this.undeploy(this.nodeProvider, this.deployer, this.registry,
                    this.collectorURL);
        }

    });
    microBenchmark.discardFirstRuns(this.discardFirstRuns);
    microBenchmark.showProgress();
    microBenchmark.execute();

    return microBenchmark.getStatsRecorder();
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.StandardDeviationBigDecimalTest.java

/**
 * Tests well calculation using indices.
 *//*  w w w . j  a va2s . co m*/
@Test
public void testWellIndices() {

    for (PlateBigDecimal plate : arrayIndices) {

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getStandardDeviation();

            BigDecimal returned = deviation.well(well, begin, end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.StandardDeviationTest.java

/**
 * Tests well calculation using indices.
 *///from   www  . ja v a 2  s.  com
@Test
public void testWellIndices() {

    for (Plate plate : arrayIndices) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            int size = arrayIndices[0].first().size();
            int begin = random.nextInt(size - 5);
            int end = (begin + 4) + random.nextInt(size - (begin + 4) + 1);

            DescriptiveStatistics stat = new DescriptiveStatistics(ArrayUtils.subarray(input, begin, end));
            double resultDouble = stat.getStandardDeviation();

            BigDecimal returned = deviation.well(well, begin, end - begin, mc);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);
            assertEquals(corrected[0], corrected[1]);
        }
    }
}