Skip to content

Builders

anfis_toolbox.builders.ANFISBuilder

ANFISBuilder()

Builder class for creating ANFIS models with intuitive API.

add_input

add_input(
    name: str,
    range_min: float,
    range_max: float,
    n_mfs: int = 3,
    mf_type: str = "gaussian",
    overlap: float = 0.5,
) -> ANFISBuilder

Add an input variable with automatic membership function generation.

Parameters:

Name Type Description Default
name str

Name of the input variable

required
range_min float

Minimum value of the input range

required
range_max float

Maximum value of the input range

required
n_mfs int

Number of membership functions (default: 3)

3
mf_type str

Type of membership functions. Supported: 'gaussian', 'gaussian2', 'triangular', 'trapezoidal', 'bell', 'sigmoidal', 'sshape', 'zshape', 'pi'

'gaussian'
overlap float

Overlap factor between adjacent MFs (0.0 to 1.0)

0.5

Returns:

Type Description
ANFISBuilder

Self for method chaining

add_input_from_data

add_input_from_data(
    name: str,
    data: ArrayLike,
    n_mfs: int = 3,
    mf_type: str = "gaussian",
    overlap: float = 0.5,
    margin: float = 0.1,
    init: str | None = "grid",
    random_state: RandomStateLike = None,
) -> ANFISBuilder

Add an input inferring range_min/range_max from data with a margin.

Parameters:

Name Type Description Default
name str

Input name

required
data ArrayLike

1D array-like samples for this input

required
n_mfs int

Number of membership functions

3
mf_type str

Membership function type (see add_input)

'gaussian'
overlap float

Overlap factor between adjacent MFs

0.5
margin float

Fraction of (max-min) to pad on each side

0.1
init str | None

Initialization strategy: "grid" (default), "fcm", "random", or None. When "fcm", clusters from the data determine MF centers and widths (supports 'gaussian' and 'bell').

'grid'
random_state RandomStateLike

Optional seed for deterministic FCM initialization.

None

build

build() -> TSKANFIS

Build the ANFIS model with configured parameters.

set_rules

set_rules(
    rules: Sequence[Sequence[int]] | None,
) -> ANFISBuilder

Define an explicit set of fuzzy rules to use when building the model.

Parameters:

Name Type Description Default
rules Sequence[Sequence[int]] | None

Iterable of rules where each rule lists the membership index per input. None removes any previously configured custom rules and restores the default Cartesian-product behaviour.

required

Returns:

Type Description
ANFISBuilder

Self for method chaining.