Java Code Examples for org.apache.commons.math.stat.descriptive.DescriptiveStatistics

The following examples show how to use org.apache.commons.math.stat.descriptive.DescriptiveStatistics. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mzmine3   Source File: HeatMapTask.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void scale(double[][] peakList) {
  DescriptiveStatistics stdDevStats = new DescriptiveStatistics();

  for (int columns = 0; columns < peakList.length; columns++) {
    stdDevStats.clear();
    for (int row = 0; row < peakList[columns].length; row++) {
      if (!Double.isInfinite(peakList[columns][row]) && !Double.isNaN(peakList[columns][row])) {
        stdDevStats.addValue(peakList[columns][row]);
      }
    }

    double stdDev = stdDevStats.getStandardDeviation();

    for (int row = 0; row < peakList[columns].length; row++) {
      if (stdDev != 0) {
        peakList[columns][row] = peakList[columns][row] / stdDev;
      }
    }
  }
}
 
Example 2
public static DescriptiveStatistics frequencyToStatistics(Frequency frequency)
{
    Iterator<Comparable<?>> comparableIterator = frequency.valuesIterator();
    DescriptiveStatistics result = new DescriptiveStatistics();
    while (comparableIterator.hasNext()) {
        Comparable<?> next = comparableIterator.next();
        long count = frequency.getCount(next);

        for (int i = 0; i < count; i++) {
            if (next instanceof Number) {
                result.addValue(((Number) next).doubleValue());
            }
        }
    }

    return result;
}
 
Example 3
Source Project: astor   Source File: StatUtilsTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Run with 77 random values, assuming that the outcome has a mean of 0 and a standard deviation of 1 with a
 * precision of 1E-10.
 */

@Test
public void testNormalize2() {
    // create an sample with 77 values    
    int length = 77;
    double sample[] = new double[length];
    for (int i = 0; i < length; i++) {
        sample[i] = Math.random();
    }
    // normalize this sample
    double standardizedSample[] = StatUtils.normalize(sample);

    DescriptiveStatistics stats = new DescriptiveStatistics();
    // Add the data from the array
    for (int i = 0; i < length; i++) {
        stats.addValue(standardizedSample[i]);
    }
    // the calculations do have a limited precision    
    double distance = 1E-10;
    // check the mean an standard deviation
    Assert.assertEquals(0.0, stats.getMean(), distance);
    Assert.assertEquals(1.0, stats.getStandardDeviation(), distance);

}
 
Example 4
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - Math.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 5
public void conductExperiment(final MySQLReductionExperiment exp) throws Exception {
	List<Map<String, Object>> mccvResults = Util.conductSingleOneStepReductionExperiment(exp.getExperiment());
	DescriptiveStatistics errorRate = new DescriptiveStatistics();
	DescriptiveStatistics runtime = new DescriptiveStatistics();
	for (Map<String, Object> result : mccvResults) {
		errorRate.addValue((double) result.get("errorRate"));
		runtime.addValue((long) result.get("trainTime"));
	}

	/* prepapre values for experiment update */
	Map<String, Object> values = new HashMap<>();
	values.put(ERROR_RATE_MIN, errorRate.getMin());
	values.put(ERROR_RATE_MAX, errorRate.getMax());
	values.put(ERROR_RATE_MEAN, errorRate.getMean());
	values.put(ERROR_RATE_STD, errorRate.getStandardDeviation());
	values.put(RUNTIME_MIN, runtime.getMin());
	values.put(RUNTIME_MAX, runtime.getMax());
	values.put(RUNTIME_MEAN, runtime.getMean());
	values.put(RUNTIME_STD, runtime.getStandardDeviation());
	this.updateExperiment(exp, values);
}
 
Example 6
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }


    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }

    return value;
}
 
Example 7
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }


    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }

    return value;
}
 
Example 8
/**
 * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getValues()
 */
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - Math.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 9
/**
 * @see org.apache.commons.math.stat.descriptive.DescriptiveStatistics#getElement(int)
 */
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }

    
    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }
    
    return value;
}
 
Example 10
/**
 * Test DescriptiveStatistics - implementations that store full array of
 * values and execute multi-pass algorithms
 */
public void testDescriptiveStatistics() throws Exception {

    DescriptiveStatistics u = new DescriptiveStatistics();
    
    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);
    
    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);        
    
    loadStats("data/Michelso.txt", u);
    assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);   

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);
    
    loadStats("data/NumAcc2.txt", u);
    assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
}
 
Example 11
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - Math.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 12
Source Project: incubator-pinot   Source File: HeatMapViewResponse.java    License: Apache License 2.0 6 votes vote down vote up
public void updateStats() {

    for (Map.Entry<String, GenericResponse> entry : data.entrySet()) {
      GenericResponse genericResponse = entry.getValue();

      Map<String, Integer> columnsToIndexMapping =
          genericResponse.getSchema().getColumnsToIndexMapping();
      int i = columnsToIndexMapping.get("baselineValue");
      int j = columnsToIndexMapping.get("currentValue");

      for (String[] rowData : genericResponse.getResponseData()) {
        Double baselineValue = Double.valueOf(rowData[i]);
        Double currentValue = Double.valueOf(rowData[j]);

        DescriptiveStatistics baselineStats = new DescriptiveStatistics();
        DescriptiveStatistics currentStats = new DescriptiveStatistics();

        // Add stats
        // Update columns
        // Update column to index mapping
      }
    }
  }
 
Example 13
Source Project: astor   Source File: CertifiedDataTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test DescriptiveStatistics - implementations that store full array of
 * values and execute multi-pass algorithms
 */
public void testDescriptiveStatistics() throws Exception {

    DescriptiveStatistics u = new DescriptiveStatistics();
    
    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);
    
    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);        
    
    loadStats("data/Michelso.txt", u);
    assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);   

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);
    
    loadStats("data/NumAcc2.txt", u);
    assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
}
 
Example 14
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - Math.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 15
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - Math.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 16
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }


    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }

    return value;
}
 
Example 17
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public long getN() {
    int n = 0;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW) {
        if (list.size() > windowSize) {
            n = windowSize;
        } else {
            n = list.size();
        }
    } else {
        n = list.size();
    }
    return n;
}
 
Example 18
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - FastMath.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 19
Source Project: astor   Source File: CertifiedDataTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test DescriptiveStatistics - implementations that store full array of
 * values and execute multi-pass algorithms
 */
public void testDescriptiveStatistics() throws Exception {

    DescriptiveStatistics u = new DescriptiveStatistics();

    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Michelso.txt", u);
    assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc2.txt", u);
    assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
}
 
Example 20
Source Project: astor   Source File: CertifiedDataTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test StorelessDescriptiveStatistics
 */
public void testStoredUnivariateImpl() throws Exception {

    DescriptiveStatistics u = DescriptiveStatistics.newInstance();
    
    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), .0000000000001);
    assertEquals("PiDigits: mean", mean, u.getMean(), .0000000000001);
    
    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), .00000000000001);
    assertEquals("Mavro: mean", mean, u.getMean(), .00000000000001);        
    
    //loadStats("data/Michelso.txt");
    //assertEquals("Michelso: std", std, u.getStandardDeviation(), .00000000000001);
    //assertEquals("Michelso: mean", mean, u.getMean(), .00000000000001);   

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), .00000000000001);
    assertEquals("NumAcc1: mean", mean, u.getMean(), .00000000000001);
    
    //loadStats("data/NumAcc2.txt");
    //assertEquals("NumAcc2: std", std, u.getStandardDeviation(), .000000001);
    //assertEquals("NumAcc2: mean", mean, u.getMean(), .00000000000001);
}
 
Example 21
Source Project: astor   Source File: CertifiedDataTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test DescriptiveStatistics - implementations that store full array of
 * values and execute multi-pass algorithms
 */
public void testDescriptiveStatistics() throws Exception {

    DescriptiveStatistics u = new DescriptiveStatistics();

    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Michelso.txt", u);
    assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc2.txt", u);
    assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
}
 
Example 22
Source Project: astor   Source File: CertifiedDataTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test DescriptiveStatistics - implementations that store full array of
 * values and execute multi-pass algorithms
 */
public void testDescriptiveStatistics() throws Exception {

    DescriptiveStatistics u = new DescriptiveStatistics();

    loadStats("data/PiDigits.txt", u);
    assertEquals("PiDigits: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("PiDigits: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Mavro.txt", u);
    assertEquals("Mavro: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Mavro: mean", mean, u.getMean(), 1E-14);

    loadStats("data/Michelso.txt", u);
    assertEquals("Michelso: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("Michelso: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc1.txt", u);
    assertEquals("NumAcc1: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc1: mean", mean, u.getMean(), 1E-14);

    loadStats("data/NumAcc2.txt", u);
    assertEquals("NumAcc2: std", std, u.getStandardDeviation(), 1E-14);
    assertEquals("NumAcc2: mean", mean, u.getMean(), 1E-14);
}
 
Example 23
Source Project: astor   Source File: StatUtils.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Normalize (standardize) the series, so in the end it is having a mean of 0 and a standard deviation of 1.
 *
 * @param sample Sample to normalize.
 * @return normalized (standardized) sample.
 * @since 2.2
 */
public static double[] normalize(final double[] sample) {
    DescriptiveStatistics stats = new DescriptiveStatistics();

    // Add the data from the series to stats
    for (int i = 0; i < sample.length; i++) {
        stats.addValue(sample[i]);
    }

    // Compute mean and standard deviation
    double mean = stats.getMean();
    double standardDeviation = stats.getStandardDeviation();

    // initialize the standardizedSample, which has the same length as the sample
    double[] standardizedSample = new double[sample.length];

    for (int i = 0; i < sample.length; i++) {
        // z = (x- mean)/standardDeviation
        standardizedSample[i] = (sample[i] - mean) / standardDeviation;
    }
    return standardizedSample;
}
 
Example 24
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public long getN() {
    int n = 0;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW) {
        if (list.size() > windowSize) {
            n = windowSize;
        } else {
            n = list.size();
        }
    } else {
        n = list.size();
    }
    return n;
}
 
Example 25
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }

    
    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }
    
    return value;
}
 
Example 26
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - FastMath.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}
 
Example 27
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double getElement(int index) {

    double value = Double.NaN;

    int calcIndex = index;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        calcIndex = (list.size() - windowSize) + index;
    }


    try {
        value = transformer.transform(list.get(calcIndex));
    } catch (MathException e) {
        e.printStackTrace();
    }

    return value;
}
 
Example 28
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public long getN() {
    int n = 0;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW) {
        if (list.size() > windowSize) {
            n = windowSize;
        } else {
            n = list.size();
        }
    } else {
        n = list.size();
    }
    return n;
}
 
Example 29
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public long getN() {
    int n = 0;

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW) {
        if (list.size() > windowSize) {
            n = windowSize;
        } else {
            n = list.size();
        }
    } else {
        n = list.size();
    }
    return n;
}
 
Example 30
Source Project: astor   Source File: ListUnivariateImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public double[] getValues() {

    int length = list.size();

    // If the window size is not INFINITE_WINDOW AND
    // the current list is larger that the window size, we need to
    // take into account only the last n elements of the list
    // as definied by windowSize

    if (windowSize != DescriptiveStatistics.INFINITE_WINDOW &&
        windowSize < list.size())
    {
        length = list.size() - FastMath.max(0, list.size() - windowSize);
    }

    // Create an array to hold all values
    double[] copiedArray = new double[length];

    for (int i = 0; i < copiedArray.length; i++) {
        copiedArray[i] = getElement(i);
    }
    return copiedArray;
}