Package edu.cmu.tetrad.search
Class Fci
java.lang.Object
edu.cmu.tetrad.search.Fci
- All Implemented Interfaces:
IGraphSearch
The Fci class implements the Fast Causal Inference (FCI) algorithm for discovering causal structures from data. It
supports various configurations and rule sets for orienting edges in a partially directed acyclic graph (PDAG) or a
completed partially directed acyclic graph (CPDAG).
It provides methods for running searches, configuring the search process, and managing the independence test, variable filtering, depth settings, and other algorithm-specific options.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe ColliderRule enum defines the rules or strategies used to handle collider structures in causal inference or related algorithms. -
Constructor Summary
ConstructorsConstructorDescriptionFci(IndependenceTest test) Constructs an instance of the Fci algorithm using the specified independence test.Fci(IndependenceTest test, List<Node> searchVars) Constructs an instance of the Fci algorithm using the specified independence test and a subset of variables to include in the search. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the elapsed time recorded by the algorithm or process.Retrieves the knowledge structure maintained by this instance.Returns the sepset map maintained by this instance of the FCI algorithm.getTest()Retrieves the IndependenceTest instance.search()Searches and retrieves a graph using the specified algorithm.Executes the search process using the provided `IFas` implementation and performs various graph orientation and refinement steps based on the FCI algorithm.voidsetCompleteRuleSetUsed(boolean completeRuleSetUsed) Configures whether the complete rule set is used in the FCI algorithm during the causal discovery process.voidsetDepth(int depth) Sets the maximum depth for the algorithm's search process.voidsetDoPossibleDsep(boolean doPossibleDsep) Configures whether the possible-DSEP (Definite Separation) step is performed as part of the FCI algorithm during the causal discovery process.voidsetGuaranteePag(boolean guaranteePag) Sets the value of the guaranteePag flag.voidsetKnowledge(Knowledge knowledge) Sets the knowledge structure to be used or modified by the algorithm.voidsetLogMaxPTies(boolean enabled) Configures whether logging is enabled for ties in the MAX-P condition during the FCI algorithm's causal discovery process.voidsetLogStream(PrintStream out) Sets the log stream for capturing output messages of the algorithm's execution.voidsetMaxDiscriminatingPathLength(int maxDiscriminatingPathLength) Sets the maximum discriminating path length for the algorithm or process.voidsetMaxPDepthStratified(boolean enabled) Configures whether the depth-specific stratification of the MAX-P condition is enabled during the FCI algorithm's causal discovery process.voidsetMaxPGlobalOrder(boolean enabled) Configures whether the global MAX-P order is enabled to avoid order dependence during the causal discovery process in the FCI algorithm.voidsetMaxPMargin(double margin) Sets the maximum probability margin (max-P margin) to be used in the FCI algorithm during the causal discovery process.voidConfigures the R0 collider rule to be used in the FCI algorithm.voidsetReplicatingGraph(boolean replicatingGraph) Sets the state of the replicatingGraph flag.voidsetStable(boolean stable) Sets the stability status.voidsetTest(IndependenceTest test) Sets the independence test for the current object.voidsetVerbose(boolean verbose) Sets the verbosity level for the system.
-
Constructor Details
-
Fci
Constructs an instance of the Fci algorithm using the specified independence test.- Parameters:
test- AnIndependenceTestinstance used to evaluate conditional independence among variables in the search. This cannot be null.- Throws:
NullPointerException- If the providedtestis null.
-
Fci
Constructs an instance of the Fci algorithm using the specified independence test and a subset of variables to include in the search.- Parameters:
test- AnIndependenceTestinstance used to evaluate conditional independence among variables in the search. This cannot be null.searchVars- A list ofNodeobjects specifying the subset of variables to include in the search. Only variables from this list will be considered. Variables not in this subset are removed from the internal variable set.- Throws:
NullPointerException- If the providedtestis null.
-
-
Method Details
-
setR0ColliderRule
Configures the R0 collider rule to be used in the FCI algorithm. The R0 collider rule determines how potential colliders are oriented during the causal discovery process. If the provided rule is null, the default ruleColliderRule.SEPSETSwill be used.- Parameters:
rule- TheFci.ColliderRuleoption to specify the R0 collider rule. Possible values includeColliderRule.SEPSETS,ColliderRule.CONSERVATIVE, andColliderRule.MAX_P. A null value will default toColliderRule.SEPSETS.
-
setMaxPGlobalOrder
public void setMaxPGlobalOrder(boolean enabled) Configures whether the global MAX-P order is enabled to avoid order dependence during the causal discovery process in the FCI algorithm.- Parameters:
enabled- A boolean value to enable or disable the global MAX-P order. If true, the global MAX-P order is enforced; otherwise, it is not.
-
setMaxPDepthStratified
public void setMaxPDepthStratified(boolean enabled) Configures whether the depth-specific stratification of the MAX-P condition is enabled during the FCI algorithm's causal discovery process. This setting influences how null hypotheses are evaluated based on conditional independence at varying depths.- Parameters:
enabled- A boolean value indicating whether to enable the depth-specific stratification of the MAX-P condition. If true, depth-specific stratification is enforced; otherwise, it is not.
-
setMaxPMargin
public void setMaxPMargin(double margin) Sets the maximum probability margin (max-P margin) to be used in the FCI algorithm during the causal discovery process. This margin determines the threshold for probability-based decisions in conditional independence evaluations. If a negative value is provided, it will be reset to 0.0.- Parameters:
margin- A double value representing the maximum probability margin to set. If negative, the margin will default to 0.0.
-
setLogMaxPTies
public void setLogMaxPTies(boolean enabled) Configures whether logging is enabled for ties in the MAX-P condition during the FCI algorithm's causal discovery process. This setting primarily controls the output of informational logs when ties occur in conditional independence evaluations.- Parameters:
enabled- A boolean value indicating whether to enable or disable logging for MAX-P condition ties. If true, logging is enabled; otherwise, it is not.
-
setLogStream
Sets the log stream for capturing output messages of the algorithm's execution. This stream allows logging information to be directed to a specified PrintStream instance.- Parameters:
out- APrintStreamobject representing the output stream to which logs will be written. AcceptsSystem.out,System.err, or any otherPrintStream. Can be set tonullto disable logging.
-
setDepth
public void setDepth(int depth) Sets the maximum depth for the algorithm's search process. The depth controls the maximum number of edges that can be traversed when determining conditional independence relations. A depth of -1 indicates no limit on the depth, while non-negative values specify explicit limitations. Attempts to set a depth less than -1 result in anIllegalArgumentException.- Parameters:
depth- An integer specifying the maximum depth. Must be -1 (unlimited) or a non-negative value (≥ 0).- Throws:
IllegalArgumentException- If the provideddepthis less than -1.
-
getElapsedTime
public long getElapsedTime()Returns the elapsed time recorded by the algorithm or process.- Returns:
- A long value representing the elapsed time, typically measured in milliseconds.
-
getSepsets
Returns the sepset map maintained by this instance of the FCI algorithm. The sepset map contains information about the separating sets identified during the causal discovery process.- Returns:
- A
SepsetMapobject representing the separating sets computed within the algorithm.
-
getKnowledge
Retrieves the knowledge structure maintained by this instance.- Returns:
- A
Knowledgeobject representing the domain knowledge used or inferred by the algorithm.
-
setKnowledge
Sets the knowledge structure to be used or modified by the algorithm. The knowledge structure contains domain-specific constraints and information that guide the causal discovery process.- Parameters:
knowledge- AKnowledgeobject representing the domain-specific knowledge to set. This cannot be null.- Throws:
NullPointerException- If the providedknowledgeis null.
-
setCompleteRuleSetUsed
public void setCompleteRuleSetUsed(boolean completeRuleSetUsed) Configures whether the complete rule set is used in the FCI algorithm during the causal discovery process. This setting determines if all rules in the FCI framework will be applied.- Parameters:
completeRuleSetUsed- A boolean value indicating whether to enable or disable the usage of the complete rule set. If true, the entire rule set is used; otherwise, a subset of the rules is applied.
-
setDoPossibleDsep
public void setDoPossibleDsep(boolean doPossibleDsep) Configures whether the possible-DSEP (Definite Separation) step is performed as part of the FCI algorithm during the causal discovery process. The possible-DSEP step influences the identification of separating sets in the graph by considering potential additional conditioning sets.- Parameters:
doPossibleDsep- A boolean value indicating whether to enable or disable the possible-DSEP step. If true, the possible-DSEP step is performed; otherwise, it is not.
-
setMaxDiscriminatingPathLength
public void setMaxDiscriminatingPathLength(int maxDiscriminatingPathLength) Sets the maximum discriminating path length for the algorithm or process. If this value is set to -1, there is no limit on the path length. A non-negative value specifies the upper limit for the path length.- Parameters:
maxDiscriminatingPathLength- the maximum discriminating path length to set. Must be -1 (for no limit) or a non-negative integer.- Throws:
IllegalArgumentException- if the specified value is less than -1.
-
setVerbose
public void setVerbose(boolean verbose) Sets the verbosity level for the system. When set to true, detailed logging or additional information may be displayed or processed.- Parameters:
verbose- a boolean value where true enables verbose mode and false disables it.
-
setStable
public void setStable(boolean stable) Sets the stability status.- Parameters:
stable- a boolean value indicating whether the object is stable or not
-
setGuaranteePag
public void setGuaranteePag(boolean guaranteePag) Sets the value of the guaranteePag flag.- Parameters:
guaranteePag- the boolean value to set as the guaranteePag flag
-
search
Searches and retrieves a graph using the specified algorithm.- Specified by:
searchin interfaceIGraphSearch- Returns:
- the resulting Graph object obtained from the search operation
- Throws:
InterruptedException- if the thread executing the search is interrupted
-
search
Executes the search process using the provided `IFas` implementation and performs various graph orientation and refinement steps based on the FCI algorithm. This includes applying initial orientations, handling possible-dsep, and finalizing the graph structure according to the defined rules.The method logs details of the operations performed when the verbose flag is enabled. It also ensures the resulting graph is in a valid PAG state if the guaranteePag option is set.
- Parameters:
fas- Implementation of the `IFas` interface, providing the functionality for the Fast Adjacency Search (FAS) to find the skeleton of the graph. Must be properly configured before calling this method.- Returns:
- A `Graph` object representing the partially oriented graph (PAG) resulting from the search and orientation rules applied.
- Throws:
InterruptedException- If the execution of the search process is interrupted.
-
getTest
Retrieves the IndependenceTest instance.- Specified by:
getTestin interfaceIGraphSearch- Returns:
- the IndependenceTest instance
-
setTest
Sets the independence test for the current object. The method checks if the variables of the provided test match the variables of the existing test. If they do not match, an IllegalArgumentException will be thrown.- Specified by:
setTestin interfaceIGraphSearch- Parameters:
test- the new IndependenceTest to be set. Must have the same list of variables as the existing test.- Throws:
IllegalArgumentException- if the variables of the provided test do not match the variables of the current test.
-
setReplicatingGraph
public void setReplicatingGraph(boolean replicatingGraph) Sets the state of the replicatingGraph flag.- Parameters:
replicatingGraph- a boolean value indicating whether the graph should be in a replicating state.
-