Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

In this page you can find the example usage for java.math BigDecimal doubleValue.

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

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

/**
 * Tests well calculation using indices.
 *///from   w w  w. j a v a2 s.  c o 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);

            double[] inputArray = ArrayUtils.subarray(input, begin, end);

            DescriptiveStatistics stat = new DescriptiveStatistics(inputArray);
            double resultDouble = stat.getVariance();
            resultDouble *= inputArray.length - 1;
            resultDouble /= inputArray.length;

            BigDecimal returned = variance.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.PopulationVarianceTest.java

/**
 * Tests well calculation using indices.
 *//*  w w w. ja  v  a 2  s  .c  o m*/
@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);

            double[] inputArray = ArrayUtils.subarray(input, begin, end);

            DescriptiveStatistics stat = new DescriptiveStatistics(inputArray);
            double resultDouble = stat.getVariance();
            resultDouble *= inputArray.length - 1;
            resultDouble /= inputArray.length;

            BigDecimal returned = variance.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.PercentileTest.java

/**
 * Tests the plate statistics method./*from  w w w . j av  a2 s .c  om*/
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        int inputPercentile = 1 + random.nextInt(100);

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.plate(plate, inputPercentile);

        for (Well well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getPercentile(inputPercentile);

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests set calculation.//from  w w w  . ja va2  s . c om
 */
@Test
public void testSet() {

    int inputPercentile = 1 + random.nextInt(100);

    for (Plate plate : array) {

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.set(plate.dataSet(), inputPercentile);

        for (Well well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getPercentile(inputPercentile);

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }

}

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

/**
 * Tests the plate statistics method.//from w w  w .  j  av a  2s .c om
 */
@Test
public void testPlate() {

    for (PlateBigDecimal plate : array) {

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = variance.plate(plate, mc);

        for (WellBigDecimal well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getVariance();
            resultDouble *= well.size() - 1;
            resultDouble /= well.size();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests the plate statistics method using the values between the indices.
 *//*w w w . j a  va2 s .co  m*/
@Test
public void testPlateIndices() {

    for (Plate plate : arrayIndices) {

        int inputPercentile = 1 + random.nextInt(100);

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

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.plate(plate, begin, end - begin, inputPercentile);

        for (Well well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests the plate statistics method./*from  w w w  .j  a va  2  s. c o  m*/
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = variance.plate(plate, mc);

        for (Well well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getVariance();
            resultDouble *= well.size() - 1;
            resultDouble /= well.size();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests the plate statistics method.//from   ww w .j av  a2 s . co  m
 */
@Test
public void testPlate() {

    for (PlateBigDecimal plate : array) {

        int inputPercentile = 1 + random.nextInt(100);

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = percentile.plate(plate, inputPercentile);

        for (WellBigDecimal well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getPercentile(inputPercentile);

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

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

/**
 * Tests set calculation.//from   w  w w .  ja va 2s . c o m
 */
@Test
public void testSet() {

    for (PlateBigDecimal plate : array) {

        Map<WellBigDecimal, BigDecimal> resultMap = new TreeMap<WellBigDecimal, BigDecimal>();
        Map<WellBigDecimal, BigDecimal> returnedMap = variance.set(plate.dataSet(), mc);

        for (WellBigDecimal well : plate) {

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

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

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getVariance();
            resultDouble *= well.size() - 1;
            resultDouble /= well.size();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (WellBigDecimal well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }

}

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

/**
 * Tests set calculation using indices.//  ww w .j a  v  a  2s. co m
 */
@Test
public void testSetIndices() {

    for (Plate plate : arrayIndices) {

        int inputPercentile = 1 + random.nextInt(100);

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

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = percentile.set(plate.dataSet(), begin, end - begin,
                inputPercentile);

        for (Well well : plate) {

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

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

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

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}