Explanation (indra.explanation
)¶
Check whether a rulebased model satisfies a property (indra.explanation.model_checker
)¶

class
indra.explanation.model_checker.
ModelChecker
(model, statements=None, agent_obs=None, do_sampling=False, seed=None)[source]¶ Check a PySB model against a set of INDRA statements.
Parameters:  model (pysb.Model) – A PySB model to check.
 statements (Optional[list[indra.statements.Statement]]) – A list of INDRA Statements to check the model against.
 agent_obs (Optional[list[indra.statements.Agent]]) – A list of INDRA Agents in a given state to be observed.
 do_sampling (bool) – Whether to use breadthfirst search or weighted sampling to generate paths. Default is False (breadthfirst search).
 seed (int) – Random seed for sampling (optional, default is None).

add_statements
(stmts)[source]¶ Add to the list of statements to check against the model.
Parameters: stmts (list[indra.statements.Statement]) – The list of Statements to be added for checking.

check_model
(max_paths=1, max_path_length=5)[source]¶ Check all the statements added to the ModelChecker.
Parameters:  max_paths (Optional[int]) – The maximum number of specific paths to return for each Statement to be explained. Default: 1
 max_path_length (Optional[int]) – The maximum length of specific paths to return. Default: 5
Returns: Each tuple contains the Statement checked against the model and a PathResult object describing the results of model checking.
Return type: list of (Statement, PathResult)

check_statement
(stmt, max_paths=1, max_path_length=5)[source]¶ Check a single Statement against the model.
Parameters:  stmt (indra.statements.Statement) – The Statement to check.
 max_paths (Optional[int]) – The maximum number of specific paths to return for each Statement to be explained. Default: 1
 max_path_length (Optional[int]) – The maximum length of specific paths to return. Default: 5
Returns: True if the model satisfies the Statement.
Return type: boolean

draw_im
(fname)[source]¶ Draw and save the influence map in a file.
Parameters: fname (str) – The name of the file to save the influence map in. The extension of the file will determine the file format, typically png or pdf.

generate_im
(model)[source]¶ Return a graph representing the influence map generated by Kappa
Parameters: model (pysb.Model) – The PySB model whose influence map is to be generated Returns: graph – A MultiDiGraph representing the influence map Return type: networkx.MultiDiGraph

get_im
(force_update=False)[source]¶ Get the influence map for the model, generating it if necessary.
Parameters: force_update (bool) – Whether to generate the influence map when the function is called. If False, returns the previously generated influence map if available. Defaults to True. Returns: The influence map can be rendered as a pdf using the dot layout program as follows: im_agraph = nx.nx_agraph.to_agraph(influence_map) im_agraph.draw('influence_map.pdf', prog='dot')
Return type: networkx MultiDiGraph object containing the influence map.

prune_influence_map
()[source]¶ Remove edges between rules causing problematic nontransitivity.
First, all selfloops are removed. After this initial step, edges are removed between rules when they share all child nodes except for each other; that is, they have a mutual relationship with each other and share all of the same children.
Note that edges must be removed in batch at the end to prevent edge removal from affecting the lists of rule children during the comparison process.

prune_influence_map_subj_obj
()[source]¶ Prune influence map to include only edges where the object of the upstream rule matches the subject of the downstream rule.

score_paths
(paths, agents_values, loss_of_function=False, sigma=0.15, include_final_node=False)[source]¶ Return scores associated with a given set of paths.
Parameters:  paths (list[list[tuple[str, int]]]) – A list of paths obtained from path finding. Each path is a list of tuples (which are edges in the path), with the first element of the tuple the name of a rule, and the second element its polarity in the path.
 agents_values (dict[indra.statements.Agent, float]) – A dictionary of INDRA Agents and their corresponding measured value in a given experimental condition.
 loss_of_function (Optional[boolean]) – If True, flip the polarity of the path. For instance, if the effect of an inhibitory drug is explained, set this to True. Default: False
 sigma (Optional[float]) – The estimated standard deviation for the normally distributed measurement error in the observation model used to score paths with respect to data. Default: 0.15
 include_final_node (Optional[boolean]) – Determines whether the final node of the path is included in the score. Default: False

class
indra.explanation.model_checker.
PathMetric
(source_node, target_node, polarity, length)[source]¶ Describes results of simple path search (path existence).

source_node
¶ str – The source node of the path

target_node
¶ str – The target node of the path

polarity
¶ int – The polarity of the path between source and target

length
¶ int – The length of the path


class
indra.explanation.model_checker.
PathResult
(path_found, result_code, max_paths, max_path_length)[source]¶ Describes results of running the ModelChecker on a single Statement.

path_found
¶ bool – True if a path was found, False otherwise.

result_code
¶ string –
 STATEMENT_TYPE_NOT_HANDLED  The provided statement type is not handled
 SUBJECT_MONOMERS_NOT_FOUND  Statement subject not found in model
 OBSERVABLES_NOT_FOUND  Statement has no associated observable
 NO_PATHS_FOUND  Statement has no path for any observable
 MAX_PATH_LENGTH_EXCEEDED  Statement has no path len <= MAX_PATH_LENGTH
 PATHS_FOUND  Statement has path len <= MAX_PATH_LENGTH
 INPUT_RULES_NOT_FOUND  No rules with Statement subject found
 MAX_PATHS_ZERO  Path found but MAX_PATHS is set to zero

max_paths
¶ int – The maximum number of specific paths to return for each Statement to be explained.

max_path_length
¶ int – The maximum length of specific paths to return.

path_metrics
¶ list[
indra.explanation.model_checker.PathMetric
] – A list of PathMetric objects, each describing the results of a simple path search (path existence).

paths
¶ list[list[tuple[str, int]]] – A list of paths obtained from path finding. Each path is a list of tuples (which are edges in the path), with the first element of the tuple the name of a rule, and the second element its polarity in the path.


indra.explanation.model_checker.
remove_im_params
(model, im)[source]¶ Remove parameter nodes from the influence map.
Parameters:  model (pysb.core.Model) – PySB model.
 im (networkx.MultiDiGraph) – Influence map.
Returns: Influence map with the parameter nodes removed.
Return type: networkx.MultiDiGraph

indra.explanation.model_checker.
stmt_from_rule
(rule_name, model, stmts)[source]¶ Return the source INDRA Statement corresponding to a rule in a model.
Parameters:  rule_name (str) – The name of a rule in the given PySB model.
 model (pysb.core.Model) – A PySB model which contains the given rule.
 stmts (list[indra.statements.Statement]) – A list of INDRA Statements from which the model was assembled.
Returns: stmt – The Statement from which the given rule in the model was obtained.
Return type: