cana.function_properties.sampling module
Sampling
Shared exact / sampled prime-implicant coverage helpers for function measures (redundancy, bias, sensitivity).
For k <= exact_k_max (default 14) averages are over the full
2**k space. For larger k, minterms are sampled (default
n_samples = 2**exact_k_max). Bootstrap helpers resample contributions from
a preserved SampledPiCoverage without re-matching primes.
- class cana.function_properties.sampling.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.sampling.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.sampling.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.sampling.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.sampling.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.sampling.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.sampling.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.sampling.resolve_exact_or_sampled(schemata, *, what, k=None, exact_k_max=14, n_samples=None, rng=None, minterms=None)[source]
Run the exact / sampled two-track; return
(coverage, mode, k).Same policy as the measure front-ends: exact when
k <= exact_k_maxand minterms is omitted; otherwise samplen_samples(default2**exact_k_max) and optionally warn.- Parameters:
schemata (Mapping[int, Set[str]])
what (str)
k (int | None)
exact_k_max (int)
n_samples (int | None)
rng (Generator | None)
minterms (Sequence[str] | None)
- Return type:
Tuple[SampledPiCoverage, str, int]