## org.biojava.bio.dist
Class AbstractDistribution

    java.lang.Object
      org.biojava.utils.AbstractChangeable
          org.biojava.bio.dist.AbstractDistribution

All Implemented Interfaces:
  Distribution, Changeable

Direct Known Subclasses:
  AbstractOrderNDistribution, SimpleDistribution, UniformDistribution

    public abstract class AbstractDistribution

extends AbstractChangeable
implements Distribution

An abstract implementation of Distribution.

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

The `registerWithTrainer` method registers an `IgnoreCountsTrainer`. To make an `AbstractDistribution` subclass trainable, this method must be overridden.

Since:
  1.0
Author:
  Matthew Pocock, Thomas Down, Mark Schreiber (serialization support), Greg Cox

Nested Class Summary

Nested classes/interfaces inherited from interface org.biojava.bio.dist.Distribution
`Distribution.NullModelForwarder`

Field Summary
`protected ChangeForwarder` `nullModelForwarder` Forwarder for modifications to the null model.

Fields inherited from interface org.biojava.bio.dist.Distribution
`NULL_MODEL, WEIGHTS`

Constructor Summary
`AbstractDistribution()`

Method Summary
`boolean` `equals(Object o)`
`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)` Override this method to implement getting the weight for an atomic symbol.
`int` `hashCode()`
`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)` Implement this to set the null model.
`void` `setWeight(Symbol sym, double weight)` Set the weight of a given symbol in this distribution.
`protected abstract void` `setWeightImpl(AtomicSymbol sym, double weight)` Implement this to actually set the weight.

Methods inherited from class org.biojava.utils.AbstractChangeable
`addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, 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 ChangeForwarder nullModelForwarder

  Forwarder for modifications to the null model.

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.

  Your implementation of this method should have the following structure: ``

       ChangeSupport cs = super.getChangeSupport(ct);

       if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) {
         someForwarder = new ChangeForwarder(...

         this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange);
       }

       return cs;

  It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.

  Overrides:
    `getChangeSupport` in class `AbstractChangeable`

### setWeightImpl

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

  Implement this to actually set the weight.

  Do not inform any listeners. This has already been done for you. Just update state.

  Parameters:
    `sym` - the AtomicSymbol to update for
    `weight` - the new weight for that symbol
  Throws:
    `IllegalSymbolException` - if the symbol is not known
    `ChangeVetoException` - if the change is to be prevented

### 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 to set the weight for
    `weight` - it's new weight
  Throws:
    `IllegalSymbolException` - if sym is not known
    `ChangeVetoException` - if the update was prevented

### setNullModelImpl

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

  Implement this to set the null model.

  You should not inform any change listeners in this method. All of that work has been done for you.

  Parameters:
    `nullModel` - the new null model Distribution
  Throws:
    `IllegalAlphabetException` - if the null model is for the wrong alphabet
    `ChangeVetoException` - if your implementation wishes to block this opperation

### 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 atomic symbol should be calculated by the getWeightImpl functions.

  Specified by:
    `getWeight` in interface `Distribution`
  Parameters:
    `sym` - the Symbol to find the probability of
  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

  Override this method to implement getting the weight for an atomic symbol. You should just do what is necessary to fetch state. All the work with exceptions and listeners will have been handled for you.

  Parameters:
    `sym` - the AtomicSymbol to get the weight for
  Returns:
    the weight
  Throws:
    `IllegalSymbolException` - if sym is not known

### 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 context to register with

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object o)

  Overrides:
    `equals` in class `Object`