Network General Methods

From DSL

Jump to: navigation, search

[edit] Methods: General

  • Network()

Constructor.


  • boolean readFile(String fileName)

Fills the network with the contents of a specified file. The file name must include the full path if needed.


  • boolean writeFile(String fileName)

Writes the contents of the network to a specified file. The file name must include the full path if needed.


  • void setId(String id)

Sets the network id and throws an SMILEException if the id is not valid


  • String getId()

Returns the network id.


  • void setName(String name)

Sets the network name.


  • String getName()

Returns the network name.


  • void setDescription(String description)

Sets the network description.


  • String getDescription()

Returns the network description.


  • void setBayesianAlgorithm(int algorithmType)

Sets the type of the algorithm to be used when updating a belief network (as opposed to influence diagram).

The available algorithms are enumerated in the BayesianAlgorithmType inner class.


  • int getBayesianAlgorithm()

Returns the type of an algorithm to be used when updating a belief network (as opposed to an influence diagram).

The available algorithms are enumerated in the BayesianAlgorithmType inner class.


  • void setInfluenceDiagramAlgorithm(int agorithmType)

Sets a type of an algorithm to be used when updating an influence diagram (as opposed to Bayesian network). A Bayesian (belief) network algorithm used when solving an influence diagram will be the one set with setBayesianNetworkAlgorithm() method.

The available algorithms are enumerated in the InfluenceDiagramAlgorithmType inner class.


  • int getInfluenceDiagramAlgorithm()

Returns the type of an algorithm to be used when updating an influence diagram (as opposed to a belief network).

The available algorithms are enumerated in the InfluenceDiagramAlgorithmType inner class.


  • void updateBeliefs()

Updates the network using an algorithm set by setBayesianNetworkAlgorithm() and setInfluenceDiagramAlgorithm() methods. Only those nodes that are relevant to the nodes that are marked as targets will be updated. If no nodes are marked as targets, all the nodes of the network will be updated.


  • int addNode(int nodeType)

Adds a node of a specified type to the network. If the node is correctly created, the returning value will be its handle. This handle is guaranteed to remain constant for the lifetime of the network.

The available node types are enumerated in the NodeType inner class.


  • int addNode(int nodeType, String nodeId)

Adds a node of a specified type and with a specified id to the network. If the node is correctly created, the returning value will be its handle. For the possible values of node types please refer to addNode(int nodeType) method description.

The available node types are enumerated in the NodeType inner class.


  • int getNodeType(int nodeHandle)

int getNodeType(String nodeId)

Returns the type of a specified node.

The available node types are enumerated in the NodeType inner class.


  • int deleteNode(int nodeHandle)

int deleteNode(String nodeId)

Deletes a specified node.


  • int getNodesCount()

Returns the number of nodes in the network.


  • int getFirstNode()

Returns a handle of the first node of the network. A combination of getFirstNode() and getNextNode() methods can be used to traverse the whole network.

If the network contains no nodes ERR is returned.


  • int getNextNode(int nodeHandle)

Returns a handle of a node being next after the given node with a given handle (not necessarily is it nodeHandle+1). A combination of getFirstNode() and getNextNode() methods can be used to traverse the whole network.

If the specified node is the last one in the network ERR is returned.


  • int getNode(String nodeId)

Returns the handle of a specified node.


  • void setNodeId(int nodeHandle, String id)

void setNodeId(String oldId, String newId)

Sets the id of a specified node.


  • String getNodeId(int nodeHandle)

Returns the id of a specified node.


  • void setNodeName(int nodeHandle, String name)

void setNodeName(String nodeId, String name)

Sets the name of a specified node.


  • String getNodeName(int nodeHandle)

String getNodeName(String nodeId)

Returns the name of a specified node.


  • void setNodeDescription(int nodeHandle, String description)

void setNodeDescription(String nodeId, String description)

Sets the description of a specified node.


  • String getNodeDescription(int nodeHandle)

String getNodeDescription(String nodeId)

Returns the description of a specified node.


  • int[] getAllNodes()

Returns handles of all the nodes in the network.


  • String[] getAllNodeIds()

Returns ids of all the nodes in the network.


  • void addArc(int parentHandle, int childHandle)

void addArc(String parentId, String childId)

Adds an arc from a parent to a child. For this method to succeed, all of the following conditions must be true:

1. parentHandle (parentId) and childHandle (childId) are valid node handles (ids),

2. the arc will not create a cycle,

3. there is no arc from the parent to the child, and

4. the child can have the parent as a parent given their type (e.g., a Mau-typed node cannot have a Cpt-typed one as a parent).

Affected nodes will be invalidated if relevance reasoning is active.


  • void deleteArc(int parentHandle, int childHandle)

void deleteArc(String parentId, String childId)

Removes an arc from a parent to a child. For this method to succeed the parent and the child must be valid nodes and the arc must exist. If the node has a table indexed by the parent, this table will "shrunk", i.e., the dimension corresponding to the parent will be removed. The contents preserved correspond to the outcome 0 (zero) of the parent. Affected nodes will be invalidated if relevance is active.


  • int getOutcomeCount(int nodeHandle)

int getOutcomeCount(String nodeId)

Returns the number of outcomes of a specified node.


  • void addOutcome(int nodeHandle, String outcomeId)

void addOutcome(String nodeId, String outcomeId)

Adds a new outcome with a specified id to a specified node. The outcome will be added at the end of the outcomes list.


  • void insertOutcome(int nodeHandle, int position, String outcomeId)

void insertOutcome(String nodeId, int position, String outcomeId)

Inserts a new outcome with a specified id to a specified node. The outcome will be added at a specified position.


  • void deleteOutcome(int nodeHandle, int outcomeIndex)

void deleteOutcome(String nodeId, int outcomeIndex)

void deleteOutcome(int nodeHandle, String outcomeId)

void deleteOutcome(String nodeId, String outcomeId)

Removes a specified outcome from a specified node.


  • void setOutcomeId(int nodeHandle, int outcomeIndex, String id)

void setOutcomeId(String nodeId, int outcomeIndex, String id)

Sets the id of a specified outcome of a specified node.


  • String getOutcomeId(int nodeHandle, int outcomeIndex)

String getOutcomeId(String nodeId, int outcomeIndex)

Returns the id of a specified outcome of a specified node.


  • String[] getOutcomeIds(int nodeHandle)

String[] getOutcomeIds(String nodeId)

Returns ids of all the outcomes of a specified node.


  • int[] getParents(int nodeHandle)

int[] getParents(String nodeId)

Returns handles of all the parents of a specified node.


  • String[] getParentIds(int nodeHandle)

String[] getParentIds(String nodeId)

Returns ids of all the parents of a specified node.


  • int[] getChildren(int nodeHandle)

int[] getChildren(String nodeId)

Returns handles of all the children of a specified node.


  • String[] getChildIds(int nodeHandle)

String[] getChildIds(String nodeId)

Returns ids of all the children of a specified node.


  • void setNodeDefinition(int nodeHandle, double definition[])

void setNodeDefinition(String nodeId, double definition[])

Sets the definition of a specified node. Remember to always pass an array of the correct size.

Normally, when a node has no parents its definition is a vector (or a one-dimentional array). However, the definition can be a multidimensional array. It happens when one or more nodes index the node's definition, i.e., they are its parents. In that case those multiple dimensions have to be encoded into a vector.

The order of probabilities, is given by considering the state of the first parent of the node as the most significant coordinate (thinking of the coordinates in terms of bits), then the second parent, and so on, and finally considering the coordinate of the node itself as the least significant one.

Consult Tutorial 1 for an example on setting a node's definition.


  • double[] getNodeDefinition(int nodeHandle)

double[] getNodeDefinition(String nodeId)

Returns the definition of a specified node.

This function will always return a vector (or a one-dimentional array). If the node has one or more parents the multiple dimensions of the definitions will be encoded into a vector. You have to use the information on the number of parents and the number of their outcomes to decode the probabilities.

The order of probabilities, is given by considering the state of the first parent of the node as the most significant coordinate (thinking of the coordinates in terms of bits), then the second parent, and so on, and finally considering the coordinate of the node itself as the least significant one.


  • double[] getNodeValue(int nodeHandle)

double[] getNodeValue(String nodeId)

Returns the value matrix of a specified node. Before this method can be called value has to be updated. Update the network to validate all the values.


  • boolean isValueValid(int nodeHandle)

boolean isValueValid(String nodeId)

Checks if the value of a specified node is valid. To validate the value update the network.


  • int[] getValueIndexingParents(int nodeHandle)

int[] getValueIndexingParents(String nodeId)

Returns handles of parents which index a value of a specified node.


  • String[] getValueIndexingParentIds(int nodeHandle)

String[] getValueIndexingParentIds(String nodeId)

Returns ids of parents which index a value of a specified node.


  • void setNoisyParentStrengths(int nodeHandle, int parentIndex, int[] strengths)

void setNoisyParentStrengths(String nodeId, int parentIndex, int[] strengths)

void setNoisyParentStrengths(int nodeHandle, String parentId, int[] strengths)

void setNoisyParentStrengths(String nodeId, String parentId, int[] strengths)

Allows to set parent's strengths for a specified node in its parent node defined by parentIndex. The array strengths should contain integers ranging from 0 to n-1, where n is the number of the parent's states and 0 corresponds to the strongest influence. The "distinguished" state for the noisy-MAX should have an index of n-1.


  • int[] getNoisyParentStrengths(int nodeHandle, int parentIndex)

int[] getNoisyParentStrengths(String nodeId, int parentIndex)

int[] getNoisyParentStrengths(int nodeHandle, String parentId)

int[] getNoisyParentStrengths(String nodeId, String parentId)

Returns the array of indexes of outcomes of a specified node in a parent node defined by parentIndex, which is indexed by the strengths. The value of the array at 0th position indicates the strongest influence.


  • void setTarget(int nodeHandle, boolean target)

void setTarget(String nodeId, boolean target)

Marks a specified node as a target node. When updating the network, only those nodes that are relevant to the target nodes will be taken into account. See the section on relevance reasoning for more details.


  • boolean isTarget(int nodeHandle)

boolean isTarget(String nodeId)

Checks if a specified node is marked as target.


  • void clearAllTargets()

Clears target marks for all nodes.


  • void setEvidence(int nodeHandle, int outcomeIndex)

void setEvidence(String nodeId, int outcomeIndex)

void setEvidence(int nodeHandle, String outcomeId)

void setEvidence(String nodeId, String outcomeId)

Sets a specified outcome to be an evidence for a specified node. An outcome with the probability of 0 (zero) cannot be set as evidence.


  • int getEvidence(int nodeHandle)

int getEvidence(String nodeId)

Returns the index of an outcome being an evidence for a specified node.


  • String getEvidenceId(int nodeHandle)

String getEvidenceId(String nodeId)

Returns an id of an outcome being an evidence for the specified node.


  • boolean isEvidence(int nodeHandle)

boolean isEvidence(String nodeId)

Checks if the specified node has an evidence set.


  • void clearEvidence(int nodeHandle)

void clearEvidence(String nodeId)

Clears the evidence for a specified node. The node will be invalidated if relevance reasoning is active.


  • void clearAllEvidence()

Clears all the evidence in the network. Affected nodes will be invalidated if relevance reasoning is active.


  • void setRelevance(boolean relevance)

Relevance reasoning will take place after every change that affects the network. These changes may be structural changes (e.g., adding an arc) or definition changes (e.g., the change in the conditional distribution of a node). Using this method we can prevent relevance reasoning from taking take place after every change that affects the network.

Personal tools