de.jstacs.models.discrete.inhomogeneous
Class BayesianNetworkModel

java.lang.Object
  extended by de.jstacs.models.AbstractModel
      extended by de.jstacs.models.discrete.DiscreteGraphicalModel
          extended by de.jstacs.models.discrete.inhomogeneous.InhomogeneousDGM
              extended by de.jstacs.models.discrete.inhomogeneous.DAGModel
                  extended by de.jstacs.models.discrete.inhomogeneous.BayesianNetworkModel
All Implemented Interfaces:
InstantiableFromParameterSet, Model, Storable, Cloneable

public class BayesianNetworkModel
extends DAGModel

The class implements a Bayesian network of fixed order. It allows the user to specify some kinds of sub models including inhomogeneous Markov model (iMM), permuted Markov model (pMM) or Bayesian network (BN)

Author:
Jens Keilwagen
See Also:
StructureLearner.ModelType

Field Summary
 
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
BayesianNetworkModel(BayesianNetworkModelParameterSet params)
          The default constructor.
BayesianNetworkModel(StringBuffer representation)
          The constructor for a model in xml format.
 
Method Summary
 BayesianNetworkModel clone()
          Follows the conventions of Object's clone-method.
protected  int[] count(int[][] structure, byte maxOrder)
          Counts the occurrence of the different indegrees and check if the conventions are met.
 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.
 byte getMaximalMarkovOrder()
          This method returns the maximal used markov order if possible.
protected  String getXMLTag()
           
protected  void set(DGMParameterSet parameter, boolean trained)
          Sets the parameters as internal parameters and does some essential computations.
 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.discrete.inhomogeneous.DAGModel
checkAcyclic, createConstraints, drawParameters, emitSample, estimateParameters, getFurtherModelInfos, getLogProbFor, getNumericalCharacteristics, getProbFor, getStructure, setFurtherModelInfos, 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, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BayesianNetworkModel

public BayesianNetworkModel(BayesianNetworkModelParameterSet params)
                     throws CloneNotSupportedException,
                            IllegalArgumentException,
                            NonParsableException
The default constructor.

Parameters:
params - the parameter set
Throws:
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

BayesianNetworkModel

public BayesianNetworkModel(StringBuffer representation)
                     throws NonParsableException
The constructor for a model in xml format.

Parameters:
representation - the model in xml format
Throws:
NonParsableException - if the StringBuffer could not be parsed
Method Detail

clone

public BayesianNetworkModel clone()
                           throws CloneNotSupportedException
Description copied from class: AbstractModel
Follows the conventions of Object's clone-method.

Specified by:
clone in interface Model
Overrides:
clone in class DAGModel
Returns:
an object, that is a copy of the current 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:
1. 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
Throws:
CloneNotSupportedException

getInstanceName

public String getInstanceName()
Description copied from interface: Model
Should return a short instance name such as iMM(0), BN(2), ...

Returns:
a short instance name

getXMLTag

protected String getXMLTag()
Specified by:
getXMLTag in class DiscreteGraphicalModel
Returns:
the XML tag that is used in fromXML() and toXML()
See Also:
DiscreteGraphicalModel.fromXML(StringBuffer), DiscreteGraphicalModel.toXML()

train

public void train(Sample data,
                  double[] weights)
           throws Exception
Description copied from interface: Model
Trains the Model object given the data as 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.)
This method should work non-incrementally. That means the result of the following series: 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.

Parameters:
data - the given sequences
weights - the weights of the elements, each weight should be non-negative
Throws:
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).
See Also:
Sample.getElementAt(int), Sample.ElementEnumerator

getLogPriorTerm

public double getLogPriorTerm()
                       throws Exception
Description copied from interface: Model
Returns a value that is proportional to the log of the prior. For ML 0 should be returned.

Specified by:
getLogPriorTerm in interface Model
Overrides:
getLogPriorTerm in class DAGModel
Returns:
a value that is proportional to the log of the prior
Throws:
Exception - if something went wrong
See Also:
Model.getPriorTerm()

getMaximalMarkovOrder

public byte getMaximalMarkovOrder()
Description copied from interface: Model
This method returns the maximal used markov order if possible.

Specified by:
getMaximalMarkovOrder in interface Model
Overrides:
getMaximalMarkovOrder in class AbstractModel
Returns:
maximal used markov order

count

protected int[] count(int[][] structure,
                      byte maxOrder)
Counts the occurrence of the different indegrees and check if the conventions are met.

Parameters:
structure - the structure
maxOrder - the maximal order
Returns:
an int-array containing the occurrence of indegrees

set

protected void set(DGMParameterSet parameter,
                   boolean trained)
            throws CloneNotSupportedException,
                   NonParsableException
Description copied from class: DiscreteGraphicalModel
Sets the parameters as internal parameters and does some essential computations. Used in fromParameterSet-methods.

Overrides:
set in class InhomogeneousDGM
Parameters:
parameter - the new ParameterSet
trained - the indicator for the model
Throws:
CloneNotSupportedException - if the parmeterSet could not be cloned
NonParsableException - if the parameters of the model could not be parsed