Package edu.cmu.tetrad.graph
Class RandomGraph
java.lang.Object
edu.cmu.tetrad.graph.RandomGraph
The RandomGraph class provides methods for generating random graphs. It includes methods for generating random
directed acyclic graphs (DAGs), random graphs with arbitrary edges, and random scale-free graphs.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Generates random DAGs uniformly with certain classes of DAGs using variants of Markov chain algorithm by Malancon, Dutour, and Philippe. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addTwoCycles
(Graph graph, int numTwoCycles) addTwoCycles.static void
fixLatents1
(int numLatentConfounders, Graph graph) fixLatents1.static void
fixLatents4
(int numLatentConfounders, Graph graph) fixLatents4.static Graph
randomCyclicGraph2
(int numNodes, int numEdges, int maxDegree) Makes a cyclic graph by repeatedly adding cycles of length of 3, 4, or 5 to the graph, then finally adding two cycles.static Graph
randomCyclicGraph3
(int numNodes, int numEdges, int maxDegree, double probCycle, double probTwoCycle) Makes a cyclic graph by repeatedly adding cycles of length of 3, 4, or 5 to the graph, then finally adding two cycles.static Graph
randomDag
(int numNodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random Directed Acyclic Graph (DAG) with the specified parameters.static Dag
randomDag
(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random Directed Acyclic Graph (DAG).static Graph
randomGraph
(int numMeasures, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph based on the given parameters.static Graph
randomGraph
(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph based on the given parameters.static Graph
randomGraphRandomForwardEdges
(int numNodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph with the given parameters and random forward edges.static Graph
randomGraphRandomForwardEdges
(List<Node> nodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph with forward edges.static Graph
randomGraphRandomForwardEdges
(List<Node> nodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected, boolean layoutAsCircle) Generates a random graph with forward edges.static Graph
randomGraphUniform
(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected, int numIterations) Generates a random graph using UniformGraphGenerator with the specified parameters.static Graph
randomScaleFreeGraph
(int numNodes, int numLatentConfounders, double alpha, double beta, double delta_in, double delta_out) Generates a random scale-free graph.
-
Method Details
-
randomDag
public static Graph randomDag(int numNodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random Directed Acyclic Graph (DAG) with the specified parameters.- Parameters:
numNodes
- The number of nodes in the DAG.numLatentConfounders
- The number of latent confounders in the DAG.maxNumEdges
- The maximum number of edges in the DAG.maxDegree
- The maximum degree of each node in the DAG.maxIndegree
- The maximum indegree of each node in the DAG.maxOutdegree
- The maximum outdegree of each node in the DAG.connected
- Specifies whether the DAG should be connected.- Returns:
- The randomly generated DAG.
-
randomDag
public static Dag randomDag(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random Directed Acyclic Graph (DAG).- Parameters:
nodes
- the list of nodes in the graphnumLatentConfounders
- the number of latent confounders (unobserved variables) in the graphmaxNumEdges
- the maximum number of edges in the graphmaxDegree
- the maximum number of edges incident to a single node in the graphmaxIndegree
- the maximum number of incoming edges for a single node in the graphmaxOutdegree
- the maximum number of outgoing edges for a single node in the graphconnected
- whether the graph should be connected or not- Returns:
- a randomly generated DAG representing the causal relationships between the nodes
-
randomGraph
public static Graph randomGraph(int numMeasures, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph based on the given parameters.- Parameters:
numMeasures
- the number of nodes in the graphnumLatentConfounders
- the number of latent confounders in the graphnumEdges
- the number of edges in the graphmaxDegree
- the maximum degree of each node in the graphmaxIndegree
- the maximum indegree of each node in the graphmaxOutdegree
- the maximum outdegree of each node in the graphconnected
- indicates whether the graph should be connected or not- Returns:
- a randomly generated graph
-
randomGraph
public static Graph randomGraph(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph based on the given parameters.- Parameters:
nodes
- the list of nodes to create the graph withnumLatentConfounders
- the number of latent confounders in the graphmaxNumEdges
- the maximum number of edges in the graphmaxDegree
- the maximum total degree (in-degree + out-degree) of each nodemaxIndegree
- the maximum in-degree of each nodemaxOutdegree
- the maximum out-degree of each nodeconnected
- boolean flag indicating whether the generated graph should be connected or not- Returns:
- the randomly generated graph
-
randomGraphUniform
public static Graph randomGraphUniform(List<Node> nodes, int numLatentConfounders, int maxNumEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected, int numIterations) Generates a random graph using UniformGraphGenerator with the specified parameters.- Parameters:
nodes
- The list of nodes to be included in the graphnumLatentConfounders
- The maximum number of latent confounders to be added to the graphmaxNumEdges
- The maximum number of edges to be added to the graphmaxDegree
- The maximum degree of each node in the graphmaxIndegree
- The maximum indegree of each node in the graphmaxOutdegree
- The maximum outdegree of each node in the graphconnected
- A flag indicating whether the graph should be a connected directed acyclic graph (DAG)numIterations
- The number of iterations to generate the graph- Returns:
- The generated random graph
- Throws:
IllegalArgumentException
- if the given number of nodes is 0, or the maximum number of edges is out of range, or the maximum number of latent confounders is out of range
-
randomGraphRandomForwardEdges
public static Graph randomGraphRandomForwardEdges(int numNodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph with the given parameters and random forward edges.- Parameters:
numNodes
- the number of nodes in the graphnumLatentConfounders
- the number of latent confounders in the graphnumEdges
- the number of edges in the graphmaxDegree
- the maximum degree of a node in the graphmaxIndegree
- the maximum indegree of a node in the graphmaxOutdegree
- the maximum outdegree of a node in the graphconnected
- indicates whether the graph should be connected- Returns:
- a random graph object
-
randomGraphRandomForwardEdges
public static Graph randomGraphRandomForwardEdges(List<Node> nodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected) Generates a random graph with forward edges.- Parameters:
nodes
- the list of nodes in the graphnumLatentConfounders
- the number of latent confounders in the graphnumEdges
- the total number of edges in the graphmaxDegree
- the maximum number of edges connected to each nodemaxIndegree
- the maximum in-degree of each nodemaxOutdegree
- the maximum out-degree of each nodeconnected
- if true, ensures that the generated graph is connected- Returns:
- the random graph with forward edges
-
randomGraphRandomForwardEdges
public static Graph randomGraphRandomForwardEdges(List<Node> nodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected, boolean layoutAsCircle) Generates a random graph with forward edges.- Parameters:
nodes
- a list of nodes to create the graph withnumLatentConfounders
- the maximum number of latent confounders to includenumEdges
- the desired number of edges in the graphmaxDegree
- the maximum degree of a node in the graphmaxIndegree
- the maximum indegree of a node in the graphmaxOutdegree
- the maximum outdegree of a node in the graphconnected
- indicates if the graph should be connectedlayoutAsCircle
- indicates if the graph should be laid out in a circular pattern- Returns:
- a randomly generated graph with forward edges
- Throws:
IllegalArgumentException
- if the number of nodes is less than or equal to 0, the number of edges is negative or exceeds the possible maximum, or the number of latent confounders is negative or exceeds the number of nodes
-
randomScaleFreeGraph
public static Graph randomScaleFreeGraph(int numNodes, int numLatentConfounders, double alpha, double beta, double delta_in, double delta_out) Generates a random scale-free graph.- Parameters:
numNodes
- The number of nodes in the graph.numLatentConfounders
- The number of latent confounders in the graph.alpha
- The parameter alpha for generating node degrees in the graph.beta
- The parameter beta for generating node degrees in the graph.delta_in
- The parameter delta_in for generating node degrees in the graph.delta_out
- The parameter delta_out for generating node degrees in the graph.- Returns:
- A randomly generated scale-free graph.
-
fixLatents1
-
fixLatents4
-
randomCyclicGraph2
-
randomCyclicGraph3
public static Graph randomCyclicGraph3(int numNodes, int numEdges, int maxDegree, double probCycle, double probTwoCycle) Makes a cyclic graph by repeatedly adding cycles of length of 3, 4, or 5 to the graph, then finally adding two cycles.- Parameters:
numNodes
- a intnumEdges
- a intmaxDegree
- a intprobCycle
- a doubleprobTwoCycle
- a double- Returns:
- a
Graph
object
-
addTwoCycles
-