Java Array Sum Square sumSquared(double[] data)

Here you can find the source of sumSquared(double[] data)

Description

sum Squared

License

Open Source License

Declaration

public static double sumSquared(double[] data) 

Method Source Code

//package com.java2s;
/**// w w w.j a  v  a2  s .  c  o m
 * Copyright 2004-2006 DFKI GmbH.
 * All Rights Reserved.  Use is subject to license terms.
 *
 * This file is part of MARY TTS.
 *
 * MARY TTS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static double sumSquared(double[] data) {
        return sumSquared(data, 0.0);
    }

    public static double sumSquared(double[] data, double term) {
        double sum = 0.0;
        for (int i = 0; i < data.length; i++) {
            if (Double.isNaN(data[i]))
                continue;
            sum += (data[i] + term) * (data[i] + term);
        }
        return sum;
    }

    public static double sumSquared(double[] data, int startInd, int endInd) {
        return sumSquared(data, startInd, endInd, 0.0);
    }

    public static double sumSquared(double[] data, int startInd, int endInd, double term) {
        double sum = 0.0;
        for (int i = startInd; i <= endInd; i++)
            sum += (data[i] + term) * (data[i] + term);

        return sum;
    }
}

Related

  1. sumOfSquares(int numberOfTerms)
  2. sumOfSquares(Number[] array)
  3. sumSq(double... values)
  4. sumSq(double[] a)
  5. sumSqual(byte[] b)
  6. sumSquared(double[] data, double term)
  7. SumSquared(Object in)
  8. sumSquaredError(double[] a, double[] b)
  9. sumSquareDev(double[] values, double target)