[docs]classRandomRealization(object):"""Realization of a random node."""__seed:intdef__init__(self,random_node:RandomNode)->None:""" Args: random_node (RandomNode): Random node from which to generate a realization. """# Draw a random signed integer from the node's random number generatorself.__seed=random_node._rng.integers(0,maxsize)@propertydefseed(self)->int:"""Seed of the random realization. Returns: A signed integer representing the random seed. """returnself.__seed
[docs]defgenerator(self)->Generator:"""Initialize a new generator from the realized random seed. Returns: A new numpy generator object. """returndefault_rng(self.__seed)
[docs]classRandomNode(object):"""Random Node within a random dependency graph."""__mother_node:Optional[RandomNode]# Mother node of this node__generator:Optional[Generator]# Numpy generator object__seed:Optional[int]def__init__(self,mother_node:Optional[RandomNode]=None,seed:Optional[int]=None)->None:""" Args: mother_node (RandomNode, optional): Mother node of this random node. By default, nodes are considered to be roots. seed (int, optional): Random seed used to initialize the pseudo-random number generator. """self.seed=seedself.__mother_node=mother_node@propertydef_rng(self)->Generator:"""Random number generator. If this random node is a root node, it will return this node's generator. Otherwise, the generator of the mother's node will be returned. Returns: numpy.random.Generator: The random number generator of this node. """ifself.is_random_root:returnself.__generatorreturnself.random_mother._rng@_rng.setterdef_rng(self,value:Generator)->None:self.__generator=value@propertydefis_random_root(self)->bool:"""Is this random node a root node? :meta private: """returnself.__generatorisnotNone@propertydefseed(self)->int|None:"""Random seed of this node. :obj:`None` if no seed has been set. :meta private: """returnself.__seed@seed.setterdefseed(self,value:int)->None:self.__seed=valueself.__generator=default_rng(value)@propertydefrandom_mother(self)->RandomNode|None:"""The mother node of this random number generator. :obj:`None` if this random node is considered a root node. Note that setting the mother node will convert any random node to a child node! :meta private: """returnself.__mother_node@random_mother.setterdefrandom_mother(self,value:RandomNode)->None:"""Set the mother node of this random number generator."""self.__generator=default_rng(self.seed)ifvalueisNoneelseNoneself.__mother_node=value