Class Table
- java.lang.Object
-
- com.bayesserver.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 aTableare automatically sorted by time (if any) andVariable. This is for computational reasons.The
Tableclass stores it's values in a zero based 1-dimensional array, and the right most variable's states toggle fastest. For example if aTablecontains 3 binary variables {A,B,C} all with states {T,F} the table layout would be as follows.If a different variable ordering is required see theA B C Index T T T 0 T T F 1 T F T 2 T F F 3 F T T 4 F T F 5 F F T 6 F F F 7 TableIteratorandTableAccessorclasses.- See Also:
TableAccessor,TableIterator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTable.MarginalizeLowMemoryOptionsOptions controllingmarginalizeLowMemory(com.bayesserver.Table[]).static classTable.MaxValuestatic interfaceTable.NonZeroValuesUsed to report non zero table values.
-
Constructor Summary
Constructors Constructor Description Table(Node node)Initializes a new instance of theTableclass with the specified node variables.Table(Node... nodes)Initializes a new instance of theTableclass with all the variables from the supplied nodes.Table(Node[] nodes, HeadTail headTail)Initializes a new instance of theTableclass with all the variables from the supplied nodes.Table(Node node, Integer time)Initializes a new instance of theTableclass with the specified node variable at the specified time.Table(Table table)Initializes a new instance of theTableclass, copying the [table] passed in.Table(Table table, boolean copyValues)Initializes a new instance of theTableclass, 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 theTableclass, 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 theTableclass, copying the [table] passed in, however adjusting any times by the [timeShift].Table(Variable variable)Table(Variable... variables)Initializes a new instance of theTableclass with the specified variables.Table(VariableContext variableContext)Initializes a new instance of theTableclass from a singleVariableContext.Table(VariableContext[] variableContexts)Initializes a new instance of theTableclass with [variableContexts] specifying which variables to include in the distribution.Table(VariableContext[] buffer, int count)Initializes a new instance of theTableclass with [count] variable contexts taken from [buffer].Table(VariableContext[] buffer, int count, HeadTail headTail)Initializes a new instance of theTableclass with [count] variable contexts taken from [buffer].Table(VariableContextCollection variableContexts)Initializes a new instance of theTableclass with the variables specified in [variableContexts].Table(Variable variable, Integer time)Table(List<Variable> variables, Integer time)Initializes a new instance of theTableclass with the specified variables, at an optional time.Table(List<Variable> variables, Integer time, HeadTail headTail)Initializes a new instance of theTableclass with the specified variables, at an optional time.Table(List<VariableContext> variableContexts)Initializes a new instance of theTableclass with [variableContexts] specifying which variables to include in the distribution.Table(List<VariableContext> variableContexts, HeadTail headTail)Initializes a new instance of theTableclass with [variableContexts] specifying which variables to include in the distribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Table source)Adds the values from another table into this instance.voidaddAll(double value)Adds the specified value onto all table elements.booleanareAllValuesNonZero()Returns true if none of the values in theTableequal zero, or false otherwise.Distributioncopy()Creates a copy of the distribution.Distributioncopy(Integer timeShift)Creates a copy of the distribution, and shifts any times associated with variables by the specified amount.voidcopyFrom(double[] data)Copies values from the array into the table.voidcopyTo(double[] destination)Copies the table values to an array.voidcopyTo(Table destination)Copies all values from this instance to the destinationTable.Distributiondivide(Distribution subset)Creates a new distribution by dividing this instance by the [subset].voiddivideInPlace(Table subset)Divides this instance in place by the [subset].doubleget(int index)Gets theTablevalue at the specified index into the 1-dimensional array.doubleget(State... states)Gets the table value corresponding to the given states.doubleget(StateContext... states)Gets the table value corresponding to the given states and associated times.booleangetLocked()Locks or unlocks a distribution.Table.MaxValuegetMaxValue()Gets the maximum table value, and the index at which it occurs.DistributiongetOuter()Returns the parent distribution, if this instance is aggregated by another distribution.NodegetOwner()Gets the current owner, if assigned to a node.intgetSortedIndex(State... states)Gets the index of the table element that corresponds to a particular combination of states.intgetSortedIndex(StateContext... stateContexts)Gets the index of the table element that corresponds to a particular combination of states and their times.VariableContextCollectiongetSortedVariables()Gets the collection of variables in the distribution, sorted by time (which may be null) and the order in which variables were created.TablegetTable()Gets theTablewhich specifies the distribution over any discrete variables.Distributioninstantiate(Double[] values)Creates a table with a subset of variables by setting hard evidence on one or more variables.Tableinstantiate(Integer[] values)Creates a table with a subset of variables by setting hard evidence on one or more variables.booleanisReadOnly()Indicates whether the distribution is read only.voidmarginalize(Distribution superset)Marginalizes (sums) the [superset] into this instance.voidmarginalize(Distribution superset, PropagationMethod propagation)Marginalizes (sums) the [superset] into this instance.voidmarginalize(Table superset)Marginalizes (sums) the [superset] into this instance.voidmarginalize(Table superset, boolean initialize)Marginalizes (sums) the [superset] into this instance.voidmarginalize(Table superset, boolean initialize, PropagationMethod propagation)Marginalizes (sums) the [superset] into this instance.voidmarginalize(Table superset, PropagationMethod propagation)Marginalizes (sums) the [superset] into this instance.voidmarginalizeLowMemory(Table[] tables)Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution.voidmarginalizeLowMemory(Table[] tables, Table.MarginalizeLowMemoryOptions options)Marginalizes (sums) the combined [tables], without requiring the memory for the combined distribution.Distributionmultiply(Distribution distribution)Creates a new distribution by multiplying this instance by another distribution.voidmultiplyInPlace(double value)Multiplies all values in the distribution by the specified value.voidmultiplyInPlace(Table subset)Multiplies the [subset] into this instance.voidmultiplyInPlace(Table subset, boolean initialize)Multiplies the [subset] into this instance.voidnonZero(Table.NonZeroValues values)Returns any non zero table values, keyed by index.booleannormalize()Normalizes the distribution such that each parent combination sums to 1.booleannormalize(boolean unifyZeroSum)Normalizes the distribution such that each parent combination sums to 1.voidrandomize(RandomNumberGenerator random)Randomizes the distribution such that each parent combination sums to 1.voidset(double value, State... states)Sets the table value corresponding to the given states.voidset(double value, StateContext... states)Sets the table value corresponding to the given states and associated times.voidset(int index, double value)Sets theTablevalue at the specified index into the 1-dimensional array.voidsetAll(double value)Sets all values in theTableto a specified value.voidsetLocked(boolean value)Locks or unlocks a distribution.intsize()The data count in theTable.intstateCount(int index)Gets the number of states of a variable at the time this instance was constructed.intstateRepeat(int index)doublesum()Calculates the sum of all values in theTable.voidtimeShift(int units)Shifts any times associated with the table variables by the specified number of units.StringtoString()
-
-
-
Constructor Detail
-
Table
public Table(Table table, boolean copyValues)
Initializes a new instance of theTableclass, with the same structure as an existing [table], copying the values if requested.- Parameters:
table- The table to copy.copyValues- if set totruethe 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 theTableclass, 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 totruethe 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 theTableclass with a singleVariable. 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 theTableclass from a singleVariableContext. 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 theTableclass 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 theTableclass 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 theTableclass 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 theTableclass 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. EachVariableContextidentifies 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 theTableclass 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. EachVariableContextidentifies 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 theTableclass 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 eachVariableContext. EachVariableContextidentifies 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 theTableclass 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 theTableclass with [count] variable contexts taken from [buffer]. All values are initialized to zero.- Parameters:
buffer- The buffer ofVariableContextinstances.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 theTableclass with [count] variable contexts taken from [buffer]. All values are initialized to zero.- Parameters:
buffer- The buffer ofVariableContextinstances.count- The number of items to read from [buffer].headTail- Overrides the Head or Tail value found in eachVariableContext.- 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 theTableclass 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 theTable.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 theTableclass with a singleVariableand 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 theTableclass with all the variables from the supplied nodes. All values are initialized to zero.- Parameters:
nodes- TheNodeinstances.- 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 theTableclass with all the variables from the supplied nodes. All values are initialized to zero.- Parameters:
nodes- TheNodeinstances.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 theTableclass, 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 theTableclass, 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 theTableclass with the specified node variables. All values are initialized to zero.- Parameters:
node- The node whose variables are used to construct theTable.- 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:
timeShiftin interfaceDistribution- Parameters:
units- The number of time units to shift. Can be negative if required.- Throws:
IllegalStateException- Raised if this instance is read only.
-
getLocked
public boolean getLocked()
Locks or unlocks a distribution. The distribution cannot be modified if eitherDistribution.getLocked()istrueorDistribution.getOwner()is not null.- Specified by:
getLockedin interfaceDistribution- Returns:
trueif locked; otherwise,false.
-
setLocked
public void setLocked(boolean value)
Locks or unlocks a distribution. The distribution cannot be modified if eitherDistribution.getLocked()istrueorDistribution.getOwner()is not null.- Specified by:
setLockedin interfaceDistribution- Parameters:
value-trueif locked; otherwise,false.
-
isReadOnly
public boolean isReadOnly()
Indicates whether the distribution is read only. A distribution is read only if it is locked or is assigned to aNode.- Specified by:
isReadOnlyin interfaceDistribution- Returns:
trueif 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:
falseif a zero sum was found for any parent combination;trueotherwise- 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:
falseif a zero sum was found for any parent combination;trueotherwise.- Throws:
IllegalStateException- Raised if this instance is read only.
-
getOuter
public Distribution getOuter()
Description copied from interface:DistributionReturns the parent distribution, if this instance is aggregated by another distribution.- Specified by:
getOuterin interfaceDistribution
-
copy
public Distribution copy()
Creates a copy of the distribution. The new distribution will not have an owner.- Specified by:
copyin interfaceDistribution- 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:
copyin interfaceDistribution- 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:
getOwnerin interfaceDistribution- Returns:
- The owner, or null if not assigned to a node.
-
areAllValuesNonZero
public boolean areAllValuesNonZero()
Returns true if none of the values in theTableequal 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 thesize().- Throws:
NullPointerException- Raised if [data] is null.IllegalStateException- Raised if this instance is read only.
-
add
public void add(Table source)
Adds the values from another table into this instance. Only the- Parameters:
source- A table whose- Throws:
NullPointerException- Raised if the [source] is null.IllegalArgumentException- Raised if the table counts do not matchIllegalStateException- Raised if this instance is read only.- See Also:
of each table need match.,matches this instance.
-
copyTo
public void copyTo(Table destination)
Copies all values from this instance to the destinationTable.- 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 theTableto 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 aVariablein theTablelayout. SeeTablefor details on layout.- Parameters:
index- The index intogetSortedVariables().- 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 intogetSortedVariables().- Returns:
- The state count.
-
size
public int size()
- 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 theTablevalue at the specified index into the 1-dimensional array. SeeTablefor 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 theTablevalue at the specified index into the 1-dimensional array. SeeTablefor 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 theTableIteratorandTableAccessorclasses.- Specified by:
getSortedVariablesin interfaceDistribution- Returns:
- Variables sorted by time and the order variables were created.
-
sum
public double sum()
Calculates the sum of all values in theTable.- Returns:
- The sum of all table values.
-
getTable
public Table getTable()
Description copied from interface:DistributionGets theTablewhich specifies the distribution over any discrete variables. Often referred to as a Mixture.- Specified by:
getTablein interfaceDistribution- 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:
dividein interfaceDistribution- 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 Distribution instantiate(Double[] values)
Creates a table with a subset of variables by setting hard evidence on one or more variables. [values] should contain one entry for each- Specified by:
instantiatein interfaceDistribution- Parameters:
values- An array of nullable state indexes, one for each variable in thisTableinstance. Values are null for variables with no evidence.- Returns:
- The
Tableof 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.- See Also:
in the distribution, however entries can be null.
-
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 thisTableinstance. Values are null for variables with no evidence.- Returns:
- The
Tableof 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 aTableis first created), call an overloaded version of this method.- Specified by:
marginalizein interfaceDistribution- Parameters:
superset- ATablewhose 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 aTableis first created), call an overloaded version of this method.- Specified by:
marginalizein interfaceDistribution- Parameters:
superset- ATablewhose 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 aTableis first created), call an overloaded version of this method.- Parameters:
superset- ATablewhose 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 aTableis first created), call an overloaded version of this method.- Parameters:
superset- ATablewhose 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 theTablevalues are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.- Parameters:
superset- ATablewhose variables form a superset of the variables in this instance.initialize- Set totrueif 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 theTablevalues are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.- Parameters:
superset- ATablewhose variables form a superset of the variables in this instance.initialize- Set totrueif 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:
multiplyin interfaceDistribution- 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 theTableneeds to be initialized to 1 before multiplication use a different overload of this method.- Parameters:
subset- ATablewhose 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- ATablewhose variables form a subset of the variables in this instance.initialize- Set totrueif 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.
-
-