Batch inference, serialization & scikit-learn¶
Batch (vectorized) inference¶
Calling a system evaluates one sample. predict(**arrays) evaluates many at once
— pass an array per variable and get an array back. Available on Mamdani and
TSK.
import numpy as np
from fuzzytool import datasets
sys, *_ = datasets.credit_risk()
scores = np.array([520.0, 660.0, 800.0])
dtis = np.array([42.0, 30.0, 10.0])
sys.predict(score=scores, dti=dtis) # -> array([10.16, 6. , 1.91]), one premium per sample
The result matches calling the system once per sample, but the firing, implication and aggregation steps run vectorized.
Saving and loading systems¶
Serialize a Mamdani or TSK system to JSON and restore it later. Connectives and the defuzzifier must be given by name, variables must use built-in membership functions, and TSK consequents must be numbers or coefficient mappings.
fuzzytool.membership.to_dict/from_dict and Variable.to_dict/from_dict
expose the building blocks if you need finer control.
scikit-learn compatibility¶
ANFIS follows the estimator protocol (fit returns self, plus predict,
get_params, set_params), so it drops into a Pipeline or GridSearchCV
without importing scikit-learn at all: