Dependency analysis¶
Using these functions from myokit.lib
you can perform simple dependency
analysis algorithms on Myokit models.
This module uses matplotlib
for visualisation.
- myokit.lib.deps.plot_state_dependency_matrix(model, direct=False, knockout=[], axes=None)¶
Creates a matrix showing state variable dependency distances.
To show only direct (first-order) dependencies, set the optional argument
direct
toTrue
.Variables can be “knocked out” by adding them to the list in the
knockout
parameter. If x depends on y and y depends on z, knocking out y will prevent the method from findind x’s dependency on z.Returns a matplotlib axes object.
- myokit.lib.deps.create_state_dependency_matrix(model, direct=False, knockout=None)¶
Creates a matrix showing state variable dependency distances.
A distance of
1
from statex
to statey
means thatdot(x)
depends ony
. A distance of2
means thatdot(x)
does not depend ony
, but does depend on another state whose derivative depends directly ony
.State variables can be “knocked out” by adding them to the
knockout
list. The rows and columns for knocked out variables will be set to zero, and knocked out variables won’t be taken into account when calculating indirect dependencies (distance>1).Arguments:
model
The model to create a matrix for.
direct
True if only direct dependencies (distance=1) should be shown. In this case, the returned matrix will show the shape of the jacobian.
knockout
A list of state variables or state variable names to “knock-out”.
- myokit.lib.deps.plot_component_dependency_graph(model, axes=None, omit_states=True, omit_constants=False)¶
Draws a graph showing the dependencies between a model’s components.
Returns a matplotlib axes object.
- myokit.lib.deps.create_component_dependency_graph(model, omit_states=True, omit_constants=False)¶
Creates and returns a component dependency graph.
- myokit.lib.deps.plot_variable_dependency_graph(model, axes=None)¶
Draws a graph showing the dependencies between a model’s variables.
Returns a matplotlib axes object.
- myokit.lib.deps.create_variable_dependency_graph(model)¶
Creates a dependency graph from the given model
(Doesn’t include constants)
Internally, these functions make use of a tiny DiGraph class.
- class myokit.lib.deps.DiGraph(matrix=None)¶
A simple directed graph implementation.
If desired, a digraph can be created from an n-by-n connectivity matrix, for example
matrix=[[0, 1, 1], [0, 1, 0], [0, 0, 0]]
- add_edge(node1, node2)¶
Adds an edge from node1 to node2
- add_node(node)¶
Adds a node. You can pass an existing
Node
object or an object to use as a new node’s id.
- build_from_matrix(matrix, edges_only=False)¶
Replaces this graph’s structure with the graph defined by the given n by n connectivity matrix.
If
edges_only
is set to True, the matrix must have the same size as the current number of nodes. In this, all existing edges will be removed and replaced by the ones given in the connectivity matrix.
- cg_layers_dag()¶
Returns a layering according to the Coffman-Graham ordering scheme.
Returns a list of lists, where each inner list represents a consecutive layer.
Will raise an exception if this digraph has cycles.
- layout_layered()¶
Changes the x,y coordinates of this graph’s node resulting in a layered layout.
- matrix()¶
Returns a connectivity matrix for this graph.
- meg_dag()¶
Finds a Minimal Equivalent Graph (MEG) of a Directed Acyclic Graph (DAG) using the algorithm by Harry Hsu [1].
Will raise an exception if this digraph has self-referencing nodes.
- [1] An algorithm for finding a minimal equivalent graph of a digraph.
Harry T. Hsu (1975) Journal of the Assoclatlon for Computing Machinery, Vol 22, No. 1, January 1975, pp 11-16
- node(uid)¶
Returns the node with this id
- path_matrix()¶
Returns a path matrix for this graph, showing which nodes are reachable from which.
- remove_node(node)¶
Removes a node from this graph.
- text(matrix=False)¶
Returns an ascii view of this graph
- uid_or_node(test)¶
Safely turns ‘test’ into a node. Throws exceptions if it can’t.
- class myokit.lib.deps.Node(uid)¶
Defines a node in a graph
- add_edge_to(node)¶
Ensures an edge from this node to another
- clear_edges()¶
Removes any edges leading from this node.
- has_edge_to(test)¶
Returns true if this node points at test
- myokit.lib.deps.plot_digraph(graph, axes=None, r_node=None)¶
Returns a DiGraph object to a set of matplotlib axes.
Returns a matplotlib axes object.