public final class Table extends Object implements Distribution
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 1dimensional 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.
A  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
and TableAccessor
classes.TableAccessor
,
TableIterator
Modifier and Type  Class and Description 

static class 
Table.MarginalizeLowMemoryOptions
Options controlling
marginalizeLowMemory(com.bayesserver.Table[]) . 
static class 
Table.MaxValue 
static interface 
Table.NonZeroValues
Used to report non zero table values.

Constructor and Description 

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. 
Table(Node... nodes)
Initializes a new instance of the
Table class with all the variables from the supplied nodes. 
Table(Node node)
Initializes a new instance of the
Table class with the specified node variables. 
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... variables)
Initializes a new instance of the
Table class with the specified variables. 
Table(Variable variable)

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)

Modifier and Type  Method and 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 1dimensional 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(Random 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 1dimensional 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)

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() 
public Table(Table table, boolean copyValues)
Table
class, with the same structure as an existing [table], copying the values if requested.table
 The table to copy.copyValues
 if set to true
the values from [table] are copied, otherwise all values are initialized to zero.NullPointerException
 Raised if [table] is null.public Table(Table table, boolean copyValues, Integer timeShift)
Table
class, with the same structure as an existing [table], copying the values if requested, and optionally shifting any times.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.NullPointerException
 Raised if [table] is null.public Table(Variable variable)
Table
class with a single Variable
. All values are initialized to zero.variable
 The variable.NullPointerException
 Raised when [variable] is null.public Table(VariableContext variableContext)
Table
class from a single VariableContext
. All values are initialized to zero.variableContext
 The variable context.NullPointerException
 Raised when [variableContext] is null.public Table(List<Variable> variables, Integer time)
Table
class with the specified variables, at an optional time. All values are initialized to zero.variables
 The variables.time
 The time for the variables. Can be null.IllegalArgumentException
 Raised if a duplicate variable/time combination is detected in [variables], or if a variable has zero states.public Table(List<Variable> variables, Integer time, HeadTail headTail)
Table
class with the specified variables, at an optional time. All values are initialized to zero.variables
 The variables.time
 The time for the variables. Can be null.headTail
 Specifies whether the variables should be marked as Head or Tail.IllegalArgumentException
 Raised if a duplicate variable/time combination is detected in [variables], or if a variable has zero states.public Table(VariableContextCollection variableContexts)
Table
class with the variables specified in [variableContexts]. All values are initialized to zero.variableContexts
 The variables, times, and head/tail specifications to include in the distribution.IllegalArgumentException
 Raised if a duplicate variabletime combination is detected in [variableContexts], or if a variable has zero states.public Table(VariableContext[] variableContexts)
Table
class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.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(AB).
IllegalArgumentException
 Raised if a variabletime 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.public Table(List<VariableContext> variableContexts)
Table
class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.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(AB).
IllegalArgumentException
 Raised if a variabletime 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.public Table(List<VariableContext> variableContexts, HeadTail headTail)
Table
class with [variableContexts] specifying which variables to include in the distribution. All distribution values are initialized to zero.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(AB).
IllegalArgumentException
 Raised if a variabletime 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.public Table(Variable... variables)
Table
class with the specified variables. All values are initialized to zero.variables
 The variables.NullPointerException
 Raised if [variables] is null.IllegalArgumentException
 Raised if a duplicate variabletime combination is detected in [variables], or if a variable has zero states.public Table(VariableContext[] buffer, int count)
Table
class with [count] variable contexts taken from [buffer]. All values are initialized to zero.buffer
 The buffer of VariableContext
instances.count
 The number of items to read from [buffer].NullPointerException
 Raised if [buffer] is null.IllegalArgumentException
 Raised if a null or duplicate variabletime combination is detected in [buffer], or if a variable has zero states.public Table(VariableContext[] buffer, int count, HeadTail headTail)
Table
class with [count] variable contexts taken from [buffer]. All values are initialized to zero.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
.NullPointerException
 Raised if [buffer] is null.IllegalArgumentException
 Raised if a null or duplicate variabletime combination is detected in [buffer], or if a variable has zero states.public Table(Node node, Integer time)
Table
class with the specified node variable at the specified time. All values are initialized to zero.node
 The node whose variable is used to construct the Table
.time
 The time for the node variable. Can be null.IllegalArgumentException
 Raised if a node variable has zero states.public Table(Variable variable, Integer time)
Table
class with a single Variable
and time. All values are initialized to zero.variable
 The variable.time
 The variable time. Can be null for non temporal nodes.NullPointerException
 Raised when [variable] is null.public Table(Node... nodes)
Table
class with all the variables from the supplied nodes. All values are initialized to zero.nodes
 The Node
instances.NullPointerException
 Raised if [nodes] is null.IllegalArgumentException
 Raised if a null or duplicate variable is detected or if a variable has zero states.public Table(Node[] nodes, HeadTail headTail)
Table
class with all the variables from the supplied nodes. All values are initialized to zero.nodes
 The Node
instances.headTail
 Specifies whether the node variables should be marked as Head or Tail.NullPointerException
 Raised if [nodes] is null.IllegalArgumentException
 Raised if a null or duplicate variable is detected or if a variable has zero states.public Table(Table table)
Table
class, copying the [table] passed in.table
 The table to copy.NullPointerException
 Raised if [table] is null.public Table(Table table, Integer timeShift)
Table
class, copying the [table] passed in, however adjusting any times by the [timeShift].table
 The table to copy.timeShift
 The number of units to shift any time values associated with variables.NullPointerException
 Raised if [table] is null.public Table(Node node)
Table
class with the specified node variables. All values are initialized to zero.node
 The node whose variables are used to construct the Table
.IllegalArgumentException
 Raised if a node variable has zero states.public void nonZero(Table.NonZeroValues values)
public Table.MaxValue getMaxValue()
public void timeShift(int units)
timeShift
in interface Distribution
units
 The number of time units to shift. Can be negative if required.IllegalStateException
 Raised if this instance is read only.public boolean getLocked()
Distribution.getLocked()
is true
or Distribution.getOwner()
is not null.getLocked
in interface Distribution
true
if locked; otherwise, false
.public void setLocked(boolean value)
Distribution.getLocked()
is true
or Distribution.getOwner()
is not null.setLocked
in interface Distribution
value
 true
if locked; otherwise, false
.public boolean isReadOnly()
Node
.isReadOnly
in interface Distribution
true
if read only; otherwise, false
.public void randomize(Random random)
random
 Random number generator.IllegalStateException
 Raised if this instance is read only.public boolean normalize(boolean unifyZeroSum)
unifyZeroSum
 If true, applies a uniform distribution to any parent combinations that sum to zero.false
if a zero sum was found for any parent combination; true
otherwiseIllegalStateException
 Raised if this instance is read only.public boolean normalize()
false
if a zero sum was found for any parent combination; true
otherwise.IllegalStateException
 Raised if this instance is read only.public Distribution getOuter()
Distribution
getOuter
in interface Distribution
public Distribution copy()
copy
in interface Distribution
public Distribution copy(Integer timeShift)
copy
in interface Distribution
timeShift
 The amount to shift any times present in the distribution. Can be negative.public Node getOwner()
getOwner
in interface Distribution
public boolean areAllValuesNonZero()
Table
equal zero, or false otherwise.public void copyFrom(double[] data)
data
 Values to copy. The array can be shorter or longer than the size()
.NullPointerException
 Raised if [data] is null.IllegalStateException
 Raised if this instance is read only.public void add(Table source)
source
 A table whoseNullPointerException
 Raised if the [source] is null.IllegalArgumentException
 Raised if the table counts do not matchIllegalStateException
 Raised if this instance is read only.of each table need match.
,
matches this instance.
public void copyTo(Table destination)
Table
.destination
 The destination table, which can have a count greater than or equal to this instance.IllegalStateException
 Raised if the destination table is read only.public void copyTo(double[] destination)
destination
 The destination array, which must have length equal to or greater than this the count of this instance.NullPointerException
 Raised if [destination] is null.IllegalArgumentException
 Raised if [destination] is too short.public void addAll(double value)
value
 The value to add. Can be negative.public void setAll(double value)
Table
to a specified value.value
 The value to set all elements to.IllegalStateException
 Raised if this instance is read only.public int stateRepeat(int index)
Variable
in the Table
layout. See Table
for details on layout.index
 The index into getSortedVariables()
.public int stateCount(int index)
index
 The index into getSortedVariables()
.public int size()
public double get(State... states)
states
 The variable states that together specify a unique value in this table.
For example, if the table represents P(AB) we can access the value corresponding to P(A=True  B=False) by passing in the states A=True and B=False.public void set(double value, State... states)
states
 The variable states that together specify a unique value in this table.
For example, if the table represents P(AB) we can access the value corresponding to P(A=True  B=False) by passing in the states A=True and B=False.public double get(StateContext... states)
states
 The variable states and times that together specify a unique value in this table.public void set(double value, StateContext... states)
states
 The variable states and times that together specify a unique value in this table.public int getSortedIndex(State... states)
states
 A state for each variable.public int getSortedIndex(StateContext... stateContexts)
stateContexts
 A state and time for each variable. Time can be null for non temporal variables.public double get(int index)
Table
value at the specified index into the 1dimensional array. See Table
for information on how entries are stored.index
 The index into the underlying 1dimensional array.public void set(int index, double value)
Table
value at the specified index into the 1dimensional array. See Table
for information on how entries are stored.index
 The index into the underlying 1dimensional array.public VariableContextCollection getSortedVariables()
TableIterator
and TableAccessor
classes.getSortedVariables
in interface Distribution
public double sum()
Table
.public Table getTable()
Distribution
Table
which specifies the distribution over any discrete variables. Often referred to as a Mixture.getTable
in interface Distribution
public Distribution divide(Distribution subset)
divide
in interface Distribution
subset
 The subset to divide by.NullPointerException
 Raised if [subset] is null.public void divideInPlace(Table subset)
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.subset
 The subset to divide by.NullPointerException
 Raised if [subset] is null.IllegalStateException
 Raised if this instance is read only.public Distribution instantiate(Double[] values)
instantiate
in interface Distribution
values
 An array of nullable state indexes, one for each variable in this Table
instance. Values are null for variables with no evidence.Table
of instantiated values. I.e. The table after some variables have been set.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.in the distribution, however entries can be null.
public Table instantiate(Integer[] values)
values
 An array of nullable state indexes, one for each variable in this Table
instance. Values are null for variables with no evidence.Table
of instantiated values. I.e. The table after some variables have been set.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.public void marginalize(Distribution superset)
Table
is first created), call an overloaded version of this method.marginalize
in interface Distribution
superset
 A Table
whose variables form a superset of the variables in this instance.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.public void marginalize(Distribution superset, PropagationMethod propagation)
Table
is first created), call an overloaded version of this method.marginalize
in interface Distribution
superset
 A Table
whose variables form a superset of the variables in this instance.propagation
 The propagation method to use during marginalization.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.public void marginalize(Table superset)
Table
is first created), call an overloaded version of this method.superset
 A Table
whose variables form a superset of the variables in this instance.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.public void marginalize(Table superset, PropagationMethod propagation)
Table
is first created), call an overloaded version of this method.superset
 A Table
whose variables form a superset of the variables in this instance.propagation
 The propagation method to use during marginalization.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.public void marginalize(Table superset, boolean initialize)
Table
values are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.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.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.public void marginalize(Table superset, boolean initialize, PropagationMethod propagation)
Table
values are not zero the [initialize] parameter avoids the need to initialize all values in the distribution to 0 before performing the marginalization.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.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.public void marginalizeLowMemory(Table[] tables)
tables
 The tables whose combined distribution you wish to marginalize.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.public void marginalizeLowMemory(Table[] tables, Table.MarginalizeLowMemoryOptions options)
tables
 The tables whose combined distribution you wish to marginalize.options
 Options governing the method, including cancellation.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.public Distribution multiply(Distribution distribution)
multiply
in interface Distribution
distribution
 A distribution to multiply by.NullPointerException
 Raised if [distribution] is null.IllegalArgumentException
 Raised if the variables in [distribution] are not contained in this instance.public void multiplyInPlace(double value)
value
 The value to multiply by.IllegalStateException
 Raised if this instance is read only.public void multiplyInPlace(Table subset)
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.subset
 A Table
whose variables form a subset of the variables in this instance.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.public void multiplyInPlace(Table subset, boolean initialize)
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.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.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.Copyright © 2019. All rights reserved.