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 graphGmust be a DAG. The function samples a random cardinality for each node, and then samples a randompgmpy.TabularCPDfor each node given the cardinality of the node and the cardinality of the parents of the node. The function then assigns the sampledpgmpy.TabularCPDto the node, and assigns the relevant functions to the node. The relevant functions are theparent_function,exogenous_function, andexogenous_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
pinput tonumpy.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_ratioattribute 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
highinput tonumpy.random.integers, which normalizes the weights so that the probabilities they induce are valid and sum to 1.0. Thelowis 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.