2.5.1. pywhy_graphs.functional.make_graph_linear_gaussian#
- pywhy_graphs.functional.make_graph_linear_gaussian(G: DiGraph, node_mean_lims: List[float] | None = None, node_std_lims: List[float] | None = None, edge_functions: List[Callable[[float], float]] | None = None, edge_weight_lims: List[float] | None = None, random_state=None) DiGraph [source]#
Convert an existing DAG to a linear Gaussian graphical model.
All nodes are sampled from a normal distribution with parametrizations defined uniformly at random between the limits set by the input parameters. The edges apply then a weight and a function based on the inputs in an additive fashion. For node \(X_i\), we have:
\[\begin{split}X_i = \\sum_{j \in parents} w_j f_j(X_j) + \\epsilon_i\end{split}\]where:
- \(\\epsilon_i \sim N(\mu_i, \sigma_i)\), where \(\mu_i\) is sampled
uniformly at random from
node_mean_lims
and \(\sigma_i\) is sampled uniformly at random fromnode_std_lims
.
\(w_j \sim U(\\text{edge_weight_lims})\)
- \(f_j\) is a function sampled uniformly at random
from
edge_functions
- Parameters:
- GNetworkX DiGraph
The graph to sample data from. The graph will be modified in-place to get the weights and functions of the edges.
- node_mean_limsOptional[List[float]], optional
The lower and upper bounds of the mean of the Gaussian random variable, by default None, which defaults to a mean of 0.
- node_std_limsOptional[List[float]], optional
The lower and upper bounds of the std of the Gaussian random variable, by default None, which defaults to a std of 1.
- edge_functionsList[Callable[float]], optional
The set of edge functions that take in an iid sample from the parent and computes a transformation (possibly nonlinear), such as
(lambda x: x**2, lambda x: x)
, by default None, which defaults to the identity functionlambda x: x
.- edge_weight_limsOptional[List[float]], optional
The lower and upper bounds of the edge weight, by default None, which defaults to a weight of 1.
- random_stateint, optional
Random seed, by default None.
- Returns:
- GNetworkX DiGraph
NetworkX graph with the edge weights and functions set with node attributes set with
'parent_function'
, and'gaussian_noise_function'
. Moreover the graph attribute'linear_gaussian'
is set toTrue
.