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 aTable
are automatically sorted by time (if any) andVariable
. 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 aTable
contains 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 TableIterator
andTableAccessor
classes.- See Also:
TableAccessor
,TableIterator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Table.MarginalizeLowMemoryOptions
Options controllingmarginalizeLowMemory(com.bayesserver.Table[])
.static class
Table.MaxValue
static interface
Table.NonZeroValues
Used to report non zero table values.
-
Constructor Summary
Constructors Constructor Description Table(Node node)
Initializes a new instance of theTable
class with the specified node variables.Table(Node... nodes)
Initializes a new instance of theTable
class with all the variables from the supplied nodes.Table(Node[] nodes, HeadTail headTail)
Initializes a new instance of theTable
class with all the variables from the supplied nodes.Table(Node node, Integer time)
Initializes a new instance of theTable
class with the specified node variable at the specified time.Table(Table table)
Initializes a new instance of theTable
class, copying the [table] passed in.Table(Table table, boolean copyValues)
Initializes a new instance of theTable
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 theTable
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 theTable
class, copying the [table] passed in, however adjusting any times by the [timeShift].Table(Variable variable)
Table(Variable... variables)
Initializes a new instance of theTable
class with the specified variables.Table(VariableContext variableContext)
Initializes a new instance of theTable
class from a singleVariableContext
.Table(VariableContext[] variableContexts)
Initializes a new instance of theTable
class with [variableContexts] specifying which variables to include in the distribution.Table(VariableContext[] buffer, int count)
Initializes a new instance of theTable
class with [count] variable contexts taken from [buffer].Table(VariableContext[] buffer, int count, HeadTail headTail)
Initializes a new instance of theTable
class with [count] variable contexts taken from [buffer].Table(VariableContextCollection variableContexts)
Initializes a new instance of theTable
class with the variables specified in [variableContexts].Table(Variable variable, Integer time)
Table(List<Variable> variables, Integer time)
Initializes a new instance of theTable
class with the specified variables, at an optional time.Table(List<Variable> variables, Integer time, HeadTail headTail)
Initializes a new instance of theTable
class with the specified variables, at an optional time.Table(List<VariableContext> variableContexts)
Initializes a new instance of theTable
class with [variableContexts] specifying which variables to include in the distribution.Table(List<VariableContext> variableContexts, HeadTail headTail)
Initializes a new instance of theTable
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 theTable
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 destinationTable
.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 theTable
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 theTable
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 theTable
value at the specified index into the 1-dimensional array.void
setAll(double value)
Sets all values in theTable
to a specified value.void
setLocked(boolean value)
Locks or unlocks a distribution.int
size()
The data count in theTable
.int
stateCount(int index)
Gets the number of states of a variable at the time this instance was constructed.int
stateRepeat(int index)
double
sum()
Calculates the sum of all values in theTable
.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 theTable
class, with the same structure as an existing [table], copying the values if requested.- Parameters:
table
- The table to copy.copyValues
- if set totrue
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 theTable
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 totrue
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 theTable
class 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 theTable
class 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 theTable
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 theTable
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 theTable
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 theTable
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. EachVariableContext
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 theTable
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. EachVariableContext
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 theTable
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 eachVariableContext
. EachVariableContext
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 theTable
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 theTable
class with [count] variable contexts taken from [buffer]. All values are initialized to zero.- Parameters:
buffer
- The buffer ofVariableContext
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 theTable
class with [count] variable contexts taken from [buffer]. All values are initialized to zero.- Parameters:
buffer
- The buffer ofVariableContext
instances.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 theTable
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 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 theTable
class with a singleVariable
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 theTable
class with all the variables from the supplied nodes. All values are initialized to zero.- Parameters:
nodes
- TheNode
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 theTable
class with all the variables from the supplied nodes. All values are initialized to zero.- Parameters:
nodes
- TheNode
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 theTable
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 theTable
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 theTable
class 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:
timeShift
in 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()
istrue
orDistribution.getOwner()
is not null.- Specified by:
getLocked
in interfaceDistribution
- Returns:
true
if locked; otherwise,false
.
-
setLocked
public void setLocked(boolean value)
Locks or unlocks a distribution. The distribution cannot be modified if eitherDistribution.getLocked()
istrue
orDistribution.getOwner()
is not null.- Specified by:
setLocked
in interfaceDistribution
- Parameters:
value
-true
if 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:
isReadOnly
in interfaceDistribution
- 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 interfaceDistribution
-
copy
public Distribution copy()
Creates a copy of the distribution. The new distribution will not have an owner.- Specified by:
copy
in 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:
copy
in 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:
getOwner
in interfaceDistribution
- Returns:
- The owner, or null if not assigned to a node.
-
areAllValuesNonZero
public boolean areAllValuesNonZero()
Returns true if none of the values in theTable
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 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 theTable
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 aVariable
in theTable
layout. SeeTable
for 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 theTable
value at the specified index into the 1-dimensional array. SeeTable
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 theTable
value at the specified index into the 1-dimensional array. SeeTable
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 theTableIterator
andTableAccessor
classes.- Specified by:
getSortedVariables
in 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:Distribution
Gets theTable
which specifies the distribution over any discrete variables. Often referred to as a Mixture.- Specified by:
getTable
in 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:
divide
in 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:
instantiate
in interfaceDistribution
- Parameters:
values
- An array of nullable state indexes, one for each variable in thisTable
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.- 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 thisTable
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 aTable
is first created), call an overloaded version of this method.- Specified by:
marginalize
in interfaceDistribution
- Parameters:
superset
- ATable
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 aTable
is first created), call an overloaded version of this method.- Specified by:
marginalize
in interfaceDistribution
- Parameters:
superset
- ATable
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 aTable
is first created), call an overloaded version of this method.- Parameters:
superset
- ATable
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 aTable
is first created), call an overloaded version of this method.- Parameters:
superset
- ATable
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 theTable
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
- ATable
whose variables form a superset of the variables in this instance.initialize
- Set totrue
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 theTable
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
- ATable
whose variables form a superset of the variables in this instance.initialize
- Set totrue
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 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 theTable
needs to be initialized to 1 before multiplication use a different overload of this method.- Parameters:
subset
- ATable
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
- ATable
whose variables form a subset of the variables in this instance.initialize
- Set totrue
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.
-
-