Package regress

Class Regression

java.lang.Object
regress.Regression
All Implemented Interfaces:
Serializable

public class Regression extends Object implements Serializable
Class for multivariate polynomial regression models.
Since:
2004.05.22
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Regression(int dim, int deg)
    Create a multivariate polynomial regression model.
    Regression(table.TableMapper map, int deg)
    Create a multivariate polynomial regression model.
    Regression(table.Table atts, int deg)
    Create a multivariate polynomial regression model.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    aggregate(double[] vec, double wgt)
    Aggregate a data vector.
    double
    execute(double[] vec)
    Execute a regression function.
    double[]
    Get all regression coefficients.
    int[][]
    Get the exponents of all regression terms.
    table.Table
    Get the regression model as a table.
    table.Table
    getAsTable(boolean zeros)
    Get the regression model as a table.
    table.Table
    getAsTable(boolean zeros, double min)
    Get the regression model as a table.
    table.Table
    getAsTable(double min)
    Get the regression model as a table.
    double
    getCoeff(int i)
    Get a regression coefficient.
    int
    Get the number of regression coefficients.
    int
    Get the degree of the regression polynomial.
    table.Table
    Get the domains of the variables.
    int[]
    getExpos(int i)
    Get the exponents of a regression term.
    double
    Get the limit for the Tikhonov regularization.
    table.TableMapper
    Get the underlying table mapper.
    double
    Get the maximum for a logit transformation.
    double
    Get the minimum for a logit transformation.
    double
    Get the initial Tikhonov regularization.
    double
    Compute the sum of squared errors.
    double
    Get the sum of the data vector weights.
    int
    Get the number of variables (including the output).
    getVarName(int id)
    Get the name of a variable.
    static double
    logistic(double x)
    Compute logistic function.
    static void
    main(String[] args)
    Main function for testing basic functionality.
    static Regression
    parse(util.Scanner scan)
    Parse a regression description.
    static Regression
    parse(util.Scanner scan, table.Table atts)
    Parse a regression description.
    void
    setLim(double lim)
    Set the limit for the Tikhonov regularization.
    void
    setMax(double max)
    Set the maximum for a logit transformation.
    void
    setMin(double min)
    Set the minimum for a logit transformation.
    void
    setMinMax(double min, double max)
    Set the range for a logit transformation.
    void
    setReg(double reg)
    Set the initial Tikhonov regularization.
    void
    setRegLim(double reg, double lim)
    Set initial value and limit for the Tikhonov regularization.
    void
    Set up and solve the regression equation system.
    Describe the regression function.
    toString(double min)
    Describe the regression function.
    toString(String header)
    Describe the regression function.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Regression

      public Regression(table.Table atts, int deg) throws RegException
      Create a multivariate polynomial regression model.
      Parameters:
      atts - the underlying variables
      deg - the degree of the polynomial
      Throws:
      RegException - if there are too many regression terms
      Since:
      2004.05.22 (Christian Borgelt)
    • Regression

      public Regression(table.TableMapper map, int deg) throws RegException
      Create a multivariate polynomial regression model.
      Parameters:
      map - the underlying table mapper
      deg - the degree of the polynomial
      Throws:
      RegException - if there are too many regression terms
      Since:
      2007.05.16 (Christian Borgelt)
    • Regression

      public Regression(int dim, int deg) throws RegException
      Create a multivariate polynomial regression model.
      Parameters:
      dim - the number of variables of the data (including the output variable)
      deg - the degree of the polynomial
      Throws:
      RegException - if there are too many regression terms
      Since:
      2004.05.22 (Christian Borgelt)
  • Method Details

    • logistic

      public static double logistic(double x)
      Compute logistic function.
      Parameters:
      x - the function argument
      Returns:
      the logistic function value
      Since:
      2015.08.12 (Christian Borgelt)
    • getDomains

      public table.Table getDomains()
      Get the domains of the variables.

      Domains of the variables are available only if the regression model has been created from a table or a table mapper.

      Returns:
      the domains of the variables as a table
      Since:
      2007.05.16 (Christian Borgelt)
    • getMapper

      public table.TableMapper getMapper()
      Get the underlying table mapper.

      A table mapper is available only if the regression model has been created from a table or a table mapper.

      Returns:
      the underlying table mapper
      Since:
      2007.05.16 (Christian Borgelt)
    • setMin

      public void setMin(double min)
      Set the minimum for a logit transformation.
      Parameters:
      min - the minimum for a logit transformation
      Since:
      2015.08.12 (Christian Borgelt)
    • getMin

      public double getMin()
      Get the minimum for a logit transformation.
      Returns:
      the minimum for a logit transformation
      Since:
      2015.08.12 (Christian Borgelt)
    • setMax

      public void setMax(double max)
      Set the maximum for a logit transformation.
      Parameters:
      max - the maximum for a logit transformation
      Since:
      2007.04.12 (Christian Borgelt)
    • getMax

      public double getMax()
      Get the maximum for a logit transformation.
      Returns:
      the maximum for a logit transformation
      Since:
      2007.04.12 (Christian Borgelt)
    • setMinMax

      public void setMinMax(double min, double max)
      Set the range for a logit transformation.
      Parameters:
      min - the minimum for a logit transformation
      max - the maximum for a logit transformation
      Since:
      2015.08.12 (Christian Borgelt)
    • setReg

      public void setReg(double reg)
      Set the initial Tikhonov regularization.
      Parameters:
      reg - the initial regularization value
      Since:
      2015.08.12 (Christian Borgelt)
    • getReg

      public double getReg()
      Get the initial Tikhonov regularization.
      Returns:
      the initial regularization value
      Since:
      2015.08.12 (Christian Borgelt)
    • setLim

      public void setLim(double lim)
      Set the limit for the Tikhonov regularization.
      Parameters:
      lim - the limit for the regularization value
      Since:
      2015.08.12 (Christian Borgelt)
    • getLim

      public double getLim()
      Get the limit for the Tikhonov regularization.
      Returns:
      the limit for the regularization value
      Since:
      2015.08.12 (Christian Borgelt)
    • setRegLim

      public void setRegLim(double reg, double lim)
      Set initial value and limit for the Tikhonov regularization.
      Parameters:
      reg - the initial regularization value
      lim - the limit for the regularization value
      Since:
      2015.08.12 (Christian Borgelt)
    • getDegree

      public int getDegree()
      Get the degree of the regression polynomial.
      Returns:
      the degree of the regression polynomial
      Since:
      2004.05.22 (Christian Borgelt)
    • getVarCount

      public int getVarCount()
      Get the number of variables (including the output).
      Returns:
      the number of variables
      Since:
      2004.05.22 (Christian Borgelt)
    • getVarName

      public String getVarName(int id)
      Get the name of a variable.
      Parameters:
      id - the index of the variable
      Returns:
      the name of the i-th variable
      Since:
      2004.05.22 (Christian Borgelt)
    • getCoeffCount

      public int getCoeffCount()
      Get the number of regression coefficients.
      Returns:
      the number of regression coefficients
      Since:
      2004.05.22 (Christian Borgelt)
    • getCoeff

      public double getCoeff(int i)
      Get a regression coefficient.
      Parameters:
      i - the index of the regression coefficient
      Returns:
      the i-th regression coefficient
      Since:
      2004.05.22 (Christian Borgelt)
    • getAllCoeffs

      public double[] getAllCoeffs()
      Get all regression coefficients.
      Returns:
      the regression coefficients
      Since:
      2004.05.22 (Christian Borgelt)
    • getExpos

      public int[] getExpos(int i)
      Get the exponents of a regression term.
      Parameters:
      i - the index of the regression term
      Returns:
      the exponents of the i-th regression term
      Since:
      2007.04.13 (Christian Borgelt)
    • getAllExpos

      public int[][] getAllExpos()
      Get the exponents of all regression terms.
      Returns:
      the exponents of all regression terms
      Since:
      2004.05.22 (Christian Borgelt)
    • getSum

      public double getSum()
      Get the sum of the data vector weights.
      Returns:
      the sum of the data vector weights
      Since:
      2007.05.16 (Christian Borgelt)
    • aggregate

      public void aggregate(double[] vec, double wgt) throws RegException
      Aggregate a data vector.

      It is assumed that the value of the output/response variable is in the element with index getVarCount()-1.

      Parameters:
      vec - the data vector
      wgt - the weight of the data point
      Throws:
      RegException - if the logit transformation failed
      Since:
      2004.05.22 (Christian Borgelt)
    • solve

      public void solve() throws RegException
      Set up and solve the regression equation system.
      Throws:
      RegException - if the computation failed
      Since:
      2004.05.22 (Christian Borgelt)
    • getSSE

      public double getSSE()
      Compute the sum of squared errors.

      This functions computes the sum of squared errors from the regression coefficients and the Cholesky decomposition of the regression matrix. As this is numerically unstable, the result should be taken with a grain of salt.

      Returns:
      the sum of squared errors
      Since:
      2004.05.22 (Christian Borgelt)
    • execute

      public double execute(double[] vec)
      Execute a regression function.
      Parameters:
      vec - the data vector for which to execute the function
      Returns:
      the value of the regression function
      Since:
      2004.05.22 (Christian Borgelt)
    • getAsTable

      public table.Table getAsTable()
      Get the regression model as a table.
      Returns:
      the regression model as a table
      Since:
      2007.04.13 (Christian Borgelt)
    • getAsTable

      public table.Table getAsTable(boolean zeros)
      Get the regression model as a table.
      Parameters:
      zeros - whether to show zero exponents
      Returns:
      the regression model as a table
      Since:
      2007.05.18 (Christian Borgelt)
    • getAsTable

      public table.Table getAsTable(double min)
      Get the regression model as a table.
      Parameters:
      min - the minimum absolute value of a coefficient
      Returns:
      the regression model as a table
      Since:
      2007.03.19 (Christian Borgelt)
    • getAsTable

      public table.Table getAsTable(boolean zeros, double min)
      Get the regression model as a table.
      Parameters:
      zeros - whether to show zero exponents
      min - the minimum absolute value of a coefficient
      Returns:
      the regression model as a table
      Since:
      2007.05.18 (Christian Borgelt)
    • toString

      public String toString()
      Describe the regression function.
      Overrides:
      toString in class Object
      Returns:
      a description of the regression function
      Since:
      2004.05.22 (Christian Borgelt)
    • toString

      public String toString(String header)
      Describe the regression function.
      Parameters:
      header - the text to add as a header
      Returns:
      a description of the regression function
      Since:
      2004.05.22 (Christian Borgelt)
    • toString

      public String toString(double min)
      Describe the regression function.
      Parameters:
      min - the minimum absolute value of a coefficient
      Returns:
      a description of the regression function
      Since:
      2004.05.22 (Christian Borgelt)
    • parse

      public static Regression parse(util.Scanner scan) throws IOException
      Parse a regression description.
      Parameters:
      scan - the scanner to read the description from
      Returns:
      the parsed regression description
      Throws:
      IOException - if a read error occurs
      Since:
      2007.05.16 (Christian Borgelt)
    • parse

      public static Regression parse(util.Scanner scan, table.Table atts) throws IOException
      Parse a regression description.
      Parameters:
      scan - the scanner to read the description from
      atts - the variable domains as a table
      Returns:
      the parsed regression description
      Throws:
      IOException - if a read error occurs
      Since:
      2007.05.16 (Christian Borgelt)
    • main

      public static void main(String[] args)
      Main function for testing basic functionality.
      Parameters:
      args - the command line arguments
      Since:
      2004.06.02 (Christian Borgelt)