All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ml.regression.RegressorBase Maven / Gradle / Ivy

The newest version!
package ml.regression;

import datasets.VectorDouble;
import optimization.ISupervisedOptimizer;
import datastructs.IVector;
import datasets.DenseMatrixSet;
import maths.functions.IVectorRealFunction;

public class RegressorBase, HypothesisType extends IVectorRealFunction>> {



    /**
     * Train the regressor on the given dataset
     */
    public  OutputType train(DataSetType dataSet, VectorDouble y, ISupervisedOptimizer optimizer){
        return optimizer.optimize(dataSet, y, this.hypothesisType);
    }

    /**
     * Predict the value for the given input
     */
    public double predict(VectorDouble y){
        return (double) this.hypothesisType.evaluate(y);
    }

    /**
     * Predict the outputs over the given dataset
     */
    public VectorDouble predict(DataSetType dataSetType){

        VectorDouble predictions = new VectorDouble(dataSetType.m(), 0.0);

        for(int idx=0; idx r = dataSet.getRow(row);
            double error = y.get(row) - this.hypothesisType.evaluate(r);
            errs.set(row , error);
        }

        return errs;
    }

    /**
     * Protected constructor.
     */
    protected RegressorBase(HypothesisType hypothesis){
        this.hypothesisType = hypothesis;
    }


    /**
     * The hypothesis function assumed by the regressor
     */
    protected HypothesisType hypothesisType;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy