Class BayesPm

java.lang.Object
edu.cmu.tetrad.bayes.BayesPm
All Implemented Interfaces:
VariableSource, Pm, TetradSerializable, Serializable

public final class BayesPm extends Object implements Pm, VariableSource
Implements a discrete Bayes parametric model--that is, a DAG together with a map from the nodes in the graph to a set of discrete variables, specifying the number of categories for each variable and the name of each category for each variable. This is all the information one needs to know in order to determine the parametric form of a Bayes net up to actual values of parameters. Specific values for the Bayes net are stored in a BayesIM object (see).
Author:
josephramsey
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    BayesPm(BayesPm bayesPm)
    Copy constructor.
    BayesPm(Graph graph)
    Construct a new BayesPm using the given DAG, assigning each variable two values named "value1" and "value2" unless nodes are discrete variables with categories already defined.
    BayesPm(Graph graph, int lowerBound, int upperBound)
    Constructs a new BayesPm from the given DAG, assigning each variable a random number of values between lowerBound and upperBound.
    BayesPm(Graph graph, BayesPm oldBayesPm)
    Constructs a new BayesPm using a given DAG, using as much information from the old BayesPm as possible.
    BayesPm(Graph graph, BayesPm oldBayesPm, int lowerBound, int upperBound)
    Constructs a new BayesPm from the given DAG, using as much information from the old BayesPm as possible.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Will return true if the argument is a BayesPm with the same graph and variables.
    getCategory(Node node, int index)
    Returns the index'th value for the given node.
    int
    getCategoryIndex(Node node, String category)
    Returns the index of the given category for the given node.
    Returns the DAG.
    Returns the measured nodes.
    getNode(int index)
    Returns the node at the given index.
    getNode(String nodeName)
    Returns the node by the given name.
    int
    Returns the node index.
    int
    Returns the number of values for the given node.
    int
    Returns the number of nodes.
    static List<String>
    Returns the parameter names.
    Returns the variable for the given node.
    Returns the variable names.
    Returns the list of variables associated with this object.
    static BayesPm
    Generates a simple exemplar of this class to test serialization.
    void
    setCategories(Node node, List<String> categories)
    Sets the number of values for the given node to the given number.
    void
    setNumCategories(Node node, int numCategories)
    Sets the number of values for the given node to the given number.
    Prints out the list of values for each node.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • BayesPm

      public BayesPm(Graph graph)
      Construct a new BayesPm using the given DAG, assigning each variable two values named "value1" and "value2" unless nodes are discrete variables with categories already defined.
      Parameters:
      graph - Ibid.
    • BayesPm

      public BayesPm(Graph graph, BayesPm oldBayesPm)
      Constructs a new BayesPm using a given DAG, using as much information from the old BayesPm as possible.
      Parameters:
      graph - Ibid.
      oldBayesPm - Ibid.
    • BayesPm

      public BayesPm(Graph graph, int lowerBound, int upperBound)
      Constructs a new BayesPm from the given DAG, assigning each variable a random number of values between lowerBound and upperBound. Uses a fixed number of values if lowerBound == upperBound. The values are named "value1" ... "valuen".
      Parameters:
      graph - Ibid.
      lowerBound - Ibid.
      upperBound - Ibid.
    • BayesPm

      public BayesPm(Graph graph, BayesPm oldBayesPm, int lowerBound, int upperBound)
      Constructs a new BayesPm from the given DAG, using as much information from the old BayesPm as possible. For variables not in the old BayesPm, assigns each variable a random number of values between lowerBound and upperBound. Uses a fixed number of values if lowerBound == upperBound. The values are named "value1" ... "valuen".
      Parameters:
      graph - Ibid.
      oldBayesPm - Ibid.
      lowerBound - Ibid.
      upperBound - Ibid.
    • BayesPm

      public BayesPm(BayesPm bayesPm)
      Copy constructor.
      Parameters:
      bayesPm - Ibid.
  • Method Details

    • serializableInstance

      public static BayesPm serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      Ibid.
    • getParameterNames

      public static List<String> getParameterNames()
      Returns the parameter names.
      Returns:
      Ibid.
    • getDag

      public Graph getDag()
      Returns the DAG.
      Returns:
      the DAG as a Graph.
    • getNumCategories

      public int getNumCategories(Node node)
      Returns the number of values for the given node.
      Parameters:
      node - Ibid.
      Returns:
      the number of values for the given node.
    • getCategory

      public String getCategory(Node node, int index)
      Returns the index'th value for the given node.
      Parameters:
      node - Ibid.
      index - Ibid.
      Returns:
      the index'th value for the given node.
    • getCategoryIndex

      public int getCategoryIndex(Node node, String category)
      Returns the index of the given category for the given node.
      Parameters:
      node - Ibid.
      category - Ibid.
      Returns:
      the index of the given category for the given node.
    • setNumCategories

      public void setNumCategories(Node node, int numCategories)
      Sets the number of values for the given node to the given number.
      Parameters:
      node - Ibid.
      numCategories - Ibid.
    • equals

      public boolean equals(Object o)
      Will return true if the argument is a BayesPm with the same graph and variables.
      Overrides:
      equals in class Object
      Parameters:
      o - Ibid.
    • setCategories

      public void setCategories(Node node, List<String> categories)
      Sets the number of values for the given node to the given number.
      Parameters:
      node - Ibid.
      categories - Ibid.
    • getVariables

      public List<Node> getVariables()
      Description copied from interface: VariableSource
      Returns the list of variables associated with this object.
      Specified by:
      getVariables in interface VariableSource
      Returns:
      the list of variables associated with this object.
    • getVariableNames

      public List<String> getVariableNames()
      Returns the variable names.
      Specified by:
      getVariableNames in interface VariableSource
      Returns:
      Ibid.
    • getVariable

      public Node getVariable(Node node)
      Returns the variable for the given node.
      Parameters:
      node - Ibid.
      Returns:
      Ibid.
    • getMeasuredNodes

      public List<Node> getMeasuredNodes()
      Returns the measured nodes.
      Returns:
      the list of measured variableNodes.
    • toString

      public String toString()
      Prints out the list of values for each node.
      Overrides:
      toString in class Object
      Returns:
      Ibid.
    • getNode

      public Node getNode(String nodeName)
      Returns the node by the given name.
      Parameters:
      nodeName - Ibid.
      Returns:
      Ibid.
    • getNode

      public Node getNode(int index)
      Returns the node at the given index.
      Parameters:
      index - Ibid.
      Returns:
      Ibid.
    • getNodeIndex

      public int getNodeIndex()
      Returns the node index.
      Returns:
      -1.
    • getNumNodes

      public int getNumNodes()
      Returns the number of nodes.
      Returns:
      Ibid.