public class ConditionalTable extends java.lang.Object implements ProbDistribution
Constructing a conditional table should be done via its Builder class: builder = new ConditionalTable.Builder("variable name"); builder.addRow(...); table = builder.build();
This class represent a generic conditional distribution in which the distribution for the head variable X can be represented using arbitrary distributions of type IndependentProbDistribution.
Modifier and Type | Class and Description |
---|---|
static class |
ConditionalTable.Builder
Builder class for the conditional table.
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Set<java.lang.String> |
conditionalVars |
static java.util.logging.Logger |
log |
protected java.util.HashMap<Assignment,IndependentDistribution> |
table |
Constructor and Description |
---|
ConditionalTable(java.lang.String headVar)
Constructs a new probability table, with no values
|
ConditionalTable(java.lang.String headVar,
java.util.Map<Assignment,IndependentDistribution> distribs)
Constructs a new probability table, with the values in distribs
|
Modifier and Type | Method and Description |
---|---|
void |
addDistrib(Assignment condition,
IndependentDistribution distrib)
Adds a new continuous probability distribution associated with the given
conditional assignment
|
ConditionalTable |
copy()
Returns a copy of the probability table
|
boolean |
equals(java.lang.Object o)
Returns true if the object o is a conditional distribution with the same
content
|
java.util.Set<Assignment> |
getConditions()
Returns the set of possible conditional assignments in the table.
|
java.util.Set<java.lang.String> |
getInputVariables()
Returns the conditional variables of the table
|
ProbDistribution |
getPosterior(Assignment condition)
Returns the posterior distribution obtained by integrating the (possibly
partial) conditional assignment.
|
double |
getProb(Assignment condition,
Value head)
Returns the probability of the head assignment given the conditional
assignment.
|
IndependentDistribution |
getProbDistrib(Assignment condition)
Returns the (unconditional) probability distribution P(X) given the
conditional assignment.
|
java.util.Set<Value> |
getValues()
Returns all possible values specified in the table.
|
java.lang.String |
getVariable()
Returns the name of the random variable
|
int |
hashCode()
Returns the hashcode for the table.
|
void |
modifyVariableId(java.lang.String oldVarId,
java.lang.String newVarId)
Modifies the distribution table by replace the old variable identifier by the
new one
|
boolean |
pruneValues(double threshold)
Prunes from the table all values whose probability falls below the threshold
|
Value |
sample(Assignment condition)
Sample a head assignment from the distribution P(head|condition), given the
condition.
|
java.lang.String |
toString()
Returns a pretty print of the distribution
|
public static final java.util.logging.Logger log
protected java.util.Set<java.lang.String> conditionalVars
protected java.util.HashMap<Assignment,IndependentDistribution> table
public ConditionalTable(java.lang.String headVar)
headVar
- the name of the random variablepublic ConditionalTable(java.lang.String headVar, java.util.Map<Assignment,IndependentDistribution> distribs)
headVar
- the name of the random variabledistribs
- the distribs (one for each conditional assignment)public void modifyVariableId(java.lang.String oldVarId, java.lang.String newVarId)
modifyVariableId
in interface ProbDistribution
oldVarId
- the old variable labelnewVarId
- the new variable labelpublic void addDistrib(Assignment condition, IndependentDistribution distrib)
condition
- the conditional assignmentdistrib
- the distribution (in a continuous, function-based
representation) @ if distrib relates to a different random variablepublic boolean pruneValues(double threshold)
pruneValues
in interface ProbDistribution
threshold
- the threshold to applypublic java.lang.String getVariable()
getVariable
in interface ProbDistribution
public Value sample(Assignment condition)
sample
in interface ProbDistribution
condition
- the conditionpublic double getProb(Assignment condition, Value head)
getProb
in interface ProbDistribution
condition
- the conditional assignmenthead
- the head assignmentpublic IndependentDistribution getProbDistrib(Assignment condition)
getProbDistrib
in interface ProbDistribution
condition
- the conditional assignmentpublic ProbDistribution getPosterior(Assignment condition)
getPosterior
in interface ProbDistribution
condition
- the assignment on a subset of the conditional variablespublic java.util.Set<Value> getValues()
getValues
in interface ProbDistribution
public java.util.Set<Assignment> getConditions()
public java.util.Set<java.lang.String> getInputVariables()
getInputVariables
in interface ProbDistribution
public int hashCode()
hashCode
in class java.lang.Object
public ConditionalTable copy()
copy
in interface ProbDistribution
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object