Class 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.Links property.

    See Also:
    Network, Link
    • Constructor Detail

      • Node

        public Node()
        Initializes a new instance of the Node class, with no variables, and no name.
      • Node

        public Node​(Variable variable)
        Initializes a new instance of the Node class with a specified Variable and 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 the Node class with the specified [name]. A Variable is automatically created for the node and assigned the same name as the node with the VariableValueType specified.
        Parameters:
        name - The name to give the node and variable, which can be null or empty.
        valueType - The VariableValueType of 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 the Node class with the specified [name]. A Variable is automatically created for the node and assigned the same name as the node with the VariableValueType specified.
        Parameters:
        name - The name to give the node and variable, which can be null or empty.
        valueType - The VariableValueType of the node variable, e.g. discrete or continuous.
      • Node

        public Node​(String name,
                    int states)
        Initializes a new instance of the Node class with the specified [name] and automatically adds a discrete Variable with 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 created Variable. 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 the Node class, with the name of the node, automatically creating an associated discrete Variable and 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 associated Variable, specified by their names.
        Throws:
        NullPointerException - Raised when [states] is null.
      • Node

        public Node​(String name,
                    State... states)
        Initializes a new instance of the Node class, with the name of the node, automatically creating an associated discrete Variable and 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 associated Variable.
        Throws:
        NullPointerException - Raised when [states] is null.
      • Node

        public Node​(String name,
                    Variable... variables)
        Initializes a new instance of the Node class with a specified name and a number of variables.
        Parameters:
        name - The name for the node.
        variables - The variable(s) represented by the node.
      • Node

        public Node​(String name,
                    List<Variable> variables)
        Initializes a new instance of the Node class 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.
      • 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.
        Overrides:
        toString in class Object
        Returns:
        A String containing the name of the node which is empty 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. Use getDistributions() to perform the assignment. See NodeDistributions for 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. Use getDistributions() to perform the assignment. See NodeDistributions for 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. Use getDistributions() to perform the assignment. For temporal or noisy nodes us a different overload. See NodeDistributions for 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. Use getDistributions() to perform the assignment. See NodeDistributions for 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. Use com.bayesserver.node.Distributions#getExpressions to perform the assignment from an expression. See com.bayesserver.nodedistributions.Expressions for 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's getDistribution() property. This method is useful for creating distributions appropriate for a node. However, the returned distribution cannot be set to getDistribution() 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 the Node. 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 the Node. 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()
        The Network the 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.