de.jstacs.classifier.scoringFunctionBased
Class AbstractOptimizableFunction

java.lang.Object
  extended by de.jstacs.algorithms.optimization.DifferentiableFunction
      extended by de.jstacs.classifier.scoringFunctionBased.OptimizableFunction
          extended by de.jstacs.classifier.scoringFunctionBased.AbstractOptimizableFunction
All Implemented Interfaces:
Function
Direct Known Subclasses:
NormConditionalLogLikelihood

public abstract class AbstractOptimizableFunction
extends OptimizableFunction

This class extends OptimizableFunction and implements some common methods.

Author:
Jens Keilwagen

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.classifier.scoringFunctionBased.OptimizableFunction
OptimizableFunction.KindOfParameter
 
Field Summary
protected  int cl
          The number of different classes.
protected  double[] clazz
          The class parameters.
protected  Sample[] data
          The data that is used to evaluate this function.
protected  boolean freeParams
          Indicates whether only the free parameters or all should be used.
protected  double[] logClazz
          The logarithm of the class parameters.
protected  boolean norm
          Indicates whether a normalization should be done or not.
protected  int[] shortcut
          These shortcuts indicate the beginning of a new part in the parameter vector.
protected  double[] sum
          The sums of the weighted data per class and additional the total weight sum.
protected  double[][] weights
          The weights for the data.
 
Constructor Summary
protected AbstractOptimizableFunction(Sample[] data, double[][] weights, boolean norm, boolean freeParams)
          The constructor creates an instance using the given weighted data.
 
Method Summary
 void addTermToClassParameter(int classIndex, double term)
          This method adds the term to the class parameter of the class with index classIndex.
 double[] getClassParams(double[] params)
          Returns from the complete vector of parameters those that are for the classes.
 Sample[] getData()
          Returns the data for each class used in this OptimizableFunction.
 int getDimensionOfScope()
          Returns the dimension of the scope of the Function.
protected  int getNumberOfStarts(ScoringFunction[] score)
          Returns the number of recommended starts.
 double[] getParameters(OptimizableFunction.KindOfParameter kind)
          Returns some parameters that can be used for instance as start parameters.
abstract  void getParameters(OptimizableFunction.KindOfParameter kind, double[] erg)
          This method enables the user to get the parameters without creating a new array.
 double[][] getSequenceWeights()
          Returns the weights for each Sequence for each class used in this OptimizableFunction.
 void setParams(double[] params)
          Checks the dimension and sets the class parameters.
 
Methods inherited from class de.jstacs.classifier.scoringFunctionBased.OptimizableFunction
getNumberOfStarts, reset
 
Methods inherited from class de.jstacs.algorithms.optimization.DifferentiableFunction
evaluateGradientOfFunction, findOneDimensionalMin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jstacs.algorithms.optimization.Function
evaluateFunction
 

Field Detail

shortcut

protected int[] shortcut
These shortcuts indicate the beginning of a new part in the parameter vector.


data

protected Sample[] data
The data that is used to evaluate this function.


weights

protected double[][] weights
The weights for the data.

See Also:
data

clazz

protected double[] clazz
The class parameters.


logClazz

protected double[] logClazz
The logarithm of the class parameters.

See Also:
clazz

sum

protected double[] sum
The sums of the weighted data per class and additional the total weight sum.

See Also:
data, weights

cl

protected int cl
The number of different classes.


norm

protected boolean norm
Indicates whether a normalization should be done or not.


freeParams

protected boolean freeParams
Indicates whether only the free parameters or all should be used.

Constructor Detail

AbstractOptimizableFunction

protected AbstractOptimizableFunction(Sample[] data,
                                      double[][] weights,
                                      boolean norm,
                                      boolean freeParams)
                               throws IllegalArgumentException,
                                      WrongAlphabetException
The constructor creates an instance using the given weighted data.

Parameters:
data - the data
weights - the weights
norm - the switch for using the normalization (division by the number of sequences)
freeParams - the switch for using only the free parameters
Throws:
IllegalArgumentException - if the number of classes is not correct
WrongAlphabetException - if different alphabets are used
Method Detail

getDimensionOfScope

public final int getDimensionOfScope()
Description copied from interface: Function
Returns the dimension of the scope of the Function.

Returns:
the dimension of the scope: n with f: R^n -> R

getParameters

public abstract void getParameters(OptimizableFunction.KindOfParameter kind,
                                   double[] erg)
                            throws Exception
This method enables the user to get the parameters without creating a new array.

Parameters:
kind - the kind of the class parameters to be returned in erg
erg - the array for the start parameters
Throws:
Exception - if the array is null or does not have the correct length
See Also:
OptimizableFunction.getParameters(KindOfParameter)

getParameters

public final double[] getParameters(OptimizableFunction.KindOfParameter kind)
                             throws Exception
Description copied from class: OptimizableFunction
Returns some parameters that can be used for instance as start parameters.

Specified by:
getParameters in class OptimizableFunction
Parameters:
kind - the kind of the class parameters that will be returned
Returns:
some start parameters
Throws:
Exception - if something went wrong

setParams

public void setParams(double[] params)
               throws DimensionException
Checks the dimension and sets the class parameters.

Specified by:
setParams in class OptimizableFunction
Parameters:
params - the current values
Throws:
DimensionException - if the dimension of the current values does not match with the dimension of the internal parameters

getClassParams

public final double[] getClassParams(double[] params)
Description copied from class: OptimizableFunction
Returns from the complete vector of parameters those that are for the classes.

Specified by:
getClassParams in class OptimizableFunction
Parameters:
params - the current parameters
Returns:
the parameters for the classes

getNumberOfStarts

protected final int getNumberOfStarts(ScoringFunction[] score)
Returns the number of recommended starts.

Parameters:
score - the underlying scoring functions
Returns:
the number of recommended starts
See Also:
OptimizableFunction.getNumberOfStarts(), ScoringFunction.getNumberOfRecommendedStarts()

addTermToClassParameter

public final void addTermToClassParameter(int classIndex,
                                          double term)
Description copied from class: OptimizableFunction
This method adds the term to the class parameter of the class with index classIndex.

Specified by:
addTermToClassParameter in class OptimizableFunction
Parameters:
classIndex - the index of the class
term - the term to be added to the class parameter

getData

public Sample[] getData()
Description copied from class: OptimizableFunction
Returns the data for each class used in this OptimizableFunction.

Specified by:
getData in class OptimizableFunction
Returns:
the data for each class
See Also:
OptimizableFunction.getSequenceWeights()

getSequenceWeights

public double[][] getSequenceWeights()
Description copied from class: OptimizableFunction
Returns the weights for each Sequence for each class used in this OptimizableFunction.

Specified by:
getSequenceWeights in class OptimizableFunction
Returns:
the weights for each Sequence and each class
See Also:
OptimizableFunction.getData()