Optimisers
Training strategies for highFIS estimators.
Trainers decouple the optimisation loop from the sklearn estimator layer. GradientTrainer implements standard single-phase mini-batch gradient descent. DGTrainer implements the three-phase data-guided (DG) training protocol required by DG-TSK and DG-ALETSK. FSRETrainer implements the three-phase FSRE training protocol required by FSRE-ADATSK.
Optimisers
GradientTrainer— standard mini-batch gradient descent.DGTrainer— data-guided three-phase protocol for DG-TSK and DG-ALETSK.FSRETrainer— three-phase FSRE protocol for FSRE-ADATSK.
BaseTrainer
Bases: ABC
Abstract base class for training strategies.
A trainer encapsulates the optimisation loop and is decoupled from the sklearn estimator. Concrete subclasses implement the full training protocol — e.g., single-phase gradient descent, three-phase DG training, or hybrid LSE / gradient procedures.
fit
abstractmethod
Train model on (x, y) and return a history dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseTSK
|
The BaseTSK model to train. |
required |
x
|
Tensor
|
Training input tensor of shape |
required |
y
|
Tensor
|
Training target tensor. |
required |
x_val
|
Tensor | None
|
Optional validation input tensor. |
None
|
y_val
|
Tensor | None
|
Optional validation target tensor. |
None
|
metrics
|
list[str] | None
|
Optional list of metric names to evaluate. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary with training history. Keys depend on the concrete |
dict[str, Any]
|
implementation. GradientTrainer returns the history |
dict[str, Any]
|
dict from BaseTSK.fit(). DGTrainer |
dict[str, Any]
|
returns a dict with keys |
dict[str, Any]
|
|
Source code in highfis/optim/_base.py
DGTrainer
Bases: BaseTrainer
Three-phase trainer for DG-TSK and DG-ALETSK estimators.
Implements the data-guided (DG) training procedure described in Xue et al. (2023), which consists of three sequential phases:
- DG phase — Train gate parameters (λ, θ) and zero-order consequent parameters. For DG-TSK the antecedent MF parameters are frozen (P-FRB, paper §III-A). For DG-ALETSK the antecedents are updated together with the gates (CoCo-FRB, paper eq. 22).
- Threshold search — Grid-search over
(zeta_lambda, zeta_theta)pairs to find the pruning thresholds that maximise held-out performance, optionally refitting first-order consequents via LSE. - Fine-tune phase — Convert the model to first-order consequents and retrain with antecedent MFs and feature gates (λ) frozen.
Each phase is delegated to the corresponding method on the model: fit_dg_phase(), search_thresholds(), and fit_finetune().
Example
Initialise a DG trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dg_epochs
|
int
|
Epochs for the DG phase (phase 1). |
10
|
dg_learning_rate
|
float
|
SGD learning rate for the DG phase. |
0.01
|
dg_batch_size
|
int | None
|
Mini-batch size for the DG phase. |
512
|
dg_shuffle
|
bool
|
Reshuffle samples each epoch in the DG phase. |
True
|
dg_patience
|
int | None
|
Early-stopping patience for the DG phase. |
20
|
dg_weight_decay
|
float
|
L2 weight-decay for the DG phase. |
1e-08
|
dg_ur_weight
|
float
|
Uncertainty regularisation weight for the DG phase. |
0.0
|
dg_ur_target
|
float | None
|
Uncertainty regularisation target for the DG phase. |
None
|
zeta_lambda
|
list[float] | None
|
Grid of λ-threshold candidates for pruning. If
|
None
|
zeta_theta
|
list[float] | None
|
Grid of θ-threshold candidates. Same default. |
None
|
use_lse
|
bool
|
Refit first-order consequents via LSE during threshold
search. Recommended (default |
True
|
finetune_epochs
|
int
|
Epochs for the fine-tune phase (phase 3). |
200
|
finetune_learning_rate
|
float
|
Adam learning rate for fine-tuning. |
0.01
|
finetune_batch_size
|
int | None
|
Mini-batch size for fine-tuning. |
512
|
finetune_shuffle
|
bool
|
Reshuffle samples each epoch during fine-tuning. |
True
|
finetune_patience
|
int | None
|
Early-stopping patience for fine-tuning. |
20
|
finetune_restore_best
|
bool
|
Restore best validation weights after fine-tuning. |
True
|
finetune_weight_decay
|
float
|
L2 weight-decay for fine-tuning. |
1e-08
|
finetune_ur_weight
|
float
|
Uncertainty regularisation weight for fine-tuning. |
0.0
|
finetune_ur_target
|
float | None
|
Uncertainty regularisation target for fine-tuning. |
None
|
verbose
|
bool | int
|
Verbosity level forwarded to all three phases. |
False
|
loss
|
Callable[..., Any] | None
|
Custom loss function |
None
|
optimizer_type
|
str
|
Optimiser type used in all three phases. |
'sgd'
|
structural_pruning
|
bool
|
If |
True
|
finetune_freeze_antecedents
|
bool
|
If |
True
|
Source code in highfis/optim/_dg.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
fit
Execute the three-phase DG training procedure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseTSK
|
A DG-TSK or DG-ALETSK model instance, such as DGTSKClassifierModel, DGTSKRegressorModel, DGALETSKClassifierModel, or DGALETSKRegressorModel. |
required |
x
|
Tensor
|
Training inputs of shape |
required |
y
|
Tensor
|
Training targets. |
required |
x_val
|
Tensor | None
|
Validation inputs (used for threshold-search scoring).
When |
None
|
y_val
|
Tensor | None
|
Validation targets. |
None
|
metrics
|
list[str] | None
|
Optional list of metric names to evaluate. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in highfis/optim/_dg.py
FSRETrainer
Bases: BaseTrainer
Three-phase trainer for FSRE-ADATSK classifier and regressor models.
Implements FSRE Algorithm, which consists of three sequential phases:
- FS phase — Train with CoCo-FRB and feature gates M(λ_d) active (paper eq. 21). After training, features with gate activation M(λ_d) > τ_λ are retained.
- RE phase — Expand to En-FRB and train with rule gates M(θ_r) active (paper eq. 22). After training, rules with gate activation M(θ_r) > τ_θ are retained. For classifiers, at least n_classes rules are kept.
- Fine-tune phase — Train the pruned model without gates (paper eq. 5).
Thresholds are computed directly from scalar zeta coefficients.
Example
Initialise an FSRE trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fs_epochs
|
int
|
Epochs for the FS phase (phase 1). Default |
10
|
fs_learning_rate
|
float
|
Adam learning rate for the FS phase. |
0.01
|
fs_batch_size
|
int | None
|
Mini-batch size for the FS phase. |
512
|
fs_shuffle
|
bool
|
Reshuffle samples each epoch in the FS phase. |
True
|
fs_patience
|
int | None
|
Early-stopping patience for the FS phase. |
20
|
fs_weight_decay
|
float
|
L2 weight-decay for the FS phase. |
1e-08
|
fs_ur_weight
|
float
|
Uncertainty regularisation weight for the FS phase. |
0.0
|
fs_ur_target
|
float | None
|
Uncertainty regularisation target for the FS phase. |
None
|
re_epochs
|
int
|
Epochs for the RE phase (phase 2). Default |
10
|
re_learning_rate
|
float
|
Adam learning rate for the RE phase. |
0.01
|
re_batch_size
|
int | None
|
Mini-batch size for the RE phase. |
512
|
re_shuffle
|
bool
|
Reshuffle samples each epoch in the RE phase. |
True
|
re_patience
|
int | None
|
Early-stopping patience for the RE phase. |
20
|
re_weight_decay
|
float
|
L2 weight-decay for the RE phase. |
1e-08
|
re_ur_weight
|
float
|
Uncertainty regularisation weight for the RE phase. |
0.0
|
re_ur_target
|
float | None
|
Uncertainty regularisation target for the RE phase. |
None
|
finetune_epochs
|
int
|
Epochs for the fine-tune phase (phase 3).
Default |
100
|
finetune_learning_rate
|
float
|
Adam learning rate for fine-tuning. |
0.01
|
finetune_batch_size
|
int | None
|
Mini-batch size for fine-tuning. |
512
|
finetune_shuffle
|
bool
|
Reshuffle samples each epoch during fine-tuning. |
True
|
finetune_patience
|
int | None
|
Early-stopping patience for fine-tuning. |
20
|
finetune_restore_best
|
bool
|
Restore best validation weights after fine-tuning. |
True
|
finetune_weight_decay
|
float
|
L2 weight-decay for fine-tuning. |
1e-08
|
finetune_ur_weight
|
float
|
Uncertainty regularisation weight for fine-tuning. |
0.0
|
finetune_ur_target
|
float | None
|
Uncertainty regularisation target for fine-tuning. |
None
|
zeta_lambda
|
float
|
Coefficient to compute the feature-selection
threshold τ_λ (paper eq. 28). Larger values retain more
features; |
_DEFAULT_ZETA_LAMBDA
|
zeta_theta
|
float
|
Coefficient to compute the rule-extraction threshold
τ_θ (paper eq. 29). |
_DEFAULT_ZETA_THETA
|
structural_pruning
|
bool
|
If |
True
|
verbose
|
bool | int
|
Verbosity level forwarded to all three phases. |
False
|
loss
|
Callable[..., Any] | None
|
Custom loss function |
None
|
Source code in highfis/optim/_fsre.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
fit
Execute the three-phase FSRE training procedure (Algorithm 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseTSK
|
An FSRE-ADATSK model instance, such as FSREADATSKClassifierModel or FSREADATSKRegressorModel. |
required |
x
|
Tensor
|
Training inputs of shape |
required |
y
|
Tensor
|
Training targets. |
required |
x_val
|
Tensor | None
|
Validation inputs (used for early stopping).
When |
None
|
y_val
|
Tensor | None
|
Validation targets. |
None
|
metrics
|
list[str] | None
|
Optional list of metric names to evaluate. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with keys: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
Source code in highfis/optim/_fsre.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
GradientTrainer
Bases: BaseTrainer
Single-phase mini-batch gradient descent trainer.
This is the default trainer used by all standard highFIS estimators.
Example::
from highfis.optim import GradientTrainer
trainer = GradientTrainer(epochs=200, learning_rate=1e-3)
history = trainer.fit(model, x_train, y_train)
Initialise a gradient trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epochs
|
int
|
Maximum number of full passes over the training data. |
200
|
learning_rate
|
float
|
Initial learning rate for the Adam optimiser. |
0.01
|
batch_size
|
int | None
|
Mini-batch size. |
512
|
shuffle
|
bool
|
Reshuffle samples before each epoch. |
True
|
patience
|
int | None
|
Early-stopping patience. |
20
|
restore_best
|
bool
|
Restore the best validation weights after training. |
True
|
weight_decay
|
float
|
L2 weight-decay for consequent parameters. |
1e-08
|
ur_weight
|
float
|
Uncertainty regularisation weight. |
0.0
|
ur_target
|
float | None
|
Uncertainty regularisation target firing-level. |
None
|
verbose
|
bool | int
|
Verbosity level.
- |
False
|
loss
|
Callable[..., Any] | None
|
Custom loss function |
None
|
Source code in highfis/optim/_gradient.py
fit
Train model for :attr:epochs epochs and return the history dict.
Source code in highfis/optim/_gradient.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |