de.jstacs.classifiers.differentiableSequenceScoreBased.gendismix
Class GenDisMixClassifier

java.lang.Object
  extended by de.jstacs.classifiers.AbstractClassifier
      extended by de.jstacs.classifiers.AbstractScoreBasedClassifier
          extended by de.jstacs.classifiers.differentiableSequenceScoreBased.ScoreClassifier
              extended by de.jstacs.classifiers.differentiableSequenceScoreBased.gendismix.GenDisMixClassifier
All Implemented Interfaces:
Storable, Cloneable
Direct Known Subclasses:
MSPClassifier

public class GenDisMixClassifier
extends ScoreClassifier

This class implements a classifier the optimizes the following function

\[f(\underline{\lambda}|C,D,\underline{\alpha},\underline{\beta})
The weights $\beta_i$ have to sum to 1. For special weights the optimization turns out to be well known Of course, there are also some very interesting cases with other weights.

Author:
Jens Keilwagen
See Also:
LearningPrinciple, LogGenDisMixFunction

Nested Class Summary
 
Nested classes/interfaces inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier
AbstractScoreBasedClassifier.DoubleTableResult
 
Field Summary
protected  double[] beta
          The weights that determine a point of the simplex that corresponds to the function that is optimized by this classifier.
protected  LogGenDisMixFunction function
          The function that is optimized in this classifier.
protected  LogPrior prior
          The prior that is used in this classifier.
 
Fields inherited from class de.jstacs.classifiers.differentiableSequenceScoreBased.ScoreClassifier
hasBeenOptimized, NOT_TRAINED_VALUE, params, score, sostream, template
 
Constructor Summary
  GenDisMixClassifier(GenDisMixClassifierParameterSet params, LogPrior prior, double[] beta, DifferentiableStatisticalModel... score)
          The main constructor.
protected GenDisMixClassifier(GenDisMixClassifierParameterSet params, LogPrior prior, double lastScore, double[] beta, DifferentiableSequenceScore... score)
          This constructor creates an instance and sets the value of the last (external) optimization.
  GenDisMixClassifier(GenDisMixClassifierParameterSet params, LogPrior prior, double lastScore, double[] beta, DifferentiableStatisticalModel... score)
          This constructor creates an instance and sets the value of the last (external) optimization.
  GenDisMixClassifier(GenDisMixClassifierParameterSet params, LogPrior prior, double genBeta, double disBeta, double priorBeta, DifferentiableStatisticalModel... score)
          This convenience constructor agglomerates the genBeta, disBeta, and priorBeta into an array and calls the main constructor.
  GenDisMixClassifier(GenDisMixClassifierParameterSet params, LogPrior prior, LearningPrinciple key, DifferentiableStatisticalModel... score)
          This convenience constructor creates an array of weights for an elementary learning principle and calls the main constructor.
  GenDisMixClassifier(StringBuffer xml)
          This is the constructor for Storable.
 
Method Summary
 GenDisMixClassifier clone()
           
static GenDisMixClassifier[] create(GenDisMixClassifierParameterSet params, LogPrior prior, double[] weights, DifferentiableStatisticalModel[]... functions)
          This method creates an array of GenDisMixClassifiers by using the cross-product of the given DifferentiableStatisticalModels.
protected  void extractFurtherClassifierInfosFromXML(StringBuffer xml)
          Extracts further information of a classifier from an XML representation.
protected  LogGenDisMixFunction getFunction(DataSet[] data, double[][] weights)
          Returns the function that should be optimized.
protected  StringBuffer getFurtherClassifierInfos()
          This method returns further information of a classifier as a StringBuffer.
 String getInstanceName()
          Returns a short description of the classifier.
 int getNumberOfThreads()
          This method returns the number of used threads while optimization.
protected  String getXMLTag()
          Returns the String that is used as tag for the XML representation of the classifier.
 void setNumberOfThreads(int threads)
          This method allows to set the number of threads used while optimization.
 void setPrior(LogPrior prior)
          This method set a new prior that should be used for optimization.
 void setWeights(double... beta)
          This method set the weights for the summand of the function.
 String toString()
           
 
Methods inherited from class de.jstacs.classifiers.differentiableSequenceScoreBased.ScoreClassifier
createStructure, createStructure, doOptimization, getClassifierAnnotation, getCurrentParameterSet, getDifferentiableSequenceScore, getDifferentiableSequenceScores, getLastScore, getNumericalCharacteristics, getScore, hasBeenOptimized, initUsingParameters, isInitialized, preoptimize, setOutputStream, train
 
Methods inherited from class de.jstacs.classifiers.AbstractScoreBasedClassifier
check, check, classify, classify, createDefaultClassWeights, getClassWeight, getClassWeights, getMultiClassScores, getNumberOfClasses, getPValue, getPValue, getResults, getScore, getScores, setClassWeights, setClassWeights, setThresholdClassWeights
 
Methods inherited from class de.jstacs.classifiers.AbstractClassifier
classify, evaluate, evaluate, getAlphabetContainer, getCharacteristics, getLength, toXML, train
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

prior

protected LogPrior prior
The prior that is used in this classifier.


function

protected LogGenDisMixFunction function
The function that is optimized in this classifier.


beta

protected double[] beta
The weights that determine a point of the simplex that corresponds to the function that is optimized by this classifier.

Constructor Detail

GenDisMixClassifier

protected GenDisMixClassifier(GenDisMixClassifierParameterSet params,
                              LogPrior prior,
                              double lastScore,
                              double[] beta,
                              DifferentiableSequenceScore... score)
                       throws CloneNotSupportedException
This constructor creates an instance and sets the value of the last (external) optimization. This constructor should only be used if it is clear that now generative part is used in the objective function.

Parameters:
params - the common parameters
prior - the prior for the parameters of the classifier
lastScore - the score of the last optimization
beta - the weights for log likelihood, log conditional likelihood and log prior
score - the functions for the classes
Throws:
CloneNotSupportedException - if an instance could not be clone

GenDisMixClassifier

public GenDisMixClassifier(GenDisMixClassifierParameterSet params,
                           LogPrior prior,
                           double lastScore,
                           double[] beta,
                           DifferentiableStatisticalModel... score)
                    throws CloneNotSupportedException
This constructor creates an instance and sets the value of the last (external) optimization.

Parameters:
params - the common parameters
prior - the prior for the parameters of the classifier
lastScore - the score of the last optimization
beta - the weights for log likelihood, log conditional likelihood and log prior
score - the functions for the classes
Throws:
CloneNotSupportedException - if an instance could not be clone

GenDisMixClassifier

public GenDisMixClassifier(GenDisMixClassifierParameterSet params,
                           LogPrior prior,
                           double[] beta,
                           DifferentiableStatisticalModel... score)
                    throws CloneNotSupportedException
The main constructor.

Parameters:
params - the common parameters
prior - the prior for the parameters of the classifier
beta - the weights for log likelihood, log conditional likelihood and log prior
score - the functions for the classes
Throws:
CloneNotSupportedException - if an instance could not be clone

GenDisMixClassifier

public GenDisMixClassifier(GenDisMixClassifierParameterSet params,
                           LogPrior prior,
                           double genBeta,
                           double disBeta,
                           double priorBeta,
                           DifferentiableStatisticalModel... score)
                    throws CloneNotSupportedException
This convenience constructor agglomerates the genBeta, disBeta, and priorBeta into an array and calls the main constructor.

Parameters:
params - the common parameters
prior - the prior for the parameters of the classifier
genBeta - the weight for the log likelihood
disBeta - the weight for the log conditional likelihood
priorBeta - the weight for the log prior
score - the functions for the classes
Throws:
CloneNotSupportedException - if an instance could not be clone

GenDisMixClassifier

public GenDisMixClassifier(GenDisMixClassifierParameterSet params,
                           LogPrior prior,
                           LearningPrinciple key,
                           DifferentiableStatisticalModel... score)
                    throws CloneNotSupportedException
This convenience constructor creates an array of weights for an elementary learning principle and calls the main constructor.

Parameters:
params - the common parameters
prior - the prior for the parameters of the classifier
key - the key for an elementary LearningPrinciple
score - the functions for the classes
Throws:
CloneNotSupportedException - if an instance could not be clone
See Also:
LearningPrinciple.getBeta(LearningPrinciple)

GenDisMixClassifier

public GenDisMixClassifier(StringBuffer xml)
                    throws NonParsableException
This is the constructor for Storable.

Parameters:
xml - the xml representation
Throws:
NonParsableException - if the representation could not be parsed.
Method Detail

clone

public GenDisMixClassifier clone()
                          throws CloneNotSupportedException
Overrides:
clone in class ScoreClassifier
Throws:
CloneNotSupportedException

getFunction

protected LogGenDisMixFunction getFunction(DataSet[] data,
                                           double[][] weights)
                                    throws Exception
Description copied from class: ScoreClassifier
Returns the function that should be optimized.

Specified by:
getFunction in class ScoreClassifier
Parameters:
data - the data sets
weights - the weights of the sequences of the data sets
Returns:
the function that should be optimized
Throws:
Exception - if something went wrong

setPrior

public void setPrior(LogPrior prior)
This method set a new prior that should be used for optimization. Since it could not be ensured that the classifier is optimal now isTrained will return false after invoking this method.

Parameters:
prior - the new prior

setWeights

public void setWeights(double... beta)
                throws IllegalArgumentException
This method set the weights for the summand of the function. Since it could not be ensured that the classifier is optimal now isTrained will return false after invoking this method.

Parameters:
beta - the weights
Throws:
IllegalArgumentException - if the weights array is not correct
See Also:
LearningPrinciple.getBeta(LearningPrinciple)

getXMLTag

protected String getXMLTag()
Description copied from class: AbstractClassifier
Returns the String that is used as tag for the XML representation of the classifier. This method is used by the methods AbstractClassifier.fromXML(StringBuffer) and AbstractClassifier.toXML().

Specified by:
getXMLTag in class ScoreClassifier
Returns:
the String that is used as tag for the XML representation of the classifier

getFurtherClassifierInfos

protected StringBuffer getFurtherClassifierInfos()
Description copied from class: AbstractClassifier
This method returns further information of a classifier as a StringBuffer. This method is used by the method AbstractClassifier.toXML() and should not be made public.

Overrides:
getFurtherClassifierInfos in class ScoreClassifier
Returns:
further information of a classifier as a StringBuffer
See Also:
AbstractClassifier.toXML()

extractFurtherClassifierInfosFromXML

protected void extractFurtherClassifierInfosFromXML(StringBuffer xml)
                                             throws NonParsableException
Description copied from class: AbstractClassifier
Extracts further information of a classifier from an XML representation. This method is used by the method AbstractClassifier.fromXML(StringBuffer) and should not be made public.

Overrides:
extractFurtherClassifierInfosFromXML in class ScoreClassifier
Parameters:
xml - the XML representation as StringBuffer
Throws:
NonParsableException - if the information could not be parsed out of the XML representation (the StringBuffer could not be parsed)
See Also:
AbstractClassifier.fromXML(StringBuffer)

create

public static GenDisMixClassifier[] create(GenDisMixClassifierParameterSet params,
                                           LogPrior prior,
                                           double[] weights,
                                           DifferentiableStatisticalModel[]... functions)
                                    throws CloneNotSupportedException
This method creates an array of GenDisMixClassifiers by using the cross-product of the given DifferentiableStatisticalModels.

Parameters:
params - the parameters that will be used in all classifiers
prior - the prior that will be used in all classifiers
weights - the weights that will be used in all classifiers
functions - the DifferentiableStatisticalModels
  1. functions[i] are the DifferentiableStatisticalModels that can be used for class i
  2. functions.length has to be at least 2
Returns:
an array of GenDisMixClassifiers
Throws:
CloneNotSupportedException - if the some item could not be cloned
See Also:
GenDisMixClassifier(GenDisMixClassifierParameterSet, LogPrior, double[], DifferentiableStatisticalModel[])

getInstanceName

public String getInstanceName()
Description copied from class: AbstractClassifier
Returns a short description of the classifier.

Overrides:
getInstanceName in class ScoreClassifier
Returns:
a short description of the classifier

getNumberOfThreads

public int getNumberOfThreads()
This method returns the number of used threads while optimization.

Returns:
the number of used threads while optimization

toString

public String toString()
Overrides:
toString in class Object

setNumberOfThreads

public void setNumberOfThreads(int threads)
                        throws SimpleParameter.IllegalValueException
This method allows to set the number of threads used while optimization.

Parameters:
threads - the number of threads
Throws:
SimpleParameter.IllegalValueException - if the number of threads is not possible