Package edu.cmu.tetrad.sem
Class CyclicStableUtils
java.lang.Object
edu.cmu.tetrad.sem.CyclicStableUtils
Utilities to stabilize arbitrary directed graphs with cycles.
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidinitializeInternalEdgesRandom(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.static SemIm.CyclicSimResultQuick demo: build a graph, stabilize, simulate.static voidscaleInternalEdges(SemIm im, Graph g, List<Node> scc, double factor) Scale all internal edges of an SCC by a factor.static SemIm.CyclicSimResultsimulateStableFixedRadius(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.static SemIm.CyclicSimResultsimulateStableProductCapped(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).static doublespectralRadiusAbs(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.static voidstabilizeAllSccsFixedRadius(SemIm im, Graph g, double s, double coefLow, double coefHigh) Stabilize an existing SemIm in-place: enforce per-SCC spectral radius target s.static voidstabilizeAllSccsFixedRadiusScaleOnly(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.Kosaraju's algorithm for strongly connected components.
-
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 fromn- the number of samples to generates- the fixed spectral radius for each SCCcoefLow- the lower bound for coefficient valuescoefHigh- the upper bound for coefficient valuesseed- the random seed for reproducibility, or -1 for random seedparams- 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 fromn- the number of samples to generatemaxProd- the maximum product of spectral radii for SCCscoefLow- the lower bound for coefficient valuescoefHigh- the upper bound for coefficient valuesseed- the random seed for reproducibility, or -1 for random seedparams- the parameters for the SEM model- Returns:
- the simulated data and SEM model
-
stabilizeAllSccsFixedRadiusScaleOnly
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 stabilizedg- the graph containing the strongly connected components to stabilizes- 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 stabilizedg- the graph containing the strongly connected components to stabilizes- the target spectral radius for each SCC; must be in the range (0, 1)coefLow- the lower bound for the random coefficient rangecoefHigh- 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 stabilizedg- the graph containing the strongly connected components to stabilizescc- the strongly connected component to initialize internal edges forlow- the lower bound for the random coefficient rangehigh- the upper bound for the random coefficient range- Throws:
IllegalArgumentException- if the value of s is not in the range (0, 1)
-
scaleInternalEdges
Scale all internal edges of an SCC by a factor.- Parameters:
im- the SEM instance representing the structural equation model to be stabilizedg- the graph containing the strongly connected components to stabilizescc- the strongly connected component to initialize internal edges forfactor- the scaling factor to apply to internal edges + * @throws IllegalArgumentException if the value of s is not in the range (0, 1)
-
spectralRadiusAbs
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 informationg- the graph representing the structural relationships between nodesscc- 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
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
Quick demo: build a graph, stabilize, simulate.- Returns:
- the result.
-