de.jstacs.classifier.scoringFunctionBased.logPrior
Class CompositeLogPrior

java.lang.Object
  extended by de.jstacs.algorithms.optimization.DifferentiableFunction
      extended by de.jstacs.classifier.scoringFunctionBased.logPrior.LogPrior
          extended by de.jstacs.classifier.scoringFunctionBased.logPrior.CompositeLogPrior
All Implemented Interfaces:
Function, Storable

public class CompositeLogPrior
extends LogPrior

This class implements a composite prior that can be used for NormalizableScoringFunction. The prior for each NormalizableScoringFunction should be the (transformed) prior of the corresponding generative model. So e.g. for a PWM one should use an product of Dirichlets. The prior is more or less implemented in the NormalizableScoringFunction. For the class variables the prior uses a (transformed) Dirichlet with hyperparameters equal to the ESS of the classes.

If this class uses only the free parameters the class implements a real prior the is normalized to 1. If it used all parameters the function does not have (and is in general) not normalized to 1. Fortunately this is no problem, since it can be shown the it makes no difference in the optimization.

Author:
Jan Grau, Jens Keilwagen
See Also:
NormalizableScoringFunction, NormalizableScoringFunction.addGradientOfLogPriorTerm(double[], int), NormalizableScoringFunction.getLogPriorTerm()

Field Summary
 
Fields inherited from class de.jstacs.classifier.scoringFunctionBased.logPrior.LogPrior
UNKNOWN
 
Constructor Summary
CompositeLogPrior()
          The main constructor.
CompositeLogPrior(StringBuffer xml)
          The constructor for the Storable interface.
 
Method Summary
 void addGradientFor(double[] params, double[] grad)
          Adds the gradient of the log-prior using the current parameters to a given vector.
 double evaluateFunction(double[] x)
          Evaluates the function at a certain vector (in mathematical sense) x.
 int getDimensionOfScope()
          Returns the dimension of the scope of the Function.
 String getInstanceName()
          Returns a short instance name.
 CompositeLogPrior getNewInstance()
          This method returns an empty new instance of the current prior.
 void set(boolean freeParameters, ScoringFunction... funs)
          Resets all pre-computed values to their initial values using the ScoringFunctions funs.
 StringBuffer toXML()
          Encodes the prior as an XML representation.
 
Methods inherited from class de.jstacs.classifier.scoringFunctionBased.logPrior.LogPrior
evaluateGradientOfFunction
 
Methods inherited from class de.jstacs.algorithms.optimization.DifferentiableFunction
findOneDimensionalMin
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeLogPrior

public CompositeLogPrior()
The main constructor.


CompositeLogPrior

public CompositeLogPrior(StringBuffer xml)
The constructor for the Storable interface.

Parameters:
xml - the StringBuffer
Method Detail

set

public void set(boolean freeParameters,
                ScoringFunction... funs)
         throws Exception
Description copied from class: LogPrior
Resets all pre-computed values to their initial values using the ScoringFunctions funs.

Overrides:
set in class LogPrior
Parameters:
freeParameters - the switch for using only the free parameters or all parameters in a ScoringFunction
funs - the ScoringFunctions for the prior
Throws:
Exception - if the ScoringFunctions could not be set

addGradientFor

public void addGradientFor(double[] params,
                           double[] grad)
                    throws EvaluationException
Description copied from class: LogPrior
Adds the gradient of the log-prior using the current parameters to a given vector.

Specified by:
addGradientFor in class LogPrior
Parameters:
params - the parameters
grad - the vector
Throws:
EvaluationException - if the gradient could not be evaluated

evaluateFunction

public double evaluateFunction(double[] x)
                        throws DimensionException,
                               EvaluationException
Description copied from interface: Function
Evaluates the function at a certain vector (in mathematical sense) x.

Parameters:
x - the current vector
Returns:
the evaluation of the function
Throws:
DimensionException - if dim(x) != n, with f: R^n -> R
EvaluationException - if there was something wrong during the evaluation of the function

getDimensionOfScope

public 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

getNewInstance

public CompositeLogPrior getNewInstance()
                                 throws CloneNotSupportedException
Description copied from class: LogPrior
This method returns an empty new instance of the current prior. The method works similar to clone, but does not clone ScoringFunction s that may be inside the instance. The ScoringFunctions must be set by an invocation of the method LogPrior.set(boolean, ScoringFunction...).

Specified by:
getNewInstance in class LogPrior
Returns:
a new empty instance of the prior
Throws:
CloneNotSupportedException - if something went wrong while cloning
See Also:
LogPrior.set(boolean, ScoringFunction...)

toXML

public StringBuffer toXML()
Description copied from class: LogPrior
Encodes the prior as an XML representation. It does not encode all information, since the method LogPrior.set(boolean, ScoringFunction...) has to be invoked after decoding.

Specified by:
toXML in interface Storable
Specified by:
toXML in class LogPrior
Returns:
the XML representation;

getInstanceName

public String getInstanceName()
Description copied from class: LogPrior
Returns a short instance name.

Specified by:
getInstanceName in class LogPrior
Returns:
a short instance name