boofun.core.errormodels

Error models for Boolean function analysis.

This module provides various error models for handling uncertainty, noise, and approximation in Boolean function computations.

Functions

create_error_model(model_type, **kwargs)

Factory function to create error models.

Classes

ErrorModel()

Abstract base class for all error models.

ExactErrorModel()

Exact error model - no errors or uncertainty.

LinearErrorModel()

Linear error propagation model using uncertainties library.

NoiseErrorModel([noise_rate, random_seed])

Noise error model for handling bit-flip and measurement errors.

PACErrorModel([epsilon, delta])

PAC (Probably Approximately Correct) error model.

class boofun.core.errormodels.ErrorModel[source]

Abstract base class for all error models.

abstractmethod apply_error(result: Any) Any[source]

Apply error model to a computation result.

Parameters:

result – The original computation result

Returns:

Result with error model applied

abstractmethod get_confidence(result: Any) float[source]

Get confidence level for a result.

Parameters:

result – Computation result

Returns:

Confidence level between 0 and 1

abstractmethod is_reliable(result: Any) bool[source]

Check if result meets reliability threshold.

Parameters:

result – Computation result

Returns:

True if result is considered reliable

class boofun.core.errormodels.ExactErrorModel[source]

Exact error model - no errors or uncertainty.

This model assumes perfect computation with no noise or approximation.

apply_error(result: Any) Any[source]

Return result unchanged.

get_confidence(result: Any) float[source]

Always return maximum confidence.

is_reliable(result: Any) bool[source]

Always reliable for exact computations.

class boofun.core.errormodels.PACErrorModel(epsilon: float = 0.1, delta: float = 0.1)[source]

PAC (Probably Approximately Correct) error model.

Provides probabilistic guarantees with specified error and confidence bounds.

__init__(epsilon: float = 0.1, delta: float = 0.1)[source]

Initialize PAC error model.

Parameters:
  • epsilon – Approximation error bound (0 < epsilon < 1)

  • delta – Confidence failure probability (0 < delta < 1)

apply_error(result: Any) Dict[str, Any][source]

Apply PAC bounds to result.

Returns:

Dictionary with result and PAC bounds

get_confidence(result: Any) float[source]

Return PAC confidence level.

is_reliable(result: Any) bool[source]

Check if confidence meets threshold (>= 0.9).

combine_pac_bounds(error1: PACErrorModel, error2: PACErrorModel, operation: str) PACErrorModel[source]

Combine PAC learning error bounds for two results.

Parameters:
  • error1 – PAC error models to combine

  • error2 – PAC error models to combine

  • operation – Type of operation (‘addition’, ‘multiplication’, etc.)

Returns:

Combined PAC error model

class boofun.core.errormodels.NoiseErrorModel(noise_rate: float = 0.01, random_seed: int | None = None)[source]

Noise error model for handling bit-flip and measurement errors.

Simulates realistic noise in Boolean function evaluation and analysis.

__init__(noise_rate: float = 0.01, random_seed: int | None = None)[source]

Initialize noise error model.

Parameters:
  • noise_rate – Probability of bit flip (0 <= noise_rate <= 0.5)

  • random_seed – Random seed for reproducible noise

apply_error(result: bool | ndarray) bool | ndarray[source]

Apply bit-flip noise to Boolean results.

Parameters:

result – Boolean result(s)

Returns:

Result(s) with noise applied

get_confidence(result: Any) float[source]

Return confidence based on noise level.

is_reliable(result: Any) bool[source]

Check if noise level allows reliable results.

class boofun.core.errormodels.LinearErrorModel[source]

Linear error propagation model using uncertainties library.

Provides automatic differentiation-based error propagation.

__init__()[source]

Initialize linear error model.

apply_error(result: Any, std_dev: float = 0.01) Any[source]

Apply linear error propagation.

Parameters:
  • result – Computation result

  • std_dev – Standard deviation of error

Returns:

Result with uncertainty information

propagate_binary_op(left_error: Any, right_error: Any, operation: callable) Any[source]

Automatic error propagation for binary operations.

Parameters:
  • left_error – Left operand with uncertainty

  • right_error – Right operand with uncertainty

  • operation – Operation function

Returns:

Result with propagated uncertainty

get_confidence(result: Any) float[source]

Return confidence based on relative error.

is_reliable(result: Any) bool[source]

Check if relative error is acceptable.

boofun.core.errormodels.create_error_model(model_type: str, **kwargs) ErrorModel[source]

Factory function to create error models.

Parameters:
  • model_type – Type of error model (‘exact’, ‘pac’, ‘noise’, ‘linear’)

  • **kwargs – Model-specific parameters

Returns:

Configured error model