PBN module documentation¶
Module containing the PBN class and helpers.
- class bang.core.pbn.pbn.PBN(n_nodes: int, n_functions: list[int], n_variables: list[int], functions: list[list[bool]], parent_variable_indices: list[list[int]], function_probabilities: list[list[float]], perturbation_rate: float, non_perturbed_nodes: list[int], n_parallel: int = 512, update_type: Literal['asynchronous_random_order', 'asynchronous_one_random', 'synchronous'] = 'asynchronous_one_random', save_history: bool = True, steps_batch_size=100000)¶
Class representing the PBN and the execution of simulations on it.
- Parameters:
n_nodes (int) – The number of nodes.
n_functions (list[int]) – The size of each node.
n_variables (list[int]) – The size of each node’s truth table.
functions (list[list[bool]]) – The truth table of each node.
parent_variable_indices (list[list[int]]) – The index of each node’s truth table.
function_probabilities (list[list[float]]) – The selection probability of each function.
perturbation_rate (float) – The probability of perturbation at each step.
non_perturbed_nodes (list[int]) – Index of nodes without perturbation.
n_parallel (int, optional) – The number of parallel simulations. Defaults to 512.
history (np.ndarray) – The execution history of the PBN, tracking the states of all trajectories.
latest_state (np.ndarray) – The last encountered state of the PBN’s trajectories.
previous_simulations (list[np.ndarray]) – list of previous simulations.
update_type (str) – The type of update to use. The possible values are “asynchronous_one_random”, “asynchronous_random_order”, “synchronous”
save_history (bool) – Whether to save the history of the PBN.
steps_batch_size (int) – The size of the batch of the maximum number of steps executed in a single kernel invocation.
- block_graph(filename: str | None = None, format: Literal['pdf', 'png', 'svg'] = 'svg', number_from_one: bool = False) Digraph ¶
Plot the blocks of a Probabilistic Boolean Network (PBN).
This function creates a directed graph where each node represents a block in the PBN, and each edge represents a transition between blocks.
- Parameters:
filename (str, optional) – The filename to save the graph. If None, the graph is not saved.
format (Literal['pdf', 'png', 'svg']) – The format to save the graph in. Default is ‘svg’.
number_from_one (bool) – If True, the nodes are numbered starting from 1. If False, they are numbered starting from 0. Default is False.
- Returns:
A graphviz.Digraph object representing the block graph.
- Return type:
graphviz.Digraph
- blocks_detect_attractors(repr: Literal['int']) list[list[int]] ¶
- blocks_detect_attractors(repr: Literal['bool']) list[list[list[bool]]]
Detects attractors in the system using a divide-and-conquer block-based approach.
Returns¶
- attractor_stateslist[list[list[bool]]] or list[list[int]]
list of attractors where attractors are coded as lists of lists of bools, lists of bools representing the states.
- blocks_detect_attractors_parallel() list[numpy.ndarray[Any, numpy.dtype[numpy.uint32]]] ¶
Detects attractors in the system using a divide-and-conquer block-based approach parallelized on the cpu as well as gpu.
Returns¶
- attractor_statesnumpy.NDArray[np.uint32]
list of attractors where attractors are coded as 2D lists od 32 bit unsigned integers.
- clone_with(n: int | None = None, nf: list[int] | None = None, nv: list[int] | None = None, F: list[list[bool]] | None = None, varFInt: list[list[int]] | None = None, cij: list[list[float]] | None = None, perturbation: float | None = None, npNode: list[int] | None = None, n_parallel: int | None = None, update_type: Literal['asynchronous_random_order', 'asynchronous_one_random', 'synchronous'] | None = None, save_history: bool | None = None, steps_batch_size: int | None = None) PBN ¶
Creates a clone of the PBN with the specified parameters. If a parameter is not provided, the corresponding attribute of the original PBN is used.
- Parameters:
n (int, optional) – The number of nodes.
nf (list[int], optional) – The size of each node.
nv (list[int], optional) – The size of each node’s truth table.
F (list[list[bool]], optional) – The truth table of each node.
varFInt (list[list[int]], optional) – The index of each node’s truth table.
cij (list[list[float]], optional) – The selection probability of each node.
perturbation (float, optional) – The perturbation rate.
npNode (list[int], optional) – Index of nodes without perturbation.
n_parallel (int, optional) – The number of parallel simulations.
update_type (str, optional) – The type of update to use. The possible values are “asynchronous_one_random”, “asynchronous_random_order”, “synchronous”
save_history (bool, optional) – Whether to save the history of the PBN.
steps_batch_size (int, optional) – The size of the batch of the maximum number of steps executed in a single kernel invocation.
- Returns:
A new PBN object with the specified parameters.
- Return type:
- dependency_graph(filename: str | None = None, format: Literal['pdf', 'png', 'svg'] = 'svg', number_from_one: bool = False) Digraph ¶
Plot the dependency graph of a Probabilistic Boolean Network (PBN).
This function creates a directed graph where each node represents a variable in the PBN, and each edge represents a dependency between variables. An edge from node $i$ to node $j$ indicates that the value of $i$ influences the value of $j$.
- Parameters:
filename (str, optional) – The filename to save the graph as a PNG image. If None, the graph is not saved.
format (Literal['pdf', 'png', 'svg']) – The format to save the graph in. Default is ‘svg’.
number_from_one (bool) – If True, the nodes are numbered starting from 1. If False, they are numbered starting from 0. Default is False.
- Returns:
A graphviz.Digraph object representing the dependency graph.
- Return type:
graphviz.Digraph
- get_blocks(repr: Literal['int']) list[list[int]] ¶
- get_blocks(repr: Literal['bool']) list[list[list[bool]]]
- get_blocks() list[list[list[bool]]]
Returns the blocks of the PBN.
- Parameters:
repr (str, optional) – The representation type. Can be “bool” or “int”. Defaults to “bool”.
- Returns:
The blocks of the PBN.
- Return type:
list[list[bool]] or list[list[int]]
- monolithic_detect_attractors(initial_states, repr: Literal['bool']) list[list[list[bool]]] ¶
- monolithic_detect_attractors(initial_states, repr: Literal['int']) list[list[int]]
- monolithic_detect_attractors(initial_states) list[list[list[bool]]]
Detects all atractor states in PBN
Parameters¶
- initial_stateslist[list[Bool]]
list of investigated states.
Returns¶
- attractor_stateslist[list[int]]
list of attractors where attractors are coded as lists of ints, ints representing the states.
- monte_carlo_detect_attractors(trajectory_length: int, attractor_length: int, repr='bool')¶
Detects attractors in the system by running multiple trajectories and checking for repetitions.
Parameters¶
- trajectory_lengthint
Length after which we assume each trajectory is in attractor.
- initial_trajectory_lengthint, optional
Length of trajectory from which we read attractors.
Returns¶
- attractor_stateslist[list[list[bool]]] or list[list[int]]
list of attractors where attractors are coded as lists of lists of bools, lists of bools representing the states.
- reduce_truthtables(states: list[list[int]]) tuple ¶
Reduces truth tables of PBN by removing states that do not change.
- Parameters:
states (list[list[int]]) – list of investigated states. States are lists of int with length n where i-th index represents i-th variable. 0 represents False and 1 represents True.
- Returns:
Tuple containing list of indices of variables that change between states and truth tables with removed constant variables.
- Return type:
tuple
- save_last_state(filename: str)¶
Saves the last encountered state of the PBN’s trajectories to a CSV file.
- Parameters:
filename (str) – The name of the file to save the last state.
- save_trajectories(filename: str)¶
Saves the execution history of the PBN to a CSV file.
- Parameters:
filename (str) – The name of the file to save the history.
- set_states(states: list[list[bool]] | ndarray[Any, dtype[uint32]], reset_history: bool = False, stream=None)¶
Sets the initial states of the PBN. If the number of trajectories is different than the number of previous trajectories, the history will be pushed into self.previous_simulations and the active history will be reset.
- Parameters:
states (list[list[bool]]) – list of states to be set.
reset_history (bool, optional) – If True, the history of the PBN will be reset. Defaults to False.
- simple_steps(n_steps: int, actions: ndarray[Any, dtype[uint64]] | None = None, device: Literal['cuda', 'cpu'] = 'cuda')¶
Simulates the PBN for a given number of steps.
- Parameters:
n_steps (int) – Number of steps to simulate.
actions (npt.NDArray[np.uint], optional) – Array of actions to be performed on the PBN. Defaults to None.
- Raises:
ValueError – If the initial state is not set before simulation.
- trajectory_graph(index: int, filename: str | None = None, format: Literal['pdf', 'png', 'svg'] = 'svg', show_labels: bool = True) Digraph ¶
Plot the trajectory of a Probabilistic Boolean Network (PBN).
This function creates a directed graph where each node represents a state in the trajectory, and each edge represents a transition between states.
- Parameters:
index (int) – The index of the trajectory to plot.
filename (str, optional) – The filename to save the graph. If None, the graph is not saved.
format (Literal['pdf', 'png', 'svg']) – The format to save the graph in. Default is ‘svg’.
show_labels (bool) – Whether to show labels on the nodes. Default is True. If set to False, the nodes are represented as points.
number_from_one (bool) – If True, the nodes are numbered starting from 1. If False, they are numbered starting from 0. Default is False.
- Returns:
A graphviz.Digraph object representing the trajectory graph.
- Return type:
graphviz.Digraph
- property cum_extra_functions: list[int]¶
Returns a list of cumulative extra functions.
- Returns:
list of cumulative extra functions.
- Return type:
list[int]
- property cum_n_functions: ndarray¶
Returns the cumulative sum of all elements in nf.
- Returns:
Cumulative sum of all elements in nf.
- Return type:
np.ndarray
- property cum_n_variables: ndarray¶
Returns the cumulative sum of all elements in nv.
- Returns:
Cumulative sum of all elements in nv.
- Return type:
np.ndarray
- property extra_function_index: list[int]¶
Returns a list of extra function indices.
- Returns:
list of extra function indices.
- Return type:
list[int]
- property extra_functions: list[int]¶
Returns a list of extra functions.
- Returns:
list of extra functions.
- Return type:
list[int]
- property function_probabilities: list[list[float]]¶
Returns the selection probability of each function per node.
- Returns:
The selection probability of each function per node.
- Return type:
list[list[float]]
- property functions: list[list[bool]]¶
Returns the truth table of each node.
- Returns:
The truth table of each node.
- Return type:
list[list[bool]]
- property history: ndarray¶
Returns the execution history of the PBN, tracking the states of all trajectories.
- Returns:
The execution history of the PBN.
- Return type:
np.ndarray
- property history_bool: list[list[list[bool]]]¶
Returns the execution history of the PBN in boolean representation.
- Returns:
The execution history of the PBN in boolean representation.
- Return type:
list[list[list[bool]]]
- property integer_functions: list[int]¶
Returns the integer representation of the truth table for each node.
- Returns:
Integer representation of the truth table for each node.
- Return type:
list[int]
- property last_state: ndarray¶
Returns the last encountered state of the PBN’s trajectories.
- Returns:
The last encountered state of the PBN’s trajectories.
- Return type:
np.ndarray
- property last_state_bool: list[list[bool]]¶
Returns the last encountered state of the PBN’s trajectories in boolean representation.
- Returns:
The last encountered state of the PBN’s trajectories in boolean representation.
- Return type:
list[list[bool]]
- property n_extra_function_index: int¶
Returns the number of extra function indices.
- Returns:
The number of extra function indices.
- Return type:
int
- property n_extra_functions: int¶
Returns the number of extra functions.
- Returns:
The number of extra functions.
- Return type:
int
- property n_functions: list[int]¶
Returns the size of each node.
- Returns:
The size of each node.
- Return type:
list[int]
- property n_nodes: int¶
Returns the number of nodes.
- Returns:
The number of nodes.
- Return type:
int
- property n_variables: list[int]¶
Returns the size of each node’s truth table.
- Returns:
The size of each node’s truth table.
- Return type:
list[int]
- property non_perturbed_nodes: list[int]¶
Returns the indices of nodes without perturbation.
- Returns:
The indices of nodes without perturbation.
- Return type:
list[int]
- property parent_variable_indices: list[list[int]]¶
Returns the indices of the parent nodes for every boolean function.
- Returns:
The indices of the parent nodes by function.
- Return type:
list[list[int]]
- property perturbation_rate: float¶
Returns the perturbation rate.
- Returns:
The perturbation rate.
- Return type:
float
- property previous_simulations: list[numpy.ndarray]¶
Returns the list of previous simulation histories. A new simulation history is added every time the number of trajectories changes.
- Returns:
The list of previous simulations.
- Return type:
list[np.ndarray]
- property state_size: int¶
Returns the number of 32-bit integers needed to store all variables.
- Returns:
Number of 32-bit integers needed to store all variables.
- Return type:
int
- bang.core.pbn.pbn.load_from_file(path: str, format: str = 'sbml', n_parallel=512) PBN ¶
Loads a PBN from files of format .pbn or .sbml.
- Parameters:
path (str) – Path to the file of format .pbn.
format (str, optional) – Choose the format. Can be either ‘sbml’ for files with .sbml format or ‘assa’ for files with .pbn format. Defaults to ‘sbml’.
- Returns:
PBN object representing the network from the file.
- Return type:
- Raises:
ValueError – If the format is invalid.