Modifier and Type | Field and Description |
---|---|
protected java.util.Set<Value> |
cachedValues |
protected ProbDistribution |
distrib |
inputNodes, nodeId, outputNodes
Constructor and Description |
---|
ChanceNode(java.lang.String nodeId,
ProbDistribution distrib)
Creates a new chance node, with the given identifier and probability
distribution
|
ChanceNode(java.lang.String nodeId,
Value value)
Creates a change node with a unique value (associated with a probability 1.0)
|
Modifier and Type | Method and Description |
---|---|
void |
addInputNode(BNode inputNode)
Adds a new (input) relation for the node
|
ChanceNode |
copy()
Returns a copy of the node.
|
ProbDistribution |
getDistrib()
Returns the probability distribution attached to the node
|
java.util.Map<Assignment,java.lang.Double> |
getFactor()
Returns the "factor matrix" mapping assignments of conditional variables + the
node variable to a probability value.
|
int |
getNbValues()
Returns the number of values for the node
|
double |
getProb(Assignment condition,
Value nodeValue)
Returns the probability associated with the conditional assignment and the
node value, if one is defined.
|
double |
getProb(Value nodeValue)
Returns the probability associated with a specific value, according to the
current distribution.
|
java.util.Set<Value> |
getValues()
Returns a discrete set of values for the node.
|
int |
hashCode()
Returns the hashcode for the node (based on the hashcode of the identifier and
the distribution).
|
protected void |
modifyVariableId(java.lang.String oldId,
java.lang.String newId)
Replaces the identifier for the input and output nodes with the new identifier
|
void |
pruneValues(double threshold)
Prune the values with a probability below a given threshold
|
Value |
sample()
Returns a sample value for the node, according to the probability distribution
currently defined.
|
Value |
sample(Assignment condition)
Returns a sample value for the node, given a condition.
|
void |
setDistrib(ProbDistribution distrib)
Sets the probability distribution of the node, and erases the existing one.
|
void |
setId(java.lang.String newId)
Replaces the node identifier with a new one
|
java.lang.String |
toString()
Returns the string representation of the distribution.
|
addInputNode_internal, addInputNodes, addOutputNode_internal, compareTo, equals, getAncestorIds, getAncestors, getAncestorsIds, getClique, getDescendantIds, getDescendants, getDescendantsIds, getId, getInputNodeIds, getInputNodes, getInputNodes, getOutputNodes, getOutputNodes, getOutputNodesIds, getPossibleConditions, hasAncestor, hasDescendant, hasDescendant, hasInputNode, hasOutputNode, hasOutputNode, removeAllRelations, removeInputNode_internal, removeInputNode, removeInputNodes, removeOutputNode, setNetwork
protected ProbDistribution distrib
protected java.util.Set<Value> cachedValues
public ChanceNode(java.lang.String nodeId, ProbDistribution distrib)
nodeId
- the unique node identifierdistrib
- the probability distribution for the nodepublic ChanceNode(java.lang.String nodeId, Value value)
nodeId
- the node identifiervalue
- the single value for the nodepublic void setDistrib(ProbDistribution distrib)
distrib
- the distribution for the nodepublic void addInputNode(BNode inputNode)
addInputNode
in class BNode
inputNode
- the input node to connectpublic void setId(java.lang.String newId)
public void pruneValues(double threshold)
threshold
- the probability thresholdpublic double getProb(Value nodeValue)
The method assumes that the node is conditionally independent of every other node. If it isn't, one should use the getProb(condition, nodeValue) method instead.
NB: the method should *not* be used to perform sophisticated inference, as it is not optimised and might lead to distorted results for very dependent networks
nodeValue
- the value for the nodepublic double getProb(Assignment condition, Value nodeValue)
condition
- the conditionnodeValue
- the valuepublic Value sample()
The method assumes that the node is conditionally independent of every other node. If it isn't, one should use the sample(condition) method instead.
public Value sample(Assignment condition)
condition
- the value assignment on conditional nodespublic java.util.Set<Value> getValues()
public int getNbValues()
public ProbDistribution getDistrib()
public java.util.Map<Assignment,java.lang.Double> getFactor()
public ChanceNode copy()
public int hashCode()
public java.lang.String toString()
protected void modifyVariableId(java.lang.String oldId, java.lang.String newId)
BNode
modifyVariableId
in class BNode
oldId
- the old label for the nodenewId
- the new label for the node