petri_net_nn.interpretability¶
interpretability ¶
Distil learned weights back into readable decision rules.
Addresses §8's fourth open problem from the architecture spec:
The structural interpretability of the architecture — which subnet shows the anomaly — is a genuine advantage over black-box ML. But the learned weights within each subnet are not directly interpretable. … The next research question is whether the learned weights can be distilled back into readable decision rules — closing the loop from neural learning to interpretable business logic.
Three pieces:
-
Rule extraction.
extract_routing_ruleswalks the compiled module's structure for XOR-shape transitions (N transitions sharing one input place, no other consumers) and reads the learned weights / thresholds out as a single crossover value per pair: "input above X → transition A, otherwise → transition B".extract_and_join_rulesdoes the same for synchronisation transitions (multi-input AND-joins), reading the input weights and threshold as a weighted-vote or uniform-quorum rule. -
Bootstrap confidence intervals.
bootstrap_xor_ruleandbootstrap_and_join_ruleresample the training trace list with replacement N times, retrain a fresh module per resample, extract the rule, and report the distribution of rule parameters. ReturnsXORRuleCI/AndJoinRuleCIwith percentile-based confidence intervals and a direction-agreement rate — the Phase 13 answer to "should I trust this rule in production?". -
Prose explanations.
explain_anomalywalks residuals and formats them as a paragraph;prose_for_xor_ruleandprose_for_and_join_ruledo the same for rules (with or without bootstrap CIs attached). All three turn the extractors' structured output into a plain-English paragraph a non-technical reader can act on.
The scaffold restricts XOR rule extraction to two-way splits — the common case. N-way splits compute pairwise crossovers between the top two transitions but flag the rule as approximate; full N-way rule extraction is a follow-up.
XORRule
dataclass
¶
XORRule(input_place, transition_above, transition_below, label_above, label_below, crossover, confidence)
A distilled binary routing rule.
The trained network routes to transition_above when the
activation of input_place exceeds crossover, and to
transition_below otherwise. label_above / label_below
are the BPMN names of those transitions (falling back to the
transition IDs when unlabelled).
XORRegion
dataclass
¶
One interval of an N-way XOR routing partition: the trained
network selects transition (BPMN label label) whenever the
activation of the shared input place lies in [lower, upper].
AndJoinRule
dataclass
¶
A distilled AND-join (synchronisation) rule.
The transition fires when sum(weight_i * a(input_i)) > threshold
— a weighted vote over the input places. inputs lists each
input place's BPMN label and its learned weight; summary is a
short natural-language gloss (uniform-weight quorum, or explicit
weighted vote if weights vary).
XORPartition
dataclass
¶
N-way routing rule for a single XOR-shape group, expressed as contiguous input intervals each mapped to a winning transition.
XORRuleCI
dataclass
¶
XORRuleCI(rule, n_bootstrap, confidence, crossover_samples, crossover_mean, crossover_median, crossover_ci_low, crossover_ci_high, direction_agreement)
An :class:XORRule annotated with bootstrap-derived confidence
intervals.
Attributes¶
rule
The point-estimate rule — extracted from the module trained
on the full trace list (no resampling). This is the rule
you would report if you weren't computing CIs at all.
n_bootstrap
How many bootstrap resamples were trained.
confidence
The nominal coverage of the percentile interval below
(e.g. 0.95 for a 95% CI). Used to compute the interval
endpoints as the (1 − confidence)/2 and (1 + confidence)/2
percentiles of the bootstrap samples.
crossover_samples
The crossover values extracted from each bootstrap-trained
module. NaN samples (occur when the trained weight gap is
too small to discriminate) are filtered out before computing
the summary statistics — they're effectively "no rule" and
shouldn't pull the CI around.
crossover_mean / crossover_median
Summary statistics over the (non-NaN) samples.
crossover_ci_low / crossover_ci_high
Percentile-based confidence interval bounds. nan if too
few valid samples to compute.
direction_agreement
Fraction of bootstrap samples whose transition_above /
transition_below direction matches the point estimate.
1.0 means every resample agrees; values below ~0.8 are a
red flag that the rule's direction is data-dependent.
description ¶
One-line summary including the CI; useful for log lines and quick assertions.
Source code in petri_net_nn/interpretability.py
AndJoinRuleCI
dataclass
¶
AndJoinRuleCI(rule, n_bootstrap, confidence, threshold_samples, threshold_mean, threshold_median, threshold_ci_low, threshold_ci_high, quorum_agreement)
An :class:AndJoinRule annotated with bootstrap-derived
confidence intervals on its threshold.
Attributes¶
rule
The point-estimate rule from training on the full trace list.
n_bootstrap, confidence
As for :class:XORRuleCI.
threshold_samples
Bootstrap-sample thresholds.
threshold_mean / threshold_median / threshold_ci_low /
threshold_ci_high
Summary statistics over the samples.
quorum_agreement
Fraction of bootstrap samples whose extracted quorum
("all N", "≥ k of N", or "weighted") matches the point
estimate's quorum gloss. A low value suggests the join's
synchronisation rule is brittle under data resampling.
Counterfactual
dataclass
¶
Counterfactual(target_transition, target_label, flipped_place, flipped_channel, original_input, counterfactual_input, original_activation, counterfactual_activation)
A minimal-change explanation: what input value at one place would have flipped a target transition's firing decision.
Attributes¶
target_transition
The transition whose firing is being explained.
target_label
Human label for target_transition.
flipped_place
The input place whose value was varied to flip the outcome.
flipped_channel
Either "marking" (the place activation) or "value"
(the coloured-token value channel — used for CPN routing
where the structural guard reads per-token values).
original_input
The value of flipped_place in the base scenario.
counterfactual_input
The value at which target_transition's firing
activation crosses the 0.5 threshold.
original_activation
Firing activation of target_transition at
original_input.
counterfactual_activation
Firing activation of target_transition at
counterfactual_input. Should be near 0.5 by
construction.
description ¶
One-line description suitable for log lines.
Source code in petri_net_nn/interpretability.py
SensitivityReport
dataclass
¶
SensitivityReport(target_transition, target_label, base_activation, marking_gradients=dict(), value_gradients=dict())
Local sensitivity of one transition's firing activation to each input at a given base point.
Attributes¶
target_transition
The transition whose firing we measured.
target_label
Human label for target_transition.
base_activation
Firing activation of target_transition at the base
inputs — useful for sanity-checking that we're near a
decision boundary (gradients far from 0.5 are less
informative).
marking_gradients
Per-place gradient of the target's activation with respect
to the marking channel at that place. Larger magnitude
means the firing decision pivots more on this input.
value_gradients
Per-place gradient on the coloured-token value channel.
Empty when base_values wasn't supplied.
ranked ¶
Inputs sorted by descending absolute gradient. Each entry
is (place, channel, gradient) where channel is
"marking" or "value" — so a place can appear twice
if it's driven through both channels (rare). When
top_n is given, returns only the top N.
Source code in petri_net_nn/interpretability.py
DisagreementSample
dataclass
¶
One grid point where the two variants disagree on at least one corresponded transition.
Attributes¶
input_marking
Place activations at this sample point.
input_values
Per-token value channel at this sample point, or None
when the comparison didn't use a value grid.
diverging
Map of label → (variant_a_activation, variant_b_activation)
for transitions where the two variants disagreed at this
point. Only diverging transitions appear here — the report
is a disagreement sample, not a full state dump.
ComparisonReport
dataclass
¶
ComparisonReport(n_samples, paired_labels, unmatched_a, unmatched_b, hard_agreement_rate, soft_agreement_rate, per_transition_agreement, disagreement_samples, tolerance)
Outcome of comparing two trained variants over a grid of input points.
Attributes¶
n_samples
How many grid points were evaluated.
paired_labels
Transition labels that were matched between the two
variants. Variants of the same process usually share
labels; this list pins which ones the comparison actually
ran on. Labels present in only one variant are skipped
(and recorded in unmatched_a / unmatched_b for
diagnostic purposes).
unmatched_a, unmatched_b
Labels present in variant A / B but not in the other.
Useful for catching variants that differ structurally
before reading the agreement numbers.
hard_agreement_rate
Fraction of (sample, transition) pairs where both variants'
firing activations fell on the same side of 0.5 — the
same firing decision.
soft_agreement_rate
Fraction where the two activations were within
tolerance of each other. Stricter when tolerance is
small, looser when large.
per_transition_agreement
Per-label hard-agreement rate. Sorted-descending lists
which transitions agree most reliably; sorted-ascending
surfaces the ones most prone to divergence.
disagreement_samples
Specific grid points where at least one transition
diverged (under the hard-agreement definition). Capped at
max_disagreement_samples to keep the report a
bounded-size object.
tolerance
Echo of the soft-agreement tolerance used. Recorded so
the report is self-describing.
find_xor_groups ¶
Return XOR-shape transition groups detected structurally.
Two patterns count as XOR groups:
-
Single-input XOR — N transitions all sharing a single input place, each with that place as their only input. This is the §5 Subnet 2 / classic BPMN XOR-split.
-
Shared-preset XOR — N transitions all having the same (multi-place) input set. They compete for the same combined precondition; the trained weights and thresholds determine which fires. This shape arises in protocols like 2PC where a routing decision is gated by both a control token and a data message — the decision is XOR-shaped but the precondition is conjunctive.
The returned tuple's first element is a discriminative input place — for the single-input case it is the unique input; for the shared-preset case it is one place from the shared preset (sorted, first). Rule-extraction callers can use this place as the input axis to read crossovers from, treating other shared inputs as constant context.
Source code in petri_net_nn/interpretability.py
extract_xor_rule ¶
Derive the routing crossover for one binary XOR pair from the trained weights. The continuous-relaxation comparison
w_A·a(P) - θ_A vs w_B·a(P) - θ_B
has a single crossover point at a(P) = (θ_A - θ_B) / (w_A - w_B) when the weight gap is non-zero, with direction determined by the sign of the gap. The crossover is the rule's threshold; the magnitude of the gap is its confidence (small gap = the two transitions discriminate weakly, regardless of where the crossover sits).
Source code in petri_net_nn/interpretability.py
extract_routing_rules ¶
Apply :func:extract_xor_rule to every two-way XOR group in the
net. N-way groups are skipped — use
:func:extract_routing_partitions to get the piecewise
representation that covers all arities. For shared-preset groups
(multi-input competing transitions), the discriminative input is
chosen automatically from the trained weight gaps.
Source code in petri_net_nn/interpretability.py
extract_xor_partition ¶
N-way XOR partition. For N competing transitions sharing
input_place as their only input, derive the piecewise winner
on the input interval [input_range[0], input_range[1]]. Each
transition is treated as a linear pre-activation
w_i · a(P) - θ_i; the partition records which transition has
the maximum pre-activation on each contiguous sub-interval.
Source code in petri_net_nn/interpretability.py
find_and_join_transitions ¶
Return transitions with at least two distinct input places — the synchronisation (AND-join) shape from §5 Subnet 4. The BPMN parser's XOR-join translation produces multiple transitions each with one input arc, so those are not picked up here.
Source code in petri_net_nn/interpretability.py
extract_and_join_rule ¶
Distil an AND-join transition's learned weights into a weighted-vote rule. If the learned weights are roughly uniform the rule is rendered as a quorum ("fires when at least k of n inputs are active"); otherwise it is rendered as an explicit weighted sum threshold.
Source code in petri_net_nn/interpretability.py
extract_and_join_rules ¶
Apply :func:extract_and_join_rule to every synchronisation
transition in the net.
Source code in petri_net_nn/interpretability.py
extract_routing_partitions ¶
Apply :func:extract_xor_partition to every XOR-shape group in
the net, regardless of arity. For shared-preset groups the
discriminative input is chosen automatically. Returns one
XORPartition per group.
Source code in petri_net_nn/interpretability.py
explain_anomaly ¶
Produce a human-readable explanation of why trace is
anomalous under module. Walks the per-transition residuals
from :func:petri_net_nn.traces.anomaly_score, sorts by
magnitude, and formats the top contributors as prose using the
transitions' BPMN labels.
Source code in petri_net_nn/interpretability.py
bootstrap_xor_rule ¶
bootstrap_xor_rule(module_factory, traces, *, attribute_to_marking, input_place, transition_a, transition_b, n_bootstrap=100, confidence=0.95, steps=500, lr=0.1, attribute_to_values=None, seed=None)
Bootstrap-resample the trace list, train a fresh module per
resample, extract the XOR rule, and report the distribution of
crossovers as an :class:XORRuleCI.
Parameters¶
module_factory
A zero-argument callable that builds a fresh
:class:PetriNetModule ready to train. The bootstrap
algorithm calls it n_bootstrap + 1 times — once for the
point estimate on the full trace list, then once per
resample. Each call MUST return an independent module: the
factory exists to capture the net's structure while keeping
the random initialisation fresh per call.
traces
The training trace list. Bootstrap samples are drawn with
replacement from this list.
attribute_to_marking
Same role as in :func:petri_net_nn.train_on_traces — maps
each trace to its input-marking dict.
attribute_to_values
Optional CPN value channel. Passed through to
:func:train_on_traces for each bootstrap run.
input_place, transition_a, transition_b
The XOR pair to extract — the same arguments as
:func:extract_xor_rule.
n_bootstrap
Number of bootstrap resamples. Default 100. Higher gives
tighter CIs at higher training cost.
confidence
Coverage of the percentile interval (default 0.95).
steps, lr
Forwarded to the per-resample training. The defaults match
train_on_traces.
seed
Optional integer seed for the bootstrap RNG. The per-resample
training is not re-seeded — initialisation variance across
resamples is part of what bootstrap is measuring.
Returns¶
XORRuleCI Bundle of the point estimate, the bootstrap distribution, and the percentile-CI / direction-agreement stats.
Source code in petri_net_nn/interpretability.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
bootstrap_and_join_rule ¶
bootstrap_and_join_rule(module_factory, traces, *, attribute_to_marking, transition, n_bootstrap=100, confidence=0.95, steps=500, lr=0.1, attribute_to_values=None, seed=None)
Same shape as :func:bootstrap_xor_rule but for AND-join rules.
Returns an :class:AndJoinRuleCI with the threshold distribution
and a quorum agreement score — the fraction of bootstrap
samples whose extracted quorum gloss matches the point estimate's.
A drop in quorum agreement means the join's synchronisation
behaviour is data-dependent: across plausible re-samples of the
training data, sometimes it looks like an "all N" join and
sometimes like a "≥ k of N" weighted vote.
Source code in petri_net_nn/interpretability.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
prose_for_xor_rule ¶
Render an XOR rule (with or without bootstrap CI) as a paragraph in plain English.
Parameters¶
rule
Either a bare :class:XORRule (just the point estimate)
or an :class:XORRuleCI (point estimate + confidence
interval). When a CI is supplied, the prose includes both
the percentile interval and the direction-agreement rate.
input_label
Optional human-readable name for the input quantity. The
rule stores the place id (e.g. p_application), which
is fine in code but ugly in a regulator-facing paragraph.
Supply input_label="application amount" to substitute
a domain term.
Source code in petri_net_nn/interpretability.py
prose_for_and_join_rule ¶
Render an AND-join rule (with or without bootstrap CI) as a
paragraph in plain English. The point-estimate rule's
summary field already carries a gloss like "all 3 inputs"
or "at least 2 of 3 inputs" or a weighted-vote description;
we wrap that in narrative prose plus any CI annotations.
Source code in petri_net_nn/interpretability.py
find_counterfactual ¶
find_counterfactual(module, base_marking, *, flip_place, target_transition, base_values=None, flip_channel='marking', search_range=(0.0, 1.0), tolerance=0.001, interval_tolerance=None, max_iterations=50)
Binary-search the input at flip_place to find the
crossing point where target_transition's firing activation
flips across 0.5.
Parameters¶
module
The trained module to query. Its forward pass is what
drives the search.
base_marking
The starting input marking — the original scenario whose
outcome we want to flip. Used to compute the original
firing activation at target_transition.
flip_place
The place whose input we vary.
target_transition
The transition whose firing we want to flip. The
counterfactual is the smallest change to flip_place's
value that makes target_transition's activation cross
0.5.
base_values
Optional CPN value channel for module(input_values=...).
Required when flip_channel="value" since the search
varies an entry of this dict; ignored when
flip_channel="marking".
flip_channel
"marking" (default) varies the activation at
flip_place; "value" varies the per-token value
the compiled guards read. Use "value" for
coloured-Petri-net scenarios like credit_approval_coloured
where the relevant decision quantity is the token value,
not the activation.
search_range
Lower and upper bound for the binary search. For marking
channels, the usual [0, 1]; for value channels, the
domain of the relevant attribute (e.g. (0, 10000) for
loan amounts).
tolerance
Activation tolerance: stop when the midpoint's firing
activation is within this distance of 0.5. Default
1e-3, which puts the counterfactual well inside the
decision boundary.
interval_tolerance
Search-interval tolerance: stop when the bracketing
interval shrinks below this width. Defaults to
(search_range[1] - search_range[0]) * 1e-4 — i.e.
four decimal digits of resolution on the input scale.
Set explicitly for non-default search ranges if you want
a different floor (e.g. 1.0 for monetary amounts where
finer than £1 doesn't matter).
max_iterations
Hard cap on bisection iterations — protects against
non-monotone activations that won't converge.
Returns¶
Counterfactual | None
None when no crossing exists in search_range —
the activation stays on the same side of 0.5 at both
endpoints, meaning a counterfactual within those bounds
doesn't exist. Otherwise the Counterfactual pinning
the original-input, counterfactual-input, and activation
pair.
Source code in petri_net_nn/interpretability.py
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 | |
prose_for_counterfactual ¶
Render a counterfactual as a paragraph in plain English.
Parameters¶
cf
The :class:Counterfactual to describe.
input_label
Optional human-readable name for the flipped input.
Useful when the place id is something like
p_application but the regulator-facing prose wants
"application amount".
Source code in petri_net_nn/interpretability.py
transition_sensitivity ¶
Compute per-input gradient magnitudes of
target_transition's firing activation at the base point.
The gradient of the activation with respect to each input captures the local sensitivity — how much the firing decision changes when we nudge that input. Larger gradient magnitude means the model is leaning more on that input at this base point. Inputs with near-zero gradient are locally irrelevant (either the model genuinely doesn't use them, or we're in a saturated regime far from any decision boundary).
Parameters¶
module The trained module whose sensitivities to compute. base_marking Input marking at which to evaluate gradients. Typically the original case in a counterfactual investigation, or a representative instance from the training distribution. target_transition The transition whose firing is being explained. base_values Optional coloured-token value channel. When supplied, the report also contains value-channel gradients — useful for CPN scenarios where the routing decision pivots on the per-token value rather than the place activation.
Source code in petri_net_nn/interpretability.py
1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 | |
input_importance ¶
input_importance(module, traces, *, attribute_to_marking, transitions=None, attribute_to_values=None)
Aggregate per-input importance across a trace set.
For each trace and each scored transition, computes the gradient of that transition's firing activation with respect to each input. Aggregates by summing the absolute gradients across traces and transitions — places with a large summed gradient are the ones the trained network leans on most heavily for its overall decision-making.
The aggregate is reported separately for the marking channel
and the value channel: a key like "marking:p_request" or
"value:p_submitted" keeps the two channels distinguishable
in scenarios where both matter.
Parameters¶
module
The trained module.
traces
The trace set across which to aggregate. Importance is
averaged-by-summation, so a larger trace set gives more
stable scores.
attribute_to_marking
Maps each trace to its input marking dict.
transitions
Which transitions' activations to score against. Defaults
to "all transitions whose label doesn't look auto-generated"
— matches the convention used by train_on_traces and
anomaly_score.
attribute_to_values
Optional value channel — same role as in
train_on_traces.
Returns¶
dict[str, float]
Importance scores keyed by "<channel>:<place_id>".
Sorted-by-descending-value through sorted(..., reverse=True)
on .items() gives the ranked importance list.
Source code in petri_net_nn/interpretability.py
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 | |
prose_for_sensitivity ¶
Render a sensitivity report as a paragraph in plain English.
Lists the top-N inputs ranked by absolute gradient magnitude, with directional language ("increasing this input raises / lowers the firing of …") so the reader doesn't have to map a signed number to behaviour themselves.
Parameters¶
report
The :class:SensitivityReport to describe.
top_n
How many inputs to enumerate (default 3). The full ranking
is available via report.ranked(); the prose just picks
the leading items.
input_labels
Optional {place_id: human_label} mapping for
substituting domain terms ("application amount" rather
than "p_application"). Each key is a place id (without
the channel prefix); both channels of the same place will
be relabelled together.
Source code in petri_net_nn/interpretability.py
compare_variants ¶
compare_variants(module_a, module_b, *, input_grid=None, input_value_grid=None, correspondence=None, tolerance=0.1, max_disagreement_samples=50)
Compare two trained variants across a grid of input points.
For each input combination in the Cartesian product of
input_grid (marking channel) and input_value_grid
(coloured-token value channel), evaluate both modules and
compare each pair of corresponded transitions' firing
activations.
Parameters¶
module_a, module_b
The two trained variants to compare. Usually two trainings
of structurally-bisimilar nets — see are_bisimilar /
are_weakly_bisimilar. The function itself doesn't
check bisimilarity; it compares whatever you pass in.
input_grid
Place activations to vary. Keys are place ids that exist
in both modules (when in doubt, pass the same place id
appearing as a source in both — variants of the same
process share input names). Values are lists of activation
values to evaluate. The Cartesian product gives the
sample set.
input_value_grid
Optional coloured-token value channel grid. Same shape as
input_grid. When supplied, each combined grid point
runs through both the marking and value channels of both
modules.
correspondence
Override the default label-matching. Keys are an arbitrary
identifier the user chooses (often the human label), values
are (transition_id_in_a, transition_id_in_b) pairs.
Use this when the two variants use different labels for
the same conceptual step (e.g. "Approve loan" vs
"Loan approval").
tolerance
Soft-agreement tolerance: two activations are softly
equal when |a - b| <= tolerance. Default 0.1.
max_disagreement_samples
Hard cap on the number of disagreement samples carried in
the report — protects against a single grid sweep
producing thousands of divergent points and bloating the
report.
Returns¶
ComparisonReport
Bundled outcome: agreement rates, per-transition rates,
and up to max_disagreement_samples divergent grid
points for inspection.
Source code in petri_net_nn/interpretability.py
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 | |
prose_for_comparison_report ¶
Render a cross-variant comparison report as a paragraph.
Reports overall hard- and soft-agreement rates, names the transitions most prone to disagreement, and flags any label mismatches between the two variants. Suitable for inclusion in a refactoring proposal or a model-risk review.
Parameters¶
report
The :class:ComparisonReport to describe.
top_disagreement
How many of the most-divergent transitions to list (default
3). Surfaces the worst offenders without burying the reader
in a long table; the full per-transition breakdown is
always available on report.per_transition_agreement.
Source code in petri_net_nn/interpretability.py
1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 | |