Java BigDecimal stdBigDecimal(List vector, BigDecimal avg)

Here you can find the source of stdBigDecimal(List vector, BigDecimal avg)

Description

std Big Decimal

License

Open Source License

Declaration

public static BigDecimal stdBigDecimal(List<Double> vector, BigDecimal avg) 

Method Source Code

//package com.java2s;
/**/*from www  .j a  va 2  s.  c o m*/
 * Part of program for analyze speech signal 
 * Copyright (c) 2008 Mindaugas Greibus (spantus@gmail.com)
 * http://code.google.com/p/spantus/
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 675 Mass Ave, Cambridge, MA 02139, USA.
 * 
 */

import java.math.BigDecimal;
import java.math.RoundingMode;

import java.util.List;

public class Main {
    public static BigDecimal stdBigDecimal(List<Double> vector, BigDecimal avg) {
        BigDecimal accum = BigDecimal.ZERO;
        //       BigDecimal dev = BigDecimal.ZERO;
        BigDecimal accum2 = BigDecimal.ZERO;
        BigDecimal len = BigDecimal.valueOf(vector.size());

        for (Double float1 : vector) {
            BigDecimal val = BigDecimal.valueOf(float1);
            BigDecimal dev = val.subtract(avg);
            accum = accum.add(dev.pow(2));
            accum2 = accum2.add(dev);
        }
        BigDecimal accum2Sqr = accum2.pow(2);
        BigDecimal accum2SqrNorm = accum2Sqr.divide(len, RoundingMode.HALF_UP);
        BigDecimal var = accum.subtract(accum2SqrNorm).divide(len, RoundingMode.HALF_UP);
        return BigDecimal.valueOf(Math.sqrt(var.doubleValue()));
    }
}

Related

  1. secondsBigDecimalFromDuration(long s, int n)
  2. signum(final BigDecimal value)
  3. sine(BigDecimal x)
  4. sortByValues( Map map)
  5. sortMapByBDValue(Map oriMap)
  6. stddev(List numbers, boolean biasCorrected, MathContext context)
  7. stdDevMaxFromMapField(List> dataList, String fieldName, BigDecimal stdDevMultiplier)
  8. Str2BigDecimal(String a)
  9. str2BigDicimal(String strbigdecimal)