cana.canalization.cm_lut module
Reconstruct a look-up table (LUT) from a Canalizing Map (CM) graph.
This module interprets a CM as a networkx.DiGraph of typed nodes.
Evaluation is modular and topology-based: each node activates from its
predecessors according to its node kind. Edge type attributes (if
present) are ignored for scoring — they may still be used for drawing or
legacy CANA compatibility.
Notes
A CM encodes schemata as McCulloch–Pitts-style threshold units, optionally nested to express two-symbol / permutation structure.
Node kinds
variable+mode=input: active iff the assignment matchesvalue.variable+mode=output: normally active iff any predecessor is active (used when asking whether the node itself is on). Autoregulation exception: CANA’scanalizing_mapreuses the samevar-{id}-out-{v}node as both the current-state literal and the next-state output, which creates a directed cycle. When that variable’s key appears in the assignment, evaluation treats the node as an input literal (assignment match) so thresholds can fire; output claims are still decided byclaimed_outputs()via threshold predecessors.threshold: active iff(# active predecessors) >= tau. Optional annotationrole(seeTHRESHOLD_ROLES) describes the canalization layer; it does not change evaluation.fusion: active iff any predecessor is active (logical OR). Equivalent to a threshold withtau=1; kept for legacy / drawing.
Firing / claim rule
score(thr) = # active predecessors
fire <=> score >= tau
claim(out) <=> any predecessor of the output variable is active
Per input assignment, collect claimed output polarities:
{0}or{1}→ that LUT entry.{0, 1}→ conflict at that row.{}→ uncovered (incomplete).
Inputs that never appear in the CM are free variables over the full 2^k
table. Input order is taken from input_order if given, otherwise from
sorted input ids discovered in the graph.
- cana.canalization.cm_lut.ROLE_SCHEMA = 'schema'
Two-symbol schema unit (typically a root that feeds an output).
- cana.canalization.cm_lut.ROLE_SYMMETRY = 'symmetry'
Permutation-symmetry aggregate over one or more polarity groups.
- cana.canalization.cm_lut.ROLE_POLARITY0 = 'polarity0'
0-polarity fibre within a permutation symmetry.
- cana.canalization.cm_lut.ROLE_POLARITY1 = 'polarity1'
1-polarity fibre within a permutation symmetry.
- cana.canalization.cm_lut.THRESHOLD_ROLES = frozenset({'polarity0', 'polarity1', 'schema', 'symmetry'})
Allowed values for
make_threshold()’sroleargument.
- class cana.canalization.cm_lut.CMLutResult(outputs, input_names, has_conflict, is_incomplete, conflict_states=<factory>, uncovered_states=<factory>)[source]
Bases:
objectResult of reconstructing a LUT from a canalizing map.
- Parameters:
outputs (List[int | None])
input_names (List[str | int])
has_conflict (bool)
is_incomplete (bool)
conflict_states (List[str])
uncovered_states (List[str])
- outputs
LUT entries indexed by the integer whose binary representation is the input state (MSB = first input).
Nonemeans uncovered or conflicted.- Type:
list of {0, 1, None}
- input_names
Ordered input identifiers used for the LUT (MSB first).
- Type:
list of int or str
- has_conflict
Trueif at least one input state is claimed by both output polarities.- Type:
bool
- is_incomplete
Trueif at least one input state is claimed by no t-unit.- Type:
bool
- conflict_states
Binary state strings (MSB first) that are conflicted.
- Type:
list of str
- uncovered_states
Binary state strings (MSB first) that are uncovered.
- Type:
list of str
- outputs: List[int | None]
- input_names: List[str | int]
- has_conflict: bool
- is_incomplete: bool
- conflict_states: List[str]
- uncovered_states: List[str]
- lut_string(uncovered='?', conflict='X')[source]
Return a compact string view of the LUT.
- Parameters:
uncovered (str, optional) – Character used for uncovered rows. Default is
'?'.conflict (str, optional) – Character used for conflicted rows. Default is
'X'.
- Returns:
One character per LUT row, length
2**k.- Return type:
str
- cana.canalization.cm_lut.iter_nodes_of_type(cm, node_type)[source]
Yield CM nodes whose
typeattribute equalsnode_type.- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
node_type (str) – Node type to select (
'variable','threshold', or'fusion').
- Yields:
node_id (hashable) – Graph node identifier.
data (dict) – Node attribute dictionary.
- Return type:
Iterable[Tuple[Any, dict]]
- cana.canalization.cm_lut.discover_input_keys(cm)[source]
Discover input identifiers present in the CM.
Prefers numeric ids parsed from node names
var-{id}-out-{val}, otherwise uses the nodelabel(or the node id). Returned sorted for a stable LUT order.Includes
mode=inputvariables andmode=outputvariables that feed a threshold/fusion (CANA autoregulation reuses output node ids as self-literals).- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
- Returns:
Sorted input keys (integers first, then string labels).
- Return type:
list of int or str
- cana.canalization.cm_lut.node_active(cm, node_id, assignment, memo=None)[source]
Return whether a CM node is active under an assignment.
Activation is defined by node kind and predecessors only (edge types are ignored):
input variable: assignment matches
valueoutput variable: if the variable key is in
assignment(self-loop / shared CANA id used as a literal), assignment matchesvalue; otherwise any predecessor is activefusion: any predecessor is active
threshold: number of active predecessors
>= tau
- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
node_id (hashable) – Node to evaluate.
assignment (dict) – Mapping from input key to
0or1.memo (dict, optional) – Per-assignment cache. Values are
True/Falsewhen resolved, orNonewhile a node is on the recursion stack (cycle guard for non-variable combinational cycles).
- Returns:
Trueif the node is active.- Return type:
bool
- Raises:
ValueError – If evaluating
node_idencounters a directed cycle among threshold/fusion nodes, or ifnode_idhas an unknowntype.
- cana.canalization.cm_lut.fusion_active(cm, fusion_id, assignment)[source]
Return whether a fusion node is active under an assignment.
A fusion is active iff any of its predecessors is active (logical OR).
- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
fusion_id (hashable) – Fusion node id.
assignment (dict) – Mapping from input key to
0or1.
- Returns:
Trueif at least one predecessor is active.- Return type:
bool
- Raises:
ValueError – If
fusion_idis not a fusion node.
- cana.canalization.cm_lut.tunit_score(cm, thr_id, assignment)[source]
Compute the score of a threshold unit under an assignment.
The score is the number of active predecessors (inputs, fusions, or nested thresholds).
- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
thr_id (hashable) – Threshold (t-unit) node id.
assignment (dict) – Mapping from input key to
0or1.
- Returns:
Non-negative contribution count.
- Return type:
int
- Raises:
ValueError – If
thr_idis not a threshold node.
- cana.canalization.cm_lut.tunit_fires(cm, thr_id, assignment)[source]
Return whether a threshold unit fires under an assignment.
Fires when
tunit_score(cm, thr_id, assignment) >= tau.- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
thr_id (hashable) – Threshold (t-unit) node id.
assignment (dict) – Mapping from input key to
0or1.
- Returns:
Trueif the t-unit fires.- Return type:
bool
- Raises:
ValueError – If
thr_idis not a threshold node.
- cana.canalization.cm_lut.claimed_outputs(cm, assignment)[source]
Return output polarities claimed under an assignment.
An output variable claims its polarity when any of its predecessors is active (typically a firing schema-level threshold).
- Parameters:
cm (networkx.DiGraph) – Canalizing map graph.
assignment (dict) – Mapping from input key to
0or1.
- Returns:
Subset of
{0, 1}. Empty if nothing claims; both values if there is a conflict.- Return type:
set of int
- cana.canalization.cm_lut.lut_from_canalizing_map(cm, input_order=None)[source]
Build a (possibly partial or conflicting) LUT from a canalizing map.
- Parameters:
cm (networkx.DiGraph) – Canalizing map as a directed graph of typed nodes. Evaluation uses topology and node kinds only (see module docstring).
input_order (sequence of int or str, optional) – Explicit input order (MSB first). If omitted, inputs are discovered from the graph and sorted via
discover_input_keys().
- Returns:
Reconstructed LUT together with conflict / incompleteness flags and the lists of affected binary states.
- Return type:
Notes
This function is purely graph-based. It does not call
BooleanNode.canalizing_mapor two-symbol canalization code.
- cana.canalization.cm_lut.input_ids_in_order(G)[source]
Return input variable ids in first-seen label order.
Suitable as
input_orderforlut_from_canalizing_map().- Parameters:
G (DiGraph)
- Return type:
List[int]
- cana.canalization.cm_lut.connect(G, src, dst)[source]
Add an edge, inferring
typefrom endpoint node kinds.Does not mutate threshold attributes (no
outstamping).- Parameters:
G (networkx.DiGraph) – CM graph.
src (hashable) – Existing node ids.
dst (hashable) – Existing node ids.
- Raises:
ValueError – If the
(src_kind, dst_kind)pair is not allowed.- Return type:
None
- cana.canalization.cm_lut.make_input_node(G, label, value)[source]
Add an input variable node;
labeldetermines the sharedvar_id.- Parameters:
G (networkx.DiGraph) – Graph to mutate.
label (str) – Input name. New labels get a fresh id; existing labels reuse theirs.
value (int) – Polarity (
0or1).
- Returns:
Node name
var-{id}-out-{value}.- Return type:
str
- Raises:
ValueError – If this
(label, value)pair already exists, orvalueis not 0/1.
- cana.canalization.cm_lut.make_output_node(G, label, value)[source]
Add an output variable node for the CM’s single function label.
- Parameters:
G (networkx.DiGraph) – Graph to mutate.
label (str) – Function / output name. Both polarities share one allocated id.
value (int) – Output polarity (
0or1).
- Returns:
Node name
var-{output_id}-out-{value}.- Return type:
str
- Raises:
ValueError – If a different output label is already registered, if this polarity already exists, or if
valueis not 0/1.
- cana.canalization.cm_lut.make_threshold(G, tau, role='schema')[source]
Add a threshold (t-unit) node;
tidis assigned automatically.Thresholds do not store an
outpolarity — claims come only from edges into output variables, so build order does not matter.- Parameters:
G (networkx.DiGraph) – Graph to mutate.
tau (int) – Firing threshold.
role (str, optional) – Canalization-layer annotation (does not affect evaluation). One of
THRESHOLD_ROLES. Default is'schema'.
- Returns:
Node name
thr-{tid}.- Return type:
str
- Raises:
ValueError – If
roleis not inTHRESHOLD_ROLES.
- cana.canalization.cm_lut.make_fusion(G)[source]
Add a fusion junction node; index is assigned automatically.
Fusion is legacy OR sugar (equivalent to a
tau=1threshold over inputs). Prefer nested thresholds for new maps.- Parameters:
G (networkx.DiGraph) – Graph to mutate.
- Returns:
Node name
fus-{index}.- Return type:
str