Skip to content

Estimators

sklearn-compatible TSK estimator wrappers.

All public estimator classes are re-exported from their respective sub-modules.

ADATSKClassifier

Bases: _BaseClassifierEstimator

TSK classifier with adaptive softmin antecedent (ADATSK).

The firing strength of each rule is computed with the Ada-softmin operator.

Reference

G. Xue, Q. Chang, J. Wang, K. Zhang and N. R. Pal, "An Adaptive Neuro-Fuzzy System With Integrated Feature Selection and Rule Extraction for High-Dimensional Classification Problems," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 7, pp. 2167-2181, July 2023, doi: 10.1109/TFUZZ.2022.3220950.

Example
from highfis import ADATSKClassifier

clf = ADATSKClassifier(n_mfs=30, random_state=0)
clf.fit(X_train, y_train)

Initialise an ADATSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of MFs per feature (default 3).

3
mf_init str

MF initialization strategy (default "grid" for paper-style evenly spaced centers). Other options: "kmeans", "minibatch_kmeans", "fcm".

'grid'
sigma_scale float | str

Sigma scale factor used by clustering initializers. In paper-strict mode, Gaussian sigmas are reset to 1 and frozen.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

Rule-base strategy. Default "coco" to match the paper.

'coco'
batch_size int | None

Mini-batch size. Default None (full-batch GD).

None
shuffle bool

Whether to reshuffle each epoch. Default False.

False
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience. Default None (disabled).

None
restore_best bool

Restore best validation weights. Default False.

False
weight_decay float

L2 weight decay for consequent parameters. Default 0.0.

0.0
freeze_antecedent_in_high_dim bool

If True (default), freeze antecedent parameters when n_features >= high_dim_threshold.

True
high_dim_threshold int

Feature-count threshold used to trigger antecedent freezing (default 1000).

1000
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_adaptive.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = False,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = None,
    restore_best: bool = False,
    weight_decay: float = 0.0,
    freeze_antecedent_in_high_dim: bool = True,
    high_dim_threshold: int = 1000,
    device: str = "cpu",
) -> None:
    """Initialise an ADATSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of MFs per feature (default ``3``).
        mf_init: MF initialization strategy (default ``"grid"`` for paper-style
            evenly spaced centers). Other options: ``"kmeans"``,
            ``"minibatch_kmeans"``, ``"fcm"``.
        sigma_scale: Sigma scale factor used by clustering initializers.
            In paper-strict mode, Gaussian sigmas are reset to ``1`` and frozen.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: Rule-base strategy. Default ``"coco"`` to match the paper.
        batch_size: Mini-batch size. Default ``None`` (full-batch GD).
        shuffle: Whether to reshuffle each epoch. Default ``False``.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience. Default ``None`` (disabled).
        restore_best: Restore best validation weights. Default ``False``.
        weight_decay: L2 weight decay for consequent parameters. Default ``0.0``.
        freeze_antecedent_in_high_dim: If ``True`` (default), freeze
            antecedent parameters when ``n_features >= high_dim_threshold``.
        high_dim_threshold: Feature-count threshold used to trigger
            antecedent freezing (default ``1000``).
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    resolved_n_mfs = n_mfs
    resolved_mf_init = mf_init
    resolved_sigma_scale = sigma_scale
    resolved_rule_base = rule_base
    resolved_epochs = epochs
    resolved_learning_rate = learning_rate
    resolved_batch_size = batch_size

    super().__init__(
        input_configs=input_configs,
        n_mfs=resolved_n_mfs,
        mf_init=resolved_mf_init,
        sigma_scale=resolved_sigma_scale,
        random_state=random_state,
        epochs=resolved_epochs,
        learning_rate=resolved_learning_rate,
        verbose=verbose,
        rule_base=resolved_rule_base,
        batch_size=resolved_batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.freeze_antecedent_in_high_dim = freeze_antecedent_in_high_dim
    self.high_dim_threshold = high_dim_threshold

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Fit the ADATSK classifier estimator.

Source code in highfis/estimators/_adaptive.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> ADATSKClassifier:
    """Fit the ADATSK classifier estimator."""
    return cast(ADATSKClassifier, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

ADATSKRegressor

Bases: _BaseRegressorEstimator

TSK regressor with adaptive softmin antecedent (ADATSK).

The firing strength of each rule is computed with the Ada-softmin operator.

Reference

G. Xue, Q. Chang, J. Wang, K. Zhang and N. R. Pal, "An Adaptive Neuro-Fuzzy System With Integrated Feature Selection and Rule Extraction for High-Dimensional Classification Problems," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 7, pp. 2167-2181, July 2023, doi: 10.1109/TFUZZ.2022.3220950.

Example
from highfis import ADATSKRegressor

reg = ADATSKRegressor(n_mfs=30, random_state=0)
reg.fit(X_train, y_train)

Initialise an ADATSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of MFs per feature (default 3).

3
mf_init str

MF initialization strategy (default "grid").

'grid'
sigma_scale float | str

Sigma scale factor used by clustering initializers. In paper-style mode, Gaussian sigmas are reset to 1 and frozen.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

Rule-base strategy. Default "coco".

'coco'
batch_size int | None

Mini-batch size. Default None (full-batch GD).

None
shuffle bool

Whether to reshuffle each epoch. Default False.

False
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience. Default None (disabled).

None
restore_best bool

Restore best validation weights. Default False.

False
weight_decay float

L2 weight decay for consequent parameters. Default 0.0.

0.0
freeze_antecedent_in_high_dim bool

If True (default), freeze antecedent parameters when n_features >= high_dim_threshold.

True
high_dim_threshold int

Feature-count threshold used to trigger antecedent freezing (default 1000).

1000
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_adaptive.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = False,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = None,
    restore_best: bool = False,
    weight_decay: float = 0.0,
    freeze_antecedent_in_high_dim: bool = True,
    high_dim_threshold: int = 1000,
    device: str = "cpu",
) -> None:
    """Initialise an ADATSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of MFs per feature (default ``3``).
        mf_init: MF initialization strategy (default ``"grid"``).
        sigma_scale: Sigma scale factor used by clustering initializers.
            In paper-style mode, Gaussian sigmas are reset to ``1`` and frozen.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: Rule-base strategy. Default ``"coco"``.
        batch_size: Mini-batch size. Default ``None`` (full-batch GD).
        shuffle: Whether to reshuffle each epoch. Default ``False``.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience. Default ``None`` (disabled).
        restore_best: Restore best validation weights. Default ``False``.
        weight_decay: L2 weight decay for consequent parameters. Default ``0.0``.
        freeze_antecedent_in_high_dim: If ``True`` (default), freeze
            antecedent parameters when ``n_features >= high_dim_threshold``.
        high_dim_threshold: Feature-count threshold used to trigger
            antecedent freezing (default ``1000``).
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.freeze_antecedent_in_high_dim = freeze_antecedent_in_high_dim
    self.high_dim_threshold = high_dim_threshold

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

ADMTSKClassifier

Bases: _BaseClassifierEstimator

ADMTSK classifier estimator with Composite GMF and adaptive Dombi lambda.

ADMTSK is an adaptive Dombi TSK fuzzy system designed for high-dimensional inference. It combines a Dombi T-norm antecedent with a positive lower-bound Composite Gaussian membership function (CGMF) and normalized first-order consequents.

Reference

G. Xue, L. Hu, J. Wang and S. Ablameyko, "ADMTSK: A High-Dimensional Takagi-Sugeno-Kang Fuzzy System Based on Adaptive Dombi T-Norm," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 6, pp. 1767-1780, June 2025, doi: 10.1109/TFUZZ.2025.3535640.

Example
from highfis import ADMTSKClassifier

clf = ADMTSKClassifier()
clf.fit(X_train, y_train)

Initialize an ADMTSK classifier estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of per-feature input configurations.

None
n_mfs int

Number of membership functions per input when using mf_init="kmeans", "minibatch_kmeans", or "grid".

3
mf_init str

Initialisation strategy for MFs: "kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'grid'
sigma_scale float | str

Scale factor used to initialise Gaussian MF sigma values.

1.0
random_state int | None

Random seed for MF initialisation and weights.

None
epochs int

Maximum number of training epochs.

50
learning_rate float

Learning rate for the optimizer.

0.01
verbose bool | int

Verbosity level for training output.

False
rule_base str | None

Rule base strategy override, typically "coco" or "cartesian".

'coco'
batch_size int | None

Mini-batch size for training.

None
shuffle bool

Whether to shuffle training data each epoch.

True
ur_weight float

Uniform-rule regularisation weight.

0.0
ur_target float | None

Target average rule activation for uniform regularisation.

None
consequent_batch_norm bool

If True, apply batch normalization to consequent inputs.

False
pfrb_max_rules int | None

Maximum number of rules for point-based FRB.

None
patience int | None

Early stopping patience. Use None to disable.

20
restore_best bool

If True, restore the best validation weights.

True
weight_decay float

Weight decay applied during training.

0.0
adaptive bool

If True, use adaptive lambda selection for Dombi T-norm.

True
lambda_ float

Fixed Dombi parameter when adaptive is False.

1.0
lower_bound float

Lower bound used by Composite GMF.

1.0 / math.e
k float

Heuristic constant used to compute adaptive lambda.

10.0
zero_consequent_init bool

If True (default), initialize consequent parameters to zero.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'

Raises:

Type Description
ValueError

If estimator hyperparameters are invalid.

Source code in highfis/estimators/_dombi.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 50,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    adaptive: bool = True,
    lambda_: float = 1.0,
    lower_bound: float = 1.0 / math.e,
    k: float = 10.0,
    zero_consequent_init: bool = True,
    device: str = "cpu",
) -> None:
    """Initialize an ADMTSK classifier estimator.

    Args:
        input_configs: Optional list of per-feature input configurations.
        n_mfs: Number of membership functions per input when using
            ``mf_init="kmeans"``, ``"minibatch_kmeans"``, or ``"grid"``.
        mf_init: Initialisation strategy for MFs: ``"kmeans"`` (default),
            ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Scale factor used to initialise Gaussian MF sigma
            values.
        random_state: Random seed for MF initialisation and weights.
        epochs: Maximum number of training epochs.
        learning_rate: Learning rate for the optimizer.
        verbose: Verbosity level for training output.
        rule_base: Rule base strategy override, typically ``"coco"`` or
            ``"cartesian"``.
        batch_size: Mini-batch size for training.
        shuffle: Whether to shuffle training data each epoch.
        ur_weight: Uniform-rule regularisation weight.
        ur_target: Target average rule activation for uniform regularisation.
        consequent_batch_norm: If True, apply batch normalization to
            consequent inputs.
        pfrb_max_rules: Maximum number of rules for point-based FRB.
        patience: Early stopping patience. Use ``None`` to disable.
        restore_best: If True, restore the best validation weights.
        weight_decay: Weight decay applied during training.
        adaptive: If True, use adaptive lambda selection for Dombi T-norm.
        lambda_: Fixed Dombi parameter when adaptive is False.
        lower_bound: Lower bound used by Composite GMF.
        k: Heuristic constant used to compute adaptive lambda.
        zero_consequent_init: If True (default), initialize
            consequent parameters to zero.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).

    Raises:
        ValueError: If estimator hyperparameters are invalid.
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.adaptive = adaptive
    self.lambda_ = lambda_
    self.lower_bound = lower_bound
    self.k = k
    self.zero_consequent_init = zero_consequent_init

__sklearn_is_fitted__

Check fitted status via model_ only, ignoring lambda_ (trailing underscore).

Source code in highfis/estimators/_dombi.py
def __sklearn_is_fitted__(self) -> bool:
    """Check fitted status via model_ only, ignoring lambda_ (trailing underscore)."""
    return hasattr(self, "model_")

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

ADMTSKRegressor

Bases: _BaseRegressorEstimator

ADMTSK regressor estimator with Composite GMF and adaptive Dombi lambda.

ADMTSK is an adaptive Dombi TSK fuzzy system designed for high-dimensional inference. It combines a Dombi T-norm antecedent with a positive lower-bound Composite Gaussian membership function (CGMF) and normalized first-order consequents.

Reference

G. Xue, L. Hu, J. Wang and S. Ablameyko, "ADMTSK: A High-Dimensional Takagi-Sugeno-Kang Fuzzy System Based on Adaptive Dombi T-Norm," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 6, pp. 1767-1780, June 2025, doi: 10.1109/TFUZZ.2025.3535640.

Example
from highfis import ADMTSKRegressor

reg = ADMTSKRegressor()
reg.fit(X_train, y_train)

Initialize an ADMTSK regressor estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of per-feature input configurations.

None
n_mfs int

Number of membership functions per input when using mf_init="kmeans", "minibatch_kmeans", or "grid".

3
mf_init str

Initialisation strategy for MFs: "kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'grid'
sigma_scale float | str

Scale factor used to initialise Gaussian MF sigma values.

1.0
random_state int | None

Random seed for MF initialisation and weights.

None
epochs int

Maximum number of training epochs.

50
learning_rate float

Learning rate for the optimizer.

0.01
verbose bool | int

Verbosity level for training output.

False
rule_base str | None

Rule base strategy override, typically "coco" or "cartesian".

'coco'
batch_size int | None

Mini-batch size for training.

None
shuffle bool

Whether to shuffle training data each epoch.

True
ur_weight float

Uniform-rule regularisation weight.

0.0
ur_target float | None

Target average rule activation for uniform regularisation.

None
consequent_batch_norm bool

If True, apply batch normalization to consequent inputs.

False
patience int | None

Early stopping patience. Use None to disable.

20
restore_best bool

If True, restore the best validation weights.

True
weight_decay float

Weight decay applied during training.

0.0
adaptive bool

If True, use adaptive lambda selection for Dombi T-norm.

True
lambda_ float

Fixed Dombi parameter when adaptive is False.

1.0
lower_bound float

Lower bound used by Composite GMF.

1.0 / math.e
k float

Heuristic constant used to compute adaptive lambda.

10.0
zero_consequent_init bool

If True (default), initialize consequent parameters to zero.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'

Raises:

Type Description
ValueError

If estimator hyperparameters are invalid.

Source code in highfis/estimators/_dombi.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 50,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    adaptive: bool = True,
    lambda_: float = 1.0,
    lower_bound: float = 1.0 / math.e,
    k: float = 10.0,
    zero_consequent_init: bool = True,
    device: str = "cpu",
) -> None:
    """Initialize an ADMTSK regressor estimator.

    Args:
        input_configs: Optional list of per-feature input configurations.
        n_mfs: Number of membership functions per input when using
            ``mf_init="kmeans"``, ``"minibatch_kmeans"``, or ``"grid"``.
        mf_init: Initialisation strategy for MFs: ``"kmeans"`` (default),
            ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Scale factor used to initialise Gaussian MF sigma
            values.
        random_state: Random seed for MF initialisation and weights.
        epochs: Maximum number of training epochs.
        learning_rate: Learning rate for the optimizer.
        verbose: Verbosity level for training output.
        rule_base: Rule base strategy override, typically ``"coco"`` or
            ``"cartesian"``.
        batch_size: Mini-batch size for training.
        shuffle: Whether to shuffle training data each epoch.
        ur_weight: Uniform-rule regularisation weight.
        ur_target: Target average rule activation for uniform regularisation.
        consequent_batch_norm: If True, apply batch normalization to
            consequent inputs.
        patience: Early stopping patience. Use ``None`` to disable.
        restore_best: If True, restore the best validation weights.
        weight_decay: Weight decay applied during training.
        adaptive: If True, use adaptive lambda selection for Dombi T-norm.
        lambda_: Fixed Dombi parameter when adaptive is False.
        lower_bound: Lower bound used by Composite GMF.
        k: Heuristic constant used to compute adaptive lambda.
        zero_consequent_init: If True (default), initialize
            consequent parameters to zero.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).

    Raises:
        ValueError: If estimator hyperparameters are invalid.
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.adaptive = adaptive
    self.lambda_ = lambda_
    self.lower_bound = lower_bound
    self.k = k
    self.zero_consequent_init = zero_consequent_init

__sklearn_is_fitted__

Check fitted status via model_ only, ignoring lambda_ (trailing underscore).

Source code in highfis/estimators/_dombi.py
def __sklearn_is_fitted__(self) -> bool:
    """Check fitted status via model_ only, ignoring lambda_ (trailing underscore)."""
    return hasattr(self, "model_")

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

ADPTSKClassifier

Bases: _BaseClassifierEstimator

TSK classifier with ADP-softmin antecedent and Gaussian PIMF.

The firing strengths of each rule are computed with the ADP-softmin operator, and membership functions are wrapped as Gaussian PIMFs to preserve a positive infimum during high-dimensional training.

Reference

Ma, M., Qian, L., Zhang, Y., Fang, Q., & Xue, G. (2025). An adaptive double-parameter softmin based Takagi-Sugeno-Kang fuzzy system for high-dimensional data. Fuzzy Sets and Systems, 521, 109582. https://doi.org/10.1016/j.fss.2025.109582

Example
from highfis import ADPTSKClassifier

clf = ADPTSKClassifier()
clf.fit(X_train, y_train)

Initialise an ADPTSK classifier estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of :class:InputConfig instances, one per feature. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of membership functions per feature or k-means clusters.

3
mf_init str

Membership-function initialization strategy. Defaults to "grid" to match the paper's fixed antecedent initialization.

'grid'
sigma_scale float | str

Scale factor for Gaussian MF sigma initialization.

1.0
random_state int | None

Seed for k-means and PyTorch weight initialization.

None
epochs int

Maximum number of training epochs (default 200).

200
learning_rate float

Initial learning rate for the Adam optimizer (default 0.001).

0.001
verbose bool | int

Verbosity level for training output.

False
rule_base str | None

Rule-base strategy (default "coco").

'coco'
batch_size int | None

Mini-batch size. None uses paper-style dynamic defaults: full-batch for N < 500 and 20% of samples for N >= 500.

None
shuffle bool

Whether to shuffle training samples each epoch.

True
ur_weight float

Uniform-rule regularization weight.

0.0
ur_target float | None

Target average rule activation for UR.

None
consequent_batch_norm bool

Apply batch normalization to consequent linear layers.

False
pfrb_max_rules int | None

Maximum rules for point-based FRB when rule_base="pfrb".

None
patience int | None

Early-stopping patience. None disables early stopping.

20
restore_best bool

Restore the best validation model weights after training. stopping.

True
weight_decay float

L2 weight decay coefficient for consequent parameters.

0.0
kappa float

ADPTSK κ parameter controlling the double-softmin geometry.

690.0
xi float

ADPTSK ξ parameter controlling adaptive softmin sharpness.

700.0
k float

Gaussian PIMF scaling constant used when wrapping the input MFs.

1.0
eps float | None

Optional lower bound for Gaussian PIMF values.

None
zero_consequent_init bool

If True (default), initialize consequent parameters to zeros.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_adaptive.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 200,
    learning_rate: float = 1e-3,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    kappa: float = 690.0,
    xi: float = 700.0,
    k: float = 1.0,
    eps: float | None = None,
    zero_consequent_init: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise an ADPTSK classifier estimator.

    Args:
        input_configs: Optional list of :class:`InputConfig` instances,
            one per feature. Only ``name`` is used when
            ``mf_init="kmeans"``.
        n_mfs: Number of membership functions per feature or k-means
            clusters.
        mf_init: Membership-function initialization strategy.
            Defaults to ``"grid"`` to match the paper's fixed
            antecedent initialization.
        sigma_scale: Scale factor for Gaussian MF sigma initialization.
        random_state: Seed for k-means and PyTorch weight initialization.
        epochs: Maximum number of training epochs (default ``200``).
        learning_rate: Initial learning rate for the Adam optimizer
            (default ``0.001``).
        verbose: Verbosity level for training output.
        rule_base: Rule-base strategy (default ``"coco"``).
        batch_size: Mini-batch size. ``None`` uses paper-style dynamic
            defaults: full-batch for ``N < 500`` and ``20%`` of samples
            for ``N >= 500``.
        shuffle: Whether to shuffle training samples each epoch.
        ur_weight: Uniform-rule regularization weight.
        ur_target: Target average rule activation for UR.
        consequent_batch_norm: Apply batch normalization to consequent
            linear layers.
        pfrb_max_rules: Maximum rules for point-based FRB when
            ``rule_base="pfrb"``.
        patience: Early-stopping patience. ``None`` disables early stopping.
        restore_best: Restore the best validation model weights after
            training.
            stopping.
        weight_decay: L2 weight decay coefficient for consequent parameters.
        kappa: ADPTSK ``κ`` parameter controlling the double-softmin
            geometry.
        xi: ADPTSK ``ξ`` parameter controlling adaptive softmin sharpness.
        k: Gaussian PIMF scaling constant used when wrapping the input MFs.
        eps: Optional lower bound for Gaussian PIMF values.
        zero_consequent_init: If ``True`` (default), initialize
            consequent parameters to zeros.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.kappa = kappa
    self.xi = xi
    self.k = k
    self.eps = eps
    self.zero_consequent_init = zero_consequent_init

__sklearn_tags__

Mark as poor_score: ADPTSK uses kappa=690 designed for high-dimensional data.

Source code in highfis/estimators/_adaptive.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: ADPTSK uses kappa=690 designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.classifier_tags.poor_score = True
    return tags

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities, replacing NaNs with uniform probabilities.

ADPTSK uses parameters designed for high-dimensional data which can be unstable on low-dimensional datasets, causing NaNs.

Source code in highfis/estimators/_adaptive.py
def predict_proba(self, x: Any) -> np.ndarray:
    """Predict class probabilities, replacing NaNs with uniform probabilities.

    ADPTSK uses parameters designed for high-dimensional data which can
    be unstable on low-dimensional datasets, causing NaNs.
    """
    result = super().predict_proba(x)
    if np.any(np.isnan(result)):
        n_classes = self.classes_.shape[0] if hasattr(self, "classes_") else 2
        nan_rows = np.any(np.isnan(result), axis=1)
        result[nan_rows] = 1.0 / n_classes
        result = np.nan_to_num(result, nan=1.0 / n_classes, posinf=1.0 / n_classes, neginf=1.0 / n_classes)
    return result

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

ADPTSKRegressor

Bases: _BaseRegressorEstimator

TSK regressor with ADP-softmin antecedent and Gaussian PIMF.

The firing strengths of each rule are computed with the ADP-softmin operator, and membership functions are wrapped as Gaussian PIMFs to preserve a positive infimum during high-dimensional training.

Reference

Ma, M., Qian, L., Zhang, Y., Fang, Q., & Xue, G. (2025). An adaptive double-parameter softmin based Takagi-Sugeno-Kang fuzzy system for high-dimensional data. Fuzzy Sets and Systems, 521, 109582. https://doi.org/10.1016/j.fss.2025.109582

Example
from highfis import ADPTSKRegressor

reg = ADPTSKRegressor()
reg.fit(X_train, y_train)

Initialise an ADPTSK regressor estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of :class:InputConfig instances, one per feature. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of membership functions per feature or k-means clusters.

3
mf_init str

Membership-function initialization strategy. Defaults to "grid" to match the paper's fixed antecedent initialization.

'grid'
sigma_scale float | str

Scale factor for Gaussian MF sigma initialization.

1.0
random_state int | None

Seed for k-means and PyTorch weight initialization.

None
epochs int

Maximum number of training epochs (default 200).

200
learning_rate float

Initial learning rate for the Adam optimizer (default 0.001).

0.001
verbose bool | int

Verbosity level for training output.

False
rule_base str | None

Rule-base strategy (default "coco").

'coco'
batch_size int | None

Mini-batch size. None uses paper-style dynamic defaults: full-batch for N < 500 and 20% of samples for N >= 500.

None
shuffle bool

Whether to shuffle training samples each epoch.

True
ur_weight float

Uniform-rule regularization weight.

0.0
ur_target float | None

Target average rule activation for UR.

None
consequent_batch_norm bool

Apply batch normalization to consequent linear layers.

False
pfrb_max_rules int | None

Maximum rules for point-based FRB when rule_base="pfrb".

None
patience int | None

Early-stopping patience. None disables early stopping.

20
restore_best bool

Restore the best validation model weights after training. stopping.

True
weight_decay float

L2 weight decay coefficient for consequent parameters.

0.0
kappa float

ADPTSK κ parameter controlling the double-softmin geometry.

690.0
xi float

ADPTSK ξ parameter controlling adaptive softmin sharpness.

700.0
k float

Gaussian PIMF scaling constant used when wrapping the input MFs.

1.0
eps float | None

Optional lower bound for Gaussian PIMF values.

None
zero_consequent_init bool

If True (default), initialize consequent parameters to zeros.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_adaptive.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 200,
    learning_rate: float = 1e-3,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    kappa: float = 690.0,
    xi: float = 700.0,
    k: float = 1.0,
    eps: float | None = None,
    zero_consequent_init: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise an ADPTSK regressor estimator.

    Args:
        input_configs: Optional list of :class:`InputConfig` instances,
            one per feature. Only ``name`` is used when
            ``mf_init="kmeans"``.
        n_mfs: Number of membership functions per feature or k-means
            clusters.
        mf_init: Membership-function initialization strategy.
            Defaults to ``"grid"`` to match the paper's fixed
            antecedent initialization.
        sigma_scale: Scale factor for Gaussian MF sigma initialization.
        random_state: Seed for k-means and PyTorch weight initialization.
        epochs: Maximum number of training epochs (default ``200``).
        learning_rate: Initial learning rate for the Adam optimizer
            (default ``0.001``).
        verbose: Verbosity level for training output.
        rule_base: Rule-base strategy (default ``"coco"``).
        batch_size: Mini-batch size. ``None`` uses paper-style dynamic
            defaults: full-batch for ``N < 500`` and ``20%`` of samples
            for ``N >= 500``.
        shuffle: Whether to shuffle training samples each epoch.
        ur_weight: Uniform-rule regularization weight.
        ur_target: Target average rule activation for UR.
        consequent_batch_norm: Apply batch normalization to consequent
            linear layers.
        pfrb_max_rules: Maximum rules for point-based FRB when
            ``rule_base="pfrb"``.
        patience: Early-stopping patience. ``None`` disables early stopping.
        restore_best: Restore the best validation model weights after
            training.
            stopping.
        weight_decay: L2 weight decay coefficient for consequent parameters.
        kappa: ADPTSK ``κ`` parameter controlling the double-softmin
            geometry.
        xi: ADPTSK ``ξ`` parameter controlling adaptive softmin sharpness.
        k: Gaussian PIMF scaling constant used when wrapping the input MFs.
        eps: Optional lower bound for Gaussian PIMF values.
        zero_consequent_init: If ``True`` (default), initialize
            consequent parameters to zeros.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.kappa = kappa
    self.xi = xi
    self.k = k
    self.eps = eps
    self.zero_consequent_init = zero_consequent_init

__sklearn_tags__

Mark as poor_score: ADPTSK uses kappa=690 designed for high-dimensional data.

Source code in highfis/estimators/_adaptive.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: ADPTSK uses kappa=690 designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.regressor_tags.poor_score = True
    return tags

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict, replacing NaN with zeros to guard against training instability.

ADPTSK uses kappa=690/xi=700 tuned for high-dimensional data. On sklearn's low-dimensional test sets the model may produce NaN due to gradient instability during the ADP-softmin backward pass. Since poor_score=True is set, this guard does not affect real-world high-dimensional use cases.

Source code in highfis/estimators/_adaptive.py
def predict(self, x: Any) -> np.ndarray:
    """Predict, replacing NaN with zeros to guard against training instability.

    ADPTSK uses kappa=690/xi=700 tuned for high-dimensional data. On
    sklearn's low-dimensional test sets the model may produce NaN due
    to gradient instability during the ADP-softmin backward pass.
    Since ``poor_score=True`` is set, this guard does not affect
    real-world high-dimensional use cases.
    """
    result = super().predict(x)
    if np.any(np.isnan(result)):
        result = np.nan_to_num(result, nan=0.0, posinf=0.0, neginf=0.0)
    return result

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

AYATSKClassifier

Bases: _BaseClassifierEstimator

TSK classifier with an adaptive Yager T-norm in the antecedent.

AYATSK extends TSK by using an adaptive Yager T-norm aggregation and optional positive lower-bound membership functions to improve stability and performance in high-dimensional settings.

Reference

G. Xue, Y. Yang and J. Wang, "Adaptive Yager T-Norm-Based Takagi-Sugeno-Kang Fuzzy Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 55, no. 12, pp. 9802-9815, Dec. 2025, doi: 10.1109/TSMC.2025.3621346.

Example
from highfis import AYATSKClassifier

clf = AYATSKClassifier(n_mfs=30, random_state=0)
clf.fit(X_train, y_train)

Initialise an AYATSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init falls back to clustering.

None
n_mfs int

Number of fuzzy sets per feature (default 3).

3
mf_init str

Membership-function initialization strategy. Defaults to "grid" for the paper-style CEMF initialization.

'grid'
sigma_scale float | str

Sigma scale factor for non-default initialisation.

1.0
random_state int | None

Seed for clustering and weight initialisation.

None
epochs int

Maximum training epochs (default 200).

200
learning_rate float

Adam learning rate (default 0.001).

0.001
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

Rule-base strategy. Defaults to "coco".

'coco'
batch_size int | None

Mini-batch size. None applies the paper policy: full-batch when N < 500 and 0.1 * N otherwise.

None
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum point-based FRB rules (unused by AYATSK).

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

0.0
k float

CEMF lower-bound control parameter. Must be > 1.

10.0
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_yager.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 200,
    learning_rate: float = 1e-3,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    k: float = 10.0,
    device: str = "cpu",
) -> None:
    """Initialise an AYATSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init`` falls back to clustering.
        n_mfs: Number of fuzzy sets per feature (default ``3``).
        mf_init: Membership-function initialization strategy.  Defaults
            to ``"grid"`` for the paper-style CEMF initialization.
        sigma_scale: Sigma scale factor for non-default initialisation.
        random_state: Seed for clustering and weight initialisation.
        epochs: Maximum training epochs (default ``200``).
        learning_rate: Adam learning rate (default ``0.001``).
        verbose: Print per-epoch progress.
        rule_base: Rule-base strategy. Defaults to ``"coco"``.
        batch_size: Mini-batch size. ``None`` applies the paper policy:
            full-batch when ``N < 500`` and ``0.1 * N`` otherwise.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum point-based FRB rules (unused by
            AYATSK).
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        k: CEMF lower-bound control parameter. Must be ``> 1``.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.k = k

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

AYATSKRegressor

Bases: _BaseRegressorEstimator

TSK regressor with an adaptive Yager T-norm in the antecedent.

AYATSK extends TSK by using an adaptive Yager T-norm aggregation and optional positive lower-bound membership functions to improve stability and performance in high-dimensional settings.

Reference

G. Xue, Y. Yang and J. Wang, "Adaptive Yager T-Norm-Based Takagi-Sugeno-Kang Fuzzy Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 55, no. 12, pp. 9802-9815, Dec. 2025, doi: 10.1109/TSMC.2025.3621346.

Example
from highfis import AYATSKRegressor

reg = AYATSKRegressor(n_mfs=30, random_state=0)
reg.fit(X_train, y_train)

Initialise an AYATSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init falls back to clustering.

None
n_mfs int

Number of fuzzy sets per feature (default 3).

3
mf_init str

Membership-function initialization strategy. Defaults to "grid" for the paper-style CEMF initialization.

'grid'
sigma_scale float | str

Sigma scale factor for non-default initialisation.

1.0
random_state int | None

Seed for clustering and weight initialisation.

None
epochs int

Maximum training epochs (default 200).

200
learning_rate float

Adam learning rate (default 0.001).

0.001
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

Rule-base strategy. Defaults to "coco".

'coco'
batch_size int | None

Mini-batch size. None applies the paper policy: full-batch when N < 500 and 0.1 * N otherwise.

None
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

0.0
k float

CEMF lower-bound control parameter. Must be > 1.

10.0
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_yager.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "grid",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 200,
    learning_rate: float = 1e-3,
    verbose: bool | int = False,
    rule_base: str | None = "coco",
    batch_size: int | None = None,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 0.0,
    k: float = 10.0,
    device: str = "cpu",
) -> None:
    """Initialise an AYATSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init`` falls back to clustering.
        n_mfs: Number of fuzzy sets per feature (default ``3``).
        mf_init: Membership-function initialization strategy.  Defaults
            to ``"grid"`` for the paper-style CEMF initialization.
        sigma_scale: Sigma scale factor for non-default initialisation.
        random_state: Seed for clustering and weight initialisation.
        epochs: Maximum training epochs (default ``200``).
        learning_rate: Adam learning rate (default ``0.001``).
        verbose: Print per-epoch progress.
        rule_base: Rule-base strategy. Defaults to ``"coco"``.
        batch_size: Mini-batch size. ``None`` applies the paper policy:
            full-batch when ``N < 500`` and ``0.1 * N`` otherwise.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        k: CEMF lower-bound control parameter. Must be ``> 1``.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.k = k

__sklearn_tags__

Mark as poor_score: AYATSK is designed for high-dimensional data.

Source code in highfis/estimators/_yager.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: AYATSK is designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.regressor_tags.poor_score = True
    return tags

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

DGALETSKClassifier

Bases: FSREADATSKClassifier

DG-ALETSK classifier with ALE-softmin antecedent and double-group gates.

DG-ALETSK extends FSRE-ADATSK by replacing the adaptive softmin with the Adaptive Ln-Exp (ALE) softmin — a smoother variant with improved numerical stability. It also uses a zero-order consequent in the DG (data-guided) training phase and optionally converts to first-order after gate-based pruning. Training follows the three-phase DG protocol:

  1. DG phase — Train gate parameters, antecedent MFs, and zero-order consequents (CoCo-FRB; antecedents are not frozen unlike DG-TSK).
  2. Threshold search — Grid-search for the pruning thresholds (zeta_lambda, zeta_theta) that maximise held-out accuracy.
  3. Fine-tune phase — Train first-order consequents with antecedent MFs and feature gates frozen.
Reference

G. Xue, J. Wang, B. Yuan and C. Dai, "DG-ALETSK: A High-Dimensional Fuzzy Approach With Simultaneous Feature Selection and Rule Extraction," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 11, pp. 3866-3880, Nov. 2023, doi: 10.1109/TFUZZ.2023.3270445.

Example
from highfis import DGALETSKClassifier

clf = DGALETSKClassifier(n_mfs=30, random_state=0)
clf.fit(X_train, y_train, x_val=X_val, y_val=y_val)

Initialise a DG-ALETSK classifier.

Parameters:

Name Type Description Default
lambda_init float

Accepted for API compatibility (not used by DG-ALETSK; see :class:FSREADATSKClassifier).

1.0
use_en_frb bool

If True, use the Enhanced FRB (En-FRB).

False
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
dg_epochs int

Maximum epochs for phase 1 (DG training).

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tune). Default 50 follows the DG-ALETSK paper setup.

50
learning_rate float

Adam learning rate for both phases.

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco", "cartesian", or "pfrb". Default "pfrb" follows the paper workflow.

'pfrb'
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum number of point-based FRB rules when rule_base='pfrb'. If None (default), uses paper-style automatic cap: 100 rules (or 50 when D >= 10000).

None
patience int | None

Early-stopping patience. None disables.

20
restore_best bool

Restore best validation weights after fine-tuning.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda list[float] | None

Grid of λ-pruning threshold candidates. Default follows the paper: [0.05, 0.1, 0.15, 0.2, 0.25, 0.3].

None
zeta_theta list[float] | None

Grid of θ-pruning threshold candidates. Default follows the paper: [0.05, 0.1, 0.15, 0.2, 0.25, 0.3].

None
use_lse bool

Refit first-order consequents via LSE during threshold search. Default False for the classification path.

False
trainer BaseTrainer | None

Optional custom :class:~highfis.optim.BaseTrainer. When None (default) a :class:~highfis.optim.DGTrainer is built from this estimator's hyperparameters.

None
optimizer_type str

Optimizer type. "sgd" (default, paper) or "adamw".

'sgd'
structural_pruning bool

If True (default), apply hard structural pruning after threshold search.

True
freeze_antecedents_finetune bool

If True (default), freeze MF parameters and feature gates during fine-tuning.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dg_aletsk.py
def __init__(
    self,
    *,
    lambda_init: float = 1.0,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    dg_epochs: int = 100,
    finetune_epochs: int = 50,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "pfrb",
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: list[float] | None = None,
    zeta_theta: list[float] | None = None,
    use_lse: bool = False,
    trainer: BaseTrainer | None = None,
    optimizer_type: str = "sgd",
    structural_pruning: bool = True,
    freeze_antecedents_finetune: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise a DG-ALETSK classifier.

    Args:
        lambda_init: Accepted for API compatibility (not used by
            DG-ALETSK; see :class:`FSREADATSKClassifier`).
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB).
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``,
            or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        dg_epochs: Maximum epochs for phase 1 (DG training).
        finetune_epochs: Maximum epochs for phase 3 (fine-tune).
            Default ``50`` follows the DG-ALETSK paper setup.
        learning_rate: Adam learning rate for both phases.
        verbose: Print per-epoch progress.
        rule_base: ``"coco"``, ``"cartesian"``, or ``"pfrb"``.
            Default ``"pfrb"`` follows the paper workflow.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum number of point-based FRB rules when
            ``rule_base='pfrb'``. If ``None`` (default), uses
            paper-style automatic cap: ``100`` rules (or ``50`` when
            ``D >= 10000``).
        patience: Early-stopping patience.  ``None`` disables.
        restore_best: Restore best validation weights after fine-tuning.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Grid of λ-pruning threshold candidates. Default
            follows the paper: ``[0.05, 0.1, 0.15, 0.2, 0.25, 0.3]``.
        zeta_theta: Grid of θ-pruning threshold candidates. Default
            follows the paper: ``[0.05, 0.1, 0.15, 0.2, 0.25, 0.3]``.
        use_lse: Refit first-order consequents via LSE during threshold
            search. Default ``False`` for the classification path.
        trainer: Optional custom :class:`~highfis.optim.BaseTrainer`.
            When ``None`` (default) a :class:`~highfis.optim.DGTrainer`
            is built from this estimator's hyperparameters.
        optimizer_type: Optimizer type.  ``"sgd"`` (default, paper) or
            ``"adamw"``.
        structural_pruning: If ``True`` (default), apply hard structural
            pruning after threshold search.
        freeze_antecedents_finetune: If ``True`` (default), freeze MF
            parameters and feature gates during fine-tuning.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        lambda_init=lambda_init,
        use_en_frb=use_en_frb,
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        fs_epochs=dg_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        trainer=trainer,
        device=device,
    )
    self.dg_epochs = dg_epochs
    self.use_lse = use_lse
    self.optimizer_type = optimizer_type
    self.freeze_antecedents_finetune = freeze_antecedents_finetune
    self.finetune_epochs = finetune_epochs
    self.structural_pruning = structural_pruning
    self.zeta_lambda: list[float] | None = zeta_lambda
    self.zeta_theta: list[float] | None = zeta_theta
    self.pfrb_max_rules = pfrb_max_rules

__sklearn_tags__

Mark as poor_score: FSRE-ADATSK is designed for high-dimensional feature selection.

Source code in highfis/estimators/_fsre.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: FSRE-ADATSK is designed for high-dimensional feature selection."""
    tags = super().__sklearn_tags__()
    tags.classifier_tags.poor_score = True
    return tags

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the DG-ALETSK classifier.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_dg_aletsk.py
def fit(
    self,
    x: Any,
    y: Any,
    *,
    x_val: Any | None = None,
    y_val: Any | None = None,
    metrics: list[str] | None = None,
) -> DGALETSKClassifier:
    """Train the DG-ALETSK classifier.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    return cast(DGALETSKClassifier, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities, applying structural feature selection.

When structural pruning was applied during fit(), the original feature matrix is automatically sliced to the surviving features before being passed to the pruned model.

Parameters:

Name Type Description Default
x Any

Input array of shape (N, n_features_in_).

required

Returns:

Type Description
np.ndarray

Class probability array of shape (N, n_classes).

Source code in highfis/estimators/_fsre.py
def predict_proba(self, x: Any) -> np.ndarray:
    """Predict class probabilities, applying structural feature selection.

    When structural pruning was applied during fit(), the original
    feature matrix is automatically sliced to the surviving features before
    being passed to the pruned model.

    Args:
        x: Input array of shape ``(N, n_features_in_)``.

    Returns:
        Class probability array of shape ``(N, n_classes)``.
    """
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    history = getattr(self, "history_", None) or {}
    sf: list[int] | None = history.get("surviving_feature_indices")
    if sf is None and "threshold" in history:
        sf = history["threshold"].get("surviving_feature_indices")
    x_m = x_arr[:, sf] if sf is not None and cast(Any, self.model_).n_inputs < x_arr.shape[1] else x_arr
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_m, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

DGALETSKRegressor

Bases: FSREADATSKRegressor

DG-ALETSK regressor with ALE-softmin antecedent and double-group gates.

DG-ALETSK extends FSRE-ADATSK by replacing the adaptive softmin with the Adaptive Ln-Exp (ALE) softmin — a smoother variant with improved numerical stability. It also uses a zero-order consequent in the DG (data-guided) training phase and optionally converts to first-order after gate-based pruning. Training follows the three-phase DG protocol.

Reference

G. Xue, J. Wang, B. Yuan and C. Dai, "DG-ALETSK: A High-Dimensional Fuzzy Approach With Simultaneous Feature Selection and Rule Extraction," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 11, pp. 3866-3880, Nov. 2023, doi: 10.1109/TFUZZ.2023.3270445.

Example
from highfis import DGALETSKRegressor

reg = DGALETSKRegressor(n_mfs=30, random_state=0)
reg.fit(X_train, y_train, x_val=X_val, y_val=y_val)

Initialise a DG-ALETSK regressor.

Parameters:

Name Type Description Default
lambda_init float

Accepted for API compatibility (not used by DG-ALETSK; see :class:FSREADATSKRegressor).

1.0
use_en_frb bool

If True, use the Enhanced FRB (En-FRB).

False
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
dg_epochs int

Maximum epochs for phase 1 (DG training).

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tune).

200
learning_rate float

Adam learning rate for both phases.

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience. None disables.

20
restore_best bool

Restore best validation weights after fine-tuning.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda list[float] | None

Grid of λ-pruning threshold candidates.

None
zeta_theta list[float] | None

Grid of θ-pruning threshold candidates.

None
use_lse bool

Refit first-order consequents via LSE during threshold search (default True).

True
trainer BaseTrainer | None

Optional custom :class:~highfis.optim.BaseTrainer. When None (default) a :class:~highfis.optim.DGTrainer is built from this estimator's hyperparameters.

None
optimizer_type str

Optimizer type. "sgd" (default, paper) or "adamw".

'sgd'
structural_pruning bool

If True (default), apply hard structural pruning after threshold search.

True
freeze_antecedents_finetune bool

If True (default), freeze MF parameters and feature gates during fine-tuning.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dg_aletsk.py
def __init__(
    self,
    *,
    lambda_init: float = 1.0,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    dg_epochs: int = 100,
    finetune_epochs: int = 200,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: list[float] | None = None,
    zeta_theta: list[float] | None = None,
    use_lse: bool = True,
    trainer: BaseTrainer | None = None,
    optimizer_type: str = "sgd",
    structural_pruning: bool = True,
    freeze_antecedents_finetune: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise a DG-ALETSK regressor.

    Args:
        lambda_init: Accepted for API compatibility (not used by
            DG-ALETSK; see :class:`FSREADATSKRegressor`).
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB).
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``,
            or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        dg_epochs: Maximum epochs for phase 1 (DG training).
        finetune_epochs: Maximum epochs for phase 3 (fine-tune).
        learning_rate: Adam learning rate for both phases.
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience.  ``None`` disables.
        restore_best: Restore best validation weights after fine-tuning.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Grid of λ-pruning threshold candidates.
        zeta_theta: Grid of θ-pruning threshold candidates.
        use_lse: Refit first-order consequents via LSE during threshold
            search (default ``True``).
        trainer: Optional custom :class:`~highfis.optim.BaseTrainer`.
            When ``None`` (default) a :class:`~highfis.optim.DGTrainer`
            is built from this estimator's hyperparameters.
        optimizer_type: Optimizer type.  ``"sgd"`` (default, paper) or
            ``"adamw"``.
        structural_pruning: If ``True`` (default), apply hard structural
            pruning after threshold search.
        freeze_antecedents_finetune: If ``True`` (default), freeze MF
            parameters and feature gates during fine-tuning.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        lambda_init=lambda_init,
        use_en_frb=use_en_frb,
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        fs_epochs=dg_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        trainer=trainer,
        device=device,
    )
    self.dg_epochs = dg_epochs
    self.use_lse = use_lse
    self.optimizer_type = optimizer_type
    self.freeze_antecedents_finetune = freeze_antecedents_finetune
    self.finetune_epochs = finetune_epochs
    self.structural_pruning = structural_pruning
    self.zeta_lambda: list[float] | None = zeta_lambda
    self.zeta_theta: list[float] | None = zeta_theta

__sklearn_tags__

Mark as poor_score: DG-ALETSK is designed for high-dimensional data.

Source code in highfis/estimators/_dg_aletsk.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: DG-ALETSK is designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.regressor_tags.poor_score = True
    return tags

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the DG-ALETSK regressor.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_dg_aletsk.py
def fit(
    self,
    x: Any,
    y: Any,
    *,
    x_val: Any | None = None,
    y_val: Any | None = None,
    metrics: list[str] | None = None,
) -> DGALETSKRegressor:
    """Train the DG-ALETSK regressor.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    return cast(DGALETSKRegressor, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous targets, applying structural feature selection.

When structural pruning was applied during fit(), the original feature matrix is automatically sliced to the surviving features before being passed to the pruned model.

Parameters:

Name Type Description Default
x Any

Input array of shape (N, n_features_in_).

required

Returns:

Type Description
np.ndarray

Prediction array of shape (N,).

Source code in highfis/estimators/_fsre.py
def predict(self, x: Any) -> np.ndarray:
    """Predict continuous targets, applying structural feature selection.

    When structural pruning was applied during fit(), the original
    feature matrix is automatically sliced to the surviving features before
    being passed to the pruned model.

    Args:
        x: Input array of shape ``(N, n_features_in_)``.

    Returns:
        Prediction array of shape ``(N,)``.
    """
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    history = getattr(self, "history_", None) or {}
    sf: list[int] | None = history.get("surviving_feature_indices")
    if sf is None and "threshold" in history:
        sf = history["threshold"].get("surviving_feature_indices")
    x_m = x_arr[:, sf] if sf is not None and cast(Any, self.model_).n_inputs < x_arr.shape[1] else x_arr
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_m, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

DGTSKClassifier

Bases: _BaseClassifierEstimator

DG-TSK classifier with M-gate antecedent and point-based FRB (P-FRB).

DG-TSK uses a data-guided M-gate function to automatically select relevant features and rules. Training follows the DG + threshold + fine-tune pipeline from Xue et al. (2023):

  1. DG phase — Train gate parameters and zero-order consequents with antecedent MFs frozen (P-FRB).
  2. Threshold search — Grid-search for the pruning thresholds (zeta_lambda, zeta_theta) that maximise held-out accuracy.
  3. Fine-tune phase — Train first-order consequents on the pruned structure.
Reference

Guangdong Xue, Jian Wang, Bingjie Zhang, Bin Yuan, Caili Dai, Double groups of gates based Takagi-Sugeno-Kang (DG-TSK) fuzzy system for simultaneous feature selection and rule extraction, Fuzzy Sets and Systems, Volume 469, 2023, 108627, ISSN 0165-0114, https://doi.org/10.1016/j.fss.2023.108627.

Example
from highfis import DGTSKClassifier

clf = DGTSKClassifier(n_mfs=30, rule_base="pfrb", random_state=0)
clf.fit(X_train, y_train, x_val=X_val, y_val=y_val)

Initialise a DG-TSK classifier.

Parameters:

Name Type Description Default
use_en_frb bool

If True, use the Enhanced FRB (En-FRB) for rule extraction (P-FRB). Default False keeps CoCo-FRB.

False
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
dg_epochs int

Maximum epochs for phase 1 (DG training). Default 10 matches the paper's experimental setting.

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tune). Default 200.

200
learning_rate float

Adam learning rate for both phase 1 and phase 3.

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco", "cartesian", or "pfrb". Defaults to "pfrb" for the paper-strict DG-TSK path, which initialises one rule per training sample.

'pfrb'
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum number of point-based FRB rules when rule_base='pfrb'. Defaults to 300 to match the paper's experimental cap.

300
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda list[float] | None

Grid of λ-pruning threshold candidates. None uses paper default [0.5].

None
zeta_theta list[float] | None

Grid of θ-pruning threshold candidates. None uses paper default [0.01].

None
use_lse bool

Refit first-order consequents via LSE during threshold search. Defaults to False for the paper-faithful classification path.

False
trainer BaseTrainer | None

Optional custom :class:~highfis.optim.BaseTrainer. When None (default) a :class:~highfis.optim.DGTrainer is built from this estimator's hyperparameters. Pass a :class:~highfis.optim.GradientTrainer to use single-phase training instead.

None
optimizer_type str

Optimizer type. "sgd" (default, paper) or "adamw".

'sgd'
structural_pruning bool

If True (default), apply hard structural pruning after threshold search.

True
freeze_antecedents_finetune bool

If True, freeze MF parameters and feature gates during fine-tuning. Defaults to False to optimize antecedents and consequents in fine-tuning.

False
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dg_tsk.py
def __init__(
    self,
    *,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    dg_epochs: int = 100,
    finetune_epochs: int = 200,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "pfrb",
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = 300,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: list[float] | None = None,
    zeta_theta: list[float] | None = None,
    use_lse: bool = False,
    trainer: BaseTrainer | None = None,
    optimizer_type: str = "sgd",
    structural_pruning: bool = True,
    freeze_antecedents_finetune: bool = False,
    device: str = "cpu",
) -> None:
    """Initialise a DG-TSK classifier.

    Args:
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB) for rule
            extraction (P-FRB). Default ``False`` keeps CoCo-FRB.
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        dg_epochs: Maximum epochs for phase 1 (DG training).  Default
            ``10`` matches the paper's experimental setting.
        finetune_epochs: Maximum epochs for phase 3 (fine-tune).
            Default ``200``.
        learning_rate: Adam learning rate for both phase 1 and phase 3.
        verbose: Print per-epoch progress.
        rule_base: ``"coco"``, ``"cartesian"``, or ``"pfrb"``.  Defaults
            to ``"pfrb"`` for the paper-strict DG-TSK path, which
            initialises one rule per training sample.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum number of point-based FRB rules when
            ``rule_base='pfrb'``. Defaults to ``300`` to match the
            paper's experimental cap.
        patience: Early-stopping patience (default ``20``). Set to
            ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Grid of λ-pruning threshold candidates.  ``None``
            uses paper default ``[0.5]``.
        zeta_theta: Grid of θ-pruning threshold candidates.  ``None``
            uses paper default ``[0.01]``.
        use_lse: Refit first-order consequents via LSE during threshold
            search.  Defaults to ``False`` for the paper-faithful
            classification path.
        trainer: Optional custom :class:`~highfis.optim.BaseTrainer`.
            When ``None`` (default) a :class:`~highfis.optim.DGTrainer`
            is built from this estimator's hyperparameters.  Pass a
            :class:`~highfis.optim.GradientTrainer` to use single-phase
            training instead.
        optimizer_type: Optimizer type.  ``"sgd"`` (default, paper) or
            ``"adamw"``.
        structural_pruning: If ``True`` (default), apply hard structural
            pruning after threshold search.
        freeze_antecedents_finetune: If ``True``, freeze MF parameters
            and feature gates during fine-tuning. Defaults to ``False``
            to optimize antecedents and consequents in fine-tuning.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    self.use_en_frb = use_en_frb
    self.dg_epochs = dg_epochs
    self.finetune_epochs = finetune_epochs
    self.zeta_lambda = zeta_lambda
    self.zeta_theta = zeta_theta
    self.use_lse = use_lse
    self.optimizer_type = optimizer_type
    self.structural_pruning = structural_pruning
    self.freeze_antecedents_finetune = freeze_antecedents_finetune
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=dg_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        device=device,
        trainer=trainer,
    )

__sklearn_tags__

Mark as poor_score: DG-TSK is designed for high-dimensional data.

Source code in highfis/estimators/_dg_tsk.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: DG-TSK is designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.classifier_tags.poor_score = True
    return tags

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the DG-TSK classifier.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_dg_tsk.py
def fit(
    self,
    x: Any,
    y: Any,
    *,
    x_val: Any | None = None,
    y_val: Any | None = None,
    metrics: list[str] | None = None,
) -> DGTSKClassifier:
    """Train the DG-TSK classifier.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    return cast(DGTSKClassifier, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted DGTSKClassifier, restoring first-order architecture.

Source code in highfis/estimators/_dg_tsk.py
@classmethod
def load(cls, path: str) -> DGTSKClassifier:
    """Load a persisted DGTSKClassifier, restoring first-order architecture."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]
    estimator.model_ = estimator._build_model(
        deserialize_input_mfs(model_init["input_mfs_config"]),
        int(model_init["n_classes"]),
        str(model_init["rule_base"]),
        rules=model_init.get("rules"),
    )
    if model_init.get("is_first_order", False):  # pragma: no branch
        cast(FirstOrderModelProtocol, estimator.model_).convert_to_first_order()
        mode = model_init.get("consequent_mode")
        if isinstance(mode, str) and hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = mode  # type: ignore[attr-defined]
    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    from sklearn.preprocessing import LabelEncoder

    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities, applying any surviving-feature pruning from fit().

Source code in highfis/estimators/_dg_tsk.py
def predict_proba(self, x: Any) -> np.ndarray:
    """Predict class probabilities, applying any surviving-feature pruning from fit()."""
    from sklearn.utils.validation import check_is_fitted

    check_is_fitted(self, "model_")
    from sklearn.utils.validation import validate_data

    x_arr = validate_data(self, x, reset=False)
    x_model = _select_dgtsking_surviving_features(self, x_arr)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_model, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator including first-order architecture flag.

Source code in highfis/estimators/_dg_tsk.py
def save(self, path: str) -> None:
    """Persist estimator including first-order architecture flag."""
    from sklearn.utils.validation import check_is_fitted

    check_is_fitted(self, "model_")
    is_first_order = not isinstance(
        self.model_.consequent_layer,  # type: ignore[attr-defined]
        GatedClassificationZeroOrderConsequentLayer,
    )
    consequent_mode = (
        str(self.model_.consequent_layer.mode)  # type: ignore[attr-defined]
        if is_first_order and hasattr(self.model_.consequent_layer, "mode")  # type: ignore[attr-defined]
        else None
    )
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),  # type: ignore[attr-defined]
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "is_first_order": is_first_order,
            "consequent_mode": consequent_mode,
            "rules": rules,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

DGTSKRegressor

Bases: _BaseRegressorEstimator

DG-TSK regressor with M-gate antecedent and point-based FRB (P-FRB).

DG-TSK uses a data-guided M-gate function to automatically select relevant features and rules. Training follows the three-phase protocol from Xue et al. (2023).

Reference

Guangdong Xue, Jian Wang, Bingjie Zhang, Bin Yuan, Caili Dai, Double groups of gates based Takagi-Sugeno-Kang (DG-TSK) fuzzy system for simultaneous feature selection and rule extraction, Fuzzy Sets and Systems, Volume 469, 2023, 108627, ISSN 0165-0114, https://doi.org/10.1016/j.fss.2023.108627.

Example
from highfis import DGTSKRegressor

reg = DGTSKRegressor(n_mfs=30, rule_base="pfrb", random_state=0)
reg.fit(X_train, y_train, x_val=X_val, y_val=y_val)

Initialise a DG-TSK regressor.

Parameters:

Name Type Description Default
use_en_frb bool

If True, use the Enhanced FRB (En-FRB) for rule extraction (P-FRB). Default False keeps CoCo-FRB.

False
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
dg_epochs int

Maximum epochs for phase 1 (DG training). Default 10 matches the paper's experimental setting.

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tune). Default 200.

200
learning_rate float

Adam learning rate for both phase 1 and phase 3.

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco", "cartesian", or "pfrb". Defaults to "pfrb" for the paper-strict DG-TSK regressor path.

'pfrb'
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum number of point-based FRB rules when rule_base='pfrb'. None uses all training samples.

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda list[float] | None

Grid of λ-pruning threshold candidates.

None
zeta_theta list[float] | None

Grid of θ-pruning threshold candidates.

None
use_lse bool

Refit first-order consequents via LSE during threshold search. Recommended (default True).

True
trainer BaseTrainer | None

Optional custom :class:~highfis.optim.BaseTrainer. When None (default) a :class:~highfis.optim.DGTrainer is built from this estimator's hyperparameters.

None
optimizer_type str

Optimizer type. "sgd" (default, paper) or "adamw".

'sgd'
structural_pruning bool

If True (default), apply hard structural pruning after threshold search.

True
freeze_antecedents_finetune bool

If True (default), freeze MF parameters and feature gates during fine-tuning.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dg_tsk.py
def __init__(
    self,
    *,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    dg_epochs: int = 100,
    finetune_epochs: int = 200,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = "pfrb",
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: list[float] | None = None,
    zeta_theta: list[float] | None = None,
    use_lse: bool = True,
    trainer: BaseTrainer | None = None,
    optimizer_type: str = "sgd",
    structural_pruning: bool = True,
    freeze_antecedents_finetune: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise a DG-TSK regressor.

    Args:
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB) for rule
            extraction (P-FRB). Default ``False`` keeps CoCo-FRB.
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        dg_epochs: Maximum epochs for phase 1 (DG training).  Default
            ``10`` matches the paper's experimental setting.
        finetune_epochs: Maximum epochs for phase 3 (fine-tune).
            Default ``200``.
        learning_rate: Adam learning rate for both phase 1 and phase 3.
        verbose: Print per-epoch progress.
        rule_base: ``"coco"``, ``"cartesian"``, or ``"pfrb"``.  Defaults
            to ``"pfrb"`` for the paper-strict DG-TSK regressor path.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum number of point-based FRB rules when
            ``rule_base='pfrb'``. ``None`` uses all training samples.
        patience: Early-stopping patience (default ``20``). Set to
            ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Grid of λ-pruning threshold candidates.
        zeta_theta: Grid of θ-pruning threshold candidates.
        use_lse: Refit first-order consequents via LSE during threshold
            search.  Recommended (default ``True``).
        trainer: Optional custom :class:`~highfis.optim.BaseTrainer`.
            When ``None`` (default) a :class:`~highfis.optim.DGTrainer`
            is built from this estimator's hyperparameters.
        optimizer_type: Optimizer type.  ``"sgd"`` (default, paper) or
            ``"adamw"``.
        structural_pruning: If ``True`` (default), apply hard structural
            pruning after threshold search.
        freeze_antecedents_finetune: If ``True`` (default), freeze MF
            parameters and feature gates during fine-tuning.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    self.use_en_frb = use_en_frb
    self.dg_epochs = dg_epochs
    self.finetune_epochs = finetune_epochs
    self.zeta_lambda = zeta_lambda
    self.zeta_theta = zeta_theta
    self.use_lse = use_lse
    self.optimizer_type = optimizer_type
    self.structural_pruning = structural_pruning
    self.freeze_antecedents_finetune = freeze_antecedents_finetune
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=dg_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
        trainer=trainer,
    )

__sklearn_tags__

Mark as poor_score: DG-TSK is designed for high-dimensional data.

Source code in highfis/estimators/_dg_tsk.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: DG-TSK is designed for high-dimensional data."""
    tags = super().__sklearn_tags__()
    tags.regressor_tags.poor_score = True
    return tags

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted DGTSKRegressor, restoring first-order architecture.

Source code in highfis/estimators/_dg_tsk.py
@classmethod
def load(cls, path: str) -> DGTSKRegressor:
    """Load a persisted DGTSKRegressor, restoring first-order architecture."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]
    estimator.model_ = estimator._build_regressor_model(
        deserialize_input_mfs(model_init["input_mfs_config"]),
        str(model_init["rule_base"]),
        rules=model_init.get("rules"),
    )
    if model_init.get("is_first_order", False):  # pragma: no branch
        cast(FirstOrderModelProtocol, estimator.model_).convert_to_first_order()
        mode = model_init.get("consequent_mode")
        if isinstance(mode, str) and hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = mode  # type: ignore[attr-defined]
    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict regression values, applying any surviving-feature pruning from fit().

Source code in highfis/estimators/_dg_tsk.py
def predict(self, x: Any) -> np.ndarray:
    """Predict regression values, applying any surviving-feature pruning from fit()."""
    from sklearn.utils.validation import check_is_fitted, validate_data

    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    x_model = _select_dgtsking_surviving_features(self, x_arr)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_model, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator including first-order architecture flag.

Source code in highfis/estimators/_dg_tsk.py
def save(self, path: str) -> None:
    """Persist estimator including first-order architecture flag."""
    from sklearn.utils.validation import check_is_fitted

    check_is_fitted(self, "model_")
    is_first_order = not isinstance(
        self.model_.consequent_layer,  # type: ignore[attr-defined]
        GatedRegressionZeroOrderConsequentLayer,
    )
    consequent_mode = (
        str(self.model_.consequent_layer.mode)  # type: ignore[attr-defined]
        if is_first_order and hasattr(self.model_.consequent_layer, "mode")  # type: ignore[attr-defined]
        else None
    )
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),  # type: ignore[attr-defined]
            "rule_base": self.rule_base_,
            "is_first_order": is_first_order,
            "consequent_mode": consequent_mode,
            "rules": rules,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

DombiTSKClassifier

Bases: _BaseClassifierEstimator

TSK classifier with a fixed Dombi T-norm in the antecedent.

DombiTSK extends TSK fuzzy inference by using a Dombi t-norm aggregation in antecedent evaluation while keeping first-order linear consequents.

Reference

G. Xue, L. Hu, J. Wang and S. Ablameyko, "ADMTSK: A High-Dimensional Takagi-Sugeno-Kang Fuzzy System Based on Adaptive Dombi T-Norm," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 6, pp. 1767-1780, June 2025, doi: 10.1109/TFUZZ.2025.3535640.

Example
from highfis import DombiTSKClassifier

clf = DombiTSKClassifier(n_mfs=30, random_state=0)
clf.fit(X_train, y_train)

Initialise a DombiTSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended; the Dombi T-norm handles high-dimensional stability without inflating sigma.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum point-based FRB rules (unused by DombiTSK).

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
lambda_ float

Dombi parameter λ > 0.

1.0
lower_bound float

Lower bound for Composite GMF.

1.0 / math.e
zero_consequent_init bool

If True (default), initialize consequent parameters to zero.

True
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dombi.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    lambda_: float = 1.0,
    lower_bound: float = 1.0 / math.e,
    zero_consequent_init: bool = True,
    device: str = "cpu",
) -> None:
    """Initialise a DombiTSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended; the Dombi
            T-norm handles high-dimensional stability without inflating
            sigma.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum point-based FRB rules (unused by
            DombiTSK).
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        lambda_: Dombi parameter ``λ > 0``.
        lower_bound: Lower bound for Composite GMF.
        zero_consequent_init: If ``True`` (default), initialize consequent parameters to zero.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.lambda_ = lambda_
    self.lower_bound = lower_bound
    self.zero_consequent_init = zero_consequent_init

__sklearn_is_fitted__

Check fitted status via model_ only, ignoring lambda_ (trailing underscore).

Source code in highfis/estimators/_dombi.py
def __sklearn_is_fitted__(self) -> bool:
    """Check fitted status via model_ only, ignoring lambda_ (trailing underscore)."""
    return hasattr(self, "model_")

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

DombiTSKRegressor

Bases: _BaseRegressorEstimator

TSK regressor with a fixed Dombi T-norm in the antecedent.

DombiTSK extends TSK fuzzy inference by using a Dombi t-norm aggregation in antecedent evaluation while keeping first-order linear consequents.

Reference

G. Xue, L. Hu, J. Wang and S. Ablameyko, "ADMTSK: A High-Dimensional Takagi-Sugeno-Kang Fuzzy System Based on Adaptive Dombi T-Norm," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 6, pp. 1767-1780, June 2025, doi: 10.1109/TFUZZ.2025.3535640.

Example
from highfis import DombiTSKRegressor

reg = DombiTSKRegressor(n_mfs=30, random_state=0)
reg.fit(X_train, y_train)

Initialise a DombiTSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_dombi.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise a DombiTSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

FSREADATSKClassifier

Bases: _BaseClassifierEstimator

FSRE-ADATSK classifier with adaptive softmin antecedent and gated consequents.

FSRE-ADATSK (Feature Selection and Rule Extraction) extends ADATSK.

Reference

G. Xue, Q. Chang, J. Wang, K. Zhang and N. R. Pal, "An Adaptive Neuro-Fuzzy System With Integrated Feature Selection and Rule Extraction for High-Dimensional Classification Problems," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 7, pp. 2167-2181, July 2023, doi: 10.1109/TFUZZ.2022.3220950.

Example
from highfis import FSREADATSKClassifier

clf = FSREADATSKClassifier()
clf.fit(X_train, y_train)

Initialise an FSRE-ADATSK classifier.

Parameters:

Name Type Description Default
lambda_init float

Accepted for API compatibility but not used by FSRE-ADATSK or DG-ALETSK. FSRE-ADATSK computes its adaptive softmin index directly from membership values; DG-ALETSK uses the fixed exponent ξ = 700 per paper eq. 22. Default 1.0.

1.0
use_en_frb bool

If True, use the Enhanced FRB (En-FRB) whose size grows linearly with the number of features, allowing more candidate rules for the RE phase. Xue et al. (2023) activate En-FRB after the FS phase; set False (default) to keep the compact CoCo-FRB.

False
input_configs list[InputConfig] | None

Per-feature InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
fs_epochs int

Maximum epochs for phase 1 (FS training). Default 10.

100
re_epochs int

Maximum epochs for phase 2 (RE training). Default 10.

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tuning). Default 100.

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda float

Feature-selection threshold coefficient (paper eq. 28). Larger values retain more features. Default 0.5.

0.5
zeta_theta float

Rule-extraction threshold coefficient (paper eq. 29). Larger values retain more rules. Default 0.3.

0.3
structural_pruning bool

If True (default), hard-prune the model architecture after each threshold step.

True
trainer BaseTrainer | None

Optional custom BaseTrainer. When None (default) an FSRETrainer is built automatically from this estimator's hyperparameters.

None
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'

Raises:

Type Description
ValueError

If lambda_init <= 0.

Source code in highfis/estimators/_fsre.py
def __init__(
    self,
    *,
    lambda_init: float = 1.0,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    fs_epochs: int = 100,
    re_epochs: int = 100,
    finetune_epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: float = 0.5,
    zeta_theta: float = 0.3,
    structural_pruning: bool = True,
    trainer: BaseTrainer | None = None,
    device: str = "cpu",
) -> None:
    """Initialise an FSRE-ADATSK classifier.

    Args:
        lambda_init: Accepted for API compatibility but not used by
            FSRE-ADATSK or DG-ALETSK.  FSRE-ADATSK computes its
            adaptive softmin index directly from membership values;
            DG-ALETSK uses the fixed exponent ``ξ = 700`` per
            paper eq. 22.  Default ``1.0``.
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB) whose
            size grows linearly with the number of features, allowing
            more candidate rules for the RE phase. Xue et al. (2023)
            activate En-FRB after the FS phase; set ``False`` (default)
            to keep the compact CoCo-FRB.
        input_configs: Per-feature InputConfig list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for k-means and weight initialisation.
        fs_epochs: Maximum epochs for phase 1 (FS training). Default ``10``.
        re_epochs: Maximum epochs for phase 2 (RE training). Default ``10``.
        finetune_epochs: Maximum epochs for phase 3 (fine-tuning). Default ``100``.
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Feature-selection threshold coefficient (paper eq. 28).
            Larger values retain more features.  Default ``0.5``.
        zeta_theta: Rule-extraction threshold coefficient (paper eq. 29).
            Larger values retain more rules.  Default ``0.3``.
        structural_pruning: If ``True`` (default), hard-prune the model
            architecture after each threshold step.
        trainer: Optional custom BaseTrainer.
            When ``None`` (default) an FSRETrainer is built automatically
            from this estimator's hyperparameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).

    Raises:
        ValueError: If ``lambda_init <= 0``.
    """
    self.lambda_init = lambda_init
    self.use_en_frb = use_en_frb
    self.fs_epochs = fs_epochs
    self.re_epochs = re_epochs
    self.finetune_epochs = finetune_epochs
    self.zeta_lambda = zeta_lambda
    self.zeta_theta = zeta_theta
    self.structural_pruning = structural_pruning

    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=fs_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
        trainer=trainer,
    )

__sklearn_tags__

Mark as poor_score: FSRE-ADATSK is designed for high-dimensional feature selection.

Source code in highfis/estimators/_fsre.py
def __sklearn_tags__(self) -> Any:
    """Mark as poor_score: FSRE-ADATSK is designed for high-dimensional feature selection."""
    tags = super().__sklearn_tags__()
    tags.classifier_tags.poor_score = True
    return tags

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Fit the FSRE-ADATSK classifier estimator, checking lambda_init.

Source code in highfis/estimators/_fsre.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> FSREADATSKClassifier:
    """Fit the FSRE-ADATSK classifier estimator, checking lambda_init."""
    if self.lambda_init is not None and self.lambda_init <= 0.0:
        raise ValueError("lambda_init must be > 0")
    return cast(FSREADATSKClassifier, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities, applying structural feature selection.

When structural pruning was applied during fit(), the original feature matrix is automatically sliced to the surviving features before being passed to the pruned model.

Parameters:

Name Type Description Default
x Any

Input array of shape (N, n_features_in_).

required

Returns:

Type Description
np.ndarray

Class probability array of shape (N, n_classes).

Source code in highfis/estimators/_fsre.py
def predict_proba(self, x: Any) -> np.ndarray:
    """Predict class probabilities, applying structural feature selection.

    When structural pruning was applied during fit(), the original
    feature matrix is automatically sliced to the surviving features before
    being passed to the pruned model.

    Args:
        x: Input array of shape ``(N, n_features_in_)``.

    Returns:
        Class probability array of shape ``(N, n_classes)``.
    """
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    history = getattr(self, "history_", None) or {}
    sf: list[int] | None = history.get("surviving_feature_indices")
    if sf is None and "threshold" in history:
        sf = history["threshold"].get("surviving_feature_indices")
    x_m = x_arr[:, sf] if sf is not None and cast(Any, self.model_).n_inputs < x_arr.shape[1] else x_arr
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_m, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

FSREADATSKRegressor

Bases: _BaseRegressorEstimator

FSRE-ADATSK regressor with adaptive softmin antecedent and gated consequents.

FSRE-ADATSK (Feature Selection and Rule Extraction) extends ADATSK.

Reference

G. Xue, Q. Chang, J. Wang, K. Zhang and N. R. Pal, "An Adaptive Neuro-Fuzzy System With Integrated Feature Selection and Rule Extraction for High-Dimensional Classification Problems," in IEEE Transactions on Fuzzy Systems, vol. 31, no. 7, pp. 2167-2181, July 2023, doi: 10.1109/TFUZZ.2022.3220950.

Example

from highfis import FSREADATSKRegressor

reg = FSREADATSKRegressor() reg.fit(X_train, y_train)

Initialise an FSRE-ADATSK regressor.

Parameters:

Name Type Description Default
lambda_init float

Accepted for API compatibility but not used by FSRE-ADATSK or DG-ALETSK. FSRE-ADATSK computes its adaptive softmin index directly from membership values; DG-ALETSK uses the fixed exponent ξ = 700 per paper eq. 22. Default 1.0.

1.0
use_en_frb bool

If True, use the Enhanced FRB (En-FRB) for rule extraction. Default False keeps CoCo-FRB.

False
input_configs list[InputConfig] | None

Per-feature InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
fs_epochs int

Maximum epochs for phase 1 (FS training). Default 10.

100
re_epochs int

Maximum epochs for phase 2 (RE training). Default 10.

100
finetune_epochs int

Maximum epochs for phase 3 (fine-tuning). Default 100.

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
zeta_lambda float

Feature-selection threshold coefficient (paper eq. 28). Larger values retain more features. Default 0.5.

0.5
zeta_theta float

Rule-extraction threshold coefficient (paper eq. 29). Larger values retain more rules. Default 0.3.

0.3
structural_pruning bool

If True (default), hard-prune the model architecture after each threshold step.

True
trainer BaseTrainer | None

Optional custom BaseTrainer. When None (default) an FSRETrainer is built automatically from this estimator's hyperparameters.

None
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'

Raises:

Type Description
ValueError

If lambda_init <= 0.

Source code in highfis/estimators/_fsre.py
def __init__(
    self,
    *,
    lambda_init: float = 1.0,
    use_en_frb: bool = False,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    fs_epochs: int = 100,
    re_epochs: int = 100,
    finetune_epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    zeta_lambda: float = 0.5,
    zeta_theta: float = 0.3,
    structural_pruning: bool = True,
    trainer: BaseTrainer | None = None,
    device: str = "cpu",
) -> None:
    """Initialise an FSRE-ADATSK regressor.

    Args:
        lambda_init: Accepted for API compatibility but not used by
            FSRE-ADATSK or DG-ALETSK.  FSRE-ADATSK computes its
            adaptive softmin index directly from membership values;
            DG-ALETSK uses the fixed exponent ``ξ = 700`` per
            paper eq. 22.  Default ``1.0``.
        use_en_frb: If ``True``, use the Enhanced FRB (En-FRB) for rule
            extraction. Default ``False`` keeps CoCo-FRB.
        input_configs: Per-feature InputConfig list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for k-means and weight initialisation.
        fs_epochs: Maximum epochs for phase 1 (FS training). Default ``10``.
        re_epochs: Maximum epochs for phase 2 (RE training). Default ``10``.
        finetune_epochs: Maximum epochs for phase 3 (fine-tuning). Default ``100``.
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        zeta_lambda: Feature-selection threshold coefficient (paper eq. 28).
            Larger values retain more features.  Default ``0.5``.
        zeta_theta: Rule-extraction threshold coefficient (paper eq. 29).
            Larger values retain more rules.  Default ``0.3``.
        structural_pruning: If ``True`` (default), hard-prune the model
            architecture after each threshold step.
        trainer: Optional custom BaseTrainer.
            When ``None`` (default) an FSRETrainer is built automatically
            from this estimator's hyperparameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).

    Raises:
        ValueError: If ``lambda_init <= 0``.
    """
    self.lambda_init = lambda_init
    self.use_en_frb = use_en_frb
    self.fs_epochs = fs_epochs
    self.re_epochs = re_epochs
    self.finetune_epochs = finetune_epochs
    self.zeta_lambda = zeta_lambda
    self.zeta_theta = zeta_theta
    self.structural_pruning = structural_pruning
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=fs_epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
        trainer=trainer,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Fit the FSRE-ADATSK regressor, checking lambda_init.

Source code in highfis/estimators/_fsre.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> FSREADATSKRegressor:
    """Fit the FSRE-ADATSK regressor, checking lambda_init."""
    if self.lambda_init is not None and self.lambda_init <= 0.0:
        raise ValueError("lambda_init must be > 0")
    return cast(FSREADATSKRegressor, super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics))

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous targets, applying structural feature selection.

When structural pruning was applied during fit(), the original feature matrix is automatically sliced to the surviving features before being passed to the pruned model.

Parameters:

Name Type Description Default
x Any

Input array of shape (N, n_features_in_).

required

Returns:

Type Description
np.ndarray

Prediction array of shape (N,).

Source code in highfis/estimators/_fsre.py
def predict(self, x: Any) -> np.ndarray:
    """Predict continuous targets, applying structural feature selection.

    When structural pruning was applied during fit(), the original
    feature matrix is automatically sliced to the surviving features before
    being passed to the pruned model.

    Args:
        x: Input array of shape ``(N, n_features_in_)``.

    Returns:
        Prediction array of shape ``(N,)``.
    """
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    history = getattr(self, "history_", None) or {}
    sf: list[int] | None = history.get("surviving_feature_indices")
    if sf is None and "threshold" in history:
        sf = history["threshold"].get("surviving_feature_indices")
    x_m = x_arr[:, sf] if sf is not None and cast(Any, self.model_).n_inputs < x_arr.shape[1] else x_arr
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_m, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

HDFISMinClassifier

Bases: _BaseClassifierEstimator

HDFIS-min classifier estimator with minimum T-norm antecedents.

HDFIS-min freezes antecedent membership parameters and uses a minimum T-norm aggregation in the antecedent, so that only consequent parameters are optimized during training. This matches the paper's observation that minimum-based high-dimensional inference is best handled by fixing the antecedent structure and training the rule consequents.

References

G. Xue, J. Wang, K. Zhang and N. R. Pal, "High-Dimensional Fuzzy Inference Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 54, no. 1, pp. 507-519, Jan. 2024, doi: 10.1109/TSMC.2023.3311475.

Example
from highfis import HDFISMinClassifier

clf = HDFISMinClassifier()
clf.fit(X_train, y_train)
preds = clf.predict(X_test)

Initialise an HDFIS-min classifier estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of MFs/rules for grid/k-means initialisation. Defaults to 5.

5
mf_init str

MF initialisation strategy. Defaults to "kmeans".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size. Defaults to 512.

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum number of point-based FRB rules when rule_base='pfrb'. None uses all training samples.

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

Restore best validation weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_hdfis.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise an HDFIS-min classifier estimator.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of MFs/rules for grid/k-means initialisation.
            Defaults to ``5``.
        mf_init: MF initialisation strategy. Defaults to ``"kmeans"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size. Defaults to ``512``.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum number of point-based FRB rules when
            ``rule_base='pfrb'``. ``None`` uses all training samples.
        patience: Early-stopping patience (default ``20``).
            Set to ``None`` to disable early stopping.
        restore_best: Restore best validation weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

HDFISMinRegressor

Bases: _BaseRegressorEstimator

HDFIS-min regressor estimator with minimum T-norm antecedents.

HDFIS-min freezes antecedent membership parameters and uses a minimum T-norm aggregation in the antecedent, so that only consequent parameters are optimized during training. This design avoids the nondifferentiability of the minimum operator while preserving first-order TSK consequents.

References

G. Xue, J. Wang, K. Zhang and N. R. Pal, "High-Dimensional Fuzzy Inference Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 54, no. 1, pp. 507-519, Jan. 2024, doi: 10.1109/TSMC.2023.3311475.

Example
from highfis import HDFISMinRegressor

reg = HDFISMinRegressor()
reg.fit(X_train, y_train)
preds = reg.predict(X_test)

Initialise an HDFIS-min regressor estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of MFs/rules for grid/k-means initialisation. Defaults to 5.

5
mf_init str

MF initialisation strategy. Defaults to "kmeans".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size. Defaults to 512.

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

Restore best validation weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_hdfis.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise an HDFIS-min regressor estimator.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of MFs/rules for grid/k-means initialisation.
            Defaults to ``5``.
        mf_init: MF initialisation strategy. Defaults to ``"kmeans"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size. Defaults to ``512``.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``).
            Set to ``None`` to disable early stopping.
        restore_best: Restore best validation weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

HDFISProdClassifier

Bases: _BaseClassifierEstimator

HDFIS-prod classifier estimator with dimension-dependent Gaussian MFs.

HDFIS-prod combines the standard product T-norm with a dimension-dependent Gaussian membership function (DMF) to avoid numeric underflow in very high-dimensional feature spaces while preserving first-order TSK consequents.

References

G. Xue, J. Wang, K. Zhang and N. R. Pal, "High-Dimensional Fuzzy Inference Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 54, no. 1, pp. 507-519, Jan. 2024, doi: 10.1109/TSMC.2023.3311475.

Example
from highfis import HDFISProdClassifier

clf = HDFISProdClassifier()
clf.fit(X_train, y_train)

Initialise an HDFIS-prod classifier estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of MFs/rules for grid/k-means initialisation. Defaults to 5.

5
mf_init str

MF initialisation strategy. Defaults to "kmeans".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size. Defaults to 512.

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum number of point-based FRB rules when rule_base='pfrb'. None uses all training samples.

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

Restore best validation weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
xi float

Precision constant used to compute the DMF scale exponent \(\rho\) when rho is None. Must be greater than 1.

745.0
rho float | None

Scale exponent for the dimension-dependent Gaussian MF. When None, computed as 1 - log(xi) / log(D).

None
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_hdfis.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    xi: float = 745.0,
    rho: float | None = None,
    device: str = "cpu",
) -> None:
    r"""Initialise an HDFIS-prod classifier estimator.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of MFs/rules for grid/k-means initialisation.
            Defaults to ``5``.
        mf_init: MF initialisation strategy. Defaults to ``"kmeans"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size. Defaults to ``512``.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum number of point-based FRB rules when
            ``rule_base='pfrb'``. ``None`` uses all training samples.
        patience: Early-stopping patience (default ``20``).
            Set to ``None`` to disable early stopping.
        restore_best: Restore best validation weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        xi: Precision constant used to compute the DMF scale exponent
            $\rho$ when *rho* is ``None``. Must be greater than 1.
        rho: Scale exponent for the dimension-dependent Gaussian MF.
            When ``None``, computed as ``1 - log(xi) / log(D)``.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.xi = xi
    self.rho = rho

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

HDFISProdRegressor

Bases: _BaseRegressorEstimator

HDFIS-prod regressor estimator with dimension-dependent Gaussian MFs.

HDFIS-prod combines the standard product T-norm with a dimension-dependent Gaussian membership function (DMF) to avoid numeric underflow in very high-dimensional feature spaces while preserving first-order TSK consequents.

References

G. Xue, J. Wang, K. Zhang and N. R. Pal, "High-Dimensional Fuzzy Inference Systems," in IEEE Transactions on Systems, Man, and Cybernetics: Systems, vol. 54, no. 1, pp. 507-519, Jan. 2024, doi: 10.1109/TSMC.2023.3311475.

Example
from highfis import HDFISProdRegressor

reg = HDFISProdRegressor()
reg.fit(X_train, y_train)

Initialise an HDFIS-prod regressor estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of MFs/rules for grid/k-means initialisation. Defaults to 5.

5
mf_init str

MF initialisation strategy. Defaults to "kmeans".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 recommended.

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size. Defaults to 512.

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

Restore best validation weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
xi float

Precision constant used to compute the DMF scale exponent \(\rho\) when rho is None. Must be greater than 1.

745.0
rho float | None

Scale exponent for the dimension-dependent Gaussian MF. When None, computed as 1 - log(xi) / log(D).

None
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_hdfis.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    xi: float = 745.0,
    rho: float | None = None,
    device: str = "cpu",
) -> None:
    r"""Initialise an HDFIS-prod regressor estimator.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of MFs/rules for grid/k-means initialisation.
            Defaults to ``5``.
        mf_init: MF initialisation strategy. Defaults to ``"kmeans"``.
        sigma_scale: Sigma scale factor. ``1.0`` recommended.
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size. Defaults to ``512``.
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``).
            Set to ``None`` to disable early stopping.
        restore_best: Restore best validation weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        xi: Precision constant used to compute the DMF scale exponent
            $\rho$ when *rho* is ``None``. Must be greater than 1.
        rho: Scale exponent for the dimension-dependent Gaussian MF.
            When ``None``, computed as ``1 - log(xi) / log(D)``.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.xi = xi
    self.rho = rho

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

HTSKClassifier

Bases: _BaseClassifierEstimator

HTSK classifier for high-dimensional TSK inference.

HTSK replaces the standard product t-norm with a geometric mean over membership values and performs rule normalization in log-space.

References

Y. Cui, D. Wu and Y. Xu, "Curse of Dimensionality for TSK Fuzzy Neural Networks: Explanation and Solutions," 2021 International Joint Conference on Neural Networks (IJCNN), Shenzhen, China, 2021, pp. 1-8, doi: 10.1109/IJCNN52387.2021.9534265.

Example
from highfis import HTSKClassifier

clf = HTSKClassifier()
clf.fit(X_train, y_train)

Initialise an HTSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs. (default 3)

3
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 is recommended for HTSK.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs. (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian". Defaults to "coco" for kmeans and "cartesian" for grid.

None
batch_size int | None

Mini-batch size. (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum point-based FRB rules (unused by HTSK).

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_htsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise an HTSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs. (default ``3``)
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` is recommended for HTSK.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs. (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``. Defaults to
            ``"coco"`` for kmeans and ``"cartesian"`` for grid.
        batch_size: Mini-batch size. (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum point-based FRB rules (unused by HTSK).
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

HTSKRegressor

Bases: _BaseRegressorEstimator

HTSK regressor for high-dimensional TSK inference.

HTSK replaces the standard product t-norm with a geometric mean over membership values and performs rule normalization in log-space.

References

Y. Cui, D. Wu and Y. Xu, "Curse of Dimensionality for TSK Fuzzy Neural Networks: Explanation and Solutions," 2021 International Joint Conference on Neural Networks (IJCNN), Shenzhen, China, 2021, pp. 1-8, doi: 10.1109/IJCNN52387.2021.9534265.

Example
from highfis import HTSKRegressor

reg = HTSKRegressor()
reg.fit(X_train, y_train)

Initialise an HTSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs. (default 3).

3
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Scale factor for sigma initialisation when mf_init="kmeans". 1.0 is recommended for HTSK.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs. (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian". Defaults to "coco" for kmeans and "cartesian" for grid.

None
batch_size int | None

Mini-batch size. (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum point-based FRB rules (unused by HTSK).

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_htsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise an HTSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs. (default ``3``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Scale factor for sigma initialisation when
            ``mf_init="kmeans"``. ``1.0`` is recommended for HTSK.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs. (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``. Defaults to
            ``"coco"`` for kmeans and ``"cartesian"`` for grid.
        batch_size: Mini-batch size. (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum point-based FRB rules (unused by HTSK).
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    resolved_n_mfs = 3 if n_mfs is None else n_mfs
    resolved_mf_init = "kmeans" if mf_init is None else mf_init
    resolved_sigma_scale = 1.0 if sigma_scale is None else sigma_scale
    resolved_rule_base = rule_base
    resolved_epochs = 100 if epochs is None else epochs
    resolved_learning_rate = 1e-2 if learning_rate is None else learning_rate
    resolved_batch_size = 512 if batch_size is None else batch_size
    super().__init__(
        input_configs=input_configs,
        n_mfs=resolved_n_mfs,
        mf_init=resolved_mf_init,
        sigma_scale=resolved_sigma_scale,
        random_state=random_state,
        epochs=resolved_epochs,
        learning_rate=resolved_learning_rate,
        verbose=verbose,
        rule_base=resolved_rule_base,
        batch_size=resolved_batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

InputConfig dataclass

Per-feature configuration for Gaussian MF grid initialisation.

This dataclass controls how membership functions are placed on a single input feature when mf_init="grid". When mf_init="kmeans" only the name field is used; centres and sigmas are derived from k-means cluster centroids.

Attributes:

Name Type Description
name str

Feature name. Used as the key in the membership-function dictionary passed to the underlying TSK model.

n_mfs int

Number of Gaussian MFs to place on this feature. Must be >= 1.

overlap float

Spacing factor between neighbouring MF centres. A larger value widens each MF (more overlap); 0.5 corresponds to roughly half-width overlap at the midpoint between centres.

margin float

Fractional padding added to the observed feature range before centre placement. 0.10 extends each side of [x_min, x_max] by 10 percent so edge centres are not clipped to extreme values.

Example
from highfis.estimators import InputConfig

configs = [
    InputConfig(name="sepal_length", n_mfs=3),
    InputConfig(name="sepal_width", n_mfs=5, overlap=0.3),
]

LogTSKClassifier

Bases: _BaseClassifierEstimator

LogTSK classifier with inverse-log rule normalization.

LogTSK uses product antecedent aggregation and inverse-log normalization of log-domain rule strengths. The resulting rule weights are normalized with L1 normalization across rules, which makes the model scale-invariant in log-space and avoids the softmax saturation that occurs in high-dimensional inputs.

Reference

Y. Cui, D. Wu and Y. Xu, "Curse of Dimensionality for TSK Fuzzy Neural Networks: Explanation and Solutions," 2021 International Joint Conference on Neural Networks (IJCNN), pp. 1-8, doi: 10.1109/IJCNN52387.2021.9534265.

Example
from highfis import LogTSKClassifier

clf = LogTSKClassifier()
clf.fit(X_train, y_train)

Initialise a LogTSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 is recommended (the log-space defuzzifier is scale-invariant).

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_logtsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise a LogTSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` is recommended (the
            log-space defuzzifier is scale-invariant).
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
    )

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

LogTSKRegressor

Bases: _BaseRegressorEstimator

LogTSK regressor with inverse-log rule normalization.

LogTSK uses product antecedent aggregation and inverse-log normalization of log-domain rule strengths. The resulting rule weights are normalized with L1 normalization across rules, which makes the model scale-invariant in log-space and avoids the softmax saturation that occurs in high-dimensional inputs.

Reference

Y. Cui, D. Wu and Y. Xu, "Curse of Dimensionality for TSK Fuzzy Neural Networks: Explanation and Solutions," 2021 International Joint Conference on Neural Networks (IJCNN), pp. 1-8, doi: 10.1109/IJCNN52387.2021.9534265.

Example
from highfis import LogTSKRegressor

reg = LogTSKRegressor()
reg.fit(X_train, y_train)

Initialise a LogTSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list.

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

5
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. 1.0 is recommended (the log-space defuzzifier is scale-invariant).

1.0
random_state int | None

Seed for reproducibility.

None
epochs int

Maximum training epochs (default 100).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian".

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_logtsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 5,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise a LogTSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. ``1.0`` is recommended (the
            log-space defuzzifier is scale-invariant).
        random_state: Seed for reproducibility.
        epochs: Maximum training epochs (default ``100``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

MHTSKClassifier

Bases: _BaseClassifierEstimator

Estimator for the multihead Takagi-Sugeno-Kang fuzzy system.

This estimator supports paper-derived automatic scale parameter resolution for head size and number of heads, and it optionally subsamples instances when building each head as described in the MHTSK paper.

MHTSK builds multiple sparse subantecedents from random feature subsets and jointly optimizes their rule consequents.

Reference

Z. Bian, Q. Chang, J. Wang and N. R. Pal, "Multihead Takagi-Sugeno-Kang Fuzzy System," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 8, pp. 2561-2573, Aug. 2025, doi: 10.1109/TFUZZ.2025.3569227.

Example
from highfis import MHTSKClassifier

clf = MHTSKClassifier()
clf.fit(X_train, y_train)

Initialize a MHTSK classifier estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of per-feature input configurations. Only the feature names are used for FCM-based MHTSK head construction.

None
n_mfs int

Number of FCM clusters per head (number of rules generated by each head).

3
n_heads int | None

Number of random heads. If None, this is resolved from head_size together with fcr_target or h_value.

None
head_size int | None

Number of features sampled per head. If None, defaults to round(D * 0.02) for D <= 5000 and round(D * 0.01) for larger inputs.

None
head_size_ratio float | None

Alternative relative head size, as a fraction of the input dimension.

None
fcm_m float

Fuzzification exponent for FCM cluster fitting.

2.0
rule_sigma float

Gaussian sigma applied to rule antecedent membership functions.

1.0
fcr_target float | None

Target feature coverage rate for randomly sampled heads.

None
h_value float | None

Paper-derived scale constant H used to compute the number of heads. When set, this overrides fcr_target.

None
xi float

Numeric underflow threshold constant used to bound head_size.

743.0
instance_sample_fraction float

Fraction of training instances sampled per head for FCM.

0.8
rule_extraction bool

If True, perform post-fit rule extraction (MHTSK_RE).

False
crcr_us float

Unsupervised cumulative rule contribution rate target used in extraction.

0.5
crcr_s float

Supervised cumulative rule contribution rate target used in extraction.

0.5
retrain_after_extraction bool

If True, retrain the extracted rule base after extraction.

True
random_state int | None

Random seed for reproducible head construction and FCM initialization.

None
epochs int

Maximum number of training epochs.

100
learning_rate float

Adam optimizer learning rate.

0.01
verbose bool | int

Verbosity level during training.

False
batch_size int | None

Mini-batch size for gradient descent.

512
shuffle bool

Whether to shuffle training samples each epoch.

True
ur_weight float

Weight of the uncertainty regularization term.

0.0
ur_target float | None

Target firing-level for uncertainty regularization.

None
consequent_batch_norm bool

Apply batch normalization to the consequent layer inputs.

False
patience int | None

Early-stopping patience for validation.

20
restore_best bool

Whether to restore the best validation model weights after training.

True
weight_decay float

Weight decay coefficient for the optimizer.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_mhtsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    n_heads: int | None = None,
    head_size: int | None = None,
    head_size_ratio: float | None = None,
    fcm_m: float = 2.0,
    rule_sigma: float = 1.0,
    fcr_target: float | None = None,
    h_value: float | None = None,
    xi: float = 743.0,
    instance_sample_fraction: float = 0.8,
    rule_extraction: bool = False,
    crcr_us: float = 0.5,
    crcr_s: float = 0.5,
    retrain_after_extraction: bool = True,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialize a MHTSK classifier estimator.

    Args:
        input_configs: Optional list of per-feature input configurations.
            Only the feature names are used for FCM-based MHTSK head construction.
        n_mfs: Number of FCM clusters per head (number of rules generated by each head).
        n_heads: Number of random heads. If ``None``, this is resolved from
            ``head_size`` together with ``fcr_target`` or ``h_value``.
        head_size: Number of features sampled per head. If ``None``, defaults to
            ``round(D * 0.02)`` for ``D <= 5000`` and ``round(D * 0.01)`` for larger inputs.
        head_size_ratio: Alternative relative head size, as a fraction of the input dimension.
        fcm_m: Fuzzification exponent for FCM cluster fitting.
        rule_sigma: Gaussian sigma applied to rule antecedent membership functions.
        fcr_target: Target feature coverage rate for randomly sampled heads.
        h_value: Paper-derived scale constant ``H`` used to compute the number of heads.
            When set, this overrides ``fcr_target``.
        xi: Numeric underflow threshold constant used to bound ``head_size``.
        instance_sample_fraction: Fraction of training instances sampled per head for FCM.
        rule_extraction: If ``True``, perform post-fit rule extraction (MHTSK_RE).
        crcr_us: Unsupervised cumulative rule contribution rate target used in extraction.
        crcr_s: Supervised cumulative rule contribution rate target used in extraction.
        retrain_after_extraction: If ``True``, retrain the extracted rule base after extraction.
        random_state: Random seed for reproducible head construction and FCM initialization.
        epochs: Maximum number of training epochs.
        learning_rate: Adam optimizer learning rate.
        verbose: Verbosity level during training.
        batch_size: Mini-batch size for gradient descent.
        shuffle: Whether to shuffle training samples each epoch.
        ur_weight: Weight of the uncertainty regularization term.
        ur_target: Target firing-level for uncertainty regularization.
        consequent_batch_norm: Apply batch normalization to the consequent layer inputs.
        patience: Early-stopping patience for validation.
        restore_best: Whether to restore the best validation model weights after training.
        weight_decay: Weight decay coefficient for the optimizer.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init="fcm",
        sigma_scale=1.0,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base="custom",
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=None,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.n_heads = n_heads
    self.head_size = head_size
    self.head_size_ratio = head_size_ratio
    self.fcm_m = fcm_m
    self.rule_sigma = rule_sigma
    self.fcr_target = fcr_target
    self.h_value = h_value
    self.xi = xi
    self.instance_sample_fraction = instance_sample_fraction
    self.rule_extraction = rule_extraction
    self.crcr_us = crcr_us
    self.crcr_s = crcr_s
    self.retrain_after_extraction = retrain_after_extraction

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the MHTSK classifier and optionally extract rules.

After the base training step, if rule_extraction is enabled, the firing-strength matrix is used to select a compact rule subset via the CRCR criterion. When retrain_after_extraction is also set, a second training pass is performed on the reduced model.

Source code in highfis/estimators/_mhtsk.py
def fit(
    self,
    x: Any,
    y: Any,
    *,
    x_val: Any | None = None,
    y_val: Any | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the MHTSK classifier and optionally extract rules.

    After the base training step, if ``rule_extraction`` is enabled, the
    firing-strength matrix is used to select a compact rule subset via the
    CRCR criterion.  When ``retrain_after_extraction`` is also set, a
    second training pass is performed on the reduced model.
    """
    x_arr, y_arr = check_X_y(x, y)
    super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics)

    if not bool(self.rule_extraction):
        return self

    x_t = self._as_tensor_x(x_arr)
    self.model_.eval()
    with torch.no_grad():
        norm_w = self.model_.forward_antecedents(x_t)

    y_t = torch.as_tensor(self._label_encoder_.transform(np.asarray(y_arr)), dtype=torch.long)
    selected = _extract_mhtsk_rule_indices(norm_w, y_t, self.crcr_us, self.crcr_s)
    self._extracted_rule_indices_ = selected

    input_mfs = self.model_.input_mfs
    self._build_extracted_model(input_mfs, selected)

    if self.retrain_after_extraction:
        from ..optim import GradientTrainer

        x_val_t: torch.Tensor | None = None
        y_val_t: torch.Tensor | None = None
        if x_val is not None and y_val is not None:
            x_v_arr, y_v_arr = check_X_y(x_val, y_val)
            x_val_t = self._as_tensor_x(x_v_arr)
            y_val_t = torch.as_tensor(
                self._label_encoder_.transform(np.asarray(y_v_arr)),
                dtype=torch.long,
            )
        trainer = GradientTrainer(
            epochs=int(self.epochs),
            learning_rate=float(self.learning_rate),
            batch_size=self.batch_size,
            shuffle=bool(self.shuffle),
            ur_weight=float(self.ur_weight),
            ur_target=self.ur_target,
            verbose=self.verbose,
            patience=self.patience,
            restore_best=self.restore_best,
            weight_decay=float(self.weight_decay),
        )
        self.history_ = trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

MHTSKRegressor

Bases: _BaseRegressorEstimator

Estimator for the multihead Takagi-Sugeno-Kang fuzzy system.

The regressor uses the same MHTSK head construction and scale parameter strategy as the classifier. Rule extraction is currently implemented with an unsupervised scheme only, since regression does not provide class labels for the Mann-Whitney based selection used in classification.

MHTSK builds multiple sparse subantecedents from random feature subsets and jointly optimizes their rule consequents.

Reference

Z. Bian, Q. Chang, J. Wang and N. R. Pal, "Multihead Takagi-Sugeno-Kang Fuzzy System," in IEEE Transactions on Fuzzy Systems, vol. 33, no. 8, pp. 2561-2573, Aug. 2025, doi: 10.1109/TFUZZ.2025.3569227.

Example
from highfis import MHTSKRegressor

reg = MHTSKRegressor()
reg.fit(X_train, y_train)

Initialize a MHTSK regressor estimator.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Optional list of per-feature input configurations. Only the feature names are used for FCM-based MHTSK head construction.

None
n_mfs int

Number of FCM clusters per head (number of rules generated by each head).

3
n_heads int | None

Number of random heads. If None, this is resolved from head_size together with fcr_target or h_value.

None
head_size int | None

Number of features sampled per head. If None, defaults to round(D * 0.02) for D <= 5000 and round(D * 0.01) for larger inputs.

None
head_size_ratio float | None

Alternative relative head size, as a fraction of the input dimension.

None
fcm_m float

Fuzzification exponent for FCM cluster fitting.

2.0
rule_sigma float

Gaussian sigma applied to rule antecedent membership functions.

1.0
fcr_target float | None

Target feature coverage rate for randomly sampled heads.

None
h_value float | None

Paper-derived scale constant H used to compute the number of heads. When set, this overrides fcr_target.

None
xi float

Numeric underflow threshold constant used to bound head_size.

743.0
instance_sample_fraction float

Fraction of training instances sampled per head for FCM.

0.8
rule_extraction bool

If True, perform post-fit rule extraction.

False
crcr_us float

Unsupervised cumulative rule contribution rate target used in extraction.

0.5
retrain_after_extraction bool

If True, retrain the extracted rule base after extraction.

True
random_state int | None

Random seed for reproducible head construction and FCM initialization.

None
epochs int

Maximum number of training epochs.

100
learning_rate float

Adam optimizer learning rate.

0.01
verbose bool | int

Verbosity level during training.

False
batch_size int | None

Mini-batch size for gradient descent.

512
shuffle bool

Whether to shuffle training samples each epoch.

True
ur_weight float

Weight of the uncertainty regularization term.

0.0
ur_target float | None

Target firing-level for uncertainty regularization.

None
consequent_batch_norm bool

Apply batch normalization to the consequent layer inputs.

False
patience int | None

Early-stopping patience for validation.

20
restore_best bool

Whether to restore the best validation model weights after training.

True
weight_decay float

Weight decay coefficient for the optimizer.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Notes

The regressor supports only unsupervised rule extraction via crcr_us because no label-based Mann-Whitney selection is available.

Source code in highfis/estimators/_mhtsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    n_heads: int | None = None,
    head_size: int | None = None,
    head_size_ratio: float | None = None,
    fcm_m: float = 2.0,
    rule_sigma: float = 1.0,
    fcr_target: float | None = None,
    h_value: float | None = None,
    xi: float = 743.0,
    instance_sample_fraction: float = 0.8,
    rule_extraction: bool = False,
    crcr_us: float = 0.5,
    retrain_after_extraction: bool = True,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialize a MHTSK regressor estimator.

    Args:
        input_configs: Optional list of per-feature input configurations.
            Only the feature names are used for FCM-based MHTSK head construction.
        n_mfs: Number of FCM clusters per head (number of rules generated by each head).
        n_heads: Number of random heads. If ``None``, this is resolved from
            ``head_size`` together with ``fcr_target`` or ``h_value``.
        head_size: Number of features sampled per head. If ``None``, defaults to
            ``round(D * 0.02)`` for ``D <= 5000`` and ``round(D * 0.01)`` for larger inputs.
        head_size_ratio: Alternative relative head size, as a fraction of the input dimension.
        fcm_m: Fuzzification exponent for FCM cluster fitting.
        rule_sigma: Gaussian sigma applied to rule antecedent membership functions.
        fcr_target: Target feature coverage rate for randomly sampled heads.
        h_value: Paper-derived scale constant ``H`` used to compute the number of heads.
            When set, this overrides ``fcr_target``.
        xi: Numeric underflow threshold constant used to bound ``head_size``.
        instance_sample_fraction: Fraction of training instances sampled per head for FCM.
        rule_extraction: If ``True``, perform post-fit rule extraction.
        crcr_us: Unsupervised cumulative rule contribution rate target used in extraction.
        retrain_after_extraction: If ``True``, retrain the extracted rule base after extraction.
        random_state: Random seed for reproducible head construction and FCM initialization.
        epochs: Maximum number of training epochs.
        learning_rate: Adam optimizer learning rate.
        verbose: Verbosity level during training.
        batch_size: Mini-batch size for gradient descent.
        shuffle: Whether to shuffle training samples each epoch.
        ur_weight: Weight of the uncertainty regularization term.
        ur_target: Target firing-level for uncertainty regularization.
        consequent_batch_norm: Apply batch normalization to the consequent layer inputs.
        patience: Early-stopping patience for validation.
        restore_best: Whether to restore the best validation model weights after training.
        weight_decay: Weight decay coefficient for the optimizer.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).

    Notes:
        The regressor supports only unsupervised rule extraction via
        ``crcr_us`` because no label-based Mann-Whitney selection is available.
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init="fcm",
        sigma_scale=1.0,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base="custom",
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=None,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )
    self.n_heads = n_heads
    self.head_size = head_size
    self.head_size_ratio = head_size_ratio
    self.fcm_m = fcm_m
    self.rule_sigma = rule_sigma
    self.fcr_target = fcr_target
    self.h_value = h_value
    self.xi = xi
    self.instance_sample_fraction = instance_sample_fraction
    self.rule_extraction = rule_extraction
    self.crcr_us = crcr_us
    self.retrain_after_extraction = retrain_after_extraction

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the MHTSK regressor and optionally extract rules.

After the base training step, if rule_extraction is enabled, rules are selected via the unsupervised CRCR criterion on the firing-strength matrix. When retrain_after_extraction is also set, a second training pass is performed on the reduced model.

Source code in highfis/estimators/_mhtsk.py
def fit(
    self,
    x: Any,
    y: Any,
    *,
    x_val: Any | None = None,
    y_val: Any | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the MHTSK regressor and optionally extract rules.

    After the base training step, if ``rule_extraction`` is enabled, rules
    are selected via the unsupervised CRCR criterion on the firing-strength
    matrix.  When ``retrain_after_extraction`` is also set, a second
    training pass is performed on the reduced model.
    """
    x_arr, y_arr = check_X_y(x, y)
    super().fit(x, y, x_val=x_val, y_val=y_val, metrics=metrics)

    if not bool(self.rule_extraction):
        return self

    x_t = self._as_tensor_x(x_arr)
    self.model_.eval()
    with torch.no_grad():
        norm_w = self.model_.forward_antecedents(x_t)

    selected = _extract_mhtsk_rule_indices_unsupervised(norm_w, self.crcr_us)
    self._extracted_rule_indices_ = selected

    input_mfs = self.model_.input_mfs
    self._build_extracted_model(input_mfs, selected)

    if self.retrain_after_extraction:
        from ..optim import GradientTrainer

        y_t = torch.as_tensor(np.asarray(y_arr), dtype=torch.float32)
        x_val_t: torch.Tensor | None = None
        y_val_t: torch.Tensor | None = None
        if x_val is not None and y_val is not None:
            x_v_arr, y_v_arr = check_X_y(x_val, y_val)
            x_val_t = self._as_tensor_x(x_v_arr)
            y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32)
        trainer = GradientTrainer(
            epochs=int(self.epochs),
            learning_rate=float(self.learning_rate),
            batch_size=self.batch_size,
            shuffle=bool(self.shuffle),
            ur_weight=float(self.ur_weight),
            ur_target=self.ur_target,
            verbose=self.verbose,
            patience=self.patience,
            restore_best=self.restore_best,
            weight_decay=float(self.weight_decay),
        )
        self.history_ = trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

TSKClassifier

Bases: _BaseClassifierEstimator

Vanilla TSK classifier with sum-based rule normalization.

The vanilla Takagi-Sugeno-Kang inference computes rule firing strengths with the product t-norm and normalizes them by their total sum.

References

T. Takagi and M. Sugeno, "Fuzzy identification of systems and its applications to modeling and control," in IEEE Transactions on Systems, Man, and Cybernetics, vol. SMC-15, no. 1, pp. 116-132, Jan.-Feb. 1985, doi: 10.1109/TSMC.1985.6313399.

Example
from highfis import TSKClassifier

clf = TSKClassifier(n_mfs=5, random_state=0)
clf.fit(X_train, y_train)

Initialise a vanilla TSK classifier.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

3
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. Use "auto" (= sqrt(D)) for high-dimensional data to mitigate softmax saturation (Cui et al., IJCNN 2021). 1.0 is appropriate for low- to medium-dimensional problems.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian". Defaults to "coco" for kmeans and "cartesian" for grid.

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
pfrb_max_rules int | None

Maximum point-based FRB rules (unused by TSK).

None
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_htsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    pfrb_max_rules: int | None = None,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise a vanilla TSK classifier.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. Use ``"auto"`` (= ``sqrt(D)``)
            for high-dimensional data to mitigate softmax saturation
            (Cui et al., IJCNN 2021). ``1.0`` is appropriate for low-
            to medium-dimensional problems.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``. Defaults to
            ``"coco"`` for kmeans and ``"cartesian"`` for grid.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        pfrb_max_rules: Maximum point-based FRB rules (unused by TSK).
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        pfrb_max_rules=pfrb_max_rules,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute classification evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute classification evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="classification",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK classifier on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK classifier on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )
    target_type = type_of_target(y_arr)
    if target_type in ("continuous", "continuous-multioutput"):
        raise ValueError(f"Unknown label type: {target_type}")

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    le = LabelEncoder()
    y_idx = le.fit_transform(np.asarray(y_arr))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]
    self.classes_ = le.classes_
    self._label_encoder_ = le

    _device = torch.device(str(self.device))
    self.model_ = self._build_model(input_mfs, len(self.classes_), effective_rule_base).to(_device)

    y_t = torch.as_tensor(y_idx, dtype=torch.long, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_idx = le.transform(np.asarray(y_v_arr))
        y_val_t = torch.as_tensor(y_val_idx, dtype=torch.long, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            int(model_init["n_classes"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    estimator.classes_ = np.asarray(fitted["classes"], dtype=object)
    label_encoder = LabelEncoder()
    label_encoder.classes_ = estimator.classes_
    estimator._label_encoder_ = label_encoder
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict class labels for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class labels for input samples."""
    proba = self.predict_proba(x)
    y_idx = np.argmax(proba, axis=1)
    return np.asarray(self._label_encoder_.inverse_transform(y_idx))

predict_proba

Predict class probabilities for input samples.

Source code in highfis/estimators/_base.py
def predict_proba(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict class probabilities for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    probs = cast(Any, self.model_).predict_proba(x_tensor)
    return probs.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "n_classes": len(self.classes_),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
            "classes": self.classes_.tolist(),
        },
    )
    save_checkpoint(path, checkpoint)

score

Return classification accuracy on the provided dataset.

Source code in highfis/estimators/_base.py
def score(self, X: npt.ArrayLike, y: npt.ArrayLike, sample_weight: npt.ArrayLike | None = None) -> float:
    """Return classification accuracy on the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return float(accuracy_score(y_true, y_pred, sample_weight=sample_weight))

TSKRegressor

Bases: _BaseRegressorEstimator

Vanilla TSK regressor with sum-based rule normalization.

The vanilla Takagi-Sugeno-Kang inference computes rule firing strengths with the product t-norm and normalizes them by their total sum.

References

T. Takagi and M. Sugeno, "Fuzzy identification of systems and its applications to modeling and control," in IEEE Transactions on Systems, Man, and Cybernetics, vol. SMC-15, no. 1, pp. 116-132, Jan.-Feb. 1985, doi: 10.1109/TSMC.1985.6313399.

Example
from highfis import TSKRegressor

reg = TSKRegressor(n_mfs=30, random_state=0)
reg.fit(X_train, y_train)

Initialise a vanilla TSK regressor.

Parameters:

Name Type Description Default
input_configs list[InputConfig] | None

Per-feature :class:InputConfig list. Only name is used when mf_init="kmeans".

None
n_mfs int

Number of k-means clusters / grid MFs (default 5).

3
mf_init str

"kmeans" (default), "minibatch_kmeans", "fcm", or "grid".

'kmeans'
sigma_scale float | str

Sigma scale factor. Use "auto" (= sqrt(D)) to mitigate softmax saturation on high-dimensional data. 1.0 is appropriate for low-to-medium-dimensional problems.

1.0
random_state int | None

Seed for k-means and weight initialisation.

None
epochs int

Maximum training epochs (default 10).

100
learning_rate float

Adam learning rate (default 0.01).

0.01
verbose bool | int

Print per-epoch progress.

False
rule_base str | None

"coco" or "cartesian". Defaults to "coco" for kmeans and "cartesian" for grid.

None
batch_size int | None

Mini-batch size (default 512).

512
shuffle bool

Reshuffle each epoch.

True
ur_weight float

Uncertainty regularisation weight.

0.0
ur_target float | None

Uncertainty regularisation target.

None
consequent_batch_norm bool

Batch normalisation on consequent layers.

False
patience int | None

Early-stopping patience (default 20). Set to None to disable early stopping.

20
restore_best bool

If True (default), restore the best validation model weights after training.

True
weight_decay float

L2 weight decay for consequent parameters.

1e-08
device str

Target device for training and inference (e.g., "cpu", "cuda", or "mps").

'cpu'
Source code in highfis/estimators/_htsk.py
def __init__(
    self,
    *,
    input_configs: list[InputConfig] | None = None,
    n_mfs: int = 3,
    mf_init: str = "kmeans",
    sigma_scale: float | str = 1.0,
    random_state: int | None = None,
    epochs: int = 100,
    learning_rate: float = 1e-2,
    verbose: bool | int = False,
    rule_base: str | None = None,
    batch_size: int | None = 512,
    shuffle: bool = True,
    ur_weight: float = 0.0,
    ur_target: float | None = None,
    consequent_batch_norm: bool = False,
    patience: int | None = 20,
    restore_best: bool = True,
    weight_decay: float = 1e-8,
    device: str = "cpu",
) -> None:
    """Initialise a vanilla TSK regressor.

    Args:
        input_configs: Per-feature :class:`InputConfig` list. Only
            ``name`` is used when ``mf_init="kmeans"``.
        n_mfs: Number of k-means clusters / grid MFs (default ``5``).
        mf_init: ``"kmeans"`` (default), ``"minibatch_kmeans"``, ``"fcm"``, or ``"grid"``.
        sigma_scale: Sigma scale factor. Use ``"auto"`` (= ``sqrt(D)``)
            to mitigate softmax saturation on high-dimensional data.
            ``1.0`` is appropriate for low-to-medium-dimensional problems.
        random_state: Seed for k-means and weight initialisation.
        epochs: Maximum training epochs (default ``10``).
        learning_rate: Adam learning rate (default ``0.01``).
        verbose: Print per-epoch progress.
        rule_base: ``"coco"`` or ``"cartesian"``. Defaults to
            ``"coco"`` for kmeans and ``"cartesian"`` for grid.
        batch_size: Mini-batch size (default ``512``).
        shuffle: Reshuffle each epoch.
        ur_weight: Uncertainty regularisation weight.
        ur_target: Uncertainty regularisation target.
        consequent_batch_norm: Batch normalisation on consequent layers.
        patience: Early-stopping patience (default ``20``). Set to ``None`` to disable early stopping.
        restore_best: If ``True`` (default), restore the best validation
            model weights after training.
        weight_decay: L2 weight decay for consequent parameters.
        device: Target device for training and inference (e.g., ``"cpu"``,
            ``"cuda"``, or ``"mps"``).
    """
    super().__init__(
        input_configs=input_configs,
        n_mfs=n_mfs,
        mf_init=mf_init,
        sigma_scale=sigma_scale,
        random_state=random_state,
        epochs=epochs,
        learning_rate=learning_rate,
        verbose=verbose,
        rule_base=rule_base,
        batch_size=batch_size,
        shuffle=shuffle,
        ur_weight=ur_weight,
        ur_target=ur_target,
        consequent_batch_norm=consequent_batch_norm,
        patience=patience,
        restore_best=restore_best,
        weight_decay=weight_decay,
        device=device,
    )

evaluate

Compute regression evaluation metrics for the provided dataset.

Source code in highfis/estimators/_base.py
def evaluate(
    self,
    X: npt.ArrayLike,
    y: npt.ArrayLike,
    metrics: list[str] | None = None,
    sample_weight: npt.ArrayLike | None = None,
) -> dict[str, Any]:
    """Compute regression evaluation metrics for the provided dataset."""
    y_true = np.asarray(y)
    y_pred = self.predict(X)
    return compute_metrics(
        task="regression",
        y_true=y_true,
        y_pred=y_pred,
        sample_weight=sample_weight,
        metrics=metrics,
    )

feature_importance

Compute a normalized feature importance vector from consequent weights.

Source code in highfis/estimators/_base.py
def feature_importance(self) -> np.ndarray | None:
    """Compute a normalized feature importance vector from consequent weights."""
    check_is_fitted(self, "model_")
    weights = self.model_.get_consequent_weights()
    if weights is None:
        return None

    consequent_layer = self.model_.consequent_layer
    if hasattr(consequent_layer, "rule_feature_mask"):
        rule_feature_mask = cast(Tensor, consequent_layer.rule_feature_mask)
        weights = weights * rule_feature_mask.unsqueeze(1) if weights.ndim == 3 else weights * rule_feature_mask

    abs_weights = weights.abs()
    if abs_weights.ndim == 3:
        importance = abs_weights.mean(dim=(0, 1))
    elif abs_weights.ndim == 2:
        importance = abs_weights.mean(dim=0)
    else:
        raise ValueError("unsupported consequent weight shape for feature importance")

    return _normalize_importance(importance)

fit

Train the TSK regressor on labeled samples.

Validation data should be supplied using x_val and y_val when available.

Source code in highfis/estimators/_base.py
def fit(
    self,
    x: npt.ArrayLike,
    y: npt.ArrayLike,
    *,
    x_val: npt.ArrayLike | None = None,
    y_val: npt.ArrayLike | None = None,
    metrics: list[str] | None = None,
) -> Self:
    """Train the TSK regressor on labeled samples.

    Validation data should be supplied using ``x_val`` and ``y_val``
    when available.
    """
    x_arr, y_arr = validate_data(self, x, y, reset=True)
    n_samples = x_arr.shape[0]
    n_mfs_val = getattr(self, "n_mfs", 3)
    n_mfs_val = 3 if n_mfs_val is None else n_mfs_val
    mf_init_val = getattr(self, "mf_init", "kmeans")
    required_samples = 2 if mf_init_val == "grid" else max(2, n_mfs_val)
    if n_samples < required_samples:
        raise ValueError(
            f"Found array with {n_samples} sample(s). Estimator requires at least {required_samples} samples."
        )

    if self.random_state is not None:
        torch.manual_seed(int(self.random_state))

    input_mfs, _, effective_rule_base = self._build_input_mfs(x_arr)

    self.n_features_in_ = x_arr.shape[1]

    _device = torch.device(str(self.device))
    self.model_ = self._build_regressor_model(input_mfs, effective_rule_base).to(_device)

    y_t = torch.as_tensor(np.asarray(y_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    # Prepare validation tensors if provided via fit.
    x_val_t: torch.Tensor | None = None
    y_val_t: torch.Tensor | None = None
    if (x_val is None) != (y_val is None):
        raise ValueError("x_val and y_val must be provided together")
    if x_val is not None and y_val is not None:
        x_v_arr, y_v_arr = validate_data(self, x_val, y_val, reset=False)
        x_val_t = self._as_tensor_x(x_v_arr, _device)
        y_val_t = torch.as_tensor(np.asarray(y_v_arr, dtype=np.float32), dtype=torch.float32, device=_device)

    x_t = self._as_tensor_x(x_arr, _device)
    self.rule_base_ = effective_rule_base
    self._pre_train_hook(self.model_, x_t, y_t)
    _trainer = self.trainer if self.trainer is not None else self._get_trainer()
    self.history_ = _trainer.fit(self.model_, x_t, y_t, x_val=x_val_t, y_val=y_val_t, metrics=metrics)
    return self

get_mf_params

Return model membership function metadata after fitting.

Source code in highfis/estimators/_base.py
def get_mf_params(self) -> dict[str, list[dict[str, Any]]]:
    """Return model membership function metadata after fitting."""
    check_is_fitted(self, "model_")
    return self.model_.get_mf_params()

inspect

Return a structured summary of fitted model state and rule metadata.

Source code in highfis/estimators/_base.py
def inspect(self) -> dict[str, Any]:
    """Return a structured summary of fitted model state and rule metadata."""
    check_is_fitted(self, "model_")
    return {
        "n_rules": int(self.model_.n_rules),
        "n_inputs": int(self.model_.n_inputs),
        "feature_names": list(self.model_.input_names),
        "rule_base": self.rule_base_,
        "defuzzifier_type": type(self.model_.defuzzifier).__name__,
        "mf_params": self.get_mf_params(),
        "rule_table": self.model_.get_rule_table(),
    }

load classmethod

Load a persisted estimator created by save.

Source code in highfis/estimators/_base.py
@classmethod
def load(cls, path: str) -> Self:
    """Load a persisted estimator created by save."""
    checkpoint = load_checkpoint(path)
    validate_checkpoint_payload(checkpoint, expected_estimator_class=cls.__name__)

    params: dict[str, Any] = dict(checkpoint["estimator_params"])
    if params.get("input_configs") is not None:
        params["input_configs"] = [InputConfig(**c) for c in params["input_configs"]]
    estimator = cls(**params)
    model_init = checkpoint["model_init"]
    estimator.rule_base_ = model_init["rule_base"]

    import inspect

    sig = inspect.signature(estimator._build_regressor_model)
    if "rules" in sig.parameters:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
            rules=model_init.get("rules"),
        )
    else:
        estimator.model_ = estimator._build_regressor_model(
            deserialize_input_mfs(model_init["input_mfs_config"]),
            str(model_init["rule_base"]),
        )

    consequent_mode = model_init.get("consequent_mode")
    if consequent_mode is not None:
        if hasattr(estimator.model_, "set_consequent_mode"):
            cast(Any, estimator.model_).set_consequent_mode(consequent_mode)
        elif hasattr(estimator.model_.consequent_layer, "mode"):
            estimator.model_.consequent_layer.mode = consequent_mode

    estimator.model_.load_state_dict(checkpoint["model_state_dict"])
    estimator.model_.to(torch.device(str(estimator.device)))

    fitted = checkpoint["fitted_attrs"]
    estimator.n_features_in_ = int(fitted["n_features_in"])
    if fitted.get("feature_names_in") is not None:
        estimator.feature_names_in_ = np.asarray(fitted["feature_names_in"], dtype=object)
    elif hasattr(estimator, "feature_names_in_"):
        delattr(estimator, "feature_names_in_")
    history = checkpoint.get("history")
    estimator.history_ = history if history is not None else {}
    return estimator

predict

Predict continuous target values for input samples.

Source code in highfis/estimators/_base.py
def predict(self, x: npt.ArrayLike) -> np.ndarray:
    """Predict continuous target values for input samples."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, x, reset=False)
    device_str = str(self.device).lower()
    x_tensor = torch.as_tensor(x_arr, dtype=torch.float32, device=torch.device(device_str))
    preds = cast(Any, self.model_).predict(x_tensor)
    return preds.detach().cpu().numpy()

rule_activation

Return normalized rule activations for the provided inputs.

Source code in highfis/estimators/_base.py
def rule_activation(self, X: npt.ArrayLike) -> np.ndarray:
    """Return normalized rule activations for the provided inputs."""
    check_is_fitted(self, "model_")
    x_arr = validate_data(self, X, reset=False)

    was_training = self.model_.training
    try:
        self.model_.eval()
        with torch.no_grad():
            norm_w = self.model_.forward_antecedents(self._as_tensor_x(x_arr, torch.device(str(self.device))))
    finally:
        self.model_.train(was_training)

    return _to_numpy(norm_w)

save

Persist estimator configuration, model weights and fitted metadata.

Source code in highfis/estimators/_base.py
def save(self, path: str) -> None:
    """Persist estimator configuration, model weights and fitted metadata."""
    _fnames: np.ndarray | None = getattr(self, "feature_names_in_", None)
    rules = None
    if hasattr(self.model_, "rule_layer") and hasattr(self.model_.rule_layer, "rules"):
        rules = self.model_.rule_layer.rules
    consequent_mode = getattr(self.model_.consequent_layer, "mode", None)
    checkpoint = self._build_checkpoint_base(
        model_init={
            "input_mfs_config": serialize_input_mfs(self.model_.input_mfs),
            "rule_base": self.rule_base_,
            "rules": rules,
            "consequent_mode": consequent_mode,
        },
        fitted_attrs={
            "n_features_in": int(self.n_features_in_),
            "feature_names_in": _fnames.tolist() if _fnames is not None else None,
        },
    )
    save_checkpoint(path, checkpoint)

feature_coverage_rate

Compute the feature coverage rate (FCR) for MHTSK heads.

FCR is the expected proportion of original features that are selected at least once across n_heads random subsets of size head_size.

Source code in highfis/estimators/_mhtsk.py
def feature_coverage_rate(n_features: int, head_size: int, n_heads: int) -> float:
    """Compute the feature coverage rate (FCR) for MHTSK heads.

    FCR is the expected proportion of original features that are selected at
    least once across ``n_heads`` random subsets of size ``head_size``.
    """
    if n_features <= 0:
        raise ValueError("n_features must be > 0")
    if head_size <= 0 or head_size > n_features:
        raise ValueError("head_size must be between 1 and n_features")
    if n_heads < 0:
        raise ValueError("n_heads must be >= 0")

    return 1.0 - (1.0 - float(head_size) / float(n_features)) ** float(n_heads)