Operator and Hedge
These expose the building blocks the inference engine uses internally, so you can compute degrees by hand, check homework, or write custom inference. For the formulas and properties, see Fuzzy operators.
Every function accepts either a type‑1 degree (float) or an interval type‑2 degree
((lower, upper) tuple) and returns the same kind. Mixing a float and a tuple in one call
raises TypeError.
Operator.t_norm: fuzzy AND
import ferrifuzz as ff
ff.Operator.t_norm(mu1, mu2, kind="min")
kind (aliases) | Formula | t_norm(0.7, 0.4, kind) |
|---|---|---|
"min" (godel, zadeh, standard) | 0.4 | |
"product" (prod, algebraic) | 0.28 | |
"lukasiewicz" (luk, bounded) | 0.1 | |
"drastic" | if ; if ; else | 0.0 |
"einstein" | 0.2373 | |
"hamacher" | (0 when ) | 0.3415 |
Operator.t_conorm: fuzzy OR
ff.Operator.t_conorm(mu1, mu2, kind="max")
kind (aliases) | Formula | t_conorm(0.7, 0.4, kind) |
|---|---|---|
"max" (godel, zadeh, standard) | 0.7 | |
"probor" (prob, probabilistic, algebraic) | 0.82 | |
"lukasiewicz" (luk, bounded) | 1.0 | |
"drastic" | if ; if ; else | 1.0 |
"einstein" | 0.8594 | |
"hamacher" | (1 when ) | 0.75 |
Operator.complement: fuzzy NOT
ff.Operator.complement(mu, kind="standard", param=1.0)
kind | Formula | Parameter |
|---|---|---|
"standard" (zadeh) | ignored | |
"sugeno" | param = λ, must be > −1 (λ = 0 gives the standard complement) | |
"yager" | param = w, must be > 0 (w = 1 gives the standard complement) |
ff.Operator.complement(0.7) # 0.3
ff.Operator.complement(0.7, "sugeno", 2.0) # 0.125
ff.Operator.complement(0.7, "yager", 2.0) # 0.7141...
An unknown kind, or a parameter outside its range, raises ff.FuzzyError (a
ValueError):
ferrifuzz.FuzzyError: unknown t-norm 'prdouct' (did you mean 'product'?); valid options: 'min', 'product', 'lukasiewicz', 'drastic', 'einstein', 'hamacher'
ferrifuzz.FuzzyError: Yager complement needs w > 0
Interval type‑2 degrees
T‑norms and t‑conorms apply bound by bound. The complement swaps the bounds so the result
stays ordered (lower ≤ upper):
ff.Operator.t_norm((0.6, 0.8), (0.5, 0.9)) # (0.5, 0.8)
ff.Operator.t_conorm((0.6, 0.8), (0.5, 0.9)) # (0.6, 0.9)
ff.Operator.complement((0.6, 0.8)) # (0.2, 0.4)
Hedge
A power hedge . concentrates ("very"), dilates ("somewhat"). Hedges are callable.
ff.Hedge(power: float)
| Constructor | Power | Rule word(s) |
|---|---|---|
ff.Hedge.very() | 2 | very |
ff.Hedge.extremely() | 3 | extremely |
ff.Hedge.plus() | 1.25 | plus |
ff.Hedge.minus() | 0.75 | minus |
ff.Hedge.somewhat() | 0.5 | somewhat, more_or_less |
ff.Hedge.slightly() | 0.5 | slightly |
ff.Hedge(p) | any p > 0 | (custom) |
very = ff.Hedge.very()
print(very(0.8)) # 0.64
print(very((0.6, 0.9))) # (0.36, 0.81) -- IT2: both bounds
print(very.power, very) # 2.0 Hedge(power=2)
ff.Hedge.somewhat()(0.64) # 0.8
In a rule string you don't need Hedge at all: write the word, e.g.
IF temp IS very hot THEN .... See Rule syntax.
How the engine uses them
- Inside an AND‑group of a rule, clause degrees are combined with
FuzzySystem(and_method=...); OR‑groups are combined withor_method. NOTin a rule uses the standard complement .- Hedges in rules use the powers above.
temp_hot, hum_high = 0.7, 0.4
strength = ff.Operator.t_norm(temp_hot, hum_high, "product") # 0.28, what and_method="product" computes