cana.function_properties.redundancy module
Redundancy
Input and edge redundancy of a Boolean node from one-symbol prime implicants.
For k <= exact_k_max (default 14) values are exact averages over the full
prime-implicant coverage. For larger k, minterms are sampled (default
n_samples = 2**exact_k_max) and the same per-minterm contributions are
averaged — a UserWarning is emitted on that automatic fallback
(suppress by passing exact_k_max=-1, or force exact with
exact_k_max >= k). Pass return_mode=True to get
"exact" / "sampled" alongside the value. Bootstrap confidence
intervals resample contributions from a preserved
SampledPiCoverage without
re-matching primes.
Shared sampling / bootstrap plumbing lives in
sampling and is re-exported here for
backwards compatibility.
- class cana.function_properties.redundancy.BootstrapResult(estimate, ci_low, ci_high, boot_mean, boot_std, n_samples, n_boot, ci)[source]
Bases:
objectPoint estimate with a percentile bootstrap confidence interval.
- Parameters:
estimate (float)
ci_low (float)
ci_high (float)
boot_mean (float)
boot_std (float)
n_samples (int)
n_boot (int)
ci (float)
- estimate: float
- ci_low: float
- ci_high: float
- boot_mean: float
- boot_std: float
- n_samples: int
- n_boot: int
- ci: float
- class cana.function_properties.redundancy.SampledPiCoverage(coverage, k, n_samples, outputs)[source]
Bases:
objectPartial
pi_coveragefrom sampled minterms.coveragemaps each sampled binary state to the one-symbol primes that cover it (same shape as a fullpi_coverage()dict, but only for the sample).outputsstores the polarity (0/1) of each sampled minterm so bias can be estimated without re-matching primes. Bootstrap helpers derive per-minterm contributions from this coverage without re-matching primes.- Parameters:
coverage (Dict[str, Tuple[str, ...]])
k (int)
n_samples (int)
outputs (Dict[str, int])
- coverage: Dict[str, Tuple[str, ...]]
- k: int
- n_samples: int
- outputs: Dict[str, int]
- property minterms: List[str]
- input_contributions(operator=<function mean>)[source]
- Parameters:
operator (Callable[[Sequence[float]], float])
- Return type:
ndarray
- cana.function_properties.redundancy.pi_covers(schema, binstate)[source]
Return True if one-symbol schema covers binary binstate.
- Parameters:
schema (str)
binstate (str)
- Return type:
bool
- cana.function_properties.redundancy.covering_primes(binstate, schemata)[source]
Return one-symbol PIs covering binstate (ON and OFF scanned).
- Raises:
ValueError – if no prime covers binstate (incomplete cover), or ON and OFF primes both cover it (polarity conflict).
- Parameters:
binstate (str)
schemata (Mapping[int, Set[str]])
- Return type:
List[str]
- cana.function_properties.redundancy.covering_primes_with_polarity(binstate, schemata)[source]
Return covering one-symbol PIs and the output polarity of binstate.
- Raises:
ValueError – if no prime covers binstate, or ON and OFF primes both cover it (polarity conflict).
- Parameters:
binstate (str)
schemata (Mapping[int, Set[str]])
- Return type:
Tuple[List[str], int]
- cana.function_properties.redundancy.sample_binstates(k, n, *, rng=None, replace=False)[source]
Uniform sample of n binary strings of length k.
If
not replaceandn >= 2**k, returns the full space0..2**k-1(exact enumeration path).For large k (where
2**kdoes not fit inint64), samples bitstrings directly instead of indexing intorange(2**k).- Parameters:
k (int)
n (int)
rng (Generator | None)
replace (bool)
- Return type:
List[str]
- cana.function_properties.redundancy.sample_pi_coverage(schemata, n_samples, *, rng=None, minterms=None, k=None)[source]
Sample minterms and build a partial pi-coverage dict.
- Parameters:
schemata (Mapping[int, Set[str]])
n_samples (int)
rng (Generator | None)
minterms (Sequence[str] | None)
k (int | None)
- Return type:
- cana.function_properties.redundancy.input_redundancy_from_coverage(pi_coverage, k=None, *, operator=<function mean>, norm=True)[source]
Average input redundancy over entries of a (full or sampled) coverage.
- Parameters:
pi_coverage (Mapping[str, Sequence[str]])
k (int | None)
operator (Callable[[Sequence[float]], float])
norm (bool)
- Return type:
float
- cana.function_properties.redundancy.edge_redundancy_from_coverage(pi_coverage, k=None, *, bound='mean')[source]
Per-input edge redundancy over a (full or sampled) coverage.
- Parameters:
pi_coverage (Mapping[str, Sequence[str]])
k (int | None)
bound (str)
- Return type:
List[float] | List[Tuple[float, float]]
- cana.function_properties.redundancy.input_redundancy_contributions(coverage_or_schemata, minterms, operator=<function mean>)[source]
Per-minterm Φ(#wildcards among covering PIs); shape
(n,).coverage_or_schemata may be a pi-coverage dict (binstate → PIs) or one-symbol ON/OFF schemata (polarity → PIs). Coverage is detected by whether keys look like binstates.
- Parameters:
coverage_or_schemata (Mapping[str, Sequence[str]] | Mapping[int, Set[str]])
minterms (Sequence[str])
operator (Callable[[Sequence[float]], float])
- Return type:
ndarray
- cana.function_properties.redundancy.edge_redundancy_contributions(coverage_or_schemata, minterms, bound='mean')[source]
Per-minterm edge contributions.
For
boundinlower/mean/upper: shape(n, k). Forbound == "tuple":(lower, upper)each shape(n, k).- Parameters:
coverage_or_schemata (Mapping[str, Sequence[str]] | Mapping[int, Set[str]])
minterms (Sequence[str])
bound (str)
- Return type:
ndarray | Tuple[ndarray, ndarray]
- cana.function_properties.redundancy.input_redundancy(schemata, k=None, *, operator=<function mean>, norm=True, exact_k_max=14, n_samples=None, rng=None, minterms=None, return_coverage=False, return_mode=False)[source]
Input redundancy \(k_r\) with exact / sampled two-track.
If
k <= exact_k_maxand minterms is not provided, enumerates the full2**kspace. Otherwise samplesn_samples(default2**exact_k_max) minterms.When sampling is used because
k > exact_k_max(andexact_k_max >= 0), aUserWarningis emitted. Passexact_k_max=-1to force sampling without that warning, orexact_k_max >= kfor the exact value. Withreturn_mode=True, the second (or third) return value is"exact"or"sampled".- Parameters:
schemata (Mapping[int, Set[str]])
k (int | None)
operator (Callable[[Sequence[float]], float])
norm (bool)
exact_k_max (int)
n_samples (int | None)
rng (Generator | None)
minterms (Sequence[str] | None)
return_coverage (bool)
return_mode (bool)
- Return type:
float | Tuple[float, SampledPiCoverage] | Tuple[float, str] | Tuple[float, SampledPiCoverage, str]
- cana.function_properties.redundancy.edge_redundancy(schemata, k=None, *, bound='mean', exact_k_max=14, n_samples=None, rng=None, minterms=None, return_coverage=False, return_mode=False)[source]
Per-input edge redundancy \(r_i\) with exact / sampled two-track.
Same exact/sampled two-track and warning /
return_modebehaviour asinput_redundancy().- Parameters:
schemata (Mapping[int, Set[str]])
k (int | None)
bound (str)
exact_k_max (int)
n_samples (int | None)
rng (Generator | None)
minterms (Sequence[str] | None)
return_coverage (bool)
return_mode (bool)
- Return type:
List[float] | List[Tuple[float, float]] | Tuple[List[float] | List[Tuple[float, float]], SampledPiCoverage] | Tuple[List[float] | List[Tuple[float, float]], str] | Tuple[List[float] | List[Tuple[float, float]], SampledPiCoverage, str]
- cana.function_properties.redundancy.bootstrap_input_redundancy(sampled_or_schemata=None, *, schemata=None, n_samples=None, n_boot=1000, ci=0.95, operator=<function mean>, norm=True, rng=None, minterms=None)[source]
Estimate \(k_r\) with a percentile bootstrap CI on the sample mean.
Prefer passing a preserved
SampledPiCoverageso primes are not re-matched. Schemata +n_samples/mintermsstill work (including the legacy positionalschematacall).- Parameters:
sampled_or_schemata (SampledPiCoverage | Mapping[int, Set[str]] | None)
schemata (Mapping[int, Set[str]] | None)
n_samples (int | None)
n_boot (int)
ci (float)
operator (Callable[[Sequence[float]], float])
norm (bool)
rng (Generator | None)
minterms (Sequence[str] | None)
- Return type:
- cana.function_properties.redundancy.bootstrap_edge_redundancy(sampled_or_schemata=None, *, schemata=None, n_samples=None, n_boot=1000, ci=0.95, bound='mean', rng=None, minterms=None)[source]
Estimate per-input \(r_i\) with percentile bootstrap CIs.
For
bound == "tuple", returns[(lower_result, upper_result), ...]. Prefer a preservedSampledPiCoverage; schemata +n_samplesstill work (legacy positionalschemataincluded).- Parameters:
sampled_or_schemata (SampledPiCoverage | Mapping[int, Set[str]] | None)
schemata (Mapping[int, Set[str]] | None)
n_samples (int | None)
n_boot (int)
ci (float)
bound (str)
rng (Generator | None)
minterms (Sequence[str] | None)
- Return type:
List[BootstrapResult] | List[Tuple[BootstrapResult, BootstrapResult]]