maths.errorfunctions.MSEVectorFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jstat Show documentation
Show all versions of jstat Show documentation
Java Library for Statistical Analysis.
The newest version!
package maths.errorfunctions;
import datastructs.I2DDataSet;
import datastructs.IVector;
import datasets.VectorDouble;
import maths.functions.IRegularizerFunction;
import maths.functions.IVectorRealFunction;
/**
* The Mean Square Error or MSE is defined as
* MSE = 1/N Sum_{i = 1}^N (y_i - \hat{y}_i)^2
*
* The \hat{y} value is modeled after the IVectorRealFunction passed
* to the object when instantiated
*/
public class MSEVectorFunction implements IVectorErrorRealFunction {
/**
* Constructor
*/
public MSEVectorFunction(IVectorRealFunction> hypothesis ){
this.hypothesis = hypothesis;
this.regularizerFunction = null;
}
/**
* Constructor
*/
public MSEVectorFunction(IVectorRealFunction> hypothesis, IRegularizerFunction regularizerFunction ){
this.hypothesis = hypothesis;
this.regularizerFunction = regularizerFunction;
}
/**
* Evaluate the error function using the given data, labels
* @param data
* @param labels
* @return
*/
@Override
public double evaluate(DataSetType data, VectorDouble labels){
if(data.m() != labels.size()){
throw new IllegalArgumentException("Invalid number of data points and labels vector size");
}
double result = 0.0;
for(int rowIdx=0; rowIdx VectorDouble gradients(DataSetType data, VectorDouble labels){
VectorDouble gradients = new VectorDouble(this.hypothesis.numCoeffs(), 0.0);
for(int rowIdx=0; rowIdx hypothesisGrads = this.hypothesis.coeffGradients(row);
for(int coeff=0; coeff> hypothesis;
IRegularizerFunction regularizerFunction;
}