org.biojava.bio.dist
Class AbstractDistribution

java.lang.Object
  extended byorg.biojava.utils.AbstractChangeable
      extended byorg.biojava.bio.dist.AbstractDistribution
All Implemented Interfaces:
Changeable, Distribution, java.io.Serializable
Direct Known Subclasses:
AbstractOrderNDistribution, SimpleDistribution, UniformDistribution

public abstract class AbstractDistribution
extends AbstractChangeable
implements Distribution, java.io.Serializable

An abstract implementation of Distribution.

You will need to over-ride getWeight() for a simple implementation. You may also wish to over-ride the other methods if the default implementation is not suitable.

Note that, in this implementation, the setWeight implementation throws an exception. The registerWithTrainer method registers an IgnoreCountsTrainer. To make an AbstractDistribution subclass trainable, both these methods must be overridden.

Author:
Matthew Pocock, Thomas Down, Mark Schreiber (serialization support), Greg Cox
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.biojava.bio.dist.Distribution
Distribution.NullModelForwarder
 
Field Summary
protected  Distribution.NullModelForwarder nullModelForwarder
           
protected  java.util.Map symbolIndices
           
 
Fields inherited from interface org.biojava.bio.dist.Distribution
NULL_MODEL, WEIGHTS
 
Constructor Summary
AbstractDistribution()
           
 
Method Summary
protected  ChangeSupport getChangeSupport(ChangeType ct)
          Called to retrieve the ChangeSupport for this object
 double getWeight(Symbol sym)
          Retrieve the weight for this distribution.
protected abstract  double getWeightImpl(AtomicSymbol sym)
           
 void registerWithTrainer(DistributionTrainerContext dtc)
          Register an IgnoreCountsTrainer instance as the trainer for this distribution.
 Symbol sampleSymbol()
          Sample a symbol from this state's probability distribution.
 void setNullModel(Distribution nullModel)
          Set the null model Distribution that this Distribution recognizes.
protected abstract  void setNullModelImpl(Distribution nullModel)
           
 void setWeight(Symbol sym, double weight)
          Set the weight of a given symbol in this distribution.
protected abstract  void setWeightImpl(AtomicSymbol sym, double weight)
           
 
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.biojava.bio.dist.Distribution
getAlphabet, getNullModel
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Field Detail

nullModelForwarder

protected transient Distribution.NullModelForwarder nullModelForwarder

symbolIndices

protected java.util.Map symbolIndices
Constructor Detail

AbstractDistribution

public AbstractDistribution()
Method Detail

getChangeSupport

protected ChangeSupport getChangeSupport(ChangeType ct)
Description copied from class: AbstractChangeable
Called to retrieve the ChangeSupport for this object

Overrides:
getChangeSupport in class AbstractChangeable

setWeightImpl

protected abstract void setWeightImpl(AtomicSymbol sym,
                                      double weight)
                               throws IllegalSymbolException,
                                      ChangeVetoException
Throws:
IllegalSymbolException
ChangeVetoException

setWeight

public final void setWeight(Symbol sym,
                            double weight)
                     throws IllegalSymbolException,
                            ChangeVetoException
Set the weight of a given symbol in this distribution.

This implementation informs all listeners of the change, and then calls setWeightImpl to make the actual change. Sub-classes should over-ride setWeightImpl to implement the actual storage of the weights.

Specified by:
setWeight in interface Distribution
Parameters:
sym - the Symbol emitted
weight - the probability of emitting that symbol
Throws:
IllegalSymbolException - if s is not from this state's alphabet, or if it is an ambiguity symbol and the implementation can't handle this case
ChangeVetoException - if this state does not allow weights to be tampered with, or if one of the listeners vetoed this change

setNullModelImpl

protected abstract void setNullModelImpl(Distribution nullModel)
                                  throws IllegalAlphabetException,
                                         ChangeVetoException
Throws:
IllegalAlphabetException
ChangeVetoException

setNullModel

public final void setNullModel(Distribution nullModel)
                        throws IllegalAlphabetException,
                               ChangeVetoException
Description copied from interface: Distribution
Set the null model Distribution that this Distribution recognizes.

Specified by:
setNullModel in interface Distribution
Parameters:
nullModel - the new null model Distribution
Throws:
IllegalAlphabetException - if the null model has the wrong alphabet
ChangeVetoException - if this Distirbution doesn't support setting the null model, or if one of its listeners objects

getWeight

public final double getWeight(Symbol sym)
                       throws IllegalSymbolException
Retrieve the weight for this distribution.

Performs the standard munge to handle ambiguity symbols. The actual weights for each attomic symbol should be calculated by the getWeightImpl functions.

Specified by:
getWeight in interface Distribution
Parameters:
sym - the Symbol emitted
Returns:
the probability that one of the symbols matching amb was emitted
Throws:
IllegalSymbolException - if for any reason the symbols within amb are not recognized by this state

getWeightImpl

protected abstract double getWeightImpl(AtomicSymbol sym)
                                 throws IllegalSymbolException
Throws:
IllegalSymbolException

sampleSymbol

public Symbol sampleSymbol()
Description copied from interface: Distribution
Sample a symbol from this state's probability distribution.

Specified by:
sampleSymbol in interface Distribution
Returns:
the symbol sampled

registerWithTrainer

public void registerWithTrainer(DistributionTrainerContext dtc)
Register an IgnoreCountsTrainer instance as the trainer for this distribution. Override this if you wish to implement a trainable distribution.

Specified by:
registerWithTrainer in interface Distribution
Parameters:
dtc - the DistributionTrainerContext with witch to register a trainer