|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.jstacs.models.AbstractModel de.jstacs.models.discrete.DiscreteGraphicalModel de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM de.jstacs.models.discrete.inhomogeneous.DAGModel
public abstract class DAGModel
The abstract class for directed acyclic graphical models
(DAGModel
).
Field Summary | |
---|---|
protected InhCondProb[] |
constraints
The constraints for the model. |
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 | |
---|---|
protected |
DAGModel(IDGMParameterSet params)
This is the main constructor. |
protected |
DAGModel(StringBuffer xml)
The standard constructor for the interface Storable . |
Method Summary | |
---|---|
protected static boolean |
checkAcyclic(int length,
int[][] graph)
This method checks whether a given graph is acyclic. |
DAGModel |
clone()
Follows the conventions of Object 's clone() -method. |
protected void |
createConstraints(int[][] structure)
This method creates the constraints for a given structure. |
protected void |
drawParameters(Sample data,
double[] weights)
This method draws the parameter of the model from the likelihood or the posterior, respectively. |
Sample |
emitSample(int n,
int... lengths)
This method returns a Sample object containing artificial
sequence(s). |
protected void |
estimateParameters(Sample data,
double[] weights)
This method estimates the parameter of the model from the likelihood or the posterior, respectively. |
protected StringBuffer |
getFurtherModelInfos()
Returns further model information as a StringBuffer . |
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 (a part of) the given sequence given the model. |
NumericalResultSet |
getNumericalCharacteristics()
Returns the subset of numerical values that are also returned by Model.getCharacteristics() . |
double |
getProbFor(Sequence sequence,
int startpos,
int endpos)
Returns the probability of (a part of) the given sequence given the model. |
String |
getStructure()
Returns a String representation of the underlying graph. |
protected void |
setFurtherModelInfos(StringBuffer xml)
This method replaces the internal model information with those from a StringBuffer . |
String |
toString()
Should give a simple representation (text) of the model as String
. |
Methods inherited from class de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM |
---|
check, set, setOutputStream |
Methods inherited from class de.jstacs.models.discrete.DiscreteGraphicalModel |
---|
fromXML, getCurrentParameterSet, getDescription, getESS, getXMLTag, isTrained, toXML |
Methods inherited from class de.jstacs.models.AbstractModel |
---|
getAlphabetContainer, getCharacteristics, getLength, getLogProbFor, getLogProbFor, getLogProbFor, getLogProbFor, getMaximalMarkovOrder, getPriorTerm, getProbFor, getProbFor, set, setNewAlphabetContainerInstance, train |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface de.jstacs.models.Model |
---|
getInstanceName, train |
Field Detail |
---|
protected InhCondProb[] constraints
Constructor Detail |
---|
protected DAGModel(IDGMParameterSet params) throws CloneNotSupportedException, IllegalArgumentException, NonParsableException
DAGModel
from the
given IDGMParameterSet
.
params
- the given 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 parsableInhomogeneousDGM.InhomogeneousDGM(IDGMParameterSet)
protected DAGModel(StringBuffer xml) throws NonParsableException
Storable
.
Creates a new DAGModel
out of its XML representation.
xml
- the XML representation as StringBuffer
NonParsableException
- if the DAGModel
could not be reconstructed out of the
XML representation (the StringBuffer
could not be
parsed)Storable
,
InhomogeneousDGM.InhomogeneousDGM(StringBuffer)
Method Detail |
---|
public DAGModel clone() throws CloneNotSupportedException
AbstractModel
Object
's clone()
-method.
clone
in interface Model
clone
in class InhomogeneousDGM
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();
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 cloningpublic Sample emitSample(int n, int... lengths) throws NotTrainedException, Exception
Model
Sample
object containing artificial
sequence(s).
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 given array l
.
emitSample( int n )
and
emitSample( int n, null )
should return a sample with
n
sequences of length of the model (
Model.getLength()
).
Exception
.
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.
Sample
containing the artificial sequence(s)
NotTrainedException
- if the model is not trained yet
Exception
- if the emission did not succeedSample
public double getLogPriorTerm() throws Exception
Model
Exception
- if something went wrongModel.getPriorTerm()
public 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 given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into account
NotTrainedException
- if the model is not trained yet
Exception
- if the sequence could not be handled (e.g.
startpos >
, endpos
> sequence.length
, ...) by the modelModel.getProbFor(Sequence, int, int)
public NumericalResultSet getNumericalCharacteristics()
Model
Model.getCharacteristics()
.
public double getProbFor(Sequence sequence, int startpos, int endpos) throws NotTrainedException, Exception
Model
Model.getProbFor(Sequence, int)
by the fact, that the model could be
e.g. homogeneous and therefore the length of the sequences, whose
probability should be returned, is not fixed. Additionally the end
position of the part of the given sequence is given and the probability
of the part from position startpos
to endpos
(inclusive) should be returned.
length
and the alphabets
define the type of
data that can be modeled and therefore both has to be checked.
sequence
- the given sequencestartpos
- the start position within the given sequenceendpos
- the last position to be taken into account
NotTrainedException
- if the model is not trained yet
Exception
- if the sequence could not be handled (e.g.
startpos > endpos
, endpos
> sequence.length
, ...) by the modelpublic String getStructure() throws NotTrainedException
InhomogeneousDGM
String
representation of the underlying graph.
getStructure
in class InhomogeneousDGM
String
representation of the underlying graph
NotTrainedException
- if the structure is not set, this can only be the case if the
model is not trainedpublic String toString()
Model
String
.
toString
in interface Model
toString
in class DiscreteGraphicalModel
String
protected static boolean checkAcyclic(int length, int[][] graph)
length
- the sequence length (which corresponds to the number of nodes
in the graph)graph
- the specified graph
true
if the given graph is acyclic,
false
otherwiseprotected void createConstraints(int[][] structure)
structure
- the specified structureprotected void drawParameters(Sample data, double[] weights) throws Exception
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, Sample, double[], boolean,
de.jstacs.models.discrete.Constraint...)
,
ConstraintManager.drawFreqs(double, InhCondProb...)
protected void estimateParameters(Sample data, double[] weights) throws Exception
data
- the dataweights
- the weights for the sequences in the data
Exception
- if something went wrong while counting or estimatingdrawParameters(Sample, double[])
protected StringBuffer getFurtherModelInfos()
DiscreteGraphicalModel
StringBuffer
.
getFurtherModelInfos
in class DiscreteGraphicalModel
DiscreteGraphicalModel.toXML()
protected void setFurtherModelInfos(StringBuffer xml) throws NonParsableException
DiscreteGraphicalModel
StringBuffer
.
setFurtherModelInfos
in class DiscreteGraphicalModel
xml
- contains the model information like parameters of the
distribution etc. in XML format
NonParsableException
- if the StringBuffer
could not be parsedDiscreteGraphicalModel.fromXML(StringBuffer)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |