Class 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
    • 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
      • 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
      • 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