norsys.netica
Class Node

java.lang.Object
  |
  +--norsys.netica.General
        |
        +--norsys.netica.Node
All Implemented Interfaces:
NeticaListener

public class Node
extends General

A node (object which represents a variable) in a Net (Bayesian belief network or decision network).

Since:
All versions
Version:
3.25 - June 15, 2007

Field Summary
static int CONSTANT_NODE

The value of this node is considered unchanging until the net is rebuilt.

static int CONTINUOUS_TYPE

Node is for a continuous (analog) variable.

static int DECISION_NODE

This node is for a variable that can be controlled by the agent (the "decision" node of an influence diagram).

static int DISCONNECTED_NODE

This node is just a placeholder for a disconnected link, to indicate the type of parent it requires.

static int DISCRETE_TYPE

Node is for a discrete (digital) variable.

static int EVERY_STATE

Deprecated. use State.EVERY_STATE

static int IMPOSS_STATE

Deprecated. use State.IMPOSS_STATE

static int LIKELIHOOD_FINDING

Deprecated. use Value.LIKELIHOOD_VALUE instead.

static int NATURE_NODE

The value of this node is determined by nature (also known as a "chance" or "deterministic" node).

static int NEGATIVE_FINDING

Deprecated. use Value.STATE_NOT_VALUE instead.

static int NO_FINDING

Deprecated. use Value.NO_VALUE instead.

static int TEXT_TYPE

A future type of Node, one used for holding or rendering text.

static int UNDEF_STATE

Deprecated. use State.UNDEF_STATE

static int UTILITY_NODE

This node specifies the agent's desires; its expected value will be maximized.

 
Fields inherited from class norsys.netica.General
NAME_MAX
 
Constructor Summary
Node()

Default constructor - do not call this constructor directly.

Node(java.lang.String name, int numStates, Net net)

Creates and returns a new node for net.

Node(java.lang.String name, java.lang.String stateNames, Net net)

Construct a node with the given name and state names, for the given Net.

 
Method Summary
 int addLink(Node parentNode)

Adds a link from parentNode to this node, and returns the index of the added link.

 void addStates(int firstState, java.lang.String stateNames, int numStates, double cptFill)

Adds one or more states to this node, inserting them into the existing states.

 void addToNodeset(java.lang.String nodeset)

Adds this node to the node-set named nodeset.

 int calcState()

Returns the discrete finding entered for this node if one has been entered, or the state calculated from its neighbors if that can be done deterministically (e.g., by equation or function table), or else UNDEF_STATE.

 double calcValue()

Returns the real-valued finding entered for this node if one has been entered, or the real value calculated from its neighbors if that can be done deterministically (e.g., by equation or function table), or else UNDEF_DBL.

 void delete()

Removes this node from its net, and frees all resources (e.g., memory) it was using.

 void deleteLink(int parentLinkIndex)

Delete the link entering this node from the given parent node.

 void deleteTables()

Deletes this node's function table, its CPT table, and its experience table.

 void enterFinding(int stateIndex)

Deprecated. use finding().enterState (stateIndex) instead.

 void enterFinding(java.lang.String stateName)

Deprecated. use finding().enterState (stateName) instead.

 void enterFindingNot(int stateIndex)

Deprecated. use finding().enterStateNot (stateIndex) instead.

 void enterLikelihood(float[] likelihood)

Deprecated. use finding().enterLikelihood (likelihood) instead.

 void enterValue(double value)

Deprecated. use finding().enterReal (value) instead.

 void equationToTable(int numSamples, boolean includeSamplingUncertainty, boolean addExisting)

Builds the CPT for this node based on the equation that has been associated with it (see setEquation).

 void fadeCPTable(double degree)

Smoothes the conditional probabilities (CPT) of this node to indicate greater uncertainty, which accounts for the idea that the world may have changed a little since they were last learned.

 void finalize()

Called by the garbage collector, when this node can no longer be referenced.

 Value finding()

Returns the Value object holding this node's finding (aka, "evidence") information.

 float getBelief(java.lang.String stateName)

Gets the belief that this node is in the given named state.

 float[] getBeliefs()

Returns a belief vector indicating the current probability for each state of this node.

 NodeList getChildren()

Returns a list of the children of this node.

static java.lang.String getConstructorClass()

Retrieves the classname of the class that Netica-J uses when constructing a Node.

 float[] getCPTable(float[] cpTable)

Retrieves the entire CPTable of this node as a 1-D array.

 float[] getCPTable(int[] parentStates, float[] cpTable)

Returns the conditional probabilities of this node, given that its parents are in the states indicated by the parentStates vector, by looking them up in the node's CPT table.

 float[] getCPTable(java.lang.String parentStatesStr, float[] cpTable)

This does the same as getCPTable(int[], float[]) except that it takes the parent states as a string rather than as an integer array.

 java.lang.String getEquation()

Returns the equation associated with this node, or the empty string (rather than null), if this node does not have an equation.

 float[] getExpectedUtils()

Returns a vector providing the expected utility of each choice in a decision node, considering findings currently entered.

 double getExpectedValue(double[] moments)

Returns the expected real value of this node, based on the current beliefs for this node, and if moments is non-null, moments will be filled with the moments as well.

 double[] getExperTable(int[] parentStates, double[] experTable)

Given parentStates, a vector of states for the parents of this node, this returns the "experience" of the node for the situation described by the parent states.

 int getFinding()

Deprecated. use finding().getState() instead.

 int getInputIndex(java.lang.String linkName)

Returns the link index number of the link whose name is linkName, or -1 if there isn't one with that name (case sensitive comparison).

 java.lang.String getInputName(int inputIndex)

Gets the name of this node's input (i.e., link) identified by the given index.

 int getKind()

Returns whether this node is a nature, decision, utility or constant node.

 double[] getLevels()

Returns the list of numbers used to enable a continuous node to act discrete, or enables a discrete node to provide real-valued numbers.

 float[] getLikelihood()

Deprecated. use finding().getLikelihood(null) instead.

 Net getNet()

Returns the net that this node is part of.

 int getNumStates()

Returns the number of states that this node can take on, or zero if this node is a continuous node that hasn't been discretized.

 NodeList getParents()

Returns a list of the parents of this node.

 double[] getRealFuncTable(int[] parentStates, double[] realTable)

Gets the real value of this node as a function of its parent nodes.

 void getRelatedNodes(NodeList relatedNodes, java.lang.String relation)

Finds all the Nodes that bear the relationship relation with this node and puts them in relatedNodes.

 int[] getStateFuncTable(int[] parentStates, int[] stateTable)

Gets the state value of this node as a function of its parent nodes.

 int getType()

Returns DISCRETE_TYPE if the variable corresponding to this node is discrete (digital), and CONTINUOUS_TYPE if it is continuous (analog).

 double getValueEntered()

Deprecated. use finding().getReal() instead.

 boolean hasTable(boolean[] complete)

Returns true if this node has a function table or a CPT table, otherwise false.

 boolean isBeliefUpdated()

Whether the beliefs for this node have already been calculated (by belief propagation).

 boolean isDeterministic()

Whether the value of this node, given its parents, is deterministic (versus probabilistic).

 boolean isInNodeset(java.lang.String nodeset)

Returns whether this node is a member of nodeset.

 boolean isRelated(java.lang.String relation, Node otherNode)

Tests whether this node bears the relationship relation with otherNode.

 int[] parentStatesToIndexes(java.lang.String parentStateNamesStr)

Utility to convert a comma and/or space delimited string of parent state names for this node to an array of state indexes.

 void removeFromNodeset(java.lang.String nodeset)

Removes this node from the node-set named nodeset.

 void reorderStates(int[] newOrder)

Rearranges the order of the states so that state i is moved to position newOrder[i].

 void retractFindings()

Deprecated. use finding().clear() instead.

 void reverseLink(Node parentNode)

Reverses the link from parentNode to this child node, so that instead it goes from this node to parentNode.

static void setConstructorClass(java.lang.String nodeClassNm)

Sets the classname that Netica-J will use to independently construct Nodes.

 void setCPTable(float[] cpTable)

Sets the entire CPTable of this node in one call.

 void setCPTable(int[] parentStates, float[] cpTable)

Sets the probabilities for each state of this node, conditioned on its parent nodes.

 void setCPTable(java.lang.String parentStateNames, float[] cpTable)

This does the same as setCPTable(int[], float[]) except that it takes the parent states as a string rather than as an integer array.

 void setEquation(java.lang.String eqn)

Sets the equation giving the probability of this node conditioned on its parent nodes, or the value of this node as a function of its parents.

 void setExperTable(double experience)

Sets the experience of this node as a function of its parent nodes.

 void setExperTable(int[] parentStates, double experience)

Sets the experience of this node as a function of its parent nodes.

 void setInputName(int inputIndex, java.lang.String inputName)

Sets the name of this node's input (i.e., link).

 void setKind(int kind)

Sets whether this node is a nature, decision, utility or constant node.

 void setLevels(double[] levels)

Sets the levels list of this node to levels.

 void setRealFuncTable(int[] parentStates, double funcValue)

Sets the real value of this (continuous) deterministic node as a function of its parent nodes.

 void setStateFuncTable(int[] parentStates, int funcState)

Sets the state value of this (discrete or discretized) deterministic node as a function of its parent nodes.

 void setStateNames(java.lang.String names)

Names the states of this node using the list of names names.

 State state(int stateIndex)

Returns a state of this node.

 State state(java.lang.String stateName)

Returns a state of this node.

 void switchParent(int linkIndex, Node newParent)

Switches the parent of the identified link with newParent.

 VisualNode visual()

Return the VisualNode object which can be used to control the visual display of this node in Netica Application.

 
Methods inherited from class norsys.netica.General
addListener, eventOccurred, getComment, getEnviron, getName, getTitle, removeListener, setComment, setName, setTitle, toString, user
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

public static final  int CONTINUOUS_TYPE 
Node is for a continuous (analog) variable. Opposite of DISCRETE_TYPE. See getType.


public static final  int DISCRETE_TYPE 
Node is for a discrete (digital) variable. Opposite of CONTINUOUS_TYPE. See getType.


public static final  int TEXT_TYPE 
A future type of Node, one used for holding or rendering text. Not currently used.


public static final  int CONSTANT_NODE 
The value of this node is considered unchanging until the net is rebuilt. See getKind.


public static final  int DECISION_NODE 
This node is for a variable that can be controlled by the agent (the "decision" node of an influence diagram). See getKind.


public static final  int DISCONNECTED_NODE 
This node is just a placeholder for a disconnected link, to indicate the type of parent it requires. See getKind.


public static final  int NATURE_NODE 
The value of this node is determined by nature (also known as a "chance" or "deterministic" node). This is the most common kind of node. See getKind.


public static final  int UTILITY_NODE 
This node specifies the agent's desires; its expected value will be maximized.

This is a "value" node of an influence diagram. See getKind.


public static final  int EVERY_STATE 
Deprecated. use State.EVERY_STATE


public static final  int IMPOSS_STATE 
Deprecated. use State.IMPOSS_STATE


public static final  int UNDEF_STATE 
Deprecated. use State.UNDEF_STATE


public static final  int LIKELIHOOD_FINDING 
Deprecated. use Value.LIKELIHOOD_VALUE instead.


public static final  int NEGATIVE_FINDING 
Deprecated. use Value.STATE_NOT_VALUE instead.


public static final  int NO_FINDING 
Deprecated. use Value.NO_VALUE instead.

Constructor Detail
public Node (
 String  name
 int  numStates
 Net  net 
) throws NeticaException
Creates and returns a new node for net.

If the node is for a discrete variable, pass the number of states it has for numStates.

If the node is for a variable which is continuous in the real world, pass 0 for numStates, even if you plan to later discretize it to a certain number of states (see setLevels for more details).

name will be the name of the new node. It must be different from the names of all other nodes in net (by case-sensitive comparison), and it must be a legal IDname, which means it must have NAME_MAX (30) or fewer characters, all of which are letters, digits or underscores, and it must start with a letter. If name is null, then Netica will pick a unique name for the node; you can discover what name was picked using getName after the node is formed.

The node will start off as a nature node (kind = NATURE_NODE), but it may be changed by calling setKind.

Parameters:
String    name    The name of this node.
int    numStates    The number of states for this node, if this is a discrete node. If it is continuous, then supply 0, even if you plan to later discretize it to a certain number of states. See setLevels.
Net    net    The net in which the new node is placed.

Version:

In the C Version of the API, this function is named NewNode_bn.
See Also:
delete    (reverse operation) Removes the node from its net and frees memory it uses
copyNodes    Creates nodes by duplicating them, even from another net
setKind    Set what kind of node it is (nature, decision, utility, etc.)
setLevels    The way to set the number of states if the node is for a continuous variable being discretized
setName    Later change the name
setTitle    Label the node without the IDname restriction
getType    Determine if it was created as a continuous variable node
getNumStates    Retrieve numStates
getName    Retrieve name
addLink    Link the new node with others
Net    Create a net for adding nodes

Example:
See setLevels for creating a discretized node for a continuous variable.
// Here is how you might make a new node with the 2 states // "true" and "false" using this constructor. Node node = New Node ("n1", 2, net); node.setStateNames("true, false");

public Node (
 String  name
 String  stateNames
 Net  net 
) throws NeticaException
Construct a node with the given name and state names, for the given Net.

A convenience constructor, identical to Node(String, int, Net), only where you can assign the nodes's state names immediately, rather than having to call setStateNames separately.

Parameters:
String    name    The name of this node.
String    names    A string of unique stateNames, each separated by a comma and/or space. Each stateName can be no larger than NAME_MAX (30) chararacters.
Net    parentNet    The net in which the new node will be placed.

Example:

 // Here is how you might make a new node with the 2 states "true" and "false".
 Node node = New Node ("n1", "true, false", net);

public Node ( ) throws NeticaException
Default constructor - do not call this constructor directly. The only reason it has public access is that this is required should you wish to subclass this class, since in that case you will need to supply a default public constructor for Netica to use in constructing instances of your special type of Node.

Method Detail
public int addLink (
 Node  parentNode 
) throws NeticaException
Adds a link from parentNode to this node, and returns the index of the added link.

This index will be one greater than that of the previously added link, and the existing links will maintain their same indexes.

If this node, the child node, has a table (CPT or function table), its entries are initially duplicated so its values are the same for each possible state of the new parent. In other words, they are independent of the new parent, so that the link from parent to child has no effect on probability computations until the table is changed.

parentNode must be in the same net as this node, or an exception will be thrown, and no action taken.

A warning will be generated (which can be detected by calling getWarnings) if there is already a link from parentNode to this node, or if the added link creates a cycle, but the link will be successfully added. If you don't remove one of the offending links, and later try to compile the net or do node absorption, an exception will be thrown.

Parameters:
Node    parentNode    The node which will now be one of our parents, and we its child.

Version:

This method is available in all versions.
In the C Version of the API, this function is named AddLink_bn.
See Also:
deleteLink    Removes the link between two nodes
switchParent    Switches parents without changing conditional probabilities
copyNodes    Also duplicates all the links between them

Example:

public void addToNodeset (
 String  nodeset 
) throws NeticaException
Adds this node to the node-set named nodeset.

Creates a new node-set if nodeset is not yet present in the net containing this node.

Parameters:
String    nodeset    A nodeset name.

Version:

Versions 3.22 and later have this method.
In the C Version of the API, this function is named AddNodeToNodeset_bn.
See Also:
removeFromNodeset    (inverse operation) To remove the nodes
isInNodeset    Determines if a node is in a node-set
Net.setNodesetColor    Change the display color for Netica Application
Net.reorderNodesets    To change the priority order of a net's node-sets
Net.getAllNodesets    Returns string listing all node-sets defined


public void addStates (
 int  firstState
 String  stateNames
 int  numStates
 double  cptFill 
) throws NeticaException
Adds one or more states to this node, inserting them into the existing states. The first one added will have index firstState, and numStates is the number of states that will be added. If state is zero, the states will be added before existing ones, and if it is the same as the number of states of the node ( or -1), they will be added at the end.

The names parameter can be a comma delimited list of new names for the added states, or it can be null, in which case the added states will be given default names. It must be null if the node's states currently do not have names.

Pass -1.0 for cptFill. It is only for future expansion.

This function is for discrete nodes only. It is not for continuous nodes, even if they have been discretized (use setLevels instead).

All relevant parts of this node will be properly modified to reflect the changes, including findings. The state titles and state comments of the added states will be absent.

The CPTable will be appropriately adjusted. In it, the probability of the new states will be zero.

Parameters:
int    firstState    The insertion point of the states, that is, the index of the first state inserted.
String    names    An optional, comma-delimited list of names to assign to the states. If null, then the states will receive default names.
int    numStates    The number of states to add.
double    cptFill    For future expandability. Pass -1.0 for now.

Version:

Since version 3.01
In the C Version of the API, this function is named AddNodeStates_bn.
See Also:
State.delete    Removes a single state
reorderStates    Assign a new order to the states
getNumStates    firstState must be between 0 and this, inclusive
getIndex    Retrieve the new indexes of the states
State.setName    Sets name of one state at a time
State.setTitle    Doesn't have the restrictions of a name
State.setComment    Assigns arbitrary text documentation to a state
setLevels    For continuous nodes


public int calcState ( ) throws NeticaException
Returns the discrete finding entered for this node if one has been entered, or the state calculated from its neighbors if that can be done deterministically (e.g., by equation or function table), or else UNDEF_STATE.

If this node is not a discrete or discretized node, then an exception is thrown (then use calcValue instead).

Version:

Versions 1.18 and later have this method.
In the C Version of the API, this function is named CalcNodeState_bn.
See Also:
calcValue    For real values (i.e., continuous)
getFinding    Doesn't do deterministic propagation


public double calcValue ( ) throws NeticaException
Returns the real-valued finding entered for this node if one has been entered, or the real value calculated from its neighbors if that can be done deterministically (e.g., by equation or function table), or else UNDEF_DBL.

If this node is not a continuous node, and doesn't have a levels list defined (see setLevels), then an exception is thrown (then use calcState instead).

Version:

Versions 1.18 and later have this method.
In the C Version of the API, this function is named CalcNodeValue_bn.
See Also:
calcState    For discrete nodes
GetNodeValueEntered    Doesn't do deterministic propagation


public void delete ( ) throws NeticaException
Removes this node from its net, and frees all resources (e.g., memory) it was using.

If this node has children, they will end up with disconnected links for parents, and the names of these links (if they weren't already named) will become the name of this node. If this node has parents, then links from them will simply be removed.

If a complete net is to be disposed of, use Net.finalize instead, which also deletes all its nodes.

Version:

This method is available in all versions.
In the C Version of the API, this function is named DeleteNode_bn.
See Also:
Node    (Inverse operation) Creates a new node in a net
absorbNodes    Maintains joint distribution while removing
Net.finalize    Deletes all the nodes of a net

Example:
The following method is available in NodeListEx.java:
/** * Removes all the nodes in nodeList from their net, and deletes them. * @param nodeList the nodes to delete */ static void deleteNodes (NodeList nodeList) throws NeticaException { while (nodeList.size() > 0) { Node node = (Node) nodeList.remove (0); node.delete(); } }

public void deleteLink (
 int  parentLinkIndex 
) throws NeticaException
Delete the link entering this node from the given parent node. Removes the link going to this child from the parentLinkIndexth parent node of this child.

parentLinkIndex should be 0 for the first parent, and must be less than the number of links entering this child (the parent ordering is given by getParents).

It is often more useful to be able to delete a link by specifying the 2 nodes it connects. In order to do this use the method deleteLink defined in the example below.

If this child has a CPT or function table, it is collapsed as if the removed parent were taking on its first state (state = 0), unless there is a positive finding entered for the parent, in which case it is collapsed with the parent taking on the finding state.

WARNING: When a link is deleted, keep in mind that the numbering of subsequent links changes. For example, to delete all the links entering a node, use the method "DeleteLinksEntering" example below, not:   for (pn = 0; pn < numParents; ++pn) DeleteLink (pn);

WARNING: Keep in mind that after deleting a link into node child, any list of parent nodes for child that was previously returned by getParents is no longer valid.

Parameters:
int    parentLinkIndex    The index of the parent Node whose link we wish to remove.

Version:

This method is available in all versions.
In the C Version of the API, this function is named DeleteLink_bn.
See Also:
addLink    Adds a link between two nodes
switchParent    Switches parents without changing conditional probabilities
(can be used to disconnect link instead of deleting)

Example #1:
The following method is available in NodeEx.java:
/** * Removes the single link from node 'parent' to node 'child'. * If there is no link from 'parent' to 'child', or more than one, it generates an error. * @param parent the parent node * @param child the child node */ static void deleteLink (Node parent, Node child) throws NeticaException { NodeList parents = child.getParents(); int index = parents.indexOf (parent); child.deleteLink (index); }
Example #2:
The following method is available in NodeEx.java:
/** * Removes all links entering node child * See the deleteLink comment for explanation * @param child the child node */ static void deleteLinksEntering (Node child) throws NeticaException { NodeList parents = child.getParents(); int numParents = parents.size(); for (int pn = 0; pn < numParents; ++pn) child.deleteLink (0); }

public void deleteTables ( ) throws NeticaException
Deletes this node's function table, its CPT table, and its experience table.

It does not modify this node's equation or its links.

You don't need to call this function if you are deleting the whole node, since Node.delete and Net.finalize also delete all of their nodes' tables.

Version:

Versions 2.07 and later have this method.
In the C Version of the API, this function is named DeleteNodeTables_bn.
See Also:
hasTable    Determine if a node currently has a table
deleteLink    Reduce the number of parents of the node
setStateFuncTable    Give a node a function table with its parents
setCPTable    Give a node a probabilistic table (CPT) with its parents
Node    Creates a new node without any tables


public void equationToTable (
 int  numSamples
 boolean  includeSamplingUncertainty
 boolean  addExisting 
) throws NeticaException
Builds the CPT for this node based on the equation that has been associated with it (see setEquation).

numSamples is the number of samples to make per parent condition. The higher the number, the more accurate the conversion will be, but the longer it will take. If this node and its parents are discrete, then it only takes one sample to generate an exact probability, and so in that case this argument is ignored.

includeSamplingUncertainty indicates whether to include in the generated probability table the uncertainty due to the sampling process or not. If the equations are simple (don't have narrow spikes), and the value passed for numSamples is high enough, it is better to make this argument false, so that the CPT entries for 'impossible' are zero, rather than close to zero. Otherwise make it true.

Normally you pass false for addExisting, but you can pass true if you wish the new sampling to be added to the table which already exists. If the equation conversion to table is nondeterministic (i.e., requires sampling), then calling this method twice with addExisting = true is equivalent to calling it once with a value of numSamples twice as large. So you can increase the accuracy of the conversion in small steps by repeatedly calling with addExisting = true. Or if you want to blend equations (say you want to indicate a 30% chance of equation 1 and a 70% chance of equation 2), you can call it twice, first setting equation 1 and using numSamples = 3, then setting equation 2 and using numSamples = 7. Similarly, you can blend equations with learned probabilities (see reviseCPTsByCaseFile), and those entered manually with setCPTable and setExperTable.

Parameters:
int    numSamples    The number of samples to make per parent condition.
boolean    includeSamplingUncertainty    Whether to include in the generated probability table the uncertainty due to the sampling process or not
boolean    addExisting    Whether you wish the new sampling to be added to the table which already exists. Normally false.

Version:

Versions 1.18 and later have this method.
In the C Version of the API, this function is named EquationToTable_bn.
See Also:
setEquation    Specifies the equation to be used
getEquation    Retrieves an equation, if it exists
getCPTable    Retrieve the table, if its probabilistic
getStateFuncTable    Retrieve the table, if its deterministic discrete
getRealFuncTable    Retrieve the table, if its deterministic continuous


public void fadeCPTable (
 double  degree 
) throws NeticaException
Smoothes the conditional probabilities (CPT) of this node to indicate greater uncertainty, which accounts for the idea that the world may have changed a little since they were last learned.

degree must be between 0 and 1, with 0 having no effect and 1 creating uniform distributions with no experience. Calling fadeCPTable once with degree = 1-d, and again with degree = 1-f, is equivalent to a single call with degree = 1-df.

The global variable BaseExperience is used in the calculation as shown below. It's value should be the same as it was when the learning from cases was done (if it was). It must be greater than 0, and the most common value for it is 1 (1/2 is also commonly used). You will normally set it to one of these choices, depending on your philosophy, and leave it that way permanently.

Each of the probabilities in the node's conditional probability table is modified as follows (where prob and exper are the old values of probability and experience, and prob' and exper' are the new values):

    prob'  = normalize (prob * exper - (prob * exper - BaseExperience) * degree)
    prob'  = normalize (prob * exper * (1 - degree) + degree * BaseExperience)
  exper' is obtained as the normalization factor from above. So:
    prob' * exper' = prob * exper * (1 - degree) + degree * BaseExperience

When learning in a changing environment, you would normally call fadeCPTable every once in a while, so that what has been recently learned is more strongly weighted than what was learned long ago. If an occurrence time for each case is known, and the cases are learned sequentially through time, then the amount of fading to be done is:
degree = 1 - rDt where Dt is the amount of time since the last fading was done, and r is a number less than, but close to, 1 and depends on the units of time and how quickly the environment is changing. See the example below.

Parameters:
double    degree    The amount by which to fade the probability tables; 0.0 <= degree <= 1.0

Version:

In the C Version of the API, this function is named FadeCPTable_bn.
See Also:
reviseCPTsByFindings    Is passed a 'degree', which also can be used to weight the impact of learning a case
getCPTable    Read out the faded probabilities table
getExperTable    Read out the faded experience table

Example #1:
  // The following does the same fading for a list of nodes:
  //
  static void fadeCPTsForNodes (NodeList nodes, double degree) throws NeticaException {
      for (int n = 0;  n < nodes.size();  ++n){
          Node node = (Node) nodes.get(n);
          node.fadeCPTable (degree);
      }
  }
Example #2:
  // The following bit of code may be executed in a loop which is
  //   traversed as the cases are learned, in order to do the
  //   required fading:
  //     time - the occurrence time of the last case learned
  //     lastTime - a number initialized to the time of the 1st case
  //     minDelay - a number controlling how often fading is done
  //     rate - a number determining how much fading is done
  //     net - the net being learned
  if ((time - lasttime) >= minDelay){
      double degree = 1.0 - Math.pow (rate, (double) (time - lasttime));
      fadeCPTsForNodes (net.getNodes(), degree);
      lasttime = time;
  }
  

public void finalize ( ) throws NeticaException
Called by the garbage collector, when this node can no longer be referenced.

If in your application the native node associated with this node will no longer needed when this node is to be garbage collected, then you may wish to override this method and call delete in your finalize() method.

You may, however, wish to call it directly to ensure or hasten the freeing of native resources.

If you do override this method, be sure to call the base class method (super.finalize();).

See Also:
delete    Frees the native resources used by this node

Overrides:
finalize in class java.lang.Object

public Value finding ( )
Returns the Value object holding this node's finding (aka, "evidence") information.

Call that object's methods to manage the findings information for this node.

Version:

In version 2.26 and later.
Example:
  node.finding().setState (0);  // claim finding that node is in state 0

public float getBelief (
 String  stateName 
) throws NeticaException
Gets the belief that this node is in the given named state. A convenience method based on getBeliefs. See that method for more detailed documentation.

Parameters:
String    stateName    The name of the state whose belief value we seek.

Version:
This method is available in all versions.
See Also:
getBeliefs    Retrieves beliefs for all states


public float[] getBeliefs ( ) throws NeticaException
Returns a belief vector indicating the current probability for each state of this node.

The vector will be indexed by states, with one probability for each state (if required, the state indexes can be found from their names using state("stateName").getIndex()). It will be normalized, so that the sum of its entries is 1.

This provides the current beliefs (i.e., posterior probabilities) that the variable represented by this node is in each of its states, given the net model and all findings entered into all nodes of the net (positive findings, negative findings and likelihood findings).

The net containing this node must have been compiled before calling this (with compile), or an exception will be thrown. If the net has been modified it must be recompiled, but just entering findings does not require a recompile.

this node should be a discrete or discretized nature node.

If belief updating hasn't been done since the last findings were entered, it will be done before this method returns, which can be time consuming (you can call isBeliefUpdated before calling this to find out if belief updating will be done).

If you need the beliefs to persist, make a copy of the vector returned, since its contents may become invalid after further calls to Netica API. Do not try to directly modify or free the vector returned.

Version:

This method is available in all versions.
In the C Version of the API, this function is named GetNodeBeliefs_bn.
See Also:
isBeliefUpdated    Tells whether getBeliefs will trigger belief updating
getNumStates    Determine length of vector returned
getJointProbability    More than one node at a time
compile    To do the initial compiling before entering findings
getExpectedUtils    Get the resulting expected utility of a decision node
getExpectedValue    For numeric nodes, get expected value and standard deviation

Example:
  // This method is useful to get the belief that a certain node is in
  // a certain state, based on the names of the node and state.
  //
  static float getBelief (String nodeName, String stateName, Net net) throws NeticaException {
      Node node = net.getNode (nodeName);
      int stateIndex = node.state(stateName).getIndex();
      return node.getBeliefs()[stateIndex];
  }

public NodeList getChildren ( ) throws NeticaException
Returns a list of the children of this node. Those are the nodes that have a link going to them from this node. If it has no children then the empty list (rather than null) will be returned.

If there are several links from this node to the same child, then that child will appear only once in the list returned, so the length of the returned list may be used to provide the number of unique children of this node.

Consecutive calls to this method may yield lists in different orders.

Version:

This method is available in all versions.
In the C Version of the API, this function is named GetNodeChildren_bn.
See Also:
getParents    Get a list of the parents
addLink    Create a new child
deleteLink    Remove a child


public static String getConstructorClass ( )
Retrieves the classname of the class that Netica-J uses when constructing a Node. This is the class Netica-J uses, for example, during the process of retrieving the nodes from a net that was read from file.

Version:
This method is available in all versions.
See Also:
setConstructorClass    Set the className to be used for this purpose


public float[ ] getCPTable (
 int[ ]  parentStates
 float[ ]  cpTable 
) throws NeticaException
Returns the conditional probabilities of this node, given that its parents are in the states indicated by the parentStates vector, by looking them up in the node's CPT table. The length of parentStates must be the number of parents of this node, and each of its entries provides a state for the corresponding parent. The length of the array returned is the number of states of this node, and consists the conditional probabilities:

  P (this node = state0 | parents take on parentStates)

  P (this node = state1 | parents take on parentStates)

   ...

  P (this node = stateN | parents take on parentStates)

Notice that it is not conditioned on any findings (evidence) entered into the net, so its value will not change as findings are added or belief updating is done.

null will be returned if no CPT table has been associated with this node (for example by setCPTable, setStateFuncTable, equationToTable, reviseCPTsByCaseFile or reviseCPTsByFindings), or if the table has been removed (for example by deleteTables), but no exception will be thrown. If you use only setEquation to indicate a node's relation with its parents, you must also call equationToTable before this will return non-null.

The order of the states in parentStates should match the order of the nodes in the list returned by getParents (this will be the same order that parents were added using addLink). mapStateList may be useful for that. parentStates can be null if this node has no parents.

parentStates should not include EVERY_STATE or UNDEF_STATE.

If setStateFuncTable was used to provide this node with a function table, then getCPTable can be used to retrieve that table in the form of conditional probabilities, which will all be 0 or 1.

To get all the conditional probabilities of this node at once, see the GetNodeAllProbs example below.

If you will be regularly calling this method on this node, then you may wish to re-use the array to be filledbt supplying it as parameter cpTable, in order to avoid the continuous allocation of new memory. If cpTable is null or too small, then a new array will be allocated and returned.

If parentStates is null then the entire table is returned.

Parameters:
int[]    parentStates    An array of state indexes (one per parent) for which the Conditional Probabilities are desired.
float[]    cpTable    An array to be reused and filled with the probabilities. May be null, in which case a new array will be allocated and returned. Otherwise, it should have at least as many elements as the number of states of this node. If it does not, then a new array will be allocated and returned.

Version:

This method is available in all versions.
In the C Version of the API, this function is named GetNodeProbs_bn.
See Also:
setCPTable    Sets them
hasTable    Determine if getCPTable is going to return null
getBeliefs    Conditioned on findings, but not parents
absorbNodes    Can be used to find probabilities conditioned on parents and findings
getStateFuncTable    For deterministic nodes
getExperTable    The confidence of the probabilities obtained
getParents    Indicates the order of entries in parent_states
getNumStates    Length of the array returned (plus one if node continuous)
mapStateList    To create the state list passed in

Example #1:
  // To just get the probability that node is in state, given parentStates
  //
  double prob = node.getCPTable(parentStates) [state];
Example #2:
  // Puts all the conditional probabilities of node into the array probs.
  // You could allocate probs as follows
The following method is available in NodeEx.java:
/** * Returns all the conditional probabilities of a given node as a 2-D array. * You may supply an array to re-use. If it is null, however, then one will be supplied. * @param node is the node whose CPT we are retrieving * @param probs is an array of probabilities, the first dimension being of size equal to * the size of cartesian product of the states of each parent of node. * The second dimension is the number of states of node. * i.e., float[][] probs = new float[(int) NodeListEx.sizeCartesianProduct (node.getParents())] * [node.getNumberStates()]; * It may be null, in which case an array will be allocated for you. */ static void getNodeAllProbs (Node node, float[][] probs) throws NeticaException { NodeList parents = node.getParents(); int numStates = node.getNumStates(); int[] parentStates = new int[parents.size()]; //initially all zero int probSet = 0; while (true){ float[] vecp = node.getCPTable (parentStates, null); if (vecp == null) break; for (int st = 0; st < numStates; ++st) probs[probSet][st] = vecp[st]; if (NodeListEx.nextStates (parentStates, parents)) break; ++probSet; } }

public float[ ] getCPTable (
 String  parentStatesStr
 float[ ]  cpTable 
) throws NeticaException
This does the same as getCPTable(int[], float[]) except that it takes the parent states as a string rather than as an integer array. For additional documentation, see getCPTable(int[], float[]).

Parameters:
int[]    parentStates    An array of state indexes (one per parent) for which the Conditional Probabilities are desired.
float[]    cpTable    An array to be reused and filled with the probabilities. May be null, in which case a new array will be allocated and returned. Otherwise, it should have at least as many elements as the number of states of this node. If it does not, then a new array will be allocated and returned.

Version:
This method is available in all versions.
See Also:
setCPTable    Sets them


public float[ ] getCPTable (
 float[ ]  cpTable 
) throws NeticaException
Retrieves the entire CPTable of this node as a 1-D array.

See the example below for how the retrieved probabilities will be arranged. Basically, the rule is that the largest indexed parent's states will vary most rapidly, then the second largest indexed parent's states, and so on.

The 1-D array may be given to the inverse method setCPTable.

Parameters:
float[]    cpTable    An array to be reused and filled with the probabilities from the entire CPTable. May be null, in which case a new array will be allocated and returned. Otherwise, it should have sufficient space for the entire CPTable. If it does not, then a new array will be allocated and returned.

Version:

This method is available in all versions.
See Also:
setCPTable    Sets it
getCPTable    Retrieve part of the table instead

Example #1:
  Suppose you have a node with 4 states and it has two parents.  
  Parent1 has 2 states (say 'true' and 'false').
  Parent2 has 3 states (say 'red', 'green', and 'blue'). 
  The CPT for the node is initially as follows:
   
                        |  Probabilities that node is in 
      parent1  parent2  |  state1  state2  state3  state4  
      -------  ------   |  ------  ------  ------  ------
      true     red      |  0.0     0.8     0.2     0.0
      true     green    |  0.1     0.7     0.2     0.0
      true     blue     |  0.1     0.1     0.1     0.7
      false    red      |  0.0     0.0     0.0     1.0
      false    green    |  0.0     0.0     0.2     0.8
      false    blue     |  1.0     0.0     0.0     0.0
  
  You want to retrieve the above table.
    You can do this easily by calling:
  float[] probs = node.getCPTable (null); //sets probs to an array of length 24
    
  float[] probs2 = {0.0F, 0.8F, 0.2F, 0.0F,
                    0.1F, 0.7F, 0.2F, 0.0F,
                    0.1F, 0.1F, 0.1F, 0.7F,
                    0.0F, 0.0F, 0.0F, 1.0F,
                    0.0F, 0.0F, 0.2F, 0.8F,
                    1.0F, 0.0F, 0.0F, 0.0F};
  Arrays.equals (probs, probs2); //evaluates to true.
Example #2:
  If you want to do fetch the above node's CPT repeatedly, you can save on
  the heap allocation of a new array each time as follows:
    
  float[] probs = node.getCPTable (null);
  while(...){
    ...
    node.getCPTable (probs); //reuses probs, filling it with node's CPT values
    ...
  }

public String getEquation ( ) throws NeticaException
Returns the equation associated with this node, or the empty string (rather than null), if this node does not have an equation.

For information on Netica equations, see the "Equation" chapter of Netica Application's onscreen help.

Version:

Versions 1.30 and later have this method.
In the C Version of the API, this function is named GetNodeEquation_bn.
See Also:
setEquation    Sets it
equationToTable    If this hasn't been done, equation may not match CPT table


public float[] getExpectedUtils ( ) throws NeticaException
Returns a vector providing the expected utility of each choice in a decision node, considering findings currently entered.

The vector will be indexed by states, with one utility for each state (i.e., choice).

The net containing this node must be a decision net (i.e., have decision and utility nodes), which has been compiled before calling this (with compile), or an exception will be thrown. If the net has been modified it must be recompiled, but just entering findings does not require a recompile.

Before calling this all preceding decision nodes must have positive findings entered.

this node must be a decision node.

If belief updating hasn't been done since the last findings were entered, it will be done before this method returns, which can be time consuming (you can call isBeliefUpdated before calling this to find out if belief updating will be done).

If you wish to retrieve a whole table of values, providing the optimal state to choose given the parent states, use getStateFuncTable.

Version:

Versions 1.07 and later have this method.
In the C Version of the API, this function is named GetNodeExpectedUtils_bn.
See Also:
getStateFuncTable    Retrieve table of optimal choices as a function of parent values
getNumStates    Determine the length of the vector returned
getBeliefs    For the beliefs of a nature node
getExpectedValue    Don't confuse it with this method, which gets the expected real value of a nature node


public double getExpectedValue (
 double[ ]  moments 
) throws NeticaException
Returns the expected real value of this node, based on the current beliefs for this node, and if moments is non-null, moments will be filled with the moments as well. moments[0] will be assigned the 1st moment ( the expected value, the same value that is returned by this method) and moments[1] will be assigned the 2nd moment (the standard deviation). Currently, only the first two moments are available, so if moments has more than two elements, the third onward are not set.

Returns UNDEF_DBL if the expected value couldn't be calculated.

This node must be continuous discretized, or must be discrete with a levels list defined to supply real values.

For continuous discretized nodes it assumes the belief for each state is distributed evenly over each discretized interval. Because of that, it can't handle infinite tails (returns UNDEF_DBL).

This method is not for expected utility; for that see getExpectedUtils.

Parameters:
double[]    moments    an array, which if non-null, will have up to its 0th and 1st elements set to the 1st and 2nd moments, respectively.

Version:

Versions 2.09 and later have this method.
In the C Version of the API, this function is named GetNodeExpectedValue_bn.
See Also:
getBeliefs    Returns beliefs for each state individually
getExpectedUtils    For expected utility, rather than expected real value
finding().getReal()    Retrieves a specific real-valued finding instead


public double[ ] getExperTable (
 int[ ]  parentStates
 double[ ]  experTable 
) throws NeticaException
Given parentStates, a vector of states for the parents of this node, this returns the "experience" of the node for the situation described by the parent states.

If experTable is not null it will be used to hold the returned value, rather than allocate a new array, and it will be the array reference returned.

The experience is also known as the "number of cases", ess, or estimated sample size.

If no experience value has been assigned to this parent configuration (either by learning or setExperTable), then UNDEF_DBL is returned, without generating an error.

The order of the states in parentStates should match the order of the nodes in the list returned by getParents (this will be the same order that parents were added using addLink). mapStateList may be useful for that. parentStates can be null if this node has no parents.

Parameters:
int[]    parentStates    An array of state indexes (one per parent) with which to compute and return our experience value.
double[]    experTable    An array to be reused and filled with the experience values. May be null, in which case a new array will be allocated and returned. Otherwise, it should have at least one element. If it does not, then a new array will be allocated and returned.

Version:

This method is available in all versions.
In the C Version of the API, this function is named GetNodeExperience_bn.
See Also:
setExperTable    Sets them
getCPTable    Get the corresponding probability vector
reviseCPTsByFindings    Increments experience
reviseCPTsByCaseFile    Experience will measure the number of cases with each parent configuration
mapStateList    To create the state list passed in

Example:
  //Here is a convenience method taking parentStates as a comma and/or space delimited string.
  public int[] getExperTable (String parentStatesStr) throws NeticaException {
      return getExperTable (parentStatesToIndexes (parentStatesStr), null);
  }

public int getInputIndex (