public abstract class AbstractNonlinearRegression extends BaseRegression
function(double[], double[])
- Function to be fitted. Expressed as a function of independent variables and fitting coefficients.defineVariables()
- Map the variables in function to attributes.defineCoefficients()
- Define names of fitting coefficientsUsage: *No options*
A simple example of these operations is shown in the source code of SimpleLinearModelExample
.
Currently, this code uses Powell's algorithm as implemented in Apache Common's Math Library: PowellOptimizer
Implemented Commands:
nonlinear guess <name> <guess> - Set the initial guess for a certain parameter
nonlinear maxiter <maxiter> - Set maximum number of iterations for fitting routines
AttributeSelector, trained, TrainingStats, validated, ValidationStats
Constructor and Description |
---|
AbstractNonlinearRegression() |
Modifier and Type | Method and Description |
---|---|
protected void |
addCoefficient(java.lang.String Name)
Adds a new fitting parameter to function (if not already defined).
|
protected void |
addCoefficient(java.lang.String Name,
java.lang.Double Guess)
Adds a new fitting parameter to function (if not already defined)
|
protected void |
addVariable(java.lang.String Name)
Define a variable to be used in the user function (if not already defined)
|
protected abstract void |
defineCoefficients()
Define the names and, if desired, initial guesses of fitting coefficients.
|
protected abstract void |
defineVariables()
Define which attributes are used by the function.
|
protected abstract double |
function(double[] variables,
double[] coeff)
Function defined by the user.
|
java.lang.String |
getCoefficientName(int index)
Return name of coefficient, given index
|
double |
getFittedCoefficient(int index)
Get the value of fitted coefficient
|
int |
getMaxIter()
Get the maximum number of iterations allowed
|
int |
getNFittingParameters()
Number of fitting parameters in a model.
|
java.lang.String |
getVariableName(int index) |
protected org.apache.commons.math3.analysis.MultivariateFunction |
makeObjectiveFunction(Dataset Data)
Generate an anonymous
MultivariateFunction object that calculates
the error between the equation described by the user as a function of the
fitting coefficients. |
int |
NCoefficients() |
protected int |
NVariables() |
java.lang.String |
printUsage()
Print out required format for options.
|
void |
run_protected(Dataset TrainData)
Run a model without checking if stuff is trained (use carefully)
|
java.lang.Object |
runCommand(java.util.List<java.lang.Object> Command)
Process some command described by a list of Objects.
|
java.lang.Object |
runNonlinearCommand(java.util.List<java.lang.Object> Command)
Handle commands for nonliear models
|
void |
setInitialGuess(java.lang.String Name,
double value)
Set the initial guess for a coefficient
|
void |
setMaxIterations(int MaxIter)
Define the maximum number of iterations allowed.
|
void |
setOptions(java.util.List Options)
Set any options for this object.
|
protected void |
train_protected(Dataset TrainData)
Train a model without evaluating performance
|
clone, doRobustRegression, getRobustRegressionQ, robustTraining, setRobustRegressionQ
about, crossValidate, crossValidate, crossValidate, done, externallyValidate, getAttributeSelector, getCitations, getFilter, getTrainTime, getValidationMethod, handleSetCommand, isTrained, isValidated, loadState, printCommand, printDescription, printModel_protected, printModel, printModelDescriptionDetails, resetModel, run, saveCommand, saveState, setAttributeSelector, setComponent, setFilter, train, train
public void setOptions(java.util.List Options) throws java.lang.Exception
Options
Options
- Array of options as Objects - can be null
java.lang.Exception
- if problem with inputspublic java.lang.String printUsage()
Options
public void setMaxIterations(int MaxIter)
MaxIter
- Desired maximum iteration count.public int getMaxIter()
public double getFittedCoefficient(int index)
index
- Index of coefficient to retrieveprotected org.apache.commons.math3.analysis.MultivariateFunction makeObjectiveFunction(Dataset Data)
MultivariateFunction
object that calculates
the error between the equation described by the user as a function of the
fitting coefficients.Data
- Dataset used to calculate the errorprotected abstract void defineVariables()
Variables are defined using the addVariable(java.lang.String)
function. *
In function(double[], double[])
these names are mapped to the variable
array
in the same order you define them.
protected void addVariable(java.lang.String Name)
Name
- Name of attribute to be include in equation.protected int NVariables()
public java.lang.String getVariableName(int index)
index
- Index of variable to be retrievedprotected abstract void defineCoefficients()
Coefficients are defined using the addCoefficient(java.lang.String)
function.
In function(double[], double[])
these names are mapped to the coeff
array
in the same order you define them.
protected void addCoefficient(java.lang.String Name)
Name
- Name of fitting parameterprotected void addCoefficient(java.lang.String Name, java.lang.Double Guess)
Name
- Name of fitting parameterGuess
- Initial guesspublic int NCoefficients()
public int getNFittingParameters()
AbstractRegressionModel
public java.lang.String getCoefficientName(int index)
index
- Index of coefficient topublic void setInitialGuess(java.lang.String Name, double value) throws java.lang.Exception
Name
- Name of coefficient to setvalue
- Desired initial guessjava.lang.Exception
- If there is no coefficient by that nameprotected abstract double function(double[] variables, double[] coeff)
variables
- Values of attributes used as independent variablescoeff
- Coefficients of equationprotected void train_protected(Dataset TrainData)
BaseModel
train_protected
in class BaseModel
TrainData
- Training datapublic void run_protected(Dataset TrainData)
BaseModel
run_protected
in class BaseModel
TrainData
- Training datapublic java.lang.Object runCommand(java.util.List<java.lang.Object> Command) throws java.lang.Exception
Commandable
runCommand
in interface Commandable
runCommand
in class BaseRegression
Command
- Command as a list of objectsjava.lang.Exception
- If something goes wrongpublic java.lang.Object runNonlinearCommand(java.util.List<java.lang.Object> Command) throws java.lang.Exception
Command
- java.lang.Exception