cana.canalization.canalizing_map module
Build Canalizing Map (CM) graphs from two-symbol schemata.
A canalizing map is a directed networkx.DiGraph that encodes how input
literals (and permutation-symmetric groups of them) force a Boolean node’s
output. Schemata come from two-symbol canalization; each schema becomes a
threshold unit that claims one output polarity when enough of its inputs fire.
Graph vocabulary
variablenodesvar-{id}-out-{0|1}— an input or output at a fixed polarity.thresholdnodes — fire when at leasttaupredecessors are active. Optionalroleannotates the canalization layer (schema,symmetry,polarity0,polarity1); evaluation ignores it.fusionnodes — OR of predecessors (legacy builder only, when a symmetry fibre needs only one matching literal).
Builders
legacy(build_canalizing_map_legacy()) — fibres attach directly to the schema threshold; count-1 fibres use fusion nodes.canonical(build_canalizing_map_canonical()) — nested schema → symmetry → polarity thresholds and no fusion nodes.
Callers may select a builder by name via CM_BUILDERS or pass a
callable with the same signature as build_canalizing_map_legacy().
Simplification
simplify_canalizing_map() (re-exported
here) applies deterministic farthest-from-out threshold-unit reduction
(LINEAR / AND / OR / OTHER under a compatibility gate). See
cana.canalization.cm_simplify.
- cana.canalization.canalizing_map.CM_BUILDERS: Dict[str, Callable[[...], DiGraph]] = {'canonical': <function build_canalizing_map_canonical>, 'legacy': <function build_canalizing_map_legacy>}
Named CM builders (
legacy,canonical).
- cana.canalization.canalizing_map.build_canalizing_map(two_symbols, *, node_id, inputs, name, constant=False, polarity=None, input_labels=None, k=None, builder='legacy', output=None)[source]
Build a canalizing map using a named or callable builder.
- Parameters:
builder (str or callable, optional) – Registry key in
CM_BUILDERS(default'legacy') or a callable with the same signature asbuild_canalizing_map_legacy().two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])
node_id (int)
inputs (Sequence[int])
name (str)
constant (bool)
polarity (int | None)
input_labels (Mapping[int, str] | None)
k (int | None)
output (int | None)
- Return type:
DiGraph
:param Same as
build_canalizing_map_legacy().:- Returns:
Canalizing map graph.
- Return type:
networkx.DiGraph
- Raises:
KeyError – If
builderis a string not present inCM_BUILDERS.TypeError – If
builderis neither a string nor a callable.
- Parameters:
two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])
node_id (int)
inputs (Sequence[int])
name (str)
constant (bool)
polarity (int | None)
input_labels (Mapping[int, str] | None)
k (int | None)
builder (str | Callable[[...], DiGraph])
output (int | None)
- cana.canalization.canalizing_map.build_canalizing_map_canonical(two_symbols, *, node_id, inputs, name, constant=False, output=None, input_labels=None, k=None)[source]
Build a CM graph with nested schema / symmetry / polarity thresholds.
Same parameters as
build_canalizing_map_legacy(). Unlike the legacy builder, this never creates fusion nodes: every permutation group becomes aROLE_SYMMETRYthreshold, and every nonempty polarity fibre becomes aROLE_POLARITY0/ROLE_POLARITY1threshold nested under that symmetry unit.Schema
tauis#fixed_literals + #active_permutation_groups. Symmetrytauis the number of polarity fibres in that group. Polaritytauis the fibre count in the representative schema.- Parameters:
two_symbols (Tuple[Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]], Sequence[Tuple[str, Sequence[Sequence[int]], Sequence]]])
node_id (int)
inputs (Sequence[int])
name (str)
constant (bool)
output (int | None)
input_labels (Mapping[int, str] | None)
k (int | None)
- Return type:
DiGraph
- cana.canalization.canalizing_map.build_canalizing_map_legacy(two_symbols, *, node_id, inputs, name, constant=False, output=None, input_labels=None, k=None)[source]
Build a CM graph from two-symbol schemata (legacy CANA wiring).
- Parameters:
two_symbols (tuple) –
(schemata_for_0, schemata_for_1)as produced by two-symbol canalization. Each schema entry is(schema_str, permutation_groups, same_symbol_groups).node_id (int) – Variable id for output nodes
var-{node_id}-out-{0|1}.inputs (sequence of int) – Input variable ids in LUT order (length
k).name (str) – Output variable label.
constant (bool, optional) – Stored on output variable nodes.
output (int or None, optional) – If
0or1, only that polarity is built;Nonebuilds both.input_labels (mapping, optional) – Map from input variable id to display label. Defaults to
str(id).k (int, optional) – Number of inputs. Defaults to
len(inputs).
- Returns:
Canalizing map graph.
- Return type:
networkx.DiGraph
- cana.canalization.canalizing_map.simplify_canalizing_map(cm, *, copy=True, remove_isolates=True, skip_if_edges_increase=False)[source]
Simplify a CM / DCM by threshold-unit reduction (fixed point).
Safe rewrite rules applied until no candidate remains:
Never remove or rewrite
tau=0thresholds (constant schemata).Threshold-unit reduction: if a threshold/fusion unit is LINEAR / AND / OR / OTHER and every successor class is compatible, wire all predecessors to all successors, bump each threshold/fusion successor by
tau(T)-1, and deleteT. Variables are never bumped. Compatibility:LINEAR → AND, OR, LINEAR, OTHER
AND → AND, LINEAR
OR → OR, LINEAR
OTHER → LINEAR
Non-schema OR/LINEAR units that claim variables are eligible.
Candidates are ordered farthest-from-out first (largest directed distance to a
variablenode), then bystr(node_id). One rewrite is applied per iteration.- Parameters:
cm (networkx.DiGraph) – Canalizing map or dynamics canalization map.
copy (bool, optional) – If
True(default), operate on a copy and leave cm unchanged.remove_isolates (bool, optional) – If
True(default), drop isolated nodes after rewriting.skip_if_edges_increase (bool, optional) – If
True, skip a reduction when wiring preds→succs would add more edges than removing the unit deletes. Reductions that leave the edge count unchanged are still applied. DefaultFalse.
- Returns:
Simplified graph (a copy unless
copy=False).- Return type:
networkx.DiGraph