boofun.core.representations.base
Classes
Abstract base class for all Boolean function representations |
|
|
Wrapper for handling partial/incomplete Boolean function data. |
- class boofun.core.representations.base.BooleanFunctionRepresentation[source]
Abstract base class for all Boolean function representations
- abstractmethod evaluate(inputs: ndarray, data: Any, space: Space, n_vars: int) ndarray[source]
Evaluate the function on given inputs using the provided data.
- Parameters:
inputs – Input values (binary array or boolean values)
data – Representation-specific data (coefficients, truth table, etc.)
- Returns:
Boolean result or array of results
- abstractmethod dump(data: DataType, space: Space = None, **kwargs) Dict[str, Any][source]
Export the representation data in a serializable format.
- Parameters:
data – The representation data to export
space – Optional space specification (some representations need this)
**kwargs – Representation-specific options
- Returns:
Dictionary containing the exported representation
- abstractmethod convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert from another representation to this representation.
- Parameters:
source_repr – Source representation strategy
source_data – Data in source format
**kwargs – Conversion options
- Returns:
Data in this representation’s format
- abstractmethod convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert from this representation to target representation.
- Parameters:
target_repr – Target representation strategy
data – Data in this representation’s format
**kwargs – Conversion options
- Returns:
Data in target representation’s format
- abstractmethod create_empty(n_vars: int, **kwargs) DataType[source]
Create empty representation data structure for n variables.
- abstractmethod is_complete(data: DataType) bool[source]
Check if the representation contains complete information.
- class boofun.core.representations.base.PartialRepresentation(strategy: BooleanFunctionRepresentation[DataType], data: DataType, known_mask: ndarray | None = None, n_vars: int | None = None)[source]
Wrapper for handling partial/incomplete Boolean function data.
A partial representation is useful when: - Only some outputs are known (e.g., from sampling) - Data is streaming in incrementally - Function is too large to store completely
Provides: - Confidence tracking for known vs unknown inputs - Interpolation/estimation for unknown values - Completion status and statistics
Example
>>> # Create partial truth table (only some values known) >>> known_values = {0: True, 1: False, 3: True} >>> partial = PartialRepresentation.from_sparse( ... n_vars=2, known_values=known_values ... ) >>> partial.completeness # 0.75 (3 of 4 values known) >>> partial.evaluate_with_confidence(2) # (estimated_value, confidence)
- __init__(strategy: BooleanFunctionRepresentation[DataType], data: DataType, known_mask: ndarray | None = None, n_vars: int | None = None)[source]
Initialize partial representation.
- Parameters:
strategy – The representation strategy to use
data – The partial data (may have unknown values)
known_mask – Boolean mask indicating which values are known
n_vars – Number of variables (inferred from data if not provided)
- classmethod from_sparse(n_vars: int, known_values: Dict[int, bool], strategy_name: str = 'truth_table') PartialRepresentation[source]
Create partial representation from sparse known values.
- Parameters:
n_vars – Number of variables
known_values – Dict mapping input indices to output values
strategy_name – Name of representation strategy
- Returns:
PartialRepresentation with known values filled in
- evaluate(inputs: ndarray, space: Space) Any[source]
Evaluate at inputs (returns None for unknown values).
- Parameters:
inputs – Input index or array
space – Mathematical space
- Returns:
Boolean result or None if unknown
- evaluate_with_confidence(inputs: ndarray, space: Space) tuple[Any, float][source]
Evaluate with confidence measure.
For known values, confidence is 1.0. For unknown values, estimates based on known neighbors.
- Parameters:
inputs – Input index or array
space – Mathematical space
- Returns:
Tuple of (estimated_value, confidence)
- add_value(idx: int, value: bool) None[source]
Add a known value to the partial representation.
- Parameters:
idx – Input index
value – Output value
- boofun.core.representations.base.partial_representation
alias of
PartialRepresentation