public class TranslatedDistribution extends AbstractChangeable implements Distribution, Serializable
getWeight
method returns the result of calling getWeight on the underlying
distribution, having first translated the Symbol parameter using
the supplied ReversibleTranslationTable. All changes to the
underlying distribution are reflected by the TranslatedDistribution.
The TranslatedDistribution is not directly mutable: calling
setWeight will result in a ChangeVetoException.
However, a DistributionTrainer may be registered for a
TranslatedDistribution. Any counts received by this trainer
are untranslated then forwarded to the underlying distribution. It is
valid to add counts to both a TranslatedDistribution and
its underlying distribution in a single training session, so
TranslatedDistribution objects are useful for tying
parameters together when training Markov Models.
Distribution d = DistributionFactory.DEFAULT.createDistribution(DNATools.getDNA());
d.setWeight(DNATools.a(), 0.7);
d.setWeight(DNATools.c(), 0.1);
d.setWeight(DNATools.g(), 0.1);
d.setWeight(DNATools.t(), 0.1);
Distribution complemented = new TranslatedDistribution(
DNATools.complementTable(),
d,
DistributionFactory.DEFAULT
);
System.out.println(
"complemented.getWeight(DNATools.t()) = " +
complemented.getWeight(DNATools.t())
); // Should print 0.7
Distribution.NullModelForwarderNULL_MODEL, WEIGHTS| Constructor and Description |
|---|
TranslatedDistribution(ReversibleTranslationTable table,
Distribution other,
DistributionFactory distFact)
Create a new TranslatedDistribution.
|
| Modifier and Type | Method and Description |
|---|---|
Alphabet |
getAlphabet()
The alphabet from which this spectrum emits symbols.
|
protected ChangeSupport |
getChangeSupport(ChangeType ct)
Called to retrieve the ChangeSupport for this object.
|
Distribution |
getNullModel()
Retrieve the null model Distribution that this Distribution recognizes.
|
ReversibleTranslationTable |
getTable()
Retrieve the translation table encapsulating the map from this emission
spectrum to the underlying one.
|
double |
getWeight(Symbol sym)
Return the probability that Symbol s is emitted by this spectrum.
|
void |
registerWithTrainer(DistributionTrainerContext dtc)
Register this distribution with a training context.
|
Symbol |
sampleSymbol()
Sample a symbol from this state's probability distribution.
|
void |
setNullModel(Distribution dist)
Set the null model Distribution that this Distribution recognizes.
|
void |
setWeight(Symbol sym,
double weight)
Set the probability or odds that Symbol s is emitted by this state.
|
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListenerpublic TranslatedDistribution(ReversibleTranslationTable table, Distribution other, DistributionFactory distFact) throws IllegalAlphabetException
table - a ReversibleTranslationTable used to map the symbolsother - the underlying ditributiondistFact - a DistributionFactory used to create a delegate for
stooring mapped weightsIllegalAlphabetExceptionpublic Alphabet getAlphabet()
DistributiongetAlphabet in interface Distributionpublic double getWeight(Symbol sym) throws IllegalSymbolException
DistributionReturn the probability that Symbol s is emitted by this spectrum.
If the symbol is ambiguou, then it is the sum of the probability that each one of the matching symbols was emitted.
getWeight in interface Distributionsym - the Symbol emittedIllegalSymbolException - if s is not from this state's alphabetpublic void setWeight(Symbol sym, double weight) throws IllegalSymbolException, ChangeVetoException
DistributionsetWeight in interface Distributionsym - the Symbol emittedweight - the probability of emitting that symbolIllegalSymbolException - if s is not from this state's alphabet, or
if it is an ambiguity symbol and the implementation can't handle
this caseChangeVetoException - if this state does not allow weights
to be tampered with, or if one of the listeners vetoed this changepublic Symbol sampleSymbol()
DistributionsampleSymbol in interface Distributionpublic Distribution getNullModel()
DistributiongetNullModel in interface Distributionpublic void setNullModel(Distribution dist) throws IllegalAlphabetException, ChangeVetoException
DistributionsetNullModel in interface Distributiondist - 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 ReversibleTranslationTable getTable()
public void registerWithTrainer(DistributionTrainerContext dtc)
DistributionRegister this distribution with a training context.
This should be invoked from within dtc.addDistribution(). This method is responsible for constructing a suitable DistributionTrainer instance and registering it by calling dtc.registerDistributionTrainer(this, trainer). If the distribution is a view onto another distribution, it can force the other to be registered by calling dtc.addDistribution(other), and can then get on with registering it's own trainer.
registerWithTrainer in interface Distributiondtc - the DistributionTrainerContext with witch to register a trainerprotected 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 AbstractChangeableCopyright © 2020 BioJava. All rights reserved.