Class DiscreteStateNode

java.lang.Object
es.upm.fi.cig.multictbnc.nodes.AbstractNode
es.upm.fi.cig.multictbnc.nodes.DiscreteStateNode
All Implemented Interfaces:
Node
Direct Known Subclasses:
CIMNode, CPTNode

public abstract class DiscreteStateNode extends AbstractNode
Abstract class defining common variables and methods for discrete nodes.
  • Constructor Details

    • DiscreteStateNode

      public DiscreteStateNode(String name, List<String> states)
      Initialises a discrete node given a list of states.
      Parameters:
      name - name of the node
      states - list of strings representing the states that the variable related to the node can take
    • DiscreteStateNode

      public DiscreteStateNode(String name, List<String> states, boolean isClassVariable)
      Initialises a discrete node specifying if the node is for a class variable or a feature.
      Parameters:
      name - name of the node
      states - list of strings representing the states that the variable related to the node can take
      isClassVariable - true if the node represent a class variable, false otherwise
  • Method Details

    • getIdxState

      public int getIdxState()
      Gets the index of the current state of the node.
      Returns:
      index of the current state of the node
    • getIdxStateParents

      public int getIdxStateParents()
      Gets the index for the current state of the node's parents. Return -1 if the state of one parent was not seen during training. Algorithm from https://github.com/dcodecasa/CTBNCToolkit.
      Returns:
      index for the current state of the node's parents
    • getIdxStateParents

      public int getIdxStateParents(List<String> nameParents)
      Gets the index for the current state of the specified parents of the node. Returns -1 if the state of one parent was not seen during training or if the parent does not exist. Returns 0 if the provided parent list is null or empty.
      Parameters:
      nameParents - name of the parent nodes
      Returns:
      index for the current state of the specified subset of parents
    • getNumStates

      public int getNumStates()
      Returns the number of possible states of the node.
      Returns:
      number of states of the node
    • getNumStatesParents

      public int getNumStatesParents()
      Returns the number of possible states of the parents of the node.
      Returns:
      number of states of the node's parents
    • getState

      public String getState()
      Gets the state of the node.
      Returns:
      state of the node
    • setState

      public void setState(int stateIdx)
      Sets the state index of the node. The state index is not changed if the provided index was not seen during training.
      Parameters:
      stateIdx - node state index
    • getStates

      public List<String> getStates()
      Returns a list of the states that the node can take.
      Returns:
      list of strings representing the states that the variable related to the node can take
    • setState

      public Integer setState(String state)
      Sets the state of the node and returns its id. If the state was not seen during training, -1 is returned.
      Parameters:
      state - state of the node
      Returns:
      id of the state
    • setStateParents

      public void setStateParents(int idxStateParents)
      Sets the states of the parents of the node given the index related to their state. Algorithm from https://github.com/dcodecasa/CTBNCToolkit.
      Parameters:
      idxStateParents - index of the state of the node's parents
    • clearParentAndChildrenSets

      public void clearParentAndChildrenSets()
      Description copied from interface: Node
      Remove the set of parents and children of the node. This method should be used with caution, as references to this node from others will not be affected. It is recommended its use when creating an empty PGM, i.e., we are removing all edges between nodes.
      Specified by:
      clearParentAndChildrenSets in interface Node
      Overrides:
      clearParentAndChildrenSets in class AbstractNode
    • removeParent

      public void removeParent(Node nodeParent)
      Description copied from interface: Node
      Removes a certain parent of the node.
      Specified by:
      removeParent in interface Node
      Overrides:
      removeParent in class AbstractNode
      Parameters:
      nodeParent - parent node
    • setParent

      public void setParent(Node nodeParent)
      Description copied from interface: Node
      Defines a provided node as a parent of this one.
      Specified by:
      setParent in interface Node
      Overrides:
      setParent in class AbstractNode
      Parameters:
      nodeParent - parent node
    • toString

      public String toString()
      Overrides:
      toString in class AbstractNode