Here you can find the source of squaredLoss(double[] x, double[] y, double w_0, double w_1)
Parameter | Description |
---|---|
x | the x coordinates to use |
y | the y coordinates to use |
w_0 | the first weight |
w_1 | the second weight |
public static double squaredLoss(double[] x, double[] y, double w_0, double w_1)
//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; } }