Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## de.jstacs.models.discrete.inhomogeneous
Class FSDAGModelForGibbsSampling

    java.lang.Object
      de.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.discrete.inhomogeneous.FSDAGModelForGibbsSampling

All Implemented Interfaces:
  InstantiableFromParameterSet, Model, GibbsSamplingModel, SamplingComponent, Storable, Cloneable

    public class FSDAGModelForGibbsSampling

extends FSDAGModel
implements GibbsSamplingModel

This is the class for a fixed structure directed acyclic graphical model (see `FSDAGModel`) that can be used in a Gibbs sampling.

Author:
  Berit Haldemann, Jens Keilwagen
See Also:
  `AbstractMixtureModel`

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.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(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(Sample data, double[] weights)` This method draws the parameter of the model from the likelihood or the posterior, respectively.
`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()` 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(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

### paramsFile

    protected File[] paramsFile

  The files for saving the parameters during the sampling.

### counter

    protected int[] counter

  The counter for the sampling steps of each sampling.

### samplingIndex

    protected int samplingIndex

  The index of the current sampling.

### writer

    protected BufferedWriter writer

  The writer for the `paramsFile` in a sampling.

### reader

    protected BufferedReader reader

  The reader for the `paramsFile` after a sampling.

Constructor Detail

### FSDAGModelForGibbsSampling

    public FSDAGModelForGibbsSampling(FSDAGModelForGibbsSamplingParameterSet 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

### FSDAGModelForGibbsSampling

    public FSDAGModelForGibbsSampling(StringBuffer representation)
                               throws NonParsableException

  This is the constructor for the `Storable` interface. Creates a new `FSDAGModelForGibbsSampling` out of its XML representation.

  Parameters:
    `representation` - the XML representation as `StringBuffer`
  Throws:
    `NonParsableException` - if the `StringBuffer` could not be parsed.

Method Detail

### clone

    public FSDAGModelForGibbsSampling clone()
                                     throws CloneNotSupportedException

  In this method the `reader` is set to `null` and the `paramsFile` is cloned.

  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` - if something went wrong while cloning
  See Also:
    `DAGModel.clone()`, `Object.clone()`

### parseNextParameterSet

    public boolean parseNextParameterSet()

  Description copied from interface: `SamplingComponent`
  This method allows the user to parse the next set of parameters (from a file).

  Specified by:
    `parseNextParameterSet` in interface `SamplingComponent`
  Returns:
    `true` if the parameters could be parsed, otherwise `false`
  See Also:
    `SamplingComponent.parseParameterSet(int, int)`

### parseParameterSet

    public boolean parseParameterSet(int sampling,
                                     int n)
                              throws NumberFormatException,
                                     IOException

  Description copied from interface: `SamplingComponent`
  This method allows the user to parse the set of parameters with index `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();
  } }
  `

  Specified by:
    `parseParameterSet` in interface `SamplingComponent`
  Parameters:
    `sampling` - the index of the sampling
    `n` - the index of the parameter set
  Returns:
    `true` if the parameter set could be parsed
  Throws:
    `NumberFormatException`
    `IOException`
  See Also:
    `SamplingComponent.parseNextParameterSet()`

### initForSampling

    public void initForSampling(int starts)
                         throws IOException

  Description copied from interface: `SamplingComponent`
  This method initializes the instance for the sampling. For instance this method can be used to create new files where all parameter sets are stored.

  Specified by:
    `initForSampling` in interface `SamplingComponent`
  Parameters:
    `starts` - the number of different sampling starts that will be done
  Throws:
    `IOException` - if something went wrong
  See Also:
    `File.createTempFile(String, String, java.io.File )`

### extendSampling

    public void extendSampling(int sampling,
                               boolean extend)
                        throws IOException

  Description copied from interface: `SamplingComponent`
  This method allows to extend a sampling.

  Specified by:
    `extendSampling` in interface `SamplingComponent`
  Parameters:
    `sampling` - the index of the sampling
    `extend` - whether to append the sampled parameters to an existing file or to overwrite the file
  Throws:
    `IOException` - if the file could not be handled correctly

### drawParameters

    public void drawParameters(Sample data,
                               double[] weights)
                        throws Exception

  Description copied from class: `DAGModel`
  This method draws the parameter of the model from the likelihood or the posterior, respectively.

  Specified by:
    `drawParameters` in interface `GibbsSamplingModel`
  Overrides:
    `drawParameters` in class `DAGModel`
  Parameters:
    `data` - the given data
    `weights` - the weights for the sequences in the data
  Throws:
    `Exception` - if something went wrong while counting or drawing
  See Also:
    `ConstraintManager.countInhomogeneous(de.jstacs.data.AlphabetContainer, int, Sample, double[], boolean, de.jstacs.models.discrete.Constraint...)`, `ConstraintManager.drawFreqs(double, InhCondProb...)`

### samplingStopped

    public void samplingStopped()
                         throws IOException

  Description copied from interface: `SamplingComponent`
  This method is the opposite of the method `SamplingComponent.extendSampling(int, boolean)`. It can be used for closing any streams of writer, ...

  Specified by:
    `samplingStopped` in interface `SamplingComponent`
  Throws:
    `IOException` - if something went wrong
  See Also:
    `SamplingComponent.extendSampling(int, boolean)`

### getFurtherModelInfos

    protected StringBuffer getFurtherModelInfos()

  Description copied from class: `DiscreteGraphicalModel`
  Returns further model information as a `StringBuffer`.

  Overrides:
    `getFurtherModelInfos` in class `DAGModel`
  Returns:
    further model information like parameters of the distribution etc. in XML format
  See Also:
    `DiscreteGraphicalModel.toXML()`

### setFurtherModelInfos

    protected void setFurtherModelInfos(StringBuffer xml)
                                 throws NonParsableException

  Description copied from class: `DiscreteGraphicalModel`
  This method replaces the internal model information with those from a `StringBuffer`.

  Overrides:
    `setFurtherModelInfos` in class `DAGModel`
  Parameters:
    `xml` - contains the model information like parameters of the distribution etc. in XML format
  Throws:
    `NonParsableException` - if the `StringBuffer` could not be parsed
  See Also:
    `DiscreteGraphicalModel.fromXML(StringBuffer)`

### isInSamplingMode

    public boolean isInSamplingMode()

  Description copied from interface: `SamplingComponent`
  This method returns `true` if the object is currently used in a sampling, otherwise `false`.

  Specified by:
    `isInSamplingMode` in interface `SamplingComponent`
  Returns:
    `true` if the object is currently used in a sampling, otherwise `false`

### drawParameters

    public void drawParameters(Sample data,
                               double[] weights,
                               int[][] graph)
                        throws Exception

  Description copied from class: `FSDAGModel`
  This method draws the parameters of the model from the a posteriori density. For drawing from the prior you have to set the data and their weights to `null`. Furthermore this method enables you to specify a new graph structure.

  Overrides:
    `drawParameters` in class `FSDAGModel`
  Parameters:
    `data` - a `Sample` or `null`
    `weights` - the (positive) weights for each sequence of the `Sample` or `null`
    `graph` - the graph or `null` for the current graph
  Throws:
    `Exception` - if something went wrong
  See Also:
    `DAGModel.drawParameters(Sample, double[])`, `DAGModel.checkAcyclic(int, int[][])`

### 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.

  Specified by:
    `train` in interface `Model`
  Overrides:
    `train` in class `FSDAGModel`
  Parameters:
    `data` - the given sequences as `Sample`
    `weights` - the weights of the elements, each weight should be non-negative
  Throws:
    `Exception` - if the training did not succeed (e.g. the dimension of `weights` and the number of sequences in the sample do not match)
  See Also:
    `Sample.getElementAt(int)`, `Sample.ElementEnumerator`

### train

    public void train(Sample data,
                      double[] weights,
                      int[][] graph)
               throws Exception

  Description copied from class: `FSDAGModel`
  Computes the model with structure `graph`.

  Overrides:
    `train` in class `FSDAGModel`
  Parameters:
    `data` - the `Sample`
    `weights` - the weights for the sequences in the `Sample`
    `graph` - the graph
  Throws:
    `Exception` - if something went wrong

### finalize

    protected void finalize()
                     throws Throwable

  Overrides:
    `finalize` in class `Object`
  Throws:
    `Throwable`

### acceptParameters

    public void acceptParameters()
                          throws IOException

  Description copied from interface: `SamplingComponent`
  This methods accepts the drawn parameters. Internally the drawn parameters should be saved (to a file).

  Specified by:
    `acceptParameters` in interface `SamplingComponent`
  Throws:
    `IOException` - if the file could not be handled correctly

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD