/** * This returns the minimized loss values for a given vector. * It is assumed that the x, y pairs are at * vector[i], vector[i+1] * * @param vector the vector of numbers to getFromOrigin the weights for * @return a double array with w_0 and w_1 are the associated indices. */ public static double[] weightsFor(List<Double> vector) { /* split coordinate system */ List<double[]> coords = coordSplit(vector); /* x vals */ double[] x = coords.get(0); /* y vals */ double[] y = coords.get(1); double meanX = sum(x) / x.length; double meanY = sum(y) / y.length; double sumOfMeanDifferences = sumOfMeanDifferences(x, y); double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x); double w_1 = sumOfMeanDifferences / xDifferenceOfMean; double w_0 = meanY - (w_1) * meanX; //double w_1=(n*sumOfProducts(x,y) - sum(x) * sum(y))/(n*sumOfSquares(x) - Math.pow(sum(x),2)); // double w_0=(sum(y) - (w_1 * sum(x)))/n; double[] ret = new double[vector.size()]; ret[0] = w_0; ret[1] = w_1; return ret; }//end weightsFor
/** * This returns the minimized loss values for a given vector. * It is assumed that the x, y pairs are at * vector[i], vector[i+1] * * @param vector the vector of numbers to getFromOrigin the weights for * @return a double array with w_0 and w_1 are the associated indices. */ public static double[] weightsFor(double[] vector) { /* split coordinate system */ List<double[]> coords = coordSplit(vector); /* x vals */ double[] x = coords.get(0); /* y vals */ double[] y = coords.get(1); double meanX = sum(x) / x.length; double meanY = sum(y) / y.length; double sumOfMeanDifferences = sumOfMeanDifferences(x, y); double xDifferenceOfMean = sumOfMeanDifferencesOnePoint(x); double w_1 = sumOfMeanDifferences / xDifferenceOfMean; double w_0 = meanY - (w_1) * meanX; double[] ret = new double[vector.length]; ret[0] = w_0; ret[1] = w_1; return ret; }//end weightsFor
/** * This returns the minimized loss values for a given vector. * It is assumed that the x, y pairs are at * vector[i], vector[i+1] * @param vector the vector of numbers to getFromOrigin the weights for * @return a double array with w_0 and w_1 are the associated indices. */ public static double[] weightsFor(double[] vector) { /* split coordinate system */ List<double[]> coords=coordSplit(vector); /* x vals */ double[] x=coords.get(0); /* y vals */ double[] y=coords.get(1); double meanX=sum(x)/x.length; double meanY=sum(y)/y.length; double sumOfMeanDifferences=sumOfMeanDifferences(x,y); double xDifferenceOfMean=sumOfMeanDifferencesOnePoint(x); double w_1=sumOfMeanDifferences/xDifferenceOfMean; double w_0=meanY - (w_1) * meanX; double[] ret = new double[vector.length]; ret[0]=w_0; ret[1]=w_1; return ret; }//end weightsFor
/** * This returns the minimized loss values for a given vector. * It is assumed that the x, y pairs are at * vector[i], vector[i+1] * @param vector the vector of numbers to getFromOrigin the weights for * @return a double array with w_0 and w_1 are the associated indices. */ public static double[] weightsFor(List<Double> vector) { /* split coordinate system */ List<double[]> coords=coordSplit(vector); /* x vals */ double[] x=coords.get(0); /* y vals */ double[] y=coords.get(1); double meanX=sum(x)/x.length; double meanY=sum(y)/y.length; double sumOfMeanDifferences=sumOfMeanDifferences(x,y); double xDifferenceOfMean=sumOfMeanDifferencesOnePoint(x); double w_1=sumOfMeanDifferences/xDifferenceOfMean; double w_0=meanY - (w_1) * meanX; //double w_1=(n*sumOfProducts(x,y) - sum(x) * sum(y))/(n*sumOfSquares(x) - Math.pow(sum(x),2)); // double w_0=(sum(y) - (w_1 * sum(x)))/n; double[] ret = new double[vector.size()]; ret[0]=w_0; ret[1]=w_1; return ret; }//end weightsFor