|
||||||||||
| 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.discrete.DiscreteGraphicalModel
de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM
de.jstacs.models.discrete.inhomogeneous.DAGModel
de.jstacs.models.discrete.inhomogeneous.FSDAGModel
de.jstacs.models.mixture.gibbssampling.FSDAGModelForGibbsSampling
public class FSDAGModelForGibbsSampling
This is the class for a fixed structure directed acyclic graphical model that can be used in a Gibbs sampling.
AbstractMixtureModel| Field Summary | |
|---|---|
protected int[] |
counter
The counter for the sampling steps of each sampling |
protected File[] |
paramsFile
The files for saving the parameters while 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.models.discrete.inhomogeneous.DAGModel |
|---|
constraints |
| Fields inherited from class de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM |
|---|
DEFAULT_STREAM, sostream |
| Fields inherited from class de.jstacs.models.discrete.DiscreteGraphicalModel |
|---|
params, trained |
| Fields inherited from class de.jstacs.models.AbstractModel |
|---|
alphabets, length |
| Constructor Summary | |
|---|---|
FSDAGModelForGibbsSampling(FSDAGMParameterSet params)
The default constructor. |
|
FSDAGModelForGibbsSampling(StringBuffer representation)
This is the constructor for Storable. |
|
| Method Summary | |
|---|---|
FSDAGModelForGibbsSampling |
clone()
In this method the reader is set to null |
void |
drawParameters(Sample data,
double[] weights)
This method draws the parameter of the model from the likelihood respectively posterior. |
void |
drawParameters(Sample 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()
|
void |
initModelForSampling(int starts)
This method initializes the model 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 GibbsSamplingComponent.extendSampling(int, boolean). |
protected void |
setFurtherModelInfos(StringBuffer xml)
In this method the reader is set to null |
void |
train(Sample data,
double[] weights)
Trains the Model object given the data as Sample using the specified weights. |
void |
train(Sample data,
double[] weights,
int[][] graph)
Computes the model with structure graph |
| Methods inherited from class de.jstacs.models.discrete.inhomogeneous.FSDAGModel |
|---|
getInstanceName, getMaximalMarkovOrder, getStructure, getXMLTag, set, train |
| Methods inherited from class de.jstacs.models.discrete.inhomogeneous.DAGModel |
|---|
checkAcyclic, createConstraints, emitSample, estimateParameters, getLogPriorTerm, getLogProbFor, getNumericalCharacteristics, getProbFor, toString |
| Methods inherited from class de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM |
|---|
check, setOutputStream |
| Methods inherited from class de.jstacs.models.discrete.DiscreteGraphicalModel |
|---|
fromXML, getCurrentParameterSet, getDescription, getESS, isTrained, toXML |
| Methods inherited from class de.jstacs.models.AbstractModel |
|---|
getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getPriorTerm, getProbFor, getProbFor, set, setNewAlphabetContainerInstance, 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(FSDAGMParameterSet 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 parsable
public FSDAGModelForGibbsSampling(StringBuffer representation)
throws NonParsableException
Storable.
representation - the xml representation
NonParsableException - if the representation could not be parsed.| Method Detail |
|---|
public FSDAGModelForGibbsSampling clone()
throws CloneNotSupportedException
reader is set to null
clone in interface Modelclone in class DAGModelAbstractModel (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
CloneNotSupportedExceptionpublic boolean parseNextParameterSet()
GibbsSamplingComponent
parseNextParameterSet in interface GibbsSamplingComponenttrue if the parameters could be parsed, otherwise falseGibbsSamplingComponent.parseParameterSet(int, int)
public boolean parseParameterSet(int sampling,
int n)
throws NumberFormatException,
IOException
GibbsSamplingComponentn 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++ )
{
while( b )
{
//do something
b = parseNextParameterSet();
}
parseParameterSet in interface GibbsSamplingComponentsampling - the index of the samplingn - the index of the parameter set
true if the parameter set could be parsed
NumberFormatException
IOExceptionGibbsSamplingComponent.parseNextParameterSet()
public void initModelForSampling(int starts)
throws IOException
GibbsSamplingComponent
initModelForSampling in interface GibbsSamplingComponentstarts - 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
GibbsSamplingComponent
extendSampling in interface GibbsSamplingComponentsampling - 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 correctly
public void drawParameters(Sample data,
double[] weights)
throws Exception
DAGModel
drawParameters in interface GibbsSamplingComponentdrawParameters in class DAGModeldata - the dataweights - the weights for the sequences in the data
Exception - if something went wrong while counting or drawingGibbsSamplingComponent.initModelForSampling(int),
GibbsSamplingComponent.parseParameterSet(int, int),
GibbsSamplingComponent.parseNextParameterSet()
public void samplingStopped()
throws IOException
GibbsSamplingComponentGibbsSamplingComponent.extendSampling(int, boolean). It can be
used for closing any streams of writer, ...
samplingStopped in interface GibbsSamplingComponentIOException - if something went wrongGibbsSamplingComponent.extendSampling(int, boolean)protected StringBuffer getFurtherModelInfos()
getFurtherModelInfos in class DAGModelDiscreteGraphicalModel.toXML()
protected void setFurtherModelInfos(StringBuffer xml)
throws NonParsableException
reader is set to null
setFurtherModelInfos in class DAGModelxml - contains the model infos like parameters of the distibution ... in xml format
NonParsableException - if the StringBuffer could not be parsedDiscreteGraphicalModel.fromXML(StringBuffer)public boolean isInSamplingMode()
GibbsSamplingComponenttrue if the object is currently used in a sampling, otherwise
false.
isInSamplingMode in interface GibbsSamplingComponenttrue if the object is currently used in a sampling
public void drawParameters(Sample data,
double[] weights,
int[][] graph)
throws Exception
FSDAGModelnull. Furthermore this method enables you to specify a
new graph structure.
drawParameters in class FSDAGModeldata - a sample or nullweights - the (positive) weights for each sequence of the sample or nullgraph - the graph or null for the current graph
Exception
public void train(Sample data,
double[] weights)
throws Exception
ModelSample 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 in interface Modeltrain in class FSDAGModeldata - 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 void train(Sample data,
double[] weights,
int[][] graph)
throws Exception
FSDAGModelgraph
train in class FSDAGModeldata - the sampleweights - the weights for the sequences in the samplegraph - the graph
Exception - if something went wrong
protected void finalize()
throws Throwable
finalize in class ObjectThrowable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||