boofun.core.spaces
Mathematical spaces for Boolean function analysis.
Provides conversions between different representations: - BOOLEAN_CUBE: {0, 1}^n - PLUS_MINUS_CUBE: {-1, +1}^n - REAL: ℝ^n - LOG: Log-probability space - GAUSSIAN: Standard normal space
WARNING: Some conversions are lossy (continuous → discrete). These will emit warnings unless explicitly silenced.
Classes
|
A probability measure on the Boolean hypercube. |
|
- class boofun.core.spaces.Space(value)[source]
- BOOLEAN_CUBE = 1
- PLUS_MINUS_CUBE = 2
- REAL = 3
- LOG = 4
- GAUSSIAN = 5
- static translate(input: int | float | ndarray, source_space: Space, target_space: Space) int | float | ndarray[source]
Translate a scalar or array from one space to another.
- Parameters:
input – Input value(s) to translate
source_space – Source mathematical space
target_space – Target mathematical space
- Returns:
Translated value(s) in target space
Examples
>>> Space.translate([0, 1], Space.BOOLEAN_CUBE, Space.PLUS_MINUS_CUBE) array([-1, 1]) >>> Space.translate([-1, 1], Space.PLUS_MINUS_CUBE, Space.BOOLEAN_CUBE) array([0, 1])
- class boofun.core.spaces.Measure(p: float = 0.5)[source]
A probability measure on the Boolean hypercube.
Supports uniform (p=0.5) and p-biased measures where each bit is 1 independently with probability p.
This unifies p-biased analysis: instead of calling separate functions from analysis/p_biased.py, pass a Measure to standard methods.
Examples
>>> uniform = Measure.uniform() >>> biased = Measure.p_biased(0.3) >>> biased.p # 0.3 >>> biased.sigma # sqrt(0.3 * 0.7)
- sample(n: int, rng=None) ndarray[source]
Sample a random input from this measure.
- Parameters:
n – Number of variables
rng – NumPy random generator (optional)
- Returns:
Binary array of length n