org.biojava.bio.dist
Class SimpleDistributionTrainerContext

java.lang.Object
  extended byorg.biojava.bio.dist.SimpleDistributionTrainerContext
All Implemented Interfaces:
DistributionTrainerContext, java.io.Serializable
Direct Known Subclasses:
SimpleModelTrainer

public class SimpleDistributionTrainerContext
extends java.lang.Object
implements DistributionTrainerContext, java.io.Serializable

A no-frills implementation of DistributionTrainerContext.

Author:
Matthew Pocock
See Also:
Serialized Form

Constructor Summary
SimpleDistributionTrainerContext()
           
 
Method Summary
 void addCount(Distribution dist, Symbol sym, double times)
           Registers that sym was counted in this state.
 void clearCounts()
          Clears all of the counts to zero.
 double getCount(Distribution dist, Symbol sym)
          Return the number of counts of a particular symbol which will be used to train the specified distribution.
 double getNullModelWeight()
          Retrieve the weight of the background distribution
 DistributionTrainer getTrainer(Distribution dist)
          Return the Distribution trainer object from the current context.
 void registerDistribution(Distribution dist)
           Register a distribution object with this context.
 void registerTrainer(Distribution dist, DistributionTrainer trainer)
           Register a Distribution and an associated DistributionTrainer object.
 void setNullModelWeight(double nullModelWeight)
          Assign a weight to the background distribution
 void train()
           Trains the Distribution, given a null model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDistributionTrainerContext

public SimpleDistributionTrainerContext()
Method Detail

getNullModelWeight

public double getNullModelWeight()
Retrieve the weight of the background distribution

Specified by:
getNullModelWeight in interface DistributionTrainerContext
Returns:
the null model weight

setNullModelWeight

public void setNullModelWeight(double nullModelWeight)
Assign a weight to the background distribution

Specified by:
setNullModelWeight in interface DistributionTrainerContext
Parameters:
nullModelWeight - the weight of the null model to assign.

registerDistribution

public void registerDistribution(Distribution dist)
Description copied from interface: DistributionTrainerContext

Register a distribution object with this context.

This method is a request to the context to register dist. If dist is already registered then this method should do nothing. If it is not registered, then it should invoke dist.registerWithTrainer

Specified by:
registerDistribution in interface DistributionTrainerContext
Parameters:
dist - the Distribution to register

registerTrainer

public void registerTrainer(Distribution dist,
                            DistributionTrainer trainer)
Description copied from interface: DistributionTrainerContext

Register a Distribution and an associated DistributionTrainer object.

In the registerWithTrainer method of a Distribution, it should associate itself with a trainer using this method.

Specified by:
registerTrainer in interface DistributionTrainerContext
Parameters:
dist - the distribution to be registered.
trainer - the distribution's trainer object to be registered.

getTrainer

public DistributionTrainer getTrainer(Distribution dist)
Description copied from interface: DistributionTrainerContext
Return the Distribution trainer object from the current context.

Specified by:
getTrainer in interface DistributionTrainerContext
Parameters:
dist - the Distribution whose trainer is required.

addCount

public void addCount(Distribution dist,
                     Symbol sym,
                     double times)
              throws IllegalSymbolException
Description copied from interface: DistributionTrainerContext

Registers that sym was counted in this state.

This method may be called multiple times with the same symbol. In this case, the times should be summed.

Specified by:
addCount in interface DistributionTrainerContext
Parameters:
dist - the Distribution that the symbol was associated with
sym - the Symbol seen
times - the number of times to add
Throws:
IllegalSymbolException

getCount

public double getCount(Distribution dist,
                       Symbol sym)
                throws IllegalSymbolException
Description copied from interface: DistributionTrainerContext
Return the number of counts of a particular symbol which will be used to train the specified distribution.

Specified by:
getCount in interface DistributionTrainerContext
Throws:
IllegalSymbolException

train

public void train()
           throws ChangeVetoException
Description copied from interface: DistributionTrainerContext

Trains the Distribution, given a null model.

This will use the information collected with multiple addCount calls, and the null model to generate the new weights.

Specified by:
train in interface DistributionTrainerContext
Throws:
ChangeVetoException - if any of the distributions can't be trained

clearCounts

public void clearCounts()
Description copied from interface: DistributionTrainerContext
Clears all of the counts to zero.

Specified by:
clearCounts in interface DistributionTrainerContext