Class Pc

java.lang.Object
edu.cmu.tetrad.search.Pc
All Implemented Interfaces:
IGraphSearch

public class Pc extends Object implements IGraphSearch
Pc (Unified "Classic PC")

Skeleton via FAS (stable toggle), orient unshielded triples using VANILLA/CPC/MAX_P, then Meek rules to closure. Deterministic: sorted names, canonical (x,y) endpoint ordering. No internal CI cache (wrap your test if desired).

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enum representing the permission to allow or disallow bidirected edges.
    static enum 
    Enum representing the orientation style used for colliders in a computational context.
    static final class 
    Public so callers can use it in results.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new instance of the Pc class with a given independence test.
  • Method Summary

    Modifier and Type
    Method
    Description
    Identifies and returns a list of ambiguous triples from the given graph.
    Retrieves all colliders from the provided graph based on specific criteria.
    Retrieves the Fas object associated with this instance.
    Identifies and retrieves all noncollider triples from the given graph.
    Returns the independence test associated with this instance.
    Performs a search operation based on the test variables associated with the instance.
    search(List<Node> nodes)
    Performs a search to generate a graph structure based on the provided list of nodes.
    void
    Sets the allowance for bidirected edges in the structure being analyzed.
    void
    Sets the orientation style for handling colliders in the graph.
    void
    setDepth(int depth)
    Sets the depth parameter for the instance.
    void
    setFasStable(boolean fasStable)
    Sets whether the Fast Adjacency Search (FAS) algorithm will use the "stable" modification.
    void
    Sets the knowledge object for this instance by creating a new instance based on the provided knowledge.
    void
    setLogMaxPTies(boolean enabled)
    Sets whether ties in the MAX-P conditional independence tests are logged during execution.
    void
    Sets the output stream for logging messages.
    void
    setMaxPDepthStratified(boolean enabled)
    Sets whether the MAX-P depth stratification procedure is enabled or disabled.
    void
    setMaxPGlobalOrder(boolean enabled)
    Sets the global order-independent MAX-P collider orientation option.
    void
    setMaxPMargin(double margin)
    Sets the maximum p-value margin for decision-making in the MAX-P algorithm.
    void
    setReplicatingGraph(boolean replicatingGraph)
    Sets the flag indicating whether the graph is in a replicating state.
    void
    Sets the independence test for this instance.
    void
    setTimeoutMs(long timeoutMs)
    Sets the timeout duration for this instance, specifying the maximum time (in milliseconds) the algorithm or operation is permitted to run.
    void
    setVerbose(boolean verbose)
    Sets whether this instance and its associated test will print verbose output.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Pc

      public Pc(IndependenceTest test)
      Constructs a new instance of the Pc class with a given independence test.
      Parameters:
      test - an IndependenceTest object that defines the test for conditional independence
  • Method Details

    • setKnowledge

      public void setKnowledge(Knowledge knowledge)
      Sets the knowledge object for this instance by creating a new instance based on the provided knowledge.
      Parameters:
      knowledge - the Knowledge object to be set, representing constraints or prior information about the graph structure
    • setDepth

      public void setDepth(int depth)
      Sets the depth parameter for the instance. The depth controls the maximum number of conditioning variables used in conditional independence tests.
      Parameters:
      depth - the maximum number of conditioning variables; a value of -1 typically indicates no limit.
    • setFasStable

      public void setFasStable(boolean fasStable)
      Sets whether the Fast Adjacency Search (FAS) algorithm will use the "stable" modification. The stable version ensures that edge removals during execution do not affect the search process.
      Parameters:
      fasStable - true to enable the stable FAS modification, false to disable it
    • setColliderOrientationStyle

      public void setColliderOrientationStyle(Pc.ColliderOrientationStyle rule)
      Sets the orientation style for handling colliders in the graph. The orientation style determines the method used to decide whether a triple forms a collider. Valid styles are defined in the Pc.ColliderOrientationStyle enum, such as SEPSETS, CONSERVATIVE, or MAX_P.
      Parameters:
      rule - the Pc.ColliderOrientationStyle that specifies the method used for collider orientation
    • setAllowBidirected

      public void setAllowBidirected(Pc.AllowBidirected allow)
      Sets the allowance for bidirected edges in the structure being analyzed. This method determines whether bidirected edges are permitted based on the specified option.
      Parameters:
      allow - an instance of Pc.AllowBidirected that specifies whether bidirected edges are allowed (e.g., ALLOW or DISALLOW)
    • setVerbose

      public void setVerbose(boolean verbose)
      Sets whether this instance and its associated test will print verbose output.
      Parameters:
      verbose - true to enable verbose output; false to disable it.
    • setTimeoutMs

      public void setTimeoutMs(long timeoutMs)
      Sets the timeout duration for this instance, specifying the maximum time (in milliseconds) the algorithm or operation is permitted to run.
      Parameters:
      timeoutMs - the timeout duration in milliseconds. A value of 0 or a negative number may indicate no timeout (depending on implementation).
    • setLogMaxPTies

      public void setLogMaxPTies(boolean enabled)
      Sets whether ties in the MAX-P conditional independence tests are logged during execution. If enabled, details about ties that impact decision-making in the algorithm are recorded in the logs.
      Parameters:
      enabled - true to enable logging for MAX-P ties; false to disable it
    • setLogStream

      public void setLogStream(PrintStream out)
      Sets the output stream for logging messages. The specified PrintStream will be used to capture log outputs generated during the execution of this instance.
      Parameters:
      out - the PrintStream object where the log messages will be directed. Passing null disables logging.
    • setMaxPGlobalOrder

      public void setMaxPGlobalOrder(boolean enabled)
      Sets the global order-independent MAX-P collider orientation option. This determines whether the MAX-P algorithm will apply a global ordering that is independent of the sequence of operations.
      Parameters:
      enabled - true to enable global order-independent orientation, false to disable it
    • setMaxPDepthStratified

      public void setMaxPDepthStratified(boolean enabled)
      Sets whether the MAX-P depth stratification procedure is enabled or disabled. Depth stratification can be used to adjust the way depth constraints are applied during the MAX-P algorithm, based on specific requirements.
      Parameters:
      enabled - true to enable depth stratification in MAX-P, false to disable it
    • setMaxPMargin

      public void setMaxPMargin(double margin)
      Sets the maximum p-value margin for decision-making in the MAX-P algorithm. The margin is constrained to be non-negative, ensuring that negative values are reset to 0.0.
      Parameters:
      margin - the maximum p-value margin; if provided value is less than 0.0, it will default to 0.0.
    • search

      public Graph search() throws InterruptedException
      Performs a search operation based on the test variables associated with the instance. Delegates the search to the method that accepts a list of nodes.
      Specified by:
      search in interface IGraphSearch
      Returns:
      the resulting graph structure after the search operation is completed
      Throws:
      InterruptedException - if the thread executing the search is interrupted
    • search

      public Graph search(List<Node> nodes) throws InterruptedException
      Performs a search to generate a graph structure based on the provided list of nodes. Executes a three-step process: skeleton construction using the Fast Adjacency Search (FAS), orientation of unshielded triples as colliders, and application of Meek rules to ensure proper edge orientations.
      Parameters:
      nodes - the list of nodes to be used as input for the search algorithm
      Returns:
      the resulting graph structure after the search process is completed
      Throws:
      InterruptedException - if the thread executing the search is interrupted
    • getTest

      public IndependenceTest getTest()
      Returns the independence test associated with this instance.
      Specified by:
      getTest in interface IGraphSearch
      Returns:
      the IndependenceTest object representing the test for conditional independence.
    • setTest

      public void setTest(IndependenceTest test)
      Sets the independence test for this instance. The provided test must have the same list of variables as the current test to ensure consistency. Otherwise, an exception will be thrown.
      Specified by:
      setTest in interface IGraphSearch
      Parameters:
      test - the new IndependenceTest to be set. This test must have the same list of variables as the current test.
      Throws:
      IllegalArgumentException - if the node lists of the current test and the provided test are not equal.
    • getColliderTriples

      public List<Pc.Triple> getColliderTriples(Graph g)
      Retrieves all colliders from the provided graph based on specific criteria. A collider is an unshielded triple where both parent nodes x and y point to a common child z (i.e., x -> z <- y). The method identifies all such triples in the graph and returns them.
      Parameters:
      g - the graph from which colliders are identified
      Returns:
      a list of triples representing the colliders found in the graph
    • getNoncolliderTriples

      public List<Pc.Triple> getNoncolliderTriples(Graph g)
      Identifies and retrieves all noncollider triples from the given graph. A noncollider triple is a triple where the middle node is not a collider, meaning there are no arrowheads pointing to it from either of the other two nodes.
      Parameters:
      g - the graph from which noncollider triples are to be extracted
      Returns:
      a list of noncollider triples found in the graph
    • getAmbiguousTriples

      public List<Pc.Triple> getAmbiguousTriples(Graph g)
      Identifies and returns a list of ambiguous triples from the given graph. Ambiguous triples are determined based on the structure of the graph and the relationships between nodes in each triple.
      Parameters:
      g - the graph from which ambiguous triples are to be identified
      Returns:
      a list of triples from the graph that are categorized as ambiguous
    • getFas

      public Fas getFas()
      Retrieves the Fas object associated with this instance.
      Returns:
      the Fas object
    • setReplicatingGraph

      public void setReplicatingGraph(boolean replicatingGraph)
      Sets the flag indicating whether the graph is in a replicating state.
      Parameters:
      replicatingGraph - a boolean value where true denotes that the graph is replicating and false denotes that it is not.