Class RandomGraph

java.lang.Object
edu.cmu.tetrad.graph.RandomGraph

public class RandomGraph extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static 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 Type
    Method
    Description
    static 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 numNodes, 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.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 graph
      numLatentConfounders - the number of latent confounders (unobserved variables) in the graph
      maxNumEdges - the maximum number of edges in the graph
      maxDegree - the maximum number of edges incident to a single node in the graph
      maxIndegree - the maximum number of incoming edges for a single node in the graph
      maxOutdegree - the maximum number of outgoing edges for a single node in the graph
      connected - 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 numNodes, int numLatentConfounders, int numEdges, int maxDegree, int maxIndegree, int maxOutdegree, boolean connected)
      Generates a random graph based on the given parameters.
      Parameters:
      numNodes - the number of nodes in the graph
      numLatentConfounders - the number of latent confounders in the graph
      numEdges - the number of edges in the graph
      maxDegree - the maximum degree of each node in the graph
      maxIndegree - the maximum indegree of each node in the graph
      maxOutdegree - the maximum outdegree of each node in the graph
      connected - 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 with
      numLatentConfounders - the number of latent confounders in the graph
      maxNumEdges - the maximum number of edges in the graph
      maxDegree - the maximum total degree (in-degree + out-degree) of each node
      maxIndegree - the maximum in-degree of each node
      maxOutdegree - the maximum out-degree of each node
      connected - 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 graph
      numLatentConfounders - The maximum number of latent confounders to be added to the graph
      maxNumEdges - The maximum number of edges to be added to the graph
      maxDegree - The maximum degree of each node in the graph
      maxIndegree - The maximum indegree of each node in the graph
      maxOutdegree - The maximum outdegree of each node in the graph
      connected - 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 graph
      numLatentConfounders - the number of latent confounders in the graph
      numEdges - the number of edges in the graph
      maxDegree - the maximum degree of a node in the graph
      maxIndegree - the maximum indegree of a node in the graph
      maxOutdegree - the maximum outdegree of a node in the graph
      connected - 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 graph
      numLatentConfounders - the number of latent confounders in the graph
      numEdges - the total number of edges in the graph
      maxDegree - the maximum number of edges connected to each node
      maxIndegree - the maximum in-degree of each node
      maxOutdegree - the maximum out-degree of each node
      connected - 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 with
      numLatentConfounders - the maximum number of latent confounders to include
      numEdges - the desired number of edges in the graph
      maxDegree - the maximum degree of a node in the graph
      maxIndegree - the maximum indegree of a node in the graph
      maxOutdegree - the maximum outdegree of a node in the graph
      connected - indicates if the graph should be connected
      layoutAsCircle - 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

      public static void fixLatents1(int numLatentConfounders, Graph graph)

      fixLatents1.

      Parameters:
      numLatentConfounders - a int
      graph - a Graph object
    • fixLatents4

      public static void fixLatents4(int numLatentConfounders, Graph graph)

      fixLatents4.

      Parameters:
      numLatentConfounders - a int
      graph - a Graph object
    • randomCyclicGraph2

      public 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.
      Parameters:
      numNodes - a int
      numEdges - a int
      maxDegree - a int
      Returns:
      a Graph object
    • 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 int
      numEdges - a int
      maxDegree - a int
      probCycle - a double
      probTwoCycle - a double
      Returns:
      a Graph object
    • addTwoCycles

      public static void addTwoCycles(Graph graph, int numTwoCycles)

      addTwoCycles.

      Parameters:
      graph - a Graph object
      numTwoCycles - a int