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: object

Point 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: object

Partial pi_coverage from sampled minterms.

coverage maps each sampled binary state to the one-symbol primes that cover it (same shape as a full pi_coverage() dict, but only for the sample). outputs stores 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

edge_contributions(bound='mean')[source]
Parameters:

bound (str)

Return type:

ndarray | Tuple[ndarray, ndarray]

bias_contributions()[source]

Per-minterm output bits as float64, shape (n_samples,).

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 replace and n >= 2**k, returns the full space 0..2**k-1 (exact enumeration path).

For large k (where 2**k does not fit in int64), samples bitstrings directly instead of indexing into range(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:

SampledPiCoverage

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_max and minterms is omitted; otherwise sample n_samples (default 2**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]