boofun.families.base
Base classes for Boolean function families.
A FunctionFamily represents a parameterized collection of Boolean functions indexed by the number of variables n (and possibly other parameters).
Functions
|
Create LTF family with geometrically decaying weights. |
|
Create LTF family with harmonic weights 1/(i+1). |
|
Create LTF family with power-law weights (n-i)^power. |
|
Create LTF family with uniform weights (equivalent to Majority). |
Classes
|
Metadata about a function family. |
Abstract base class for Boolean function families. |
|
|
A function family defined inductively/recursively. |
|
LTF family with weights following a pattern. |
- class boofun.families.base.FamilyMetadata(name: str, description: str, parameters: ~typing.Dict[str, str] = <factory>, asymptotics: ~typing.Dict[str, ~typing.Any] = <factory>, universal_properties: ~typing.List[str] = <factory>, n_constraints: ~typing.Callable[[int], bool] | None = None, n_constraint_description: str | None = None)[source]
Metadata about a function family.
- __init__(name: str, description: str, parameters: ~typing.Dict[str, str] = <factory>, asymptotics: ~typing.Dict[str, ~typing.Any] = <factory>, universal_properties: ~typing.List[str] = <factory>, n_constraints: ~typing.Callable[[int], bool] | None = None, n_constraint_description: str | None = None) None
- class boofun.families.base.FunctionFamily[source]
Abstract base class for Boolean function families.
A function family is a parameterized collection f_n indexed by n. Examples: Majority_n, Parity_n, Tribes_{k,n}
Subclasses must implement: - generate(n) -> BooleanFunction - metadata property
Optional overrides: - theoretical_value(property_name, n) -> theoretical prediction
- abstractmethod generate(n: int, **kwargs) BooleanFunction[source]
Generate the function for n variables.
- Parameters:
n – Number of variables
**kwargs – Additional family-specific parameters
- Returns:
BooleanFunction instance
- abstract property metadata: FamilyMetadata
Return metadata about this family.
- theoretical_value(property_name: str, n: int, **kwargs) float | None[source]
Get theoretical/asymptotic value for a property.
- Parameters:
property_name – Name of the property (e.g., “total_influence”)
n – Number of variables
**kwargs – Additional parameters (e.g., rho for noise stability)
- Returns:
Theoretical value if known, None otherwise
- class boofun.families.base.InductiveFamily(name: str = 'InductiveFamily', base_cases: Dict[int, BooleanFunction] | None = None, step_function: Callable | None = None, step_size: int = 1)[source]
A function family defined inductively/recursively.
The user provides: - base_case(n) -> BooleanFunction for small n - step(f_prev, n) -> how to extend from n-1 to n variables
This is useful for functions defined by their structure: - “Add a new variable with weight w_n” - “Apply a recursive construction”
Example
# Define Majority inductively class InductiveMajority(InductiveFamily):
- def base_case(self, n):
- if n == 1:
return bf.dictator(1, 0) # 1 variable, dictator on var 0
return None
- def step(self, f_prev, n, n_prev):
# Majority_n from Majority_{n-1} # Requires knowing the recursive structure …
- __init__(name: str = 'InductiveFamily', base_cases: Dict[int, BooleanFunction] | None = None, step_function: Callable | None = None, step_size: int = 1)[source]
Initialize an inductive family.
- Parameters:
name – Family name
base_cases – Dictionary of {n: BooleanFunction} for base cases
step_function – Function (f_prev, n) -> f_n
step_size – Number of variables added per step (default 1)
- property metadata: FamilyMetadata
Return metadata about this family.
- base_case(n: int) BooleanFunction | None[source]
Get base case for n, if it exists.
Override this in subclasses or provide base_cases dict.
- step(f_prev: BooleanFunction, n: int, n_prev: int) BooleanFunction[source]
Generate f_n from f_{n_prev}.
Override this in subclasses or provide step_function.
- Parameters:
f_prev – Function at previous step
n – Target number of variables
n_prev – Previous number of variables
- Returns:
Function with n variables
- generate(n: int, **kwargs) BooleanFunction[source]
Generate function for n variables using induction.
- class boofun.families.base.WeightPatternFamily(weight_function: Callable[[int, int], float], threshold_function: Callable[[int], float] | None = None, name: str = 'WeightPatternLTF')[source]
LTF family with weights following a pattern.
The user provides a weight function w(i, n) that determines the weight of variable i in the n-variable function.
Examples
# Uniform weights (Majority) uniform = WeightPatternFamily(lambda i, n: 1)
# Geometric weights (more dictator-like) geometric = WeightPatternFamily(lambda i, n: 2**(-i))
# Harmonic weights harmonic = WeightPatternFamily(lambda i, n: 1/(i+1))
- __init__(weight_function: Callable[[int, int], float], threshold_function: Callable[[int], float] | None = None, name: str = 'WeightPatternLTF')[source]
Initialize weight pattern family.
- Parameters:
weight_function – Function (i, n) -> weight of variable i
threshold_function – Function n -> threshold (default: 0)
name – Family name
- property metadata: FamilyMetadata
Return metadata about this family.
- generate(n: int, **kwargs) BooleanFunction[source]
Generate LTF with pattern weights.
- boofun.families.base.uniform_ltf_family(name: str = 'UniformLTF') WeightPatternFamily[source]
Create LTF family with uniform weights (equivalent to Majority).
- boofun.families.base.geometric_ltf_family(ratio: float = 0.5, name: str = 'GeometricLTF') WeightPatternFamily[source]
Create LTF family with geometrically decaying weights.
- boofun.families.base.harmonic_ltf_family(name: str = 'HarmonicLTF') WeightPatternFamily[source]
Create LTF family with harmonic weights 1/(i+1).
- boofun.families.base.power_ltf_family(power: float = 2.0, name: str = 'PowerLTF') WeightPatternFamily[source]
Create LTF family with power-law weights (n-i)^power.