|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.models.AbstractModel
de.jstacs.models.CompositeModel
public class CompositeModel
This class is for modelling sequences by modelling the different positions of the each sequence by different models. For instance one can used this class to model a sequence of subsequences, where each subsequence is modelled by a different model.
Field Summary | |
---|---|
protected int[][] |
lengths
The length for each component. |
protected Model[] |
models
The models for the components |
protected int[][] |
starts
The start indices. |
Fields inherited from class de.jstacs.models.AbstractModel |
---|
alphabets, length |
Constructor Summary | |
---|---|
CompositeModel(AlphabetContainer alphabets,
int[] assignment,
Model... models)
|
|
CompositeModel(StringBuffer stringBuff)
The constructor for the Storable interface. |
Method Summary | |
---|---|
CompositeModel |
clone()
Follows the conventions of Object 's clone-method. |
void |
fromXML(StringBuffer representation)
This method should only be used by the constructor that works on StringBuffer. |
ResultSet |
getCharacteristics()
Returns some information characterizing or describing the current instance of the model. |
String |
getInstanceName()
Should return a short instance name such as iMM(0), BN(2), ... |
int[] |
getLengthOfModels()
This method returns the length of the models in the CompositeModel |
double |
getLogPriorTerm()
Returns a value that is proportional to the log of the prior. |
double |
getLogProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the logarithm of the probability of the given sequence given the model. |
byte |
getMaximalMarkovOrder()
This method returns the maximal used markov order if possible. |
Model[] |
getModels()
Returns the a deep copy of the models. |
int |
getNumberOfModels()
This method returns the number of models in the CompositeModel |
NumericalResultSet |
getNumericalCharacteristics()
Returns the subset of numerical values that are also returned by getCharacteristsics . |
double |
getProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the probability of the given sequence given the model. |
boolean |
isTrained()
Returns true if the model has been trained successfully, false otherwise. |
protected void |
set(AlphabetContainer abc)
This method should only be invoked by the method setNewAlphabetContainerInstance( AlphabetContainer ) and not be made public. |
String |
toString()
Should give a simple representation (text) of the model as String. |
StringBuffer |
toXML()
This method returns an XML-representation of an instance of the implementing class. |
void |
train(Sample data,
double[] weights)
Trains the Model object given the data as Sample using the specified weights. |
Methods inherited from class de.jstacs.models.AbstractModel |
---|
emitSample, getAlphabetContainer, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getPriorTerm, getProbFor, getProbFor, setNewAlphabetContainerInstance, train |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Model[] models
protected int[][] starts
protected int[][] lengths
Constructor Detail |
---|
public CompositeModel(AlphabetContainer alphabets, int[] assignment, Model... models) throws IllegalArgumentException, WrongAlphabetException, CloneNotSupportedException
alphabets
- the alphabetsassignment
- an array assigning each position to a modelmodels
- the single models
IllegalArgumentException
WrongAlphabetException
- if (the parts of) the alphabet does not match with the alphabets of the models
CloneNotSupportedException
- if the models could not be clonedpublic CompositeModel(StringBuffer stringBuff) throws NonParsableException
Storable
interface.
stringBuff
- the StringBuffer
NonParsableException
- if the StringBuffer is not parsableMethod Detail |
---|
public CompositeModel clone() throws CloneNotSupportedException
AbstractModel
Object
's clone-method.
clone
in interface Model
clone
in class AbstractModel
AbstractModel
(the member-AlphabetContainer
isn't deeply cloned since it is assumed to be immutable). The type of the returned object is defined by
the class X
directly inherited from AbstractModel
. Hence X
's
clone-method should work as:Object o = (X)super.clone();
2. all additional member variables of o
defined by X
that are not of simple data-types like int, double, ... , have to be deeply
copied 3. return o
CloneNotSupportedException
public ResultSet getCharacteristics() throws Exception
Model
ObjectResult
getCharacteristics
in interface Model
getCharacteristics
in class AbstractModel
Exception
- an Exception
is thrown if some of the characteristics could not be definedStorableResult
public String getInstanceName()
Model
public int[] getLengthOfModels()
public byte getMaximalMarkovOrder() throws UnsupportedOperationException
Model
getMaximalMarkovOrder
in interface Model
getMaximalMarkovOrder
in class AbstractModel
UnsupportedOperationException
- if the model can't give a proper answerpublic NumericalResultSet getNumericalCharacteristics() throws Exception
Model
getCharacteristsics
.
Exception
- an Exception
is thrown if some of the characteristics could not be definedpublic Model[] getModels() throws CloneNotSupportedException
AbstractModel
s
CloneNotSupportedException
public int getNumberOfModels()
public double getLogPriorTerm() throws Exception
Model
Exception
- if something went wrongModel.getPriorTerm()
public double getProbFor(Sequence sequence, int startpos, int endpos) throws NotTrainedException, Exception
Model
startpos
to endpos
(inclusive) should be returned.
length
and alphabets
define the type of data that can be modeled and therefore
both has to be checked.
sequence
- the sequencestartpos
- the start positionendpos
- the last position to be taken into account
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.
Exception
- an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos
> sequence.length, ...) by the modelpublic double getLogProbFor(Sequence sequence, int startpos, int endpos) throws NotTrainedException, Exception
Model
Model.getProbFor(Sequence, int, int)
getLogProbFor
in interface Model
getLogProbFor
in class AbstractModel
sequence
- the sequencestartpos
- the start positionendpos
- the last position to be taken into account
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.
Exception
- an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos
> sequence.length, ...) by the modelModel.getProbFor(Sequence, int, int)
public boolean isTrained()
Model
public void fromXML(StringBuffer representation) throws NonParsableException
AbstractModel
toXML()
.
fromXML
in class AbstractModel
representation
- the representation
NonParsableException
- if the StringBuffer is not parsable or the representation is conflictingAbstractModel.AbstractModel(StringBuffer)
public StringBuffer toXML()
Storable
public void train(Sample data, double[] weights) throws Exception
Model
Sample
using the specified weights. The weight
at position i belongs to the element at position i. So the array weight
should have the number of
sequences in the sample as dimension. (Optionally it is possible to use weight == null
if all
weights have the value one.)
data
- the given sequencesweights
- the weights of the elements, each weight should be non-negative
Exception
- an Exception should be thrown if the training did not succeed (e.g. the weights dimension of weights
and number of samples does not match).Sample.getElementAt(int)
,
Sample.ElementEnumerator
public String toString()
Model
toString
in interface Model
toString
in class Object
protected void set(AlphabetContainer abc)
AbstractModel
setNewAlphabetContainerInstance( AlphabetContainer )
and not be made public.
setNewAlphabetContainerInstance( AlphabetContainer )
,
e.g. setting a new AlphabetContainer instance for subcomponents.
set
in class AbstractModel
abc
- the new instance
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |