Class Table

  • All Implemented Interfaces:
    Distribution

    public final class Table
    extends Object
    implements Distribution
    Used to represent probability distributions, conditional probability distributions, joint probability distributions and more general potentials, over a number of discrete variables. The order of variables in a table is determined by the order in which variables are created (and also time for temporal variables). However we recommend that you avoid using functions that require any knowledge of this ordering unless you are writing low level functions. Instead of needing an index, you can use the get and set methods that take States/Variables as parameters. (indexer methods for C#). This renders the ordering an implementation detail. The variables in a Table are automatically sorted by time (if any) and Variable. This is for computational reasons.

    The Table class stores it's values in a zero based 1-dimensional array, and the right most variable's states toggle fastest. For example if a Table contains 3 binary variables {A,B,C} all with states {T,F} the table layout would be as follows.

    ABCIndex
    TTT0
    TTF1
    TFT2
    TFF3
    FTT4
    FTF5
    FFT6
    FFF7
    If a different variable ordering is required see the TableIterator and TableAccessor classes.
    See Also:
    TableAccessor, TableIterator
    • Constructor Summary

      Constructors 
      Constructor Description
      Table​(Node node)
      Initializes a new instance of the Table class with the specified node variables.
      Table​(Node... nodes)
      Initializes a new instance of the Table class with all the variables from the supplied nodes.
      Table​(Node[] nodes, HeadTail headTail)
      Initializes a new instance of the Table class with all the variables from the supplied nodes.
      Table​(Node node, Integer time)
      Initializes a new instance of the Table class with the specified node variable at the specified time.
      Table​(Table table)
      Initializes a new instance of the Table class, copying the [table] passed in.
      Table​(Table table, boolean copyValues)
      Initializes a new instance of the Table class, with the same structure as an existing [table], copying the values if requested.
      Table​(Table table, boolean copyValues, Integer timeShift)
      Initializes a new instance of the Table class, with the same structure as an existing [table], copying the values if requested, and optionally shifting any times.
      Table​(Table table, Integer timeShift)
      Initializes a new instance of the Table class, copying the [table] passed in, however adjusting any times by the [timeShift].
      Table​(Variable variable)
      Initializes a new instance of the Table class with a single Variable.
      Table​(Variable... variables)
      Initializes a new instance of the Table class with the specified variables.
      Table​(VariableContext variableContext)
      Initializes a new instance of the Table class from a single VariableContext.
      Table​(VariableContext[] variableContexts)
      Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution.
      Table​(VariableContext[] buffer, int count)
      Initializes a new instance of the Table class with [count] variable contexts taken from [buffer].
      Table​(VariableContext[] buffer, int count, HeadTail headTail)
      Initializes a new instance of the Table class with [count] variable contexts taken from [buffer].
      Table​(VariableContextCollection variableContexts)
      Initializes a new instance of the Table class with the variables specified in [variableContexts].
      Table​(Variable variable, Integer time)
      Initializes a new instance of the Table class with a single Variable and time.
      Table​(List<Variable> variables, Integer time)
      Initializes a new instance of the Table class with the specified variables, at an optional time.
      Table​(List<Variable> variables, Integer time, HeadTail headTail)
      Initializes a new instance of the Table class with the specified variables, at an optional time.
      Table​(List<VariableContext> variableContexts)
      Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution.
      Table​(List<VariableContext> variableContexts, HeadTail headTail)
      Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(Table source)
      Adds the values from another table into this instance.
      void addAll​(double value)
      Adds the specified value onto all table elements.
      boolean areAllValuesNonZero()
      Returns true if none of the values in the Table equal zero, or false otherwise.
      Distribution copy()
      Creates a copy of the distribution.
      Distribution copy​(Integer timeShift)
      Creates a copy of the distribution, and shifts any times associated with variables by the specified amount.
      void copyFrom​(double[] data)
      Copies values from the array into the table.
      void copyTo​(double[] destination)
      Copies the table values to an array.
      void copyTo​(Table destination)
      Copies all values from this instance to the destination Table.
      Distribution divide​(Distribution subset)
      Creates a new distribution by dividing this instance by the [subset].
      void divideInPlace​(Table subset)
      Divides this instance in place by the [subset].
      double get​(int index)
      Gets the Table value at the specified index into the 1-dimensional array.
      double get​(State... states)
      Gets the table value corresponding to the given states.
      double get​(StateContext... states)
      Gets the table value corresponding to the given states and associated times.
      boolean getLocked()
      Locks or unlocks a distribution.
      Table.MaxValue getMaxValue()
      Gets the maximum table value, and the index at which it occurs.
      Distribution getOuter()
      Returns the parent distribution, if this instance is aggregated by another distribution.
      Node getOwner()
      Gets the current owner, if assigned to a node.
      int getSortedIndex​(State... states)
      Gets the index of the table element that corresponds to a particular combination of states.
      int getSortedIndex​(StateContext... stateContexts)
      Gets the index of the table element that corresponds to a particular combination of states and their times.
      VariableContextCollection getSortedVariables()
      Gets the collection of variables in the distribution, sorted by time (which may be null) and the order in which variables were created.
      Table getTable()
      Gets the Table which specifies the distribution over any discrete variables.
      Distribution instantiate​(Double[] values)
      Creates a table with a subset of variables by setting hard evidence on one or more variables.
      Table instantiate​(Integer[] values)
      Creates a table with a subset of variables by setting hard evidence on one or more variables.
      boolean isReadOnly()
      Indicates whether the distribution is read only.
      void marginalize​(Distribution superset)
      Marginalizes (sums) the [superset] into this instance.
      void marginalize​(Distribution superset, PropagationMethod propagation)
      Marginalizes (sums) the [superset] into this instance.
      void marginalize​(Table superset)
      Marginalizes (sums) the [superset] into this instance.
      void marginalize​(Table superset, boolean initialize)
      Marginalizes (sums) the [superset] into this instance.
      void marginalize​(Table superset, boolean initialize, PropagationMethod propagation)
      Marginalizes (sums) the [superset] into this instance.
      void marginalize​(Table superset, PropagationMethod propagation)
      Marginalizes (sums) the [superset] into this instance.
      void marginalizeLowMemory​(Table[] tables)
      Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution.
      void marginalizeLowMemory​(Table[] tables, Table.MarginalizeLowMemoryOptions options)
      Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution.
      Distribution multiply​(Distribution distribution)
      Creates a new distribution by multiplying this instance by another distribution.
      void multiplyInPlace​(double value)
      Multiplies all values in the distribution by the specified value.
      void multiplyInPlace​(Table subset)
      Multiplies the [subset] into this instance.
      void multiplyInPlace​(Table subset, boolean initialize)
      Multiplies the [subset] into this instance.
      void nonZero​(Table.NonZeroValues values)
      Returns any non zero table values, keyed by index.
      boolean normalize()
      Normalizes the distribution such that each parent combination sums to 1.
      boolean normalize​(boolean unifyZeroSum)
      Normalizes the distribution such that each parent combination sums to 1.
      void randomize​(RandomNumberGenerator random)
      Randomizes the distribution such that each parent combination sums to 1.
      void set​(double value, State... states)
      Sets the table value corresponding to the given states.
      void set​(double value, StateContext... states)
      Sets the table value corresponding to the given states and associated times.
      void set​(int index, double value)
      Sets the Table value at the specified index into the 1-dimensional array.
      void setAll​(double value)
      Sets all values in the Table to a specified value.
      void setLocked​(boolean value)
      Locks or unlocks a distribution.
      int size()
      The data count in the Table.
      int stateCount​(int index)
      Gets the number of states of a variable at the time this instance was constructed.
      int stateRepeat​(int index)
      Gets the number of times each state is repeated for a Variable in the Table layout.
      double sum()
      Calculates the sum of all values in the Table.
      void timeShift​(int units)
      Shifts any times associated with the table variables by the specified number of units.
      String toString()
    • Constructor Detail

      • Table

        public Table​(Table table,
                     boolean copyValues)
        Initializes a new instance of the Table class, with the same structure as an existing [table], copying the values if requested.
        Parameters:
        table - The table to copy.
        copyValues - if set to true the values from [table] are copied, otherwise all values are initialized to zero.
        Throws:
        NullPointerException - Raised if [table] is null.
      • Table

        public Table​(Table table,
                     boolean copyValues,
                     Integer timeShift)
        Initializes a new instance of the Table class, with the same structure as an existing [table], copying the values if requested, and optionally shifting any times.
        Parameters:
        table - The table to copy.
        copyValues - if set to true the values from [table] are copied, otherwise all values are initialized to zero.
        timeShift - If supplied shifts any times embedded in the source table by the specified number of units.
        Throws:
        NullPointerException - Raised if [table] is null.
      • Table

        public Table​(Variable variable)
        Initializes a new instance of the Table class with a single Variable. All values are initialized to zero.
        Parameters:
        variable - The variable.
        Throws:
        NullPointerException - Raised when [variable] is null.
      • Table

        public Table​(VariableContext variableContext)
        Initializes a new instance of the Table class from a single VariableContext. All values are initialized to zero.
        Parameters:
        variableContext - The variable context.
        Throws:
        NullPointerException - Raised when [variableContext] is null.
      • Table

        public Table​(List<Variable> variables,
                     Integer time)
        Initializes a new instance of the Table class with the specified variables, at an optional time. All values are initialized to zero.
        Parameters:
        variables - The variables.
        time - The time for the variables. Can be null.
        Throws:
        IllegalArgumentException - Raised if a duplicate variable/time combination is detected in [variables], or if a variable has zero states.
      • Table

        public Table​(List<Variable> variables,
                     Integer time,
                     HeadTail headTail)
        Initializes a new instance of the Table class with the specified variables, at an optional time. All values are initialized to zero.
        Parameters:
        variables - The variables.
        time - The time for the variables. Can be null.
        headTail - Specifies whether the variables should be marked as Head or Tail.
        Throws:
        IllegalArgumentException - Raised if a duplicate variable/time combination is detected in [variables], or if a variable has zero states.
      • Table

        public Table​(VariableContextCollection variableContexts)
        Initializes a new instance of the Table class with the variables specified in [variableContexts]. All values are initialized to zero.
        Parameters:
        variableContexts - The variables, times, and head/tail specifications to include in the distribution.
        Throws:
        IllegalArgumentException - Raised if a duplicate variable-time combination is detected in [variableContexts], or if a variable has zero states.
      • Table

        public Table​(VariableContext[] variableContexts)
        Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.
        Parameters:
        variableContexts - The variables, times and head/tail specification. Each VariableContext identifies the variable to be included and allows times to be specified for any temporal variables used in Dynamic Bayesian networks. Time must be null unless the variable belongs to a temporal node.

        Each variable is also marked as head or tail. Head variables are those on the left, and tail variables are those on the right in the expression P(A|B).

        Throws:
        IllegalArgumentException - Raised if a variable-time combination is duplicated in [variableContexts], or if a variable has zero states. Note that a variable can appear more than once if the associated times are different.
      • Table

        public Table​(List<VariableContext> variableContexts)
        Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.
        Parameters:
        variableContexts - The variables, times and head/tail specification. Each VariableContext identifies the variable to be included and allows times to be specified for any temporal variables used in Dynamic Bayesian networks. Time must be null unless the variable belongs to a temporal node.

        Each variable is also marked as head or tail. Head variables are those on the left, and tail variables are those on the right in the expression P(A|B).

        Throws:
        IllegalArgumentException - Raised if a variable-time combination is duplicated in [variableContexts], or if a variable has zero states. Note that a variable can appear more than once if the associated times are different.
      • Table

        public Table​(List<VariableContext> variableContexts,
                     HeadTail headTail)
        Initializes a new instance of the Table class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.
        Parameters:
        variableContexts - The variables and any times.
        headTail - Overrides the Head or Tail value found in each VariableContext. Each VariableContext identifies the variable to be included and allows times to be specified for any temporal variables used in Dynamic Bayesian networks. Time must be null unless the variable belongs to a temporal node.

        Each variable is also marked as head or tail. Head variables are those on the left, and tail variables are those on the right in the expression P(A|B).

        Throws:
        IllegalArgumentException - Raised if a variable-time combination is duplicated in [variableContexts], or if a variable has zero states. Note that a variable can appear more than once if the associated times are different.
      • Table

        public Table​(Variable... variables)
        Initializes a new instance of the Table class with the specified variables. All values are initialized to zero.
        Parameters:
        variables - The variables.
        Throws:
        NullPointerException - Raised if [variables] is null.
        IllegalArgumentException - Raised if a duplicate variable-time combination is detected in [variables], or if a variable has zero states.
      • Table

        public Table​(VariableContext[] buffer,
                     int count)
        Initializes a new instance of the Table class with [count] variable contexts taken from [buffer]. All values are initialized to zero.
        Parameters:
        buffer - The buffer of VariableContext instances.
        count - The number of items to read from [buffer].
        Throws:
        NullPointerException - Raised if [buffer] is null.
        IllegalArgumentException - Raised if a null or duplicate variable-time combination is detected in [buffer], or if a variable has zero states.
      • Table

        public Table​(VariableContext[] buffer,
                     int count,
                     HeadTail headTail)
        Initializes a new instance of the Table class with [count] variable contexts taken from [buffer]. All values are initialized to zero.
        Parameters:
        buffer - The buffer of VariableContext instances.
        count - The number of items to read from [buffer].
        headTail - Overrides the Head or Tail value found in each VariableContext.
        Throws:
        NullPointerException - Raised if [buffer] is null.
        IllegalArgumentException - Raised if a null or duplicate variable-time combination is detected in [buffer], or if a variable has zero states.
      • Table

        public Table​(Node node,
                     Integer time)
        Initializes a new instance of the Table class with the specified node variable at the specified time. All values are initialized to zero.
        Parameters:
        node - The node whose variable is used to construct the Table.
        time - The time for the node variable. Can be null.
        Throws:
        IllegalArgumentException - Raised if a node variable has zero states.
      • Table

        public Table​(Variable variable,
                     Integer time)
        Initializes a new instance of the Table class with a single Variable and time. All values are initialized to zero.
        Parameters:
        variable - The variable.
        time - The variable time. Can be null for non temporal nodes.
        Throws:
        NullPointerException - Raised when [variable] is null.
      • Table

        public Table​(Node... nodes)
        Initializes a new instance of the Table class with all the variables from the supplied nodes. All values are initialized to zero.
        Parameters:
        nodes - The Node instances.
        Throws:
        NullPointerException - Raised if [nodes] is null.
        IllegalArgumentException - Raised if a null or duplicate variable is detected or if a variable has zero states.
      • Table

        public Table​(Node[] nodes,
                     HeadTail headTail)
        Initializes a new instance of the Table class with all the variables from the supplied nodes. All values are initialized to zero.
        Parameters:
        nodes - The Node instances.
        headTail - Specifies whether the node variables should be marked as Head or Tail.
        Throws:
        NullPointerException - Raised if [nodes] is null.
        IllegalArgumentException - Raised if a null or duplicate variable is detected or if a variable has zero states.
      • Table

        public Table​(Table table)
        Initializes a new instance of the Table class, copying the [table] passed in.
        Parameters:
        table - The table to copy.
        Throws:
        NullPointerException - Raised if [table] is null.
      • Table

        public Table​(Table table,
                     Integer timeShift)
        Initializes a new instance of the Table class, copying the [table] passed in, however adjusting any times by the [timeShift].
        Parameters:
        table - The table to copy.
        timeShift - The number of units to shift any time values associated with variables.
        Throws:
        NullPointerException - Raised if [table] is null.
      • Table

        public Table​(Node node)
        Initializes a new instance of the Table class with the specified node variables. All values are initialized to zero.
        Parameters:
        node - The node whose variables are used to construct the Table.
        Throws:
        IllegalArgumentException - Raised if a node variable has zero states.
    • Method Detail

      • nonZero

        public void nonZero​(Table.NonZeroValues values)
        Returns any non zero table values, keyed by index.
      • getMaxValue

        public Table.MaxValue getMaxValue()
        Gets the maximum table value, and the index at which it occurs.
        Returns:
        The maximum table value and the zero based index at which it occurs.
      • timeShift

        public void timeShift​(int units)
        Shifts any times associated with the table variables by the specified number of units.
        Specified by:
        timeShift in interface Distribution
        Parameters:
        units - The number of time units to shift. Can be negative if required.
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • isReadOnly

        public boolean isReadOnly()
        Indicates whether the distribution is read only. A distribution is read only if it is locked or is assigned to a Node.
        Specified by:
        isReadOnly in interface Distribution
        Returns:
        true if read only; otherwise, false.
      • randomize

        public void randomize​(RandomNumberGenerator random)
        Randomizes the distribution such that each parent combination sums to 1.
        Parameters:
        random - Random number generator.
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • normalize

        public boolean normalize​(boolean unifyZeroSum)
        Normalizes the distribution such that each parent combination sums to 1.
        Parameters:
        unifyZeroSum - If true, applies a uniform distribution to any parent combinations that sum to zero.
        Returns:
        false if a zero sum was found for any parent combination; true otherwise
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • normalize

        public boolean normalize()
        Normalizes the distribution such that each parent combination sums to 1.
        Returns:
        false if a zero sum was found for any parent combination; true otherwise.
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • getOuter

        public Distribution getOuter()
        Description copied from interface: Distribution
        Returns the parent distribution, if this instance is aggregated by another distribution.
        Specified by:
        getOuter in interface Distribution
      • copy

        public Distribution copy()
        Creates a copy of the distribution. The new distribution will not have an owner.
        Specified by:
        copy in interface Distribution
        Returns:
        A copy of this instance.
      • copy

        public Distribution copy​(Integer timeShift)
        Creates a copy of the distribution, and shifts any times associated with variables by the specified amount. The new distribution will not have an owner.
        Specified by:
        copy in interface Distribution
        Parameters:
        timeShift - The amount to shift any times present in the distribution. Can be negative.
        Returns:
        A copy of this instance, with shifted times.
      • getOwner

        public Node getOwner()
        Gets the current owner, if assigned to a node. A distribution cannot be modified when it is assigned to a node.
        Specified by:
        getOwner in interface Distribution
        Returns:
        The owner, or null if not assigned to a node.
      • areAllValuesNonZero

        public boolean areAllValuesNonZero()
        Returns true if none of the values in the Table equal zero, or false otherwise.
        Returns:
        True if none of the values are zero; false otherwise.
      • copyFrom

        public void copyFrom​(double[] data)
        Copies values from the array into the table.
        Parameters:
        data - Values to copy. The array can be shorter or longer than the size().
        Throws:
        NullPointerException - Raised if [data] is null.
        IllegalStateException - Raised if this instance is read only.
      • copyTo

        public void copyTo​(Table destination)
        Copies all values from this instance to the destination Table.
        Parameters:
        destination - The destination table, which can have a count greater than or equal to this instance.
        Throws:
        IllegalStateException - Raised if the destination table is read only.
      • copyTo

        public void copyTo​(double[] destination)
        Copies the table values to an array.
        Parameters:
        destination - The destination array, which must have length equal to or greater than this the count of this instance.
        Throws:
        NullPointerException - Raised if [destination] is null.
        IllegalArgumentException - Raised if [destination] is too short.
      • addAll

        public void addAll​(double value)
        Adds the specified value onto all table elements.
        Parameters:
        value - The value to add. Can be negative.
      • setAll

        public void setAll​(double value)
        Sets all values in the Table to a specified value.
        Parameters:
        value - The value to set all elements to.
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • stateRepeat

        public int stateRepeat​(int index)
        Gets the number of times each state is repeated for a Variable in the Table layout. See Table for details on layout.
        Parameters:
        index - The index into getSortedVariables().
        Returns:
        The repeat count for each state.
      • stateCount

        public int stateCount​(int index)
        Gets the number of states of a variable at the time this instance was constructed.
        Parameters:
        index - The index into getSortedVariables().
        Returns:
        The state count.
      • size

        public int size()
        The data count in the Table. Equals the product of states for each Variable.
        Returns:
        The data count.
      • get

        public double get​(State... states)
        Gets the table value corresponding to the given states.
        Parameters:
        states - The variable states that together specify a unique value in this table. For example, if the table represents P(A|B) we can access the value corresponding to P(A=True | B=False) by passing in the states A=True and B=False.
        Returns:
        The table value.
      • set

        public void set​(double value,
                        State... states)
        Sets the table value corresponding to the given states.
        Parameters:
        states - The variable states that together specify a unique value in this table. For example, if the table represents P(A|B) we can access the value corresponding to P(A=True | B=False) by passing in the states A=True and B=False.
      • get

        public double get​(StateContext... states)
        Gets the table value corresponding to the given states and associated times.
        Parameters:
        states - The variable states and times that together specify a unique value in this table.
      • set

        public void set​(double value,
                        StateContext... states)
        Sets the table value corresponding to the given states and associated times.
        Parameters:
        states - The variable states and times that together specify a unique value in this table.
      • getSortedIndex

        public int getSortedIndex​(State... states)
        Gets the index of the table element that corresponds to a particular combination of states.
        Parameters:
        states - A state for each variable.
        Returns:
        The index corresponding to the states.
      • getSortedIndex

        public int getSortedIndex​(StateContext... stateContexts)
        Gets the index of the table element that corresponds to a particular combination of states and their times.
        Parameters:
        stateContexts - A state and time for each variable. Time can be null for non temporal variables.
        Returns:
        The index corresponding to the states.
      • get

        public double get​(int index)
        Gets the Table value at the specified index into the 1-dimensional array. See Table for information on how entries are stored.
        Parameters:
        index - The index into the underlying 1-dimensional array.
        Returns:
        The value at the specified index.
      • set

        public void set​(int index,
                        double value)
        Sets the Table value at the specified index into the 1-dimensional array. See Table for information on how entries are stored.
        Parameters:
        index - The index into the underlying 1-dimensional array.
      • getSortedVariables

        public VariableContextCollection getSortedVariables()
        Gets the collection of variables in the distribution, sorted by time (which may be null) and the order in which variables were created. All variables in each distribution are sorted, based on their creation order. This is for computational reasons. If you want to access the values with respect to a different variable ordering, see the TableIterator and TableAccessor classes.
        Specified by:
        getSortedVariables in interface Distribution
        Returns:
        Variables sorted by time and the order variables were created.
      • sum

        public double sum()
        Calculates the sum of all values in the Table.
        Returns:
        The sum of all table values.
      • getTable

        public Table getTable()
        Description copied from interface: Distribution
        Gets the Table which specifies the distribution over any discrete variables. Often referred to as a Mixture.
        Specified by:
        getTable in interface Distribution
        Returns:
        The table.
      • divide

        public Distribution divide​(Distribution subset)
        Creates a new distribution by dividing this instance by the [subset]. Also known as the complement. If the resulting distribution were subsequently multiplied by [subset], the result would be equivalent to this instance.
        Specified by:
        divide in interface Distribution
        Parameters:
        subset - The subset to divide by.
        Returns:
        The new distribution.
        Throws:
        NullPointerException - Raised if [subset] is null.
      • divideInPlace

        public void divideInPlace​(Table subset)
        Divides this instance in place by the [subset]. Also known as the complement.

        The term 'in place' means that this instance is modified, instead of creating a new distribution.

        If the resulting distribution were subsequently multiplied by [subset], the result would be equivalent to this instance.
        Parameters:
        subset - The subset to divide by.
        Throws:
        NullPointerException - Raised if [subset] is null.
        IllegalStateException - Raised if this instance is read only.
      • instantiate

        public Table instantiate​(Integer[] values)
        Creates a table with a subset of variables by setting hard evidence on one or more variables.
        Parameters:
        values - An array of nullable state indexes, one for each variable in this Table instance. Values are null for variables with no evidence.
        Returns:
        The Table of instantiated values. I.e. The table after some variables have been set.
        Throws:
        NullPointerException - Raised if [values] is null.
        IllegalArgumentException - Raised if the length of [values] does not equal the number of variables in the table.
        IllegalStateException - Raised if this instance is read only.
      • marginalize

        public void marginalize​(Distribution superset)
        Marginalizes (sums) the [superset] into this instance. This method initializes all values to zero before performing the marginalization. If you know that all the values are zero (e.g. when a Table is first created), call an overloaded version of this method.
        Specified by:
        marginalize in interface Distribution
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalize

        public void marginalize​(Distribution superset,
                                PropagationMethod propagation)
        Marginalizes (sums) the [superset] into this instance. This method initializes all values to zero before performing the marginalization. If you know that all the values are zero (e.g. when a Table is first created), call an overloaded version of this method.
        Specified by:
        marginalize in interface Distribution
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        propagation - The propagation method to use during marginalization.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalize

        public void marginalize​(Table superset)
        Marginalizes (sums) the [superset] into this instance. This method initializes all values to zero before performing the marginalization. If you know that all the values are zero (e.g. when a Table is first created), call an overloaded version of this method.
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalize

        public void marginalize​(Table superset,
                                PropagationMethod propagation)
        Marginalizes (sums) the [superset] into this instance. This method initializes all values to zero before performing the marginalization. If you know that all the values are zero (e.g. when a Table is first created), call an overloaded version of this method.
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        propagation - The propagation method to use during marginalization.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalize

        public void marginalize​(Table superset,
                                boolean initialize)
        Marginalizes (sums) the [superset] into this instance. By default all table values are zero, however if the Table values are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        initialize - Set to true if all values should be initialized to 0 before the marginalization.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalize

        public void marginalize​(Table superset,
                                boolean initialize,
                                PropagationMethod propagation)
        Marginalizes (sums) the [superset] into this instance. By default all table values are zero, however if the Table values are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.
        Parameters:
        superset - A Table whose variables form a superset of the variables in this instance.
        initialize - Set to true if all values should be initialized to 0 before the marginalization.
        propagation - The propagation method to use during marginalization.
        Throws:
        NullPointerException - Raised if [superset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if [superset] does not contain all the variables in this instance.
      • marginalizeLowMemory

        public void marginalizeLowMemory​(Table[] tables)
        Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution. This method uses very little memory, however in general will perform worse than the standard Marginalize routines.
        Parameters:
        tables - The tables whose combined distribution you wish to marginalize.
        Throws:
        NullPointerException - Raised if [tables] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
      • marginalizeLowMemory

        public void marginalizeLowMemory​(Table[] tables,
                                         Table.MarginalizeLowMemoryOptions options)
        Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution. This method uses very little memory, however in general will perform worse than the standard Marginalize routines.
        Parameters:
        tables - The tables whose combined distribution you wish to marginalize.
        options - Options governing the method, including cancellation.
        Throws:
        NullPointerException - Raised if [tables] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
      • multiply

        public Distribution multiply​(Distribution distribution)
        Creates a new distribution by multiplying this instance by another distribution.
        Specified by:
        multiply in interface Distribution
        Parameters:
        distribution - A distribution to multiply by.
        Returns:
        A new combined distribution.
        Throws:
        NullPointerException - Raised if [distribution] is null.
        IllegalArgumentException - Raised if the variables in [distribution] are not contained in this instance.
      • multiplyInPlace

        public void multiplyInPlace​(double value)
        Multiplies all values in the distribution by the specified value.
        Parameters:
        value - The value to multiply by.
        Throws:
        IllegalStateException - Raised if this instance is read only.
      • multiplyInPlace

        public void multiplyInPlace​(Table subset)
        Multiplies the [subset] into this instance.

        The term 'in place' means that this instance is modified, instead of creating a new distribution.

        By default all table values are zero, so if the Table needs to be initialized to 1 before multiplication use a different overload of this method.
        Parameters:
        subset - A Table whose variables form a subset of the variables in this instance.
        Throws:
        NullPointerException - Raised if [subset] is null.
        IllegalStateException - Raised if this instance is currently read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if the variables in [subset] are not contained in this instance.
      • multiplyInPlace

        public void multiplyInPlace​(Table subset,
                                    boolean initialize)
        Multiplies the [subset] into this instance.

        The term 'in place' means that this instance is modified, instead of creating a new distribution.

        By default all table values are zero, so the [initialize] parameter avoids the need to initialize all values in the distribution to 1 before performing the multiplication.
        Parameters:
        subset - A Table whose variables form a subset of the variables in this instance.
        initialize - Set to true if all values should be initialized to 1 before the multiplication.
        Throws:
        NullPointerException - Raised if [subset] is null.
        IllegalStateException - Raised if this instance is read only, or if any variables are no longer sorted correctly due to modifications of the network.
        IllegalArgumentException - Raised if the variables in [subset] are not contained in this instance.