Class CyclicStableUtils

java.lang.Object
edu.cmu.tetrad.sem.CyclicStableUtils

public final class CyclicStableUtils extends Object
Utilities to stabilize arbitrary directed graphs with cycles.
  • Method Details

    • simulateStableFixedRadius

      public static SemIm.CyclicSimResult simulateStableFixedRadius(Graph g, int n, double s, double coefLow, double coefHigh, long seed, Parameters params)
      Simulate from an arbitrary graph with SCC-wise fixed spectral radius s.
      Parameters:
      g - the graph to simulate from
      n - the number of samples to generate
      s - the fixed spectral radius for each SCC
      coefLow - the lower bound for coefficient values
      coefHigh - the upper bound for coefficient values
      seed - the random seed for reproducibility, or -1 for random seed
      params - the parameters for the SEM model
      Returns:
      the simulated data and SEM model
    • simulateStableProductCapped

      public static SemIm.CyclicSimResult simulateStableProductCapped(Graph g, int n, double maxProd, double coefLow, double coefHigh, long seed, Parameters params)
      Simulate from an arbitrary graph with SCC-wise radius capped by sqrt(maxProd).
      Parameters:
      g - the graph to simulate from
      n - the number of samples to generate
      maxProd - the maximum product of spectral radii for SCCs
      coefLow - the lower bound for coefficient values
      coefHigh - the upper bound for coefficient values
      seed - the random seed for reproducibility, or -1 for random seed
      params - the parameters for the SEM model
      Returns:
      the simulated data and SEM model
    • stabilizeAllSccsFixedRadiusScaleOnly

      public static void stabilizeAllSccsFixedRadiusScaleOnly(SemIm im, Graph g, double s)
      Stabilizes all strongly connected components (SCCs) of a given graph by scaling internal edges such that the spectral radius of each SCC does not exceed the given target value s. Operates on a fixed radius and adjusts only internal edge scales.
      Parameters:
      im - the SEM instance representing the structural equation model to be stabilized
      g - the graph containing the strongly connected components to stabilize
      s - the target spectral radius for each SCC; must be in the range (0, 1)
      Throws:
      IllegalArgumentException - if the value of s is not in the range (0, 1)
    • stabilizeAllSccsFixedRadius

      public static void stabilizeAllSccsFixedRadius(SemIm im, Graph g, double s, double coefLow, double coefHigh)
      Stabilize an existing SemIm in-place: enforce per-SCC spectral radius target s.
      Parameters:
      im - the SEM instance representing the structural equation model to be stabilized
      g - the graph containing the strongly connected components to stabilize
      s - the target spectral radius for each SCC; must be in the range (0, 1)
      coefLow - the lower bound for the random coefficient range
      coefHigh - the upper bound for the random coefficient range
      Throws:
      IllegalArgumentException - if the value of s is not in the range (0, 1)
    • initializeInternalEdgesRandom

      public static void initializeInternalEdgesRandom(SemIm im, Graph g, List<Node> scc, double low, double high)
      Randomize existing internal edges (that already exist in the graph) within [low, high], positive.
      Parameters:
      im - the SEM instance representing the structural equation model to be stabilized
      g - the graph containing the strongly connected components to stabilize
      scc - the strongly connected component to initialize internal edges for
      low - the lower bound for the random coefficient range
      high - the upper bound for the random coefficient range
      Throws:
      IllegalArgumentException - if the value of s is not in the range (0, 1)
    • scaleInternalEdges

      public static void scaleInternalEdges(SemIm im, Graph g, List<Node> scc, double factor)
      Scale all internal edges of an SCC by a factor.
      Parameters:
      im - the SEM instance representing the structural equation model to be stabilized
      g - the graph containing the strongly connected components to stabilize
      scc - the strongly connected component to initialize internal edges for
      factor - the scaling factor to apply to internal edges + * @throws IllegalArgumentException if the value of s is not in the range (0, 1)
    • spectralRadiusAbs

      public static double spectralRadiusAbs(SemIm im, Graph g, List<Node> scc)
      Computes the spectral radius of the absolute value of the coefficient matrix of the given strongly connected component (SCC) in a graph. The spectral radius is calculated using the power iteration method on a matrix constructed from the absolute values of the edge coefficients for directed edges within the SCC.
      Parameters:
      im - the SEM instance containing the structural equation model with coefficient information
      g - the graph representing the structural relationships between nodes
      scc - the list of nodes representing the strongly connected component
      Returns:
      the spectral radius of the absolute value of the coefficient matrix for the SCC
    • stronglyConnectedComponents

      public static List<List<Node>> stronglyConnectedComponents(Graph g)
      Kosaraju's algorithm for strongly connected components.
      Parameters:
      g - the graph to find strongly connected components in
      Returns:
      a list of lists, where each inner list represents a strongly connected component
    • quickDemo

      public static SemIm.CyclicSimResult quickDemo()
      Quick demo: build a graph, stabilize, simulate.
      Returns:
      the result.