public abstract class AbstractDistribution extends AbstractChangeable implements 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.
Distribution.NullModelForwarder
Modifier and Type | Field and Description |
---|---|
protected ChangeForwarder |
nullModelForwarder
Forwarder for modifications to the null model.
|
NULL_MODEL, WEIGHTS
Constructor and Description |
---|
AbstractDistribution() |
Modifier and Type | Method and Description |
---|---|
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.
|
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getAlphabet, getNullModel
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
protected transient ChangeForwarder nullModelForwarder
public AbstractDistribution()
protected ChangeSupport getChangeSupport(ChangeType ct)
AbstractChangeable
Your implementation of this method should have the following structure:
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.
ChangeSupport cs = super.getChangeSupport(ct);
if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) {
someForwarder = new ChangeForwarder(...
this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange);
}
return cs;
getChangeSupport
in class AbstractChangeable
protected abstract void setWeightImpl(AtomicSymbol sym, double weight) throws IllegalSymbolException, ChangeVetoException
Do not inform any listeners. This has already been done for you. Just update state.
sym
- the AtomicSymbol to update forweight
- the new weight for that symbolIllegalSymbolException
- if the symbol is not knownChangeVetoException
- if the change is to be preventedpublic final void setWeight(Symbol sym, double weight) throws IllegalSymbolException, ChangeVetoException
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.
setWeight
in interface Distribution
sym
- the Symbol to set the weight forweight
- it's new weightIllegalSymbolException
- if sym is not knownChangeVetoException
- if the update was preventedprotected abstract void setNullModelImpl(Distribution nullModel) throws IllegalAlphabetException, ChangeVetoException
You should not inform any change listeners in this method. All of that work has been done for you.
nullModel
- the new null model DistributionIllegalAlphabetException
- if the null model is for the wrong alphabetChangeVetoException
- if your implementation wishes to block this
opperationpublic final void setNullModel(Distribution nullModel) throws IllegalAlphabetException, ChangeVetoException
Distribution
setNullModel
in interface Distribution
nullModel
- the new null model DistributionIllegalAlphabetException
- if the null model has the wrong alphabetChangeVetoException
- if this Distirbution doesn't support setting
the null model, or if one of its listeners objectspublic final double getWeight(Symbol sym) throws IllegalSymbolException
Performs the standard munge to handle ambiguity symbols. The actual weights for each atomic symbol should be calculated by the getWeightImpl functions.
getWeight
in interface Distribution
sym
- the Symbol to find the probability ofIllegalSymbolException
- if for any reason the symbols within amb
are not recognized by this stateprotected abstract double getWeightImpl(AtomicSymbol sym) throws IllegalSymbolException
sym
- the AtomicSymbol to get the weight forIllegalSymbolException
- if sym is not knownpublic Symbol sampleSymbol()
Distribution
sampleSymbol
in interface Distribution
public void registerWithTrainer(DistributionTrainerContext dtc)
registerWithTrainer
in interface Distribution
dtc
- the context to register withCopyright © 2014 BioJava. All rights reserved.