COM.hugin.HAPI
Class DiscreteNode

java.lang.Object
  extended by COM.hugin.HAPI.Node
      extended by COM.hugin.HAPI.DiscreteNode
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
DiscreteChanceNode, DiscreteDecisionNode, DiscreteFunctionNode

public abstract class DiscreteNode
extends Node

The DiscreteNode class. Base class for all discrete nodes.


Method Summary
 boolean caseIsSet(long c)
          Returns true if a state has been set for this DiscreteNode in case c; otherwise, returns false.
 void computeExplanationData(int x, DiscreteNode Y, int y, long maxSubsetSize)
          Computes Bayes factor data for all (nonempty) subsets of evidence nodes up to the specified maximum size.
 void computeExplanationData(int state, long maxSubsetSize)
          Computes "normalized likelihoods" for the specified hypothesis and all (nonempty) subsets of evidence nodes up to the specified maximum size.
 void enterFinding(int state, double finding)
          Specifies a finding value for a given state with all other states unaffected.
 void generateTable()
          Generates the table of this DiscreteNode from its model (a missing model will trigger an ExceptionUsage).
 double getBelief(int state)
          Returns the belief for the specified state of this DiscreteNode.
 int getCaseState(long c)
          Returns the state of this DiscreteNode for case c.
 double getEnteredFinding(int state)
          Returns the entered finding for the specified state of this node.
 double getEntropy()
          Computes the entropy of this node.
 double getExpectedUtility(int state)
          Returns the expected utility associated with the specified action (state).
 NetworkModel.Kind getKind()
          Returns the Kind of this DiscreteNode.
 double getMutualInformation(DiscreteNode node)
          Computes the mutual information between this node and the specified node.
 int getNumberOfStates()
          Returns the number of states of this node.
 double getPredictedBelief(int state, long time)
          Returns the predicted belief for the specified state of this DiscreteNode at the specified time point.
 double getPropagatedFinding(int state)
          Returns the propagated finding.
 int getSampledState()
          Returns the state index of this DiscreteNode for the configuration generated by the most recent call to Domain.simulate().
 double[] getSensitivityConstants(long input)
          Returns the four constants of the specified sensitivity function.
 double[] getSensitivityConstants(long input, int output)
          Returns the four constants of the specified sensitivity function.
 int getStateIndex(java.lang.String label)
          Returns the index of the state matching the specified label.
 java.lang.String getStateLabel(int state)
          Returns the label of the specified state.
 void retractFindings()
          Retracts all findings for this node.
 void selectState(int state)
          Selects the specified state of this node.
 void setCaseState(long c, int state)
          Sets the state of this DiscreteNode to state in case c.
 void setNumberOfStates(int stateCount)
          Sets the number of states of this node.
 void setStateLabel(int state, java.lang.String newLabel)
          Sets the label of the specified state.
 void unsetCase(long c)
          Specifies that the state of this DiscreteNode is "unknown" for case c.
 
Methods inherited from class COM.hugin.HAPI.Node
addParent, addToInputs, addToOutputs, clone, createTemporalClone, delete, evidenceIsEntered, evidenceIsPropagated, evidenceToPropagate, getAttribute, getAttributes, getCategory, getChildren, getEdgeConstraint, getHome, getHomeClass, getHomeDomain, getInstance, getJunctionTree, getLabel, getMaster, getModel, getName, getParents, getPosition, getSource, getTable, getTemporalClone, getTemporalMaster, getUserData, isAlive, likelihoodIsEntered, likelihoodIsPropagated, removeFromInputs, removeFromOutputs, removeParent, reverseEdge, setAttribute, setAttributes, setEdgeConstraint, setLabel, setName, setPosition, setUserData, switchParent
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBelief

public double getBelief(int state)
                 throws ExceptionHugin
Returns the belief for the specified state of this DiscreteNode. Note that if findings have been entered since the most recent propagation, the beliefs returned may not be up-to-date.

Parameters:
state - an integer value representing which state to examine.
Returns:
A real number representing the belief.
Throws:
ExceptionHugin

getPredictedBelief

public double getPredictedBelief(int state,
                                 long time)
                          throws ExceptionHugin
Returns the predicted belief for the specified state of this DiscreteNode at the specified time point. This method accesses the predictions computed by a previous call to computeDBNPredictions.

Parameters:
state - an integer value representing which state to examine.
time - time slice index (a nonnegative integer less than the number of predicted time slices)
Returns:
A real number representing the belief.
Throws:
ExceptionHugin

getExpectedUtility

public double getExpectedUtility(int state)
                          throws ExceptionHugin
Returns the expected utility associated with the specified action (state).

Parameters:
state - An integer value designating which state to examine.
Returns:
A real value expressing the expected utility associated with the specified state.

Throws:
ExceptionHugin

getEnteredFinding

public double getEnteredFinding(int state)
                         throws ExceptionHugin
Returns the entered finding for the specified state of this node.

Parameters:
state - an integer value representing which state to examine.
Returns:
A real number representing the entered finding.
Throws:
ExceptionHugin

getPropagatedFinding

public double getPropagatedFinding(int state)
                            throws ExceptionHugin
Returns the propagated finding. That is, it returns the finding value incorporated within the current JunctionTree potentials for the specified state of this node.

Parameters:
state - an integer representing the state to be examined.
Returns:
A real number expressing the propagated finding.
Throws:
ExceptionHugin

retractFindings

public void retractFindings()
                     throws ExceptionHugin
Retracts all findings for this node. This is equivalent to setting the finding value to 1 for all states of this node.

Throws:
ExceptionHugin

getNumberOfStates

public int getNumberOfStates()
                      throws ExceptionHugin
Returns the number of states of this node. The states are numbered from 0 to N-1, where N is the number of states of the node.

Throws:
ExceptionHugin

setNumberOfStates

public void setNumberOfStates(int stateCount)
                       throws ExceptionHugin
Sets the number of states of this node.

Throws:
ExceptionHugin

getStateLabel

public java.lang.String getStateLabel(int state)
                               throws ExceptionHugin
Returns the label of the specified state.

Parameters:
state - the index (a nonnegative integer) of the state; must be less than the number of states of the node
Returns:
the label (a String) of the specified state
Throws:
ExceptionHugin

getStateIndex

public int getStateIndex(java.lang.String label)
                  throws ExceptionHugin
Returns the index of the state matching the specified label. If there is no (unique) state with the specified state label, -1 is returned.

Parameters:
label - the state label to search for
Returns:
the index of the state having the specified state label.
Throws:
ExceptionHugin

setStateLabel

public void setStateLabel(int state,
                          java.lang.String newLabel)
                   throws ExceptionHugin
Sets the label of the specified state.

Parameters:
state - the index (a nonnegative integer) of the state; must be less than the number of states of the node.
newLabel - the desired state label (a String).
Throws:
ExceptionHugin

selectState

public void selectState(int state)
                 throws ExceptionHugin
Selects the specified state of this node. This is equivalent to specifying the finding value 1 for the specified state and 0 for all other states.

Throws:
ExceptionHugin

computeExplanationData

public void computeExplanationData(int x,
                                   DiscreteNode Y,
                                   int y,
                                   long maxSubsetSize)
                            throws ExceptionHugin
Computes Bayes factor data for all (nonempty) subsets of evidence nodes up to the specified maximum size. Two hypotheses are compared: (this node)=x and Y=y. For each subset of evidence nodes (up to the specified maximum size), the Bayes factor (the support for the first hypothesis relative to the second hypothesis) is computed. The results of the computations can be accessed using getExplanation and getExplanationScore.

Parameters:
x - state of the primary hypothesis node (this node)
Y - the alternative hypothesis node
y - state of the alternative hypothesis node
maxSubsetSize - data for all subsets of evidence nodes up to this size are computed
Throws:
ExceptionHugin

computeExplanationData

public void computeExplanationData(int state,
                                   long maxSubsetSize)
                            throws ExceptionHugin
Computes "normalized likelihoods" for the specified hypothesis and all (nonempty) subsets of evidence nodes up to the specified maximum size. For each subset of evidence nodes (up to the specified maximum size), the normalized likelihood of the hypothesis is computed. The results of the computations can be accessed using getExplanation and getExplanationScore.

Parameters:
state - state of the hypothesis node (this node)
maxSubsetSize - data for all subsets of evidence nodes up to this size are computed
Throws:
ExceptionHugin

enterFinding

public void enterFinding(int state,
                         double finding)
                  throws ExceptionHugin
Specifies a finding value for a given state with all other states unaffected.

Parameters:
state - an integer representing the state to be selected. States are numbered consecutively from 0 and upwards.
finding - A nonnegative real number as the finding value.
Throws:
ExceptionHugin

getKind

public NetworkModel.Kind getKind()
Returns the Kind of this DiscreteNode.

Specified by:
getKind in class Node
Returns:
NetworkModel.H_KIND_DISCRETE.

setCaseState

public void setCaseState(long c,
                         int state)
                  throws ExceptionHugin
Sets the state of this DiscreteNode to state in case c.

Parameters:
c - the index of the case (an integer in the range 0, ..., number of cases - 1)
state - the state of the specified case for this Node
Throws:
ExceptionHugin

unsetCase

public void unsetCase(long c)
               throws ExceptionHugin
Specifies that the state of this DiscreteNode is "unknown" for case c.

Parameters:
c - the index of the case (an integer in the range 0, ..., number of cases - 1)
Throws:
ExceptionHugin

caseIsSet

public boolean caseIsSet(long c)
                  throws ExceptionHugin
Returns true if a state has been set for this DiscreteNode in case c; otherwise, returns false.

Parameters:
c - the index of the case (an integer in the range 0, ..., number of cases - 1)
Throws:
ExceptionHugin

getCaseState

public int getCaseState(long c)
                 throws ExceptionHugin
Returns the state of this DiscreteNode for case c.

Parameters:
c - the index of the case (an integer in the range 0, ..., number of cases - 1)
Throws:
ExceptionHugin

getSampledState

public int getSampledState()
                    throws ExceptionHugin
Returns the state index of this DiscreteNode for the configuration generated by the most recent call to Domain.simulate().

Throws:
ExceptionHugin

generateTable

public void generateTable()
                   throws ExceptionHugin
Generates the table of this DiscreteNode from its model (a missing model will trigger an ExceptionUsage).

Throws:
ExceptionHugin

getEntropy

public double getEntropy()
                  throws ExceptionHugin
Computes the entropy of this node.

Throws:
ExceptionHugin

getMutualInformation

public double getMutualInformation(DiscreteNode node)
                            throws ExceptionHugin
Computes the mutual information between this node and the specified node.

Parameters:
node - the other node
Throws:
ExceptionHugin

getSensitivityConstants

public double[] getSensitivityConstants(long input)
                                 throws ExceptionHugin
Returns the four constants of the specified sensitivity function. The output probability of this function was specified in the preceding call to computeSensitivityData. If the results produced by that call have been invalidated, a usage exception is thrown.

Parameters:
input - specifies a conditional probability (or policy) parameter of this node (i.e., input is the index of an entry in the CPT/policy of this node).
Returns:
an array of size 4 containing the constants of the specified sensitivity function.
Throws:
ExceptionHugin

getSensitivityConstants

public double[] getSensitivityConstants(long input,
                                        int output)
                                 throws ExceptionHugin
Returns the four constants of the specified sensitivity function. The output probability of this function must be one of the output probabilities specified in the preceding call to computeSensitivityData. If the results produced by that call have been invalidated, a usage exception is thrown.

Parameters:
input - specifies a conditional probability (or policy) parameter of this node (i.e., input is the index of an entry in the CPT/policy of this node).
output - identifies one of the output probabilities specified in the call to computeSensitivityData.
Returns:
an array of size 4 containing the constants of the specified sensitivity function.
Throws:
ExceptionHugin