2.2.1.1. pywhy_graphs.functional.discrete.make_random_discrete_graph#

pywhy_graphs.functional.discrete.make_random_discrete_graph(G: DiGraph, cardinality_lims: Dict[Any, List[int]] | None = None, weight_lims: Dict[Any, List[int]] | None = None, noise_ratio_lims: List[float] | None = None, overwrite: bool = False, random_state=None) DiGraph[source]#

Sample a random discrete graph given a graph structure.

This function samples a random discrete graph given a graph structure. The graph structure is defined by the input graph G. The graph G must be a DAG. The function samples a random cardinality for each node, and then samples a random pgmpy.TabularCPD for each node given the cardinality of the node and the cardinality of the parents of the node. The function then assigns the sampled pgmpy.TabularCPD to the node, and assigns the relevant functions to the node. The relevant functions are the parent_function, exogenous_function, and exogenous_distribution.

To sample the relevant conditional probability values within the CPT, the weights are sampled for each discrete category for each variable. The weights are sampled and used as the p input to numpy.random.choice, which normalizes the weights so that the probabilities they induce are valid.

The noise ratio is also sampled for each node, and is used to define the noise_ratio attribute of the node.

Parameters:
Gnx.DiGraph

A defined DAG.

cardinality_limsList[int], optional

The range of cardinalities for the variables, by default None, which defaults to binary.

weight_limsList[int], optional

The possible weights to sample each discrete category for each variable, by default None, which defaults to a uniform weight. The weights are sampled and used as the high input to numpy.random.integers, which normalizes the weights so that the probabilities they induce are valid and sum to 1.0. The low is always equal to 0.

noise_ratio_limsList[float], optional

The possible range for the noise ratio, by default None, which will default to all variables having noise ratio of 0.0.

overwritebool, optional

Whether to overwrite the existing attributes of the graph, by default False.

random_stateRandomGenerator, optional

The random number generator, by default None.

Returns:
Gnx.DiGraph

The altered functional DAG.