|
||||||||||
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.mixture.AbstractMixtureModel
public abstract class AbstractMixtureModel
This is the abstract class for all kinds of mixture models. It enables the user to train the parameters using
AbstractMixtureModel.Algorithm.EM
or AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
. If this instance is trained using
GIBBS_SAMPLING
the internal models that will be adjusted have to implement
GibbsSamplingComponent
. If you use Gibbs sampling temporary files will be created in the Java temp
folder. These files will be deleted if no reference to the current instance exists and the Garbage collector is
called. Therefore it is recommended to call the Garbage collector explicitly at the end of any application.
The model stores a reference to the last sample used in train. This enables the user to estimate the parameters
iteratively beginning with the current set of parameters. Therefore you can use the method
continueIterations(double[], double[][], int, int)
.
The method setOutputStream(OutputStream)
enables the user to get comments from the
train(Sample, double[])
method or to repress them.
The method getScoreForBestRun()
enables the user to optimize different instances of the
same model (clone()
) using the EM-algorithm on different CPUs, to compare the results and
to select the best trained model. This might be useful to get the results faster (measured in real time).
The reference to the internal sample is not stored if the model is stored in a StringBuffer. So you can use these
methods only after training the parameters after (re)creating a model.
GibbsSamplingComponent
,
System.gc()
Nested Class Summary | |
---|---|
static class |
AbstractMixtureModel.Algorithm
This enum defines the different types of algorithms that can be used in a AbstractMixtureModel |
static class |
AbstractMixtureModel.Parameterization
This enum defines the different types of parameterization for a probability that can be used in an AbstractMixtureModel . |
Field Summary | |
---|---|
protected AbstractMixtureModel.Algorithm |
algorithm
The type of algorithm. |
protected boolean |
algorithmHasBeenRun
A switch which indicates that the algorithm has been run for determining the parameters. |
protected Model[] |
alternativeModel
The alternative models for the EM. |
protected BurnInTest |
burnInTest
The BurnInTest that is used to stop the sampling |
protected double[] |
componentHyperParams
The hyperparameters for estimating the probabilities of the components |
protected double[] |
compProb
This array is used while training to avoid creating many new objects. |
protected int[] |
counter
The current index of the parameter set while adjustment (optimization). |
protected int |
dimension
The number of dimensions |
protected boolean |
estimateComponentProbs
The switch for estimating the component probabilities or not. |
protected File[] |
file
The file in which the component probabilities are stored. |
protected BufferedReader |
filereader
Reading component probabilities from a file. |
protected BufferedWriter |
filewriter
Saving component probabilities in a file. |
protected int |
initialIteration
The number of initial iterations. |
protected double[] |
logWeights
The log probabilities for each component. |
protected Model[] |
model
The model for the sequences. |
protected boolean[] |
optimizeModel
A switch for each model whether to optimize/adjust or not. |
protected Sample[] |
sample
The sample that was used in the last training. |
protected int |
samplingIndex
The current index of the sampling |
protected SafeOutputStream |
sostream
This is the stream for writing information while training. |
protected int |
starts
The number of starts |
protected int |
stationaryIteration
The number of iterations of the Gibbs Sampler |
protected double[] |
weights
The probabilities for each component. |
Fields inherited from class de.jstacs.models.AbstractModel |
---|
alphabets, length |
Constructor Summary | |
---|---|
protected |
AbstractMixtureModel(int length,
Model[] models,
boolean[] optimizeModel,
int dimension,
int starts,
boolean estimateComponentProbs,
double[] componentHyperParams,
double[] weights,
AbstractMixtureModel.Algorithm algorithm,
double alpha,
double eps,
AbstractMixtureModel.Parameterization parametrization,
int initialIteration,
int stationaryIteration,
BurnInTest burnInTest)
Creates a new AbstractMixtureModel. |
|
AbstractMixtureModel(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
boolean |
algorithmHasBeenRun()
This method indicates whether the parameters of the model has been determined by the internal algorithm. |
protected void |
checkLength(int index,
int l)
This method checks if the length l of the model with index index is
capable for the current instance. |
protected void |
checkModelsForGibbsSampling()
This method can be used to check whether the necessary models have implemented the GibbsSamplingComponent . |
AbstractMixtureModel |
clone()
Follows the conventions of Object 's clone-method. |
protected double |
continueIterations(double[] dataWeights,
double[][] seqweights)
This method will run the train algorithm for the current model on the internal sample. |
protected void |
continueIterations(double[] dataWeights,
double[][] seqweights,
int iterations,
int start)
This method will run the train algorithm for the current model on the internal sample. |
protected double[][] |
createSeqWeightsArray()
Creates an array that can be used for weighting sequences in the algorithm. |
protected abstract double[][] |
doFirstIteration(double[] dataWeights,
MultivariateRandomGenerator m,
MRGParams[] params)
This method will do the first step in the train algorithm for the current model on the internal sample. |
protected double[][] |
doFirstIteration(Sample data,
double[] dataWeights)
This method will do the first step in the train algorithm for the current model. |
protected double[][] |
doFirstIteration(Sample data,
double[] dataWeights,
MultivariateRandomGenerator m,
MRGParams[] params)
This method will do the first step in the train algorithm for the current model. |
static int |
draw(double[] w,
int start)
This method draws an index of an array corresponding to the probabilities encoded in the entries of the array. |
Sample |
emitSample(int n,
int... lengths)
This method returns a Sample object containing artificial sequence(s). |
protected abstract Sequence[] |
emitSampleUsingCurrentParameterSet(int n,
int... lengths)
The method returns an array of sequences using the current parameter set. |
protected void |
extendSampling(int sampling)
This method prepares the model to extend a existing sampling. |
protected void |
extractFurtherInformation(StringBuffer xml)
This method is used in the subclasses to extract further information from the xml representation and to set these as values of the instance. |
protected void |
finalize()
|
protected 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. |
protected StringBuffer |
getFurtherInformation()
This method is used in the subclasses to append further information at the xml representation. |
int |
getIndexOfMaximalComponentFor(Sequence s)
Returns the index i of the component with
P(i|s) |
String |
getInstanceName()
Should return a short instance name such as iMM(0), BN(2), ... |
double |
getLogPriorTerm()
Returns a value that is proportional to the log of the prior. |
protected double |
getLogPriorTermForComponentProbs()
This method computes the part of the prior that comes from the component probabilities. |
double |
getLogProbFor(int component,
Sequence s)
Returns the log probability for the sequence and the given component. |
double[] |
getLogProbFor(Sample data)
This method computes the logarithm of the probabilities of all sequences in the given sample. |
double |
getLogProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the logarithm of the probability of the given sequence given the model. |
protected abstract double |
getLogProbUsingCurrentParameterSetFor(int component,
Sequence s,
int start,
int end)
Returns the log probability for the sequence and the given component using the current parameter set. |
Model |
getModel(int i)
Returns the a deep copy of the i-th model. |
Model[] |
getModels()
Returns the a deep copy of the models. |
protected MultivariateRandomGenerator |
getMRG()
This method creates the multivariate random generator that will be used while initialization. |
protected MRGParams |
getMRGParams()
This method creates the parameters used in a multivariate random generator while initialisation. |
String |
getNameOfAlgorithm()
Returns the name of the used algorithm. |
protected void |
getNewComponentProbs(double[] weights)
Estimates the weights. |
protected void |
getNewParameters(int iteration,
double[][] seqWeights,
double[] w)
This method trains the internal models on the internal sample and the given weights. |
protected void |
getNewParametersForModel(int modelIndex,
int iteration,
int sampleIndex,
double[] seqWeights)
This method trains the internal model with index modelIndex on the internal sample and the given weights. |
protected abstract double |
getNewWeights(double[] dataWeights,
double[] w,
double[][] seqweights)
Computes sequence weights and returns the score. |
int |
getNumberOfComponents()
Returns the number of components the are modeled by this AbstractMixtureModel. |
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. |
double |
getScoreForBestRun()
Returns the value of optimized function from the best run of the last training |
double[] |
getWeights()
This method returns the a deep copy of the weights for each component. |
protected void |
initModelForSampling(int starts)
This method initializes the model for the sampling. |
protected void |
initWithPrior(double[] w)
This method sets the initial weights before counting the usage of each component. |
protected boolean |
isInSamplingMode()
This method returns true if the object is currently used in a sampling, otherwise
false . |
boolean |
isTrained()
Returns true if the model has been trained successfully, false otherwise. |
protected double |
iterate(int start,
double[] dataWeights,
MultivariateRandomGenerator m,
MRGParams[] params)
This method runs the train algorithm for the current model and the internal data set. |
double |
iterate(Sample data,
double[] dataWeights,
MultivariateRandomGenerator m,
MRGParams[] params)
This method runs the train algorithm for the current model. |
static int |
max(double[] w,
int start,
int end)
This method returns the index of a maximal entry in the array w betwwen index start
and end . |
protected double |
modifyWeights(double[] w)
This method modifies the computed weights for one sequence and returns the score. |
protected boolean |
parseNextParameterSet()
This method allows the user to parse the next set of parameters (from a file). |
protected boolean |
parseParameterSet(int sampling,
int burnInIteration)
This method allows the user to parse the set of parameters with index burnInIteration of a specific
sampling (from a file). |
protected void |
samplingStopped()
This method is the opposite of the method initModelForSampling . |
protected void |
set(AlphabetContainer abc)
This method should only be invoked by the method setNewAlphabetContainerInstance( AlphabetContainer ) and not be made public. |
void |
setAlpha(double alpha)
Sets the parameter of the Dirichlet which is used when you invoke train to init the gammas. |
void |
setOutputStream(OutputStream o)
Sets the OutputStream that is used e.g. for writing information while training. |
void |
setThreshold(double eps)
Sets the threshold for terminating the train algorithm. |
protected abstract void |
setTrainData(Sample data)
This method is invoked by the train method and set for a given sample the sample that should be used for train. |
protected void |
setWeights(double... weights)
Sets the weights. |
protected void |
swap()
This method swaps the current component models with the alternative model. |
StringBuffer |
toXML()
This method returns an XML-representation of an instance of the implementing class. |
void |
train(Sample data,
double[] dataWeights)
Trains the Model object given the data as Sample using the specified weights. |
Methods inherited from class de.jstacs.models.AbstractModel |
---|
getAlphabetContainer, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getMaximalMarkovOrder, getPriorTerm, getProbFor, getProbFor, setNewAlphabetContainerInstance, train |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface de.jstacs.models.Model |
---|
toString |
Field Detail |
---|
protected double[] weights
protected double[] logWeights
protected double[] componentHyperParams
protected Model[] model
protected Model[] alternativeModel
protected int starts
protected int dimension
protected SafeOutputStream sostream
protected Sample[] sample
toXML
protected boolean estimateComponentProbs
protected boolean[] optimizeModel
protected AbstractMixtureModel.Algorithm algorithm
protected boolean algorithmHasBeenRun
protected int initialIteration
protected int stationaryIteration
protected BurnInTest burnInTest
BurnInTest
that is used to stop the sampling
protected BufferedWriter filewriter
protected BufferedReader filereader
protected File[] file
protected int[] counter
protected int samplingIndex
protected double[] compProb
Constructor Detail |
---|
protected AbstractMixtureModel(int length, Model[] models, boolean[] optimizeModel, int dimension, int starts, boolean estimateComponentProbs, double[] componentHyperParams, double[] weights, AbstractMixtureModel.Algorithm algorithm, double alpha, double eps, AbstractMixtureModel.Parameterization parametrization, int initialIteration, int stationaryIteration, BurnInTest burnInTest) throws CloneNotSupportedException, IllegalArgumentException, WrongAlphabetException
length
- the length used in this modelmodels
- the single models building the AbstractMixtureModel, if the model is trained using
AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
the models that will be adjusted have to implement
GibbsSamplingComponent
optimizeModel
- an array of switches to determine whether an model should be optimized or notdimension
- the number of componentsstarts
- the number of times the algorithm will be started in the train method, at least 1estimateComponentProbs
- the switch for estimating the component probabilities in the algorithm or to hold them fixed;
if the component parameters are fixed, the values of weights
will be used, otherwise
the componentHyperParams
will be incorporated in the adjustmentcomponentHyperParams
- the hyperparameters for the component assignment prior,
estimateComponentProbs == true
null
or has to have length dimension
null
or an array with all values zero (0) than ML
parameterization
weights
- null
or the weights for the components (than weights.length == dimension
)algorithm
- either AbstractMixtureModel.Algorithm.EM
or AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
alpha
- only for AbstractMixtureModel.Algorithm.EM
train
to initialze
the gammas. It is recommended to use alpha = 1
(uniform distribution on a simplex).eps
- only for AbstractMixtureModel.Algorithm.EM
parametrization
- only for AbstractMixtureModel.Algorithm.EM
AbstractMixtureModel.Parameterization.THETA
or AbstractMixtureModel.Parameterization.LAMBDA
LAMBDA
initialIteration
- only for AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
stationaryIteration/starts
)stationaryIteration
- only for AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
burnInTest
- only for AbstractMixtureModel.Algorithm.GIBBS_SAMPLING
IllegalArgumentException
- if
length
dimension < 1
weights != null && weights.length != dimension
weights != null
and it exists an i
where weights[i] < 0
starts < 1
WrongAlphabetException
- if not all models
work on the same alphabet
CloneNotSupportedException
- if the models
can not be clonedpublic AbstractMixtureModel(StringBuffer xml) throws NonParsableException
Storable
.
xml
- the StringBuffer containing the model
NonParsableException
- if the StringBuffer can not be parsedMethod Detail |
---|
public AbstractMixtureModel 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
protected MultivariateRandomGenerator getMRG()
getMRGParams()
protected MRGParams getMRGParams()
getMRG()
public void train(Sample data, double[] dataWeights) 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 sequencesdataWeights
- 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
protected void swap()
protected abstract void setTrainData(Sample data) throws Exception
data
- the given sample
Exception
protected double[][] createSeqWeightsArray()
public double iterate(Sample data, double[] dataWeights, MultivariateRandomGenerator m, MRGParams[] params) throws Exception
data
- the sample of sequencesdataWeights
- the weights for each sequence of null
m
- the random generator for initiating the algorithmparams
- the parameters for the sequences
Exception
- if something went wrongdoFirstIteration(Sample, double[], MultivariateRandomGenerator, MRGParams[])
,
continueIterations(double[], double[][])
,
continueIterations(double[], double[][], int, int)
protected double iterate(int start, double[] dataWeights, MultivariateRandomGenerator m, MRGParams[] params) throws Exception
start
- the index of the trainingdataWeights
- the weights for each sequence of null
m
- the random generator for initiating the algorithmparams
- the parameters for the sequences
Exception
- if something went wrongdoFirstIteration(Sample, double[], MultivariateRandomGenerator, MRGParams[])
,
continueIterations(double[], double[][])
,
continueIterations(double[], double[][], int, int)
protected double[][] doFirstIteration(Sample data, double[] dataWeights) throws Exception
data
- the sample of sequencesdataWeights
- null
or the weights of each element of the sample
Exception
- if something went wrongprotected double[][] doFirstIteration(Sample data, double[] dataWeights, MultivariateRandomGenerator m, MRGParams[] params) throws Exception
data
- the sample of sequencesdataWeights
- null
or the weights of each element of the samplem
- the multivariate random generatorparams
- the parameters for the multivariate random generator
Exception
- if something went wrongprotected abstract double[][] doFirstIteration(double[] dataWeights, MultivariateRandomGenerator m, MRGParams[] params) throws Exception
dataWeights
- null
or the weights of each element of the samplem
- the multivariate random generatorparams
- the parameters for the multivariate random generator
Exception
- if something went wrongprotected double continueIterations(double[] dataWeights, double[][] seqweights) throws Exception
dataWeights
- null
or the weights of each element of the internal sample (last sample the AbstractMixtureModel was
trained on)seqweights
- null
or an array for weighting the sequences, see createSeqWeightsArray()
Exception
- if something went wrongprotected void continueIterations(double[] dataWeights, double[][] seqweights, int iterations, int start) throws Exception
dataWeights
- null
or the weights of each element of the internal sample (last sample the AbstractMixtureModel was
trained on)seqweights
- null
or an array for weighting the sequences, see createSeqWeightsArray()
iterations
- the number of iterations, that should be done.start
- The index of the run in a Model.train(Sample)
-call
Exception
- if something went wrongprotected void getNewParameters(int iteration, double[][] seqWeights, double[] w) throws Exception
iteration
- the number this method has been invokedseqWeights
- the weights for each model and sequencew
- the weights for the components
Exception
- if the training of the internal models went wrongprotected void getNewParametersForModel(int modelIndex, int iteration, int sampleIndex, double[] seqWeights) throws Exception
modelIndex
on the internal sample and the given weights.
modelIndex
- the index of the modeliteration
- the number this method has been invoked for this modelsampleIndex
- the index of the internal sample that should be usedseqWeights
- the weights for each sequence
Exception
- if the training of the internal model went wrongprotected abstract double getNewWeights(double[] dataWeights, double[] w, double[][] seqweights) throws Exception
dataWeights
- the weights for internal sample (should not be changed)w
- the array for the statistic of the component parameters (shall
be filled)seqweights
- an array containing for each component the weights for each
sequence (shall be filled)
Exception
- if something went wrongprotected double modifyWeights(double[] w)
w
- the weights
protected void initWithPrior(double[] w)
w
- the array of weightspublic double getLogProbFor(int component, Sequence s) throws Exception
component
- the index of the components
- the sequence
log P(s,component) = log P(s|component) + log P(component)
Exception
- if not trained yet or something else went wronggetNumberOfComponents()
protected abstract double getLogProbUsingCurrentParameterSetFor(int component, Sequence s, int start, int end) throws Exception
component
- the index of the components
- the sequencestart
- the start position in the sequenceend
- the end position in the sequence
log P(s,component) = log P(s|component) + log P(component)
Exception
- if not trained yet or something else went wronggetNumberOfComponents()
public double getProbFor(Sequence sequence, int startpos, int endpos) throws 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
Exception
- an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos
> sequence.length, ...) by the model
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.public final double getLogProbFor(Sequence sequence, int startpos, int endpos) throws 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
Exception
- an Exception should be thrown if the sequence could not be handled (e.g. startpos > endpos, endpos
> sequence.length, ...) by the model
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.Model.getProbFor(Sequence, int, int)
public final double[] getLogProbFor(Sample data) throws Exception
Model
getLogProbFor(Sequence)
getLogProbFor
in interface Model
getLogProbFor
in class AbstractModel
data
- the sample
Exception
- if something went wrongModel.getLogProbFor(Sequence)
public double getLogPriorTerm() throws Exception
Model
Exception
- if something went wrongModel.getPriorTerm()
protected final double getLogPriorTermForComponentProbs()
public final double getScoreForBestRun() throws NotTrainedException, OperationNotSupportedException
NotTrainedException
- if the training algorithms has not been run
OperationNotSupportedException
- if this method is used for an instance that does not use the EMtrain(Sample, double[])
,
algorithmHasBeenRun()
public String getInstanceName()
Model
public int getIndexOfMaximalComponentFor(Sequence s) throws Exception
i
of the component with
P(i|s) maximal. Therefore it computes:
i = argmax_j P(j|s) = argmax_j P(s|j) * P(j)
This method can be helpful for clustering.
- Parameters:
s
- the sequence
- Returns:
- the index of the component
- Throws:
Exception
- if not trained yet or something else went wrong- See Also:
getLogProbFor(int, Sequence)
public final Model[] getModels() throws CloneNotSupportedException
AbstractModel
s
CloneNotSupportedException
- if at least one model can not be clonedgetModel(int)
public final Model getModel(int i) throws CloneNotSupportedException
i
- the index
CloneNotSupportedException
- if at least one model can not be clonedgetModels()
public String getNameOfAlgorithm()
public final int getNumberOfComponents()
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 NumericalResultSet getNumericalCharacteristics() throws Exception
Model
getCharacteristsics
.
Exception
- an Exception
is thrown if some of the characteristics could not be definedpublic final double[] getWeights()
public boolean algorithmHasBeenRun()
true
if the internal algorithm has been used to determine the parameters of the modelpublic boolean isTrained()
Model
public final void setAlpha(double alpha) throws IllegalArgumentException
train
to init the gammas. It is
recommended to use alpha = 1 (uniform distribution on a simplex).
alpha
- 0 < alpha
IllegalArgumentException
- if alpha <<= 0
public final void setOutputStream(OutputStream o)
o=null
, than nothing will be written.
o
- the OutputStreampublic final void setThreshold(double eps) throws IllegalArgumentException
eps
- the threshold, has to be at least zero
IllegalArgumentException
- if eps < 0
protected void getNewComponentProbs(double[] weights) throws Exception
weights
- every element has to be non-negative and the dimension of weights has to be dimension
Exception
- a weight is less than 0getNumberOfComponents()
protected void setWeights(double... weights) throws IllegalArgumentException
weights
- every element has to be non-negative, the sum of all weights has to be 1 and the dimension of weights
has to be dimension
IllegalArgumentException
- a weight is less than 0, the sum is not equal to 1 or the dimension is incorrectgetNumberOfComponents()
public StringBuffer toXML()
Storable
protected StringBuffer getFurtherInformation()
extractFurtherInformation(StringBuffer)
protected 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)
protected void extractFurtherInformation(StringBuffer xml) throws NonParsableException
xml
- the xml representation
NonParsableException
- if the xml representation is not parsablegetFurtherInformation()
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 instanceprotected void checkModelsForGibbsSampling()
GibbsSamplingComponent
.
protected void checkLength(int index, int l)
l
of the model with index index
is
capable for the current instance. Otherwise an IllegalArgumentException is thrown.
index
- the index of the modell
- the length of the model
IllegalArgumentException
- if the model instance can not be used.public Sample emitSample(int n, int... lengths) throws Exception
Model
emitSample( int n, int l )
should return a sample with n
sequences of length l
.
emitSample( int n, int[] l )
should return a sample with n
sequences which have a sequence length corresponding to the entry in the array
emitSample( int n )
and emitSample( int n, null )
should return a sample with
n
sequences of length of the model (Model.getLength()
)
emitSample
in interface Model
emitSample
in class AbstractModel
n
- the number of sequences that should be contained in the returned samplelengths
- the length of the sequences for a homogeneous model; for an inhomogeneous model this parameter should be
null
or an array of size 0.
Exception
- an Exception should be thrown if the emission did not succeed.
NotTrainedException
- a NotTrainedException should be thrown if the model is not trained yet.Sample
protected abstract Sequence[] emitSampleUsingCurrentParameterSet(int n, int... lengths) throws Exception
n
- the number of sequences to be sampledlengths
- the corresponding lengths
Exception
- if it was impossible to sampleAbstractModel.emitSample(int, int...)
protected boolean parseParameterSet(int sampling, int burnInIteration) throws Exception
burnInIteration
of a specific
sampling
(from a file).
sampling
- the index of the samplingburnInIteration
- the number of iterations that should be skipped
true
is the parameter set could be parsed
Exception
- if something went wrong while reading or parsing the parameter setprotected boolean parseNextParameterSet() throws Exception
true
is the parameter set could be parsed
Exception
- if something went wrong while reading or parsing the parameter setprotected void initModelForSampling(int starts) throws IOException
starts
- the number of sampling starts
IOException
- if the files could not be handled properlyprotected void extendSampling(int sampling) throws Exception
sampling
- the index of the sampling
Exception
- if the internal files could not be handled properlyprotected void samplingStopped() throws IOException
initModelForSampling
. It can be used for closing any
streams of writer, ...
IOException
- if the FileWriter
could not be closed properlyprotected boolean isInSamplingMode()
true
if the object is currently used in a sampling, otherwise
false
.
true
if the object is currently used in a samplingprotected void finalize() throws Throwable
finalize
in class Object
Throwable
public static final int draw(double[] w, int start)
w
- an array containing probabilities starting at position start
start
- the start index
public static final int max(double[] w, int start, int end)
w
betwwen index start
and end
.
w
- an arraystart
- the start index (inclusive)end
- the end index (exclusive)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |