All Implemented Interfaces:
Node

public class CPTNode extends DiscreteStateNode
Extends the DiscreteNode class to store a CPT and the sufficient statistics for a BN.
  • Constructor Details

    • CPTNode

      public CPTNode(String name, List<String> states)
      Constructor that receives the name of the variable and its possible states.
      Parameters:
      name - name of the node
      states - list of strings representing the states that the variable related to the node can take
    • CPTNode

      public CPTNode(String name, List<String> states, boolean isClassVariable)
      Constructor that receives the name of the variable, a list of strings with its possible states and if it is a class variable.
      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
    • CPTNode

      public CPTNode(CPTNode node)
      Constructor that receives a CPTNode and clones it. Everything is cloned except the sufficient statistics.
      Parameters:
      node - node to clone
  • Method Details

    • getCPT

      public double[][] getCPT()
      Returns the conditional probability table (CPT) of the node.
      Returns:
      the conditional probability table of the node
    • setCPT

      public void setCPT(double[][] CPT)
      Establishes the CPT of the node.
      Parameters:
      CPT - CPT of the node
    • getCP

      public double getCP(int idxStateParents, int idxStateNode)
      Returns the conditional probability of a state of the node given the state of the parents.
      Parameters:
      idxStateParents - index of the parents' state
      idxStateNode - index of the node state
      Returns:
      conditional probability of a state of the node given the state of the parent
    • getSufficientStatistics

      public BNSufficientStatistics getSufficientStatistics()
      Returns sufficient statistics of the node.
      Returns:
      sufficient statistics
    • setSufficientStatistics

      public void setSufficientStatistics(SufficientStatistics sufficientStatistics)
      Establishes the sufficient statistics of a CPT node.
      Parameters:
      sufficientStatistics - sufficient statistics of a CPT node
    • estimateLogLikelihood

      public double estimateLogLikelihood()
      Description copied from interface: Node
      Returns the local log-likelihood for the node.
      Returns:
      local log-likelihood
    • sampleState

      public State sampleState(double percentageNoisyStates)
      Samples the state of the node given evidence using forward sampling. First it is sampled from a uniform * distribution, then it is iterated over the state of the nodes and accumulated the probability of each of them. * Once this accumulated probability is more than the sampled value from the uniform distribution, the current * state under study is returned.
      Parameters:
      percentageNoisyStates - value from 0 to 1 representing the probability of randomly sampling the state of the variable
      Returns:
      sampled state of the node. Null is returned if the state could not be sampled
    • areParametersEstimated

      public boolean areParametersEstimated()
      Description copied from interface: Node
      Returns true if the parameters of the node were estimated.
      Returns:
      true if the parameters of the node were estimated, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class DiscreteStateNode