Java Square Calculate squaredLoss(double[] x, double[] y, double w_0, double w_1)

Here you can find the source of squaredLoss(double[] x, double[] y, double w_0, double w_1)

Description

This will return the squared loss of the given points

License

Apache License

Parameter

Parameter Description
x the x coordinates to use
y the y coordinates to use
w_0 the first weight
w_1 the second weight

Return

the squared loss of the given points

Declaration

public static double squaredLoss(double[] x, double[] y, double w_0, double w_1) 

Method Source Code

//package com.java2s;
/*//ww w .  jav a 2 s  .co  m
 *  * Copyright 2016 Skymind, Inc.
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.
 */

public class Main {
    /**
     * This will return the squared loss of the given
     * points
     *
     * @param x   the x coordinates to use
     * @param y   the y coordinates to use
     * @param w_0 the first weight
     * @param w_1 the second weight
     * @return the squared loss of the given points
     */
    public static double squaredLoss(double[] x, double[] y, double w_0, double w_1) {
        double sum = 0;
        for (int j = 0; j < x.length; j++) {
            sum += Math.pow((y[j] - (w_1 * x[j] + w_0)), 2);
        }
        return sum;
    }
}

Related

  1. square2array(byte[][] square)
  2. square2Index(long square)
  3. squareArea(final double side)
  4. squared(int x)
  5. squaredError(double[] vector1, double[] vector2)
  6. squaredNorm(final double[] vec)
  7. squareEntries(double[][] m)
  8. squarenessRatio(final double w, final double h)
  9. squareOfSumFirstN(long n)