boofun.core.representations.ltf
Linear Threshold Function (LTF) representation for Boolean functions.
A Linear Threshold Function is defined by: f(x) = sign(w₁x₁ + w₂x₂ + … + wₙxₙ - θ)
where w = (w₁, w₂, …, wₙ) are the weights and θ is the threshold.
Functions
|
Create LTF for majority function. |
|
Create LTF for k-threshold function. |
|
Check if a Boolean function can be represented as an LTF. |
Classes
|
Parameters for a Linear Threshold Function. |
Linear Threshold Function representation for Boolean functions. |
- class boofun.core.representations.ltf.LTFParameters(weights: ndarray, threshold: float, n_vars: int)[source]
Parameters for a Linear Threshold Function.
- weights
Array of weights for each variable
- Type:
- evaluate(x: List[int] | ndarray) bool[source]
Evaluate LTF at given input.
- Parameters:
x – Binary input vector
- Returns:
Boolean output
- class boofun.core.representations.ltf.LTFRepresentation[source]
Linear Threshold Function representation for Boolean functions.
- evaluate(inputs: ndarray, data: LTFParameters, space: Space, n_vars: int) bool | ndarray[source]
Evaluate LTF representation.
- Parameters:
inputs – Input values (integer indices or binary vectors)
data – LTF parameters
space – Evaluation space
n_vars – Number of variables
- Returns:
Boolean result(s)
- convert_from(source_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) LTFParameters[source]
Convert from another representation to LTF.
Uses linear programming to find weights and threshold. Note: Not all Boolean functions can be represented as LTFs.
- convert_to(target_repr: BooleanFunctionRepresentation, source_data: Any, space: Space, n_vars: int, **kwargs) ndarray[source]
Convert LTF to another representation.
- create_empty(n_vars: int, **kwargs) LTFParameters[source]
Create empty LTF (constant False).
- is_complete(data: LTFParameters) bool[source]
Check if LTF is complete (has valid parameters).
- boofun.core.representations.ltf.is_ltf(truth_table: List[bool], n_vars: int) bool[source]
Check if a Boolean function can be represented as an LTF.
- Parameters:
truth_table – Boolean truth table
n_vars – Number of variables
- Returns:
True if function is linearly separable
- boofun.core.representations.ltf.create_majority_ltf(n_vars: int) LTFParameters[source]
Create LTF for majority function.
- Parameters:
n_vars – Number of variables (must be odd)
- Returns:
LTF parameters for majority function
- boofun.core.representations.ltf.create_threshold_ltf(n_vars: int, k: int) LTFParameters[source]
Create LTF for k-threshold function.
- Parameters:
n_vars – Number of variables
k – Threshold (output 1 if at least k variables are 1)
- Returns:
LTF parameters for threshold function