Class Node
- java.lang.Object
-
- com.bayesserver.Node
-
- All Implemented Interfaces:
Cloneable
public final class Node extends Object implements Cloneable
Represents a node with one or more variables in a Bayesian network. Note that node names must be unique per network, and are case sensitive.To specify a distribution for a node, see the
getDistribution()property.To add a directed link between two nodes, it must be added through the
Network.Linksproperty.
-
-
Constructor Summary
Constructors Constructor Description Node()Initializes a new instance of theNodeclass, with no variables, and no name.Node(Variable variable)Node(String name, int states)Node(String name, State... states)Node(String name, Variable... variables)Initializes a new instance of theNodeclass with a specified name and a number of variables.Node(String name, VariableValueType valueType)Initializes a new instance of theNodeclass with the specified [name].Node(String name, VariableValueType valueType, VariableKind kind)Initializes a new instance of theNodeclass with the specified [name].Node(String name, String[] states)Node(String name, List<Variable> variables)Initializes a new instance of theNodeclass with a specified name and a number of variables.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Nodecopy()Makes a copy of this instance.BoundsgetBounds()Gets the size and location of the node.CausalObservabilitygetCausalObservability()TheCausalObservabilityof the node.CustomPropertyCollectiongetCustomProperties()Gets custom properties associated with this instance.StringgetDescription()An optional description for the node.DistributiongetDistribution()Returns the distribution currently associated with theNode.NodeDistributionOptionsgetDistributionOptions()Options that apply to all distributions of this instance.NodeDistributionsgetDistributions()Returns the distributions associated with this instance with NodeDistributionKind = Probability.NodeGroupCollectiongetGroups()Gets the groups this node belongs to.intgetIndex()The Index of this instance in the collection of nodes belonging to a network, or -1 if the node does not belong to a network.NodeLinkCollectiongetLinks()Collection of both incoming and outgoing links (parent and child nodes).NodeLinkCollectiongetLinksIn()Collection of incoming links (linking to parent nodes).NodeLinkCollectiongetLinksOut()Collection of outgoing links (linking to child nodes).StringgetName()The name of the node.NetworkgetNetwork()TheNetworkthe node belongs to.TemporalTypegetTemporalType()TheTemporalTypeof the node.NodeVariableCollectiongetVariables()Collection of variables represented by the node.DistributionnewDistribution()Creates a new distribution suitable for the node, however does not assign it to the node'sgetDistribution()property.DistributionnewDistribution(int temporalOrder)Creates a new distribution suitable for the requested temporal order, however it is not assigned to the node.DistributionnewDistribution(NodeDistributionKey key)Creates a new distribution suitable for the requested temporal order/related node, however it is not assigned to the node.DistributionnewDistribution(NodeDistributionKey key, NodeDistributionKind kind)Creates a new distribution suitable for the requested temporal order/related node, however it is not assigned to the node.DistributionnewDistribution(NodeDistributionKey key, NodeDistributionKind kind, DistributionExpression expression)Creates a new distribution from an expression suitable for the requested temporal order/related node, however it is not assigned to the node, and neither is the expression.DistributionnewDistribution(NodeDistributionKind kind)Creates a new distribution with the given kind, however it is not assigned to the node.voidsetBounds(Bounds value)Sets the size and location of the node.voidsetCausalObservability(CausalObservability value)TheCausalObservabilityof the node.voidsetDescription(String value)An optional description for the node.voidsetDistribution(Distribution value)Returns the distribution currently associated with theNode.voidsetName(String value)The name of the node.voidsetTemporalType(TemporalType value)TheTemporalTypeof the node.StringtoString()Returns the name of the node, or an empty string if the name is null.
-
-
-
Constructor Detail
-
Node
public Node()
Initializes a new instance of theNodeclass, with no variables, and no name.
-
Node
public Node(Variable variable)
Initializes a new instance of theNodeclass with a specifiedVariableand assigns the name of the variable to the node.- Parameters:
variable- A single variable for the node.
-
Node
public Node(String name, VariableValueType valueType, VariableKind kind)
Initializes a new instance of theNodeclass with the specified [name]. AVariableis automatically created for the node and assigned the same name as the node with theVariableValueTypespecified.- Parameters:
name- The name to give the node and variable, which can be null or empty.valueType- TheVariableValueTypeof the node variable, e.g. discrete or continuous.kind- The kind of variable, e.g. Probability (standard), Decision or Utility.
-
Node
public Node(String name, VariableValueType valueType)
Initializes a new instance of theNodeclass with the specified [name]. AVariableis automatically created for the node and assigned the same name as the node with theVariableValueTypespecified.- Parameters:
name- The name to give the node and variable, which can be null or empty.valueType- TheVariableValueTypeof the node variable, e.g. discrete or continuous.
-
Node
public Node(String name, int states)
Initializes a new instance of theNodeclass with the specified [name] and automatically adds a discreteVariablewith the number of states specified in [states].- Parameters:
name- The name to give the node and variable, which can be null or empty.states- The number of states to add to the automatically createdVariable. States will be given default names.- Throws:
IllegalArgumentException- Raised when the [states] parameter is less than zero.
-
Node
public Node(String name, String[] states)
Initializes a new instance of theNodeclass, with the name of the node, automatically creating an associated discreteVariableand adds the states specified in [states] to that variable.- Parameters:
name- The name of the node and variable.states- The states to add to the associatedVariable, specified by their names.- Throws:
NullPointerException- Raised when [states] is null.
-
Node
public Node(String name, State... states)
Initializes a new instance of theNodeclass, with the name of the node, automatically creating an associated discreteVariableand adds the states specified in [states] to that variable.- Parameters:
name- The name of the node and variable.states- The states to add to the associatedVariable.- Throws:
NullPointerException- Raised when [states] is null.
-
Node
public Node(String name, Variable... variables)
Initializes a new instance of theNodeclass with a specified name and a number of variables.- Parameters:
name- The name for the node.variables- The variable(s) represented by the node.
-
-
Method Detail
-
copy
public Node copy()
Makes a copy of this instance. The copy does not include links or distribution(s).- Returns:
- The copy.
-
getCustomProperties
public CustomPropertyCollection getCustomProperties()
Gets custom properties associated with this instance. Custom properties allow storage of custom information, which will be saved with the network.
-
getGroups
public NodeGroupCollection getGroups()
Gets the groups this node belongs to.
-
getTemporalType
public TemporalType getTemporalType()
TheTemporalTypeof the node. The default value isTemporalType.CONTEMPORAL.- Throws:
IllegalStateException- Raised if the node belongs to a network, in which case the TemporalType cannot be changed. s
-
setTemporalType
public void setTemporalType(TemporalType value)
TheTemporalTypeof the node. The default value isTemporalType.CONTEMPORAL.- Throws:
IllegalStateException- Raised if the node belongs to a network, in which case the TemporalType cannot be changed. s
-
getCausalObservability
public CausalObservability getCausalObservability()
TheCausalObservabilityof the node. The default value isCausalObservability.OBSERVABLE.
-
setCausalObservability
public void setCausalObservability(CausalObservability value)
TheCausalObservabilityof the node. The default value isCausalObservability.OBSERVABLE.
-
getDistributionOptions
public NodeDistributionOptions getDistributionOptions()
Options that apply to all distributions of this instance.
-
getBounds
public Bounds getBounds()
Gets the size and location of the node.- Returns:
- The size and location of the node.
-
setBounds
public void setBounds(Bounds value)
Sets the size and location of the node.- Parameters:
value- The size and location of the node.
-
toString
public String toString()
Returns the name of the node, or an empty string if the name is null.
-
newDistribution
public Distribution newDistribution(int temporalOrder)
Creates a new distribution suitable for the requested temporal order, however it is not assigned to the node. UsegetDistributions()to perform the assignment. SeeNodeDistributionsfor more information.Note: if the resulting distribution contains continuous variables, but no discrete head variables, all table values are initialized to 1.
- Parameters:
temporalOrder- The order for the requested distribution.- Returns:
- The new distribution.
- See Also:
NodeDistributions
-
newDistribution
public Distribution newDistribution(NodeDistributionKey key)
Creates a new distribution suitable for the requested temporal order/related node, however it is not assigned to the node. UsegetDistributions()to perform the assignment. SeeNodeDistributionsfor more information.Note: if the resulting distribution contains continuous variables, but no discrete head variables, all table values are initialized to 1.
A noisy node is specified using multiple distributions, one for each parent and a leak distribution. Set the related node property to a parent, or set it to the current node to set the leak distribution. Each distribution corresponding to a parent of the noisy node has a number of constrained values which are not parameters. These are automatically set by newDistribution (see the help for noisy nodes in the main documentation for more detail).
- Parameters:
key- Identifies the order/related node for the requested distribution.- Returns:
- The new distribution.
- See Also:
NodeDistributions
-
newDistribution
public Distribution newDistribution(NodeDistributionKind kind)
Creates a new distribution with the given kind, however it is not assigned to the node. UsegetDistributions()to perform the assignment. For temporal or noisy nodes us a different overload. SeeNodeDistributionsfor more information.Note: if the resulting distribution contains continuous variables, but no discrete head variables, all table values are initialized to 1.
- Parameters:
kind- The kind of distribution to create.- Returns:
- The new distribution.
- See Also:
NodeDistributions
-
newDistribution
public Distribution newDistribution(NodeDistributionKey key, NodeDistributionKind kind)
Creates a new distribution suitable for the requested temporal order/related node, however it is not assigned to the node. UsegetDistributions()to perform the assignment. SeeNodeDistributionsfor more information.Note: if the resulting distribution contains continuous variables, but no discrete head variables, all table values are initialized to 1.
Experience table entries are also initialized to 1.
A noisy node is specified using multiple distributions, one for each parent and a leak distribution. Set the related node property to a parent, or set it to the current node to set the leak distribution. Each distribution corresponding to a parent of the noisy node has a number of constrained values which are not parameters. These are automatically set by newDistribution (see the help for noisy nodes in the main documentation for more detail).
- Parameters:
key- Identifies the order/related node for the requested distribution.kind- The kind of distribution to create.- Returns:
- The new distribution.
- See Also:
NodeDistributions
-
newDistribution
public Distribution newDistribution(NodeDistributionKey key, NodeDistributionKind kind, DistributionExpression expression)
Creates a new distribution from an expression suitable for the requested temporal order/related node, however it is not assigned to the node, and neither is the expression. Usecom.bayesserver.node.Distributions#getExpressionsto perform the assignment from an expression. Seecom.bayesserver.nodedistributions.Expressionsfor more information. *- Parameters:
key- Identifies the order/related node for the requested distribution.kind- The kind of distribution to create.expression- The expression that should be used to generate the distribution.- Returns:
- The new distribution.
- See Also:
com.bayesserver.nodedistributions.Expressions
-
newDistribution
public Distribution newDistribution()
Creates a new distribution suitable for the node, however does not assign it to the node'sgetDistribution()property. This method is useful for creating distributions appropriate for a node. However, the returned distribution cannot be set togetDistribution()until the distribution has been correctly specified.Note: if the resulting distribution contains continuous variables, but no discrete head variables, all table values are initialized to 1.
This is a helper function that creates a distribution of the required shape for a node, given its parents (and other factors such as whether it is a noisy node etc�). You do not have to use newDistribution. Instead you can create the distribution manually, however newDistribution is usually the preferred approach. In its most simple form, calling newDistribution on a node A, simply creates a Table containing the variables in A conditioned on the variables in all the parents of A (or a CLGaussian if any continuous variables are involved). You then need to specify all the parameters before assigning it to A. For noisy nodes, use one of the other overloads for NewDistribution, as noisy nodes require multiple distributions, and a key is used to specify which one is being set.- Returns:
- A new distribution.
- Throws:
IllegalArgumentException- Raised if the node or one of it's parents has zero states.
-
getDistribution
public Distribution getDistribution()
Returns the distribution currently associated with theNode. The distribution cannot be modified when it is assigned to a node. It is also automatically set to null, when certain structural changes occur (see remarks). If a structural change occurs to the network that invalidates the current distribution, it is automatically set to null. This occurs in the following situations:- States are added or removed from the node.
- States are added or removed from one of the node's parents.
- The
getLinksIn()collection changes. I.e. adding or removing a parent node. Note that if a node is removed from a network, all of its links are automatically removed also.
- Throws:
IllegalArgumentException- Raised when the distribution is invalid.
-
setDistribution
public void setDistribution(Distribution value)
Returns the distribution currently associated with theNode. The distribution cannot be modified when it is assigned to a node. It is also automatically set to null, when certain structural changes occur (see remarks). If a structural change occurs to the network that invalidates the current distribution, it is automatically set to null. This occurs in the following situations:- States are added or removed from the node.
- States are added or removed from one of the node's parents.
- The
getLinksIn()collection changes. I.e. adding or removing a parent node. Note that if a node is removed from a network, all of its links are automatically removed also.
- Throws:
IllegalArgumentException- Raised when the distribution is invalid.
-
getDistributions
public NodeDistributions getDistributions()
Returns the distributions associated with this instance with NodeDistributionKind = Probability. Some node types such as temporal nodes can have more than one distribution assigned to them.
-
getName
public String getName()
The name of the node. Node names in a network must be unique, and comparisons are case sensitive.
-
setName
public void setName(String value)
The name of the node. Node names in a network must be unique, and comparisons are case sensitive.
-
getDescription
public String getDescription()
An optional description for the node.
-
setDescription
public void setDescription(String value)
An optional description for the node.
-
getNetwork
public Network getNetwork()
TheNetworkthe node belongs to. Value will be null unless the node has been added to a network.
-
getLinks
public NodeLinkCollection getLinks()
Collection of both incoming and outgoing links (parent and child nodes).
-
getVariables
public NodeVariableCollection getVariables()
Collection of variables represented by the node.
-
getLinksIn
public NodeLinkCollection getLinksIn()
Collection of incoming links (linking to parent nodes).
-
getLinksOut
public NodeLinkCollection getLinksOut()
Collection of outgoing links (linking to child nodes).
-
getIndex
public int getIndex()
The Index of this instance in the collection of nodes belonging to a network, or -1 if the node does not belong to a network.
-
-