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_majority_ltf(n_vars)

Create LTF for majority function.

create_threshold_ltf(n_vars, k)

Create LTF for k-threshold function.

is_ltf(truth_table, n_vars)

Check if a Boolean function can be represented as an LTF.

Classes

LTFParameters(weights, threshold, n_vars)

Parameters for a Linear Threshold Function.

LTFRepresentation()

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:

numpy.ndarray

threshold

Threshold value

Type:

float

n_vars

Number of variables

Type:

int

weights: ndarray
threshold: float
n_vars: int
evaluate(x: List[int] | ndarray) bool[source]

Evaluate LTF at given input.

Parameters:

x – Binary input vector

Returns:

Boolean output

to_dict() Dict[str, Any][source]

Export LTF parameters to dictionary.

classmethod from_dict(data: Dict[str, Any]) LTFParameters[source]

Create LTF parameters from dictionary.

__init__(weights: ndarray, threshold: float, n_vars: int) None
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)

dump(data: LTFParameters, space=None, **kwargs) Dict[str, Any][source]

Export LTF representation.

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).

time_complexity_rank(n_vars: int) Dict[str, int][source]

Return time complexity for LTF operations.

get_storage_requirements(n_vars: int) Dict[str, int][source]

Return storage requirements for LTF representation.

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