Class TranslatedDistribution
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojava.bio.dist.TranslatedDistribution
-
- All Implemented Interfaces:
Serializable,Distribution,Changeable
public class TranslatedDistribution extends AbstractChangeable implements Distribution, Serializable
A translated view of some underlying distribution. ThegetWeightmethod returns the result of callinggetWeighton the underlying distribution, having first translated theSymbolparameter using the suppliedReversibleTranslationTable. All changes to the underlying distribution are reflected by theTranslatedDistribution.The
TranslatedDistributionis not directly mutable: callingsetWeightwill result in aChangeVetoException. However, aDistributionTrainermay be registered for aTranslatedDistribution. Any counts received by this trainer are untranslated then forwarded to the underlying distribution. It is valid to add counts to both aTranslatedDistributionand its underlying distribution in a single training session, soTranslatedDistributionobjects are useful for tying parameters together when training Markov Models.Example usage
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- Since:
- 1.1
- Author:
- Matthew Pocock, Thomas Down
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.dist.Distribution
Distribution.NullModelForwarder
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.dist.Distribution
NULL_MODEL, WEIGHTS
-
-
Constructor Summary
Constructors Constructor Description TranslatedDistribution(ReversibleTranslationTable table, Distribution other, DistributionFactory distFact)Create a new TranslatedDistribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AlphabetgetAlphabet()The alphabet from which this spectrum emits symbols.protected ChangeSupportgetChangeSupport(ChangeType ct)Called to retrieve the ChangeSupport for this object.DistributiongetNullModel()Retrieve the null model Distribution that this Distribution recognizes.ReversibleTranslationTablegetTable()Retrieve the translation table encapsulating the map from this emission spectrum to the underlying one.doublegetWeight(Symbol sym)Return the probability that Symbol s is emitted by this spectrum.voidregisterWithTrainer(DistributionTrainerContext dtc)Register this distribution with a training context.SymbolsampleSymbol()Sample a symbol from this state's probability distribution.voidsetNullModel(Distribution dist)Set the null model Distribution that this Distribution recognizes.voidsetWeight(Symbol sym, double weight)Set the probability or odds that Symbol s is emitted by this state.-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, 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.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
-
-
-
Constructor Detail
-
TranslatedDistribution
public TranslatedDistribution(ReversibleTranslationTable table, Distribution other, DistributionFactory distFact) throws IllegalAlphabetException
Create a new TranslatedDistribution. Make these things via getDistribuiton.- Parameters:
table- a ReversibleTranslationTable used to map the symbolsother- the underlying ditributiondistFact- a DistributionFactory used to create a delegate for stooring mapped weights- Throws:
IllegalAlphabetException
-
-
Method Detail
-
getAlphabet
public Alphabet getAlphabet()
Description copied from interface:DistributionThe alphabet from which this spectrum emits symbols.- Specified by:
getAlphabetin interfaceDistribution- Returns:
- the Alphabet associated with this spectrum
-
getWeight
public double getWeight(Symbol sym) throws IllegalSymbolException
Description copied from interface: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.
- Specified by:
getWeightin interfaceDistribution- Parameters:
sym- the Symbol emitted- Returns:
- the probability of emitting that symbol
- Throws:
IllegalSymbolException- if s is not from this state's alphabet
-
setWeight
public void setWeight(Symbol sym, double weight) throws IllegalSymbolException, ChangeVetoException
Description copied from interface:DistributionSet the probability or odds that Symbol s is emitted by this state.- Specified by:
setWeightin interfaceDistribution- Parameters:
sym- the Symbol emittedweight- 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 caseChangeVetoException- if this state does not allow weights to be tampered with, or if one of the listeners vetoed this change
-
sampleSymbol
public Symbol sampleSymbol()
Description copied from interface:DistributionSample a symbol from this state's probability distribution.- Specified by:
sampleSymbolin interfaceDistribution- Returns:
- the symbol sampled
-
getNullModel
public Distribution getNullModel()
Description copied from interface:DistributionRetrieve the null model Distribution that this Distribution recognizes.- Specified by:
getNullModelin interfaceDistribution- Returns:
- the apropriate null model
-
setNullModel
public void setNullModel(Distribution dist) throws IllegalAlphabetException, ChangeVetoException
Description copied from interface:DistributionSet the null model Distribution that this Distribution recognizes.- Specified by:
setNullModelin interfaceDistribution- Parameters:
dist- the new null model Distribution- Throws:
IllegalAlphabetException- if the null model has the wrong alphabetChangeVetoException- if this Distirbution doesn't support setting the null model, or if one of its listeners objects
-
getTable
public ReversibleTranslationTable getTable()
Retrieve the translation table encapsulating the map from this emission spectrum to the underlying one.- Returns:
- a ReversibleTranslationtTable
-
registerWithTrainer
public void registerWithTrainer(DistributionTrainerContext dtc)
Description copied from interface: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.
- Specified by:
registerWithTrainerin interfaceDistribution- Parameters:
dtc- the DistributionTrainerContext with witch to register a trainer
-
getChangeSupport
protected ChangeSupport getChangeSupport(ChangeType ct)
Description copied from class:AbstractChangeableCalled to retrieve the ChangeSupport for this object.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;- Overrides:
getChangeSupportin classAbstractChangeable
-
-