|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhomogeneousDGTrainSM
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.DAGTrainSM
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.FSDAGTrainSM
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.FSDAGModelForGibbsSampling
public class FSDAGModelForGibbsSampling
This is the class for a fixed structure directed acyclic graphical model (see
FSDAGTrainSM
) that can be used in a Gibbs sampling.
AbstractMixtureTrainSM
Field Summary | |
---|---|
protected int[] |
counter
The counter for the sampling steps of each sampling. |
protected File[] |
paramsFile
The files for saving the parameters during the sampling. |
protected BufferedReader |
reader
The reader for the paramsFile after a sampling. |
protected int |
samplingIndex
The index of the current sampling. |
protected BufferedWriter |
writer
The writer for the paramsFile in a sampling. |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.DAGTrainSM |
---|
constraints |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhomogeneousDGTrainSM |
---|
DEFAULT_STREAM, sostream |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM |
---|
params, trained |
Fields inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel |
---|
alphabets, length |
Constructor Summary | |
---|---|
FSDAGModelForGibbsSampling(FSDAGModelForGibbsSamplingParameterSet params)
The default constructor. |
|
FSDAGModelForGibbsSampling(StringBuffer representation)
This is the constructor for the Storable interface. |
Method Summary | |
---|---|
void |
acceptParameters()
This methods accepts the drawn parameters. |
FSDAGModelForGibbsSampling |
clone()
In this method the reader is set to null and
the paramsFile is cloned. |
void |
drawParameters(DataSet data,
double[] weights)
This method draws the parameter of the model from the likelihood or the posterior, respectively. |
void |
drawParameters(DataSet data,
double[] weights,
int[][] graph)
This method draws the parameters of the model from the a posteriori density. |
void |
extendSampling(int sampling,
boolean extend)
This method allows to extend a sampling. |
protected void |
finalize()
|
protected StringBuffer |
getFurtherModelInfos()
Returns further model information as a StringBuffer . |
void |
initForSampling(int starts)
This method initializes the instance for the sampling. |
boolean |
isInSamplingMode()
This method returns true if the object is currently used in
a sampling, otherwise false . |
boolean |
parseNextParameterSet()
This method allows the user to parse the next set of parameters (from a file). |
boolean |
parseParameterSet(int sampling,
int n)
This method allows the user to parse the set of parameters with index n of a certain sampling (from a file). |
void |
samplingStopped()
This method is the opposite of the method SamplingComponent.extendSampling(int, boolean) . |
protected void |
setFurtherModelInfos(StringBuffer xml)
This method replaces the internal model information with those from a StringBuffer . |
void |
train(DataSet data,
double[] weights)
Trains the TrainableStatisticalModel object given the data as DataSet using
the specified weights. |
void |
train(DataSet data,
double[] weights,
int[][] graph)
Computes the model with structure graph . |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.FSDAGTrainSM |
---|
getInstanceName, getMaximalMarkovOrder, getStructure, getXMLTag, set, train |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.DAGTrainSM |
---|
checkAcyclic, createConstraints, emitDataSet, estimateParameters, getLogPriorTerm, getLogProbFor, getNumericalCharacteristics, toString |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.inhomogeneous.InhomogeneousDGTrainSM |
---|
check, setOutputStream |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.discrete.DiscreteGraphicalTrainSM |
---|
fromXML, getCurrentParameterSet, getDescription, getESS, isInitialized, toXML |
Methods inherited from class de.jstacs.sequenceScores.statisticalModels.trainable.AbstractTrainableStatisticalModel |
---|
getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, getLogScoreFor, train |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected File[] paramsFile
protected int[] counter
protected int samplingIndex
protected BufferedWriter writer
paramsFile
in a sampling.
protected BufferedReader reader
paramsFile
after a sampling.
Constructor Detail |
---|
public FSDAGModelForGibbsSampling(FSDAGModelForGibbsSamplingParameterSet params) throws CloneNotSupportedException, IllegalArgumentException, NonParsableException
params
- the parameter set
CloneNotSupportedException
- if the parameter set could not be cloned
IllegalArgumentException
- if the parameter set is not instantiated
NonParsableException
- if the parameter set is not parsablepublic FSDAGModelForGibbsSampling(StringBuffer representation) throws NonParsableException
Storable
interface.
Creates a new FSDAGModelForGibbsSampling
out of its XML
representation.
representation
- the XML representation as StringBuffer
NonParsableException
- if the StringBuffer
could not be parsed.Method Detail |
---|
public FSDAGModelForGibbsSampling clone() throws CloneNotSupportedException
reader
is set to null
and
the paramsFile
is cloned.
clone
in interface SequenceScore
clone
in interface TrainableStatisticalModel
clone
in class DAGTrainSM
AbstractTrainableStatisticalModel
(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
AbstractTrainableStatisticalModel
. Hence X
's
clone()
-method should work as:Object o = (X)super.clone();
o
defined by
X
that are not of simple data-types like
int
, double
, ... have to be deeply
copied return o
CloneNotSupportedException
- if something went wrong while cloningDAGTrainSM.clone()
,
Object.clone()
public boolean parseNextParameterSet()
SamplingComponent
parseNextParameterSet
in interface SamplingComponent
true
if the parameters could be parsed, otherwise
false
SamplingComponent.parseParameterSet(int, int)
public boolean parseParameterSet(int sampling, int n) throws NumberFormatException, IOException
SamplingComponent
n
of a certain sampling
(from a file). The
internal numbering should start with 0. The parameter set with index 0 is
the initial (random) parameter set. It is recommended that a series of
parameter sets is accessed by the following lines:
for( sampling = 0; sampling < numSampling; sampling++ )
{
boolean b = parseParameterSet( sampling, n );
while( b )
{
//do something
b = parseNextParameterSet();
}
}
parseParameterSet
in interface SamplingComponent
sampling
- the index of the samplingn
- the index of the parameter set
true
if the parameter set could be parsed
NumberFormatException
IOException
SamplingComponent.parseNextParameterSet()
public void initForSampling(int starts) throws IOException
SamplingComponent
initForSampling
in interface SamplingComponent
starts
- the number of different sampling starts that will be done
IOException
- if something went wrongFile.createTempFile(String, String, java.io.File )
public void extendSampling(int sampling, boolean extend) throws IOException
SamplingComponent
extendSampling
in interface SamplingComponent
sampling
- the index of the samplingextend
- whether to append the sampled parameters to an existing file
or to overwrite the file
IOException
- if the file could not be handled correctlypublic void drawParameters(DataSet data, double[] weights) throws Exception
DAGTrainSM
drawParameters
in interface GibbsSamplingModel
drawParameters
in class DAGTrainSM
data
- the given dataweights
- the weights for the sequences in the data
Exception
- if something went wrong while counting or drawingConstraintManager.countInhomogeneous(de.jstacs.data.AlphabetContainer,
int, DataSet, double[], boolean,
de.jstacs.sequenceScores.statisticalModels.trainable.discrete.Constraint...)
,
ConstraintManager.drawFreqs(double, InhCondProb...)
public void samplingStopped() throws IOException
SamplingComponent
SamplingComponent.extendSampling(int, boolean)
. It can be
used for closing any streams of writer, ...
samplingStopped
in interface SamplingComponent
IOException
- if something went wrongSamplingComponent.extendSampling(int, boolean)
protected StringBuffer getFurtherModelInfos()
DiscreteGraphicalTrainSM
StringBuffer
.
getFurtherModelInfos
in class DAGTrainSM
DiscreteGraphicalTrainSM.toXML()
protected void setFurtherModelInfos(StringBuffer xml) throws NonParsableException
DiscreteGraphicalTrainSM
StringBuffer
.
setFurtherModelInfos
in class DAGTrainSM
xml
- contains the model information like parameters of the
distribution etc. in XML format
NonParsableException
- if the StringBuffer
could not be parsedDiscreteGraphicalTrainSM.fromXML(StringBuffer)
public boolean isInSamplingMode()
SamplingComponent
true
if the object is currently used in
a sampling, otherwise false
.
isInSamplingMode
in interface SamplingComponent
true
if the object is currently used in a sampling,
otherwise false
public void drawParameters(DataSet data, double[] weights, int[][] graph) throws Exception
FSDAGTrainSM
null
. Furthermore this method enables you to
specify a new graph structure.
drawParameters
in class FSDAGTrainSM
data
- a DataSet
or null
weights
- the (positive) weights for each sequence of the DataSet
or null
graph
- the graph or null
for the current graph
Exception
- if something went wrongDAGTrainSM.drawParameters(DataSet, double[])
,
DAGTrainSM.checkAcyclic(int, int[][])
public void train(DataSet data, double[] weights) throws Exception
TrainableStatisticalModel
TrainableStatisticalModel
object given the data as DataSet
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.)train(data1)
; train(data2)
should be a fully trained model over data2
and not over
data1+data2
. All parameters of the model were given by the
call of the constructor.
train
in interface TrainableStatisticalModel
train
in class FSDAGTrainSM
data
- the given sequences as DataSet
weights
- the weights of the elements, each weight should be
non-negative
Exception
- if the training did not succeed (e.g. the dimension of
weights
and the number of sequences in the
sample do not match)DataSet.getElementAt(int)
,
DataSet.ElementEnumerator
public void train(DataSet data, double[] weights, int[][] graph) throws Exception
FSDAGTrainSM
graph
.
train
in class FSDAGTrainSM
data
- the DataSet
weights
- the weights for the sequences in the DataSet
graph
- the graph
Exception
- if something went wrongprotected void finalize() throws Throwable
finalize
in class Object
Throwable
public void acceptParameters() throws IOException
SamplingComponent
acceptParameters
in interface SamplingComponent
IOException
- if the file could not be handled correctly
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |