graph TD
A[Start: What are you defining?] --> B{Membership shape or logic operation?}
B -->|Logic| C{Need AND / OR / NOT?}
C --> C1[Use FUZZY_AND]
C --> C2[Use FUZZY_OR]
C --> C3[Use FUZZY_NOT]
B -->|Membership| D{Need crisp corners or smooth transitions?}
D -->|Crisp / piecewise| E{Triangle, trapezoid, or custom piecewise?}
E --> E1[Use TRIMF]
E --> E2[Use TRAPMF]
E --> E3[Use PIECEMF]
D -->|Smooth| F{Bell/Gaussian or S/Z/Sigmoid family?}
F --> F1[Use GAUSSMF or GAUSS2MF]
F --> F2[Use GBELLMF]
F --> F3[Use SIGMF / SMF / ZMF / PIMF / PSIGMF]
C1 --> G[Aggregate output set]
C2 --> G
C3 --> G
E1 --> G
E2 --> G
E3 --> G
F1 --> G
F2 --> G
F3 --> G
G --> H[Convert to crisp output with DEFUZZ]
Fuzzy
Overview
Introduction Fuzzy logic is a framework for reasoning with degrees of truth rather than strict binary true/false states. In classical control, a condition is either satisfied or not; in fuzzy control, a condition can be partially satisfied, typically represented by a membership value in [0,1]. This makes fuzzy systems especially useful for engineering environments where measurements are noisy, linguistic rules are easier to define than exact physics, or operators naturally think in terms like “low pressure,” “moderate temperature,” and “high vibration.” A formal background appears in fuzzy logic theory, and practical numerical implementations are available through scikit-fuzzy and its API reference.
In business and industrial settings, fuzzy methods matter because many real decisions are not crisply separable. A chiller might not be simply “on” or “off” in terms of urgency; maintenance urgency might be “somewhat high.” Product quality may be “acceptable but drifting.” Demand risk may be “moderately elevated.” Fuzzy sets let teams encode this ambiguity into reproducible numeric logic. Instead of forcing unrealistic thresholds, engineers can map real sensor ranges into smooth membership curves, combine these curves with fuzzy operators, and then convert the result into a crisp action signal for actuation, ranking, or reporting.
This category provides the core building blocks for that pipeline. Membership-shape generators define linguistic terms: TRIMF, TRAPMF, GAUSSMF, GAUSS2MF, GBELLMF, SIGMF, SMF, ZMF, PIMF, PSIGMF, and PIECEMF. Logical composition operators combine conditions: FUZZY_AND, FUZZY_OR, and FUZZY_NOT. Final action extraction is handled by DEFUZZ. Together these functions support end-to-end design from variable fuzzification through rule aggregation to control output.
Compared with hard-threshold spreadsheets, fuzzy models are often easier to tune and explain to domain experts. A reliability lead can adjust the “high risk” curve shape directly rather than debating one arbitrary cutoff value. A controls engineer can widen a transition region in minutes and observe smoother actuator behavior. Because the functions are deterministic and based on standard formulations, they also fit quality-assurance and governance workflows better than ad-hoc heuristic formulas.
When to Use It Use this category when the job is to convert uncertain, continuous, or qualitative conditions into stable numerical decisions. Fuzzy control is not a replacement for all model-based control; it is a practical layer when interpretability and robustness to ambiguity are priorities.
One common use case is industrial process control with overlapping regimes. Consider a reactor temperature loop where “too cold,” “optimal,” and “too hot” overlap instead of switching at one exact degree. Membership functions such as SMF, ZMF, or TRAPMF define these regimes smoothly. Rule antecedents are combined with FUZZY_AND and FUZZY_OR, for example, “temperature is high AND pressure is high.” The aggregated control surface is translated to a valve command via DEFUZZ. This approach reduces aggressive switching near boundaries and can lower actuator wear.
A second scenario is condition-based maintenance triage. Asset teams often evaluate vibration, temperature drift, lubricant condition, and historical alarms, none of which cleanly separate “healthy” from “failing.” Membership functions like GAUSSMF or GBELLMF can represent normal operating bands with soft tails; PIMF and PSIGMF can represent plateau-like “acceptable windows.” Combining conditions through FUZZY_AND, FUZZY_OR, and FUZZY_NOT yields an interpretable risk intensity. The final maintenance priority score can then be produced by DEFUZZ, enabling work-order ranking without brittle if/else trees.
A third scenario is human-centric decision support in operations and planning. Dispatchers and planners naturally speak in linguistic terms (“demand is rising quickly,” “inventory is low but not critical”). Functions like SIGMF and GAUSS2MF can encode asymmetric transitions and central safe bands. PIECEMF is useful when policy rules are piecewise linear and easy to justify to stakeholders. The resulting fuzzy score can drive recommendations while preserving transparency, which is often harder to achieve with black-box models.
Fuzzy tools are also useful when data are limited for training complex machine learning models. If there is enough domain expertise to define credible linguistic rules, a fuzzy controller can be deployed quickly, audited easily, and iteratively tuned. They are especially strong in early-stage system design, retrofit projects, and regulated environments where explainability is mandatory.
Use caution in cases requiring strict optimality guarantees or deep multivariate dynamics over long horizons; in those contexts, model predictive control or optimization-based methods may be more appropriate. Even then, fuzzy layers can still complement those methods by handling operator overrides, fail-safe transitions, or qualitative supervisory logic.
How It Works At a high level, fuzzy control has three steps: fuzzification, inference, and defuzzification.
- Fuzzification maps a crisp input x to one or more membership values.
- Inference combines memberships through logical operators and rule structures.
- Defuzzification maps the resulting fuzzy output set back to a crisp number.
For a membership function \mu_A(x) of set A, the core requirement is:
\mu_A(x) \in [0,1].
Triangular and trapezoidal sets are standard interpretable shapes. With parameters a\le b\le c, TRIMF represents:
\mu(x)= \begin{cases} 0, & x\le a\\ \frac{x-a}{b-a}, & a < x \le b\\ \frac{c-x}{c-b}, & b < x < c\\ 0, & x\ge c \end{cases}
With a\le b\le c\le d, TRAPMF adds a flat top for sustained full membership. PIECEMF supports piecewise linear constructions aligned with FIRE-style filter logic and policy-friendly linear segments.
Smooth alternatives are often preferred when derivatives or transition smoothness matter. GAUSSMF uses a Gaussian profile,
\mu(x)=\exp\left(-\frac{(x-m)^2}{2\sigma^2}\right),
while GAUSS2MF combines two Gaussian sides with a full-membership plateau between centers. GBELLMF provides additional slope and width flexibility via a generalized bell form. Sigmoid families include SIGMF, and composite sigmoid windows are available through PSIGMF. S- and Z-curves are provided by SMF and ZMF, and PIMF offers a smooth plateau-like “pi” shape equivalent to a product of S and Z behavior.
After fuzzification, logical composition defines rule strength. In the standard max–min setting, intersections and unions are:
\mu_{A \cap B}(x)=\min(\mu_A(x),\mu_B(x)), \qquad \mu_{A \cup B}(x)=\max(\mu_A(x),\mu_B(x)).
These operations are implemented by FUZZY_AND and FUZZY_OR. Complement is
\mu_{\neg A}(x)=1-\mu_A(x),
implemented by FUZZY_NOT.
Rules typically look like: “IF temperature is high AND flow is low THEN valve command is medium-high.” Antecedent truth values are computed from memberships and fuzzy operators. Consequent membership functions are clipped/scaled by rule strength and aggregated across all rules. The resulting output fuzzy set is then converted into a crisp value using DEFUZZ.
The most common defuzzification method is centroid (center of area):
x^*=\frac{\int x\,\mu(x)\,dx}{\int \mu(x)\,dx},
which balances all activated regions and typically yields smooth control signals. Other methods such as bisector, mean of maxima, smallest of maxima, and largest of maxima can be useful for different control preferences (e.g., conservative vs. aggressive actuation).
Practical assumptions to keep in mind: - Universe arrays should be well-ordered and adequately resolved so membership shapes are represented accurately. - Parameter constraints matter (for example, ordered breakpoints in TRIMF, TRAPMF, PIMF, and PIECEMF). - Fuzzy inference does not remove noise by itself; it reframes decision boundaries. Upstream filtering may still be necessary. - Interpretability depends on disciplined naming and calibration of linguistic sets.
In Boardflare workflows, these functions let teams keep an Excel-friendly interface while relying on numerically robust Python implementations from scikit-fuzzy. That combination is often the key advantage: domain experts can reason in plain language while the underlying computation remains consistent and auditable.
Practical Example Consider a simplified HVAC supervisory controller for a manufacturing floor. The goal is to produce a fan-speed command from two inputs: temperature deviation from setpoint (\Delta T) and particulate concentration (P). The operator wants smooth behavior and interpretable rules:
- If temperature is high OR particulates are high, increase fan speed.
- If both are very high, increase fan speed aggressively.
- If temperature is near target and particulates are low, keep fan speed moderate.
Step 1 is defining universes. Suppose \Delta T \in [-5,5] °C and P\in[0,300] µg/m³. Output fan command u\in[0,100]\%.
Step 2 is creating linguistic sets. - For temperature: “cool,” “neutral,” and “hot.” “Hot” can be modeled with SMF, “cool” with ZMF, and “neutral” with GAUSSMF or TRIMF. - For particulates: “low,” “elevated,” “high.” “High” can use SIGMF, and “elevated” can use TRAPMF or GBELLMF. - For output fan speed: “low,” “medium,” “high,” represented by TRIMF or PIMF.
Step 3 is evaluating an observation, e.g., \Delta T=2.2 and P=180. Each set returns a membership degree. Assume resulting strengths include: - hot(\Delta T) = 0.74 - elevated(P) = 0.63 - high(P) = 0.41
Step 4 is computing rule activations with fuzzy operators. - Rule A: IF hot OR high-particle THEN high-speed - strength via FUZZY_OR: \max(0.74,0.41)=0.74 - Rule B: IF hot AND elevated-particle THEN high-speed - strength via FUZZY_AND: \min(0.74,0.63)=0.63 - Rule C: IF NOT hot AND low-particle THEN medium-speed - use FUZZY_NOT on hot first, then combine.
Step 5 is aggregating consequents. Output sets for “high-speed” and “medium-speed” are clipped by the rule strengths and merged (usually by max). This creates one aggregated output membership curve over u\in[0,100].
Step 6 is obtaining a crisp command with DEFUZZ, typically using centroid. Suppose the result is u=71.8\%. That value can be sent to the actuator directly or rounded per control policy.
Why this beats a hard-threshold spreadsheet in this scenario: - No abrupt jumps when readings cross single cutoffs. - Easier tuning: widen or shift curves instead of rewriting many nested conditions. - Better traceability: each rule maps to an operator-understandable statement.
Where the other membership generators fit in real tuning cycles: - GAUSS2MF can model “ideal operating band with smooth tails.” - PSIGMF can approximate soft rectangular windows. - PIECEMF is useful when facility policies are naturally piecewise linear.
In deployment, teams typically calibrate parameters from historical logs: pick initial breakpoints from percentiles, run backtests, compare actuator oscillation and comfort/compliance metrics, then refine. Because the functions are modular, updating one curve does not require redesigning the whole system.
How to Choose Selecting the right function is mostly a question of desired shape, smoothness, and interpretability.
Use TRIMF when stakeholders want maximum interpretability and you can define clear left/peak/right points. Use TRAPMF when full membership should persist across a range, not a single peak. Use PIECEMF when policy or empirical behavior is explicitly piecewise linear.
Choose GAUSSMF for smooth, symmetric concepts around a center, and GAUSS2MF when you need a smooth plateau bounded by different left/right spreads. GBELLMF is a flexible middle ground when you need tunable shoulder steepness without switching function families.
For monotonic transitions, SIGMF is the direct choice. SMF and ZMF provide classic rising/falling S-curves with intuitive foot/ceiling parameters. PIMF works well for “acceptable middle zone” definitions, while PSIGMF is useful for constructing soft rectangular windows from two sigmoids.
For logical composition, use FUZZY_AND for strict co-occurrence emphasis (soft minimum), FUZZY_OR when any condition can drive activation (soft maximum), and FUZZY_NOT for complements (e.g., “not high load”).
Finally, choose DEFUZZ method based on control behavior: - Centroid for balanced, smooth outputs in most control systems. - Bisector when equal-area partition is preferred. - MOM/SOM/LOM variants when maxima-based decisions align better with policy.
A practical selection strategy is to start simple: TRIMF/TRAPMF + FUZZY_AND/FUZZY_OR + centroid DEFUZZ. Move to smoother families (GAUSSMF, GBELLMF, PSIGMF, PIMF) only when you observe undesirable discontinuities, noisy switching, or calibration difficulty at boundaries. This staged approach keeps models explainable while still giving room for advanced tuning.
DEFUZZ
Defuzzification converts a fuzzy membership function into a single boolean or crisp numerical value. It is the final step in a fuzzy logic control system.
This function takes an array of universe variables and their corresponding fuzzy membership values, and applies a selected defuzzification method such as the centroid of area.
Excel Usage
=DEFUZZ(x, mfx, defuzz_mode)
x(list[list], required): Array of independent universe variables.mfx(list[list], required): Array of fuzzy membership values corresponding to x.defuzz_mode(str, optional, default: “centroid”): Defuzzification method to use.
Returns (float): Defuzzified crisp result.
Example 1: Centroid defuzzification of a simple triangle
Inputs:
| x | mfx | defuzz_mode | ||||
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 0 | 1 | 0 | centroid |
Excel formula:
=DEFUZZ({0,1,2}, {0,1,0}, "centroid")
Expected output:
1
Example 2: Bisector defuzzification of a symmetric triangle
Inputs:
| x | mfx | defuzz_mode | ||||
|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 0 | 1 | 0 | bisector |
Excel formula:
=DEFUZZ({0,1,2}, {0,1,0}, "bisector")
Expected output:
1
Example 3: Mean of maximum on a flat peak
Inputs:
| x | mfx | defuzz_mode | ||||||
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 0 | 1 | 1 | 0 | mom |
Excel formula:
=DEFUZZ({0,1,2,3}, {0,1,1,0}, "mom")
Expected output:
1.5
Example 4: Largest of maximum on repeated peaks
Inputs:
| x | mfx | defuzz_mode | ||||||
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 0.2 | 0.7 | 0.7 | 0.1 | lom |
Excel formula:
=DEFUZZ({0,1,2,3}, {0.2,0.7,0.7,0.1}, "lom")
Expected output:
2
Python Code
Show Code
import numpy as np
from skfuzzy import defuzz as fuzz_defuzz
def defuzz(x, mfx, defuzz_mode='centroid'):
"""
Defuzzify a membership function to return a crisp value.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.defuzz
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
mfx (list[list]): Array of fuzzy membership values corresponding to x.
defuzz_mode (str, optional): Defuzzification method to use. Valid options: Centroid, Bisector, Mean of Maximum, Min of Maximum, Max of Maximum. Default is 'centroid'.
Returns:
float: Defuzzified crisp result.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
mfx_arr = to1d(mfx)
if len(x_arr) == 0 or len(mfx_arr) == 0:
return "Error: Input arrays cannot be empty"
if len(x_arr) != len(mfx_arr):
return "Error: x and mfx must have the same number of elements"
result = fuzz_defuzz(x_arr, mfx_arr, mode=defuzz_mode)
return float(result)
except Exception as e:
return f"Error: {str(e)}"Online Calculator
FUZZY_AND
Computes the fuzzy AND operator, representing the intersection of two fully defined fuzzy sets. As a soft minimum, it returns the point-wise minimum of membership values from both sets overlapping the same universe.
Excel Usage
=FUZZY_AND(x, mfx, y, mfy)
x(list[list], required): Universe variable for the first fuzzy setmfx.mfx(list[list], required): Membership function values corresponding tox.y(list[list], required): Universe variable for the second fuzzy setmfy.mfy(list[list], required): Membership function values corresponding toy.
Returns (dict): Dictionary containing the combined universe points and the intersection membership values array.
Example 1: Fuzzy AND on matching universes
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 0.5 | 0.8 | 1 | 1 | 2 | 3 | 0.2 | 0.9 | 0.5 |
Excel formula:
=FUZZY_AND({1,2,3}, {0.5,0.8,1}, {1,2,3}, {0.2,0.9,0.5})
Expected output:
{"type":"Double","basicValue":0.2,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.2}],[{"type":"Double","basicValue":0.8}],[{"type":"Double","basicValue":0.5}]]}}}
Example 2: Fuzzy AND with overlapping shifted universes
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 0.1 | 0.7 | 1 | 1 | 2 | 3 | 0.4 | 0.9 | 0.2 |
Excel formula:
=FUZZY_AND({0,1,2}, {0.1,0.7,1}, {1,2,3}, {0.4,0.9,0.2})
Expected output:
{"type":"Double","basicValue":0.1,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.1}],[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.9}],[{"type":"Double","basicValue":0.2}]]}}}
Example 3: Fuzzy AND for singleton fuzzy sets
Inputs:
| x | mfx | y | mfy |
|---|---|---|---|
| 1 | 0.4 | 1 | 0.9 |
Excel formula:
=FUZZY_AND(1, 0.4, 1, 0.9)
Expected output:
{"type":"Double","basicValue":0.4,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.4}]]}}}
Example 4: Fuzzy AND of sparse membership profiles
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2 | 4 | 0 | 0.6 | 0.2 | 0 | 2 | 4 | 0.3 | 0.4 | 0.9 |
Excel formula:
=FUZZY_AND({0,2,4}, {0,0.6,0.2}, {0,2,4}, {0.3,0.4,0.9})
Expected output:
{"type":"Double","basicValue":0,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":4}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.2}]]}}}
Python Code
Show Code
import numpy as np
from skfuzzy import fuzzy_and as fuzz_and
def fuzzy_and(x, mfx, y, mfy):
"""
Calculate the fuzzy AND operator (intersection) of two fuzzy sets.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.fuzzy_and
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Universe variable for the first fuzzy set `mfx`.
mfx (list[list]): Membership function values corresponding to `x`.
y (list[list]): Universe variable for the second fuzzy set `mfy`.
mfy (list[list]): Membership function values corresponding to `y`.
Returns:
dict: Dictionary containing the combined universe points and the intersection membership values array.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
mfx_arr = to1d(mfx)
y_arr = to1d(y)
mfy_arr = to1d(mfy)
if len(x_arr) == 0 or len(mfx_arr) == 0 or len(y_arr) == 0 or len(mfy_arr) == 0:
return "Error: Input arrays cannot be empty"
if len(x_arr) != len(mfx_arr):
return "Error: x and mfx must have the same number of elements"
if len(y_arr) != len(mfy_arr):
return "Error: y and mfy must have the same number of elements"
z_arr, mfz_arr = fuzz_and(x_arr, mfx_arr, y_arr, mfy_arr)
return {
"type": "Double",
"basicValue": float(mfz_arr[0]) if len(mfz_arr) > 0 else 0.0,
"properties": {
"z": {
"type": "Array",
"elements": [[{"type": "Double", "basicValue": float(val)}] for val in z_arr]
},
"mfz": {
"type": "Array",
"elements": [[{"type": "Double", "basicValue": float(val)}] for val in mfz_arr]
}
}
}
except Exception as e:
return f"Error: {str(e)}"Online Calculator
FUZZY_NOT
Computes the fuzzy NOT operator, representing the complement of a fuzzy set.
This essentially reflects the membership function along the horizontal axis at y=0.5 by subtracting each membership value from 1.
Excel Usage
=FUZZY_NOT(mfx)
mfx(list[list], required): Original fuzzy membership array defined on an independent universe.
Returns (list[list]): Complement membership array of the input function.
Example 1: Complement of mixed membership values
Inputs:
| mfx | |||
|---|---|---|---|
| 0.2 | 0.5 | 0.8 | 1 |
Excel formula:
=FUZZY_NOT({0.2,0.5,0.8,1})
Expected output:
| Result |
|---|
| 0.8 |
| 0.5 |
| 0.2 |
| 0 |
Example 2: Complement of a singleton fuzzy value
Inputs:
| mfx |
|---|
| 0.25 |
Excel formula:
=FUZZY_NOT(0.25)
Expected output:
0.75
Example 3: Complement preserves zero and one bounds
Inputs:
| mfx | |
|---|---|
| 0 | 1 |
Excel formula:
=FUZZY_NOT({0,1})
Expected output:
| Result |
|---|
| 1 |
| 0 |
Example 4: Complement of a descending membership profile
Inputs:
| mfx | |||
|---|---|---|---|
| 1 | 0.75 | 0.25 | 0 |
Excel formula:
=FUZZY_NOT({1,0.75,0.25,0})
Expected output:
| Result |
|---|
| 0 |
| 0.25 |
| 0.75 |
| 1 |
Python Code
Show Code
import numpy as np
from skfuzzy import fuzzy_not as fuzz_not
def fuzzy_not(mfx):
"""
Calculate the fuzzy NOT operator (complement) of a fuzzy set.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.fuzzy_not
This example function is provided as-is without any representation of accuracy.
Args:
mfx (list[list]): Original fuzzy membership array defined on an independent universe.
Returns:
list[list]: Complement membership array of the input function.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
mfx_arr = to1d(mfx)
if len(mfx_arr) == 0:
return "Error: Input mapped array mfx cannot be empty"
result = fuzz_not(mfx_arr)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
FUZZY_OR
Computes the fuzzy OR operator, representing the union of two fully defined fuzzy sets. As a soft maximum, it returns the point-wise maximum of membership values from both sets overlapping the same universe.
Excel Usage
=FUZZY_OR(x, mfx, y, mfy)
x(list[list], required): Universe variable for the first fuzzy setmfx.mfx(list[list], required): Membership function values corresponding tox.y(list[list], required): Universe variable for the second fuzzy setmfy.mfy(list[list], required): Membership function values corresponding toy.
Returns (dict): Dictionary containing the combined universe points and the union membership values array.
Example 1: Fuzzy OR on matching universes
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 0.5 | 0.8 | 1 | 1 | 2 | 3 | 0.2 | 0.9 | 0.5 |
Excel formula:
=FUZZY_OR({1,2,3}, {0.5,0.8,1}, {1,2,3}, {0.2,0.9,0.5})
Expected output:
{"type":"Double","basicValue":0.5,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.5}],[{"type":"Double","basicValue":0.9}],[{"type":"Double","basicValue":1}]]}}}
Example 2: Fuzzy OR with overlapping shifted universes
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 0.1 | 0.7 | 1 | 1 | 2 | 3 | 0.4 | 0.9 | 0.2 |
Excel formula:
=FUZZY_OR({0,1,2}, {0.1,0.7,1}, {1,2,3}, {0.4,0.9,0.2})
Expected output:
{"type":"Double","basicValue":0.4,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.7}],[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":1}]]}}}
Example 3: Fuzzy OR for singleton fuzzy sets
Inputs:
| x | mfx | y | mfy |
|---|---|---|---|
| 1 | 0.4 | 1 | 0.9 |
Excel formula:
=FUZZY_OR(1, 0.4, 1, 0.9)
Expected output:
{"type":"Double","basicValue":0.9,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.9}]]}}}
Example 4: Fuzzy OR of sparse membership profiles
Inputs:
| x | mfx | y | mfy | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2 | 4 | 0 | 0.6 | 0.2 | 0 | 2 | 4 | 0.3 | 0.4 | 0.9 |
Excel formula:
=FUZZY_OR({0,2,4}, {0,0.6,0.2}, {0,2,4}, {0.3,0.4,0.9})
Expected output:
{"type":"Double","basicValue":0.3,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":4}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.3}],[{"type":"Double","basicValue":0.6}],[{"type":"Double","basicValue":0.9}]]}}}
Python Code
Show Code
import numpy as np
from skfuzzy import fuzzy_or as fuzz_or
def fuzzy_or(x, mfx, y, mfy):
"""
Calculate the fuzzy OR operator (union) of two fuzzy sets.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.fuzzy_or
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Universe variable for the first fuzzy set `mfx`.
mfx (list[list]): Membership function values corresponding to `x`.
y (list[list]): Universe variable for the second fuzzy set `mfy`.
mfy (list[list]): Membership function values corresponding to `y`.
Returns:
dict: Dictionary containing the combined universe points and the union membership values array.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
mfx_arr = to1d(mfx)
y_arr = to1d(y)
mfy_arr = to1d(mfy)
if len(x_arr) == 0 or len(mfx_arr) == 0 or len(y_arr) == 0 or len(mfy_arr) == 0:
return "Error: Input arrays cannot be empty"
if len(x_arr) != len(mfx_arr):
return "Error: x and mfx must have the same number of elements"
if len(y_arr) != len(mfy_arr):
return "Error: y and mfy must have the same number of elements"
z_arr, mfz_arr = fuzz_or(x_arr, mfx_arr, y_arr, mfy_arr)
return {
"type": "Double",
"basicValue": float(mfz_arr[0]) if len(mfz_arr) > 0 else 0.0,
"properties": {
"z": {
"type": "Array",
"elements": [[{"type": "Double", "basicValue": float(val)}] for val in z_arr]
},
"mfz": {
"type": "Array",
"elements": [[{"type": "Double", "basicValue": float(val)}] for val in mfz_arr]
}
}
}
except Exception as e:
return f"Error: {str(e)}"Online Calculator
GAUSS2MF
Generates a membership function with the left side up to mean1 defined by the first Gaussian, and the right side above mean2 defined by the second Gaussian.
In the range mean1 <= x <= mean2, the function has a value of 1.
Excel Usage
=GAUSS2MF(x, mean_one, sigma_one, mean_two, sigma_two)
x(list[list], required): Array of independent universe variables.mean_one(float, required): Gaussian parameter for center (mean) value of left-side Gaussian. Requires mean_one <= mean_two.sigma_one(float, required): Standard deviation of left Gaussian.mean_two(float, required): Gaussian parameter for center (mean) value of right-side Gaussian. Requires mean_two >= mean_one.sigma_two(float, required): Standard deviation of right Gaussian.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Combined Gaussian with a flat middle region
Inputs:
| x | mean_one | sigma_one | mean_two | sigma_two | |||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 2 | 0.5 | 3 | 0.5 |
Excel formula:
=GAUSS2MF({0,1,2,3,4,5}, 2, 0.5, 3, 0.5)
Expected output:
| Result |
|---|
| 0.000335463 |
| 0.135335 |
| 1 |
| 1 |
| 0.135335 |
| 0.000335463 |
Example 2: Scalar input inside the unit plateau
Inputs:
| x | mean_one | sigma_one | mean_two | sigma_two |
|---|---|---|---|---|
| 2.5 | 2 | 0.5 | 3 | 0.5 |
Excel formula:
=GAUSS2MF(2.5, 2, 0.5, 3, 0.5)
Expected output:
1
Example 3: Combined Gaussian with wider shoulders
Inputs:
| x | mean_one | sigma_one | mean_two | sigma_two | ||||
|---|---|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | -0.5 | 1 | 0.5 | 1.5 |
Excel formula:
=GAUSS2MF({-2,-1,0,1,2}, -0.5, 1, 0.5, 1.5)
Expected output:
| Result |
|---|
| 0.324652 |
| 0.882497 |
| 1 |
| 0.945959 |
| 0.606531 |
Example 4: Combined Gaussian evaluated over a negative domain
Inputs:
| x | mean_one | sigma_one | mean_two | sigma_two | ||||
|---|---|---|---|---|---|---|---|---|
| -4 | -3 | -2 | -1 | 0 | -3 | 0.75 | -1.5 | 0.75 |
Excel formula:
=GAUSS2MF({-4,-3,-2,-1,0}, -3, 0.75, -1.5, 0.75)
Expected output:
| Result |
|---|
| 0.411112 |
| 1 |
| 1 |
| 0.800737 |
| 0.135335 |
Python Code
Show Code
import numpy as np
from skfuzzy import gauss2mf as fuzz_gauss2mf
def gauss2mf(x, mean_one, sigma_one, mean_two, sigma_two):
"""
Generate a Gaussian fuzzy membership function of two combined Gaussians.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.gauss2mf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
mean_one (float): Gaussian parameter for center (mean) value of left-side Gaussian. Requires mean_one <= mean_two.
sigma_one (float): Standard deviation of left Gaussian.
mean_two (float): Gaussian parameter for center (mean) value of right-side Gaussian. Requires mean_two >= mean_one.
sigma_two (float): Standard deviation of right Gaussian.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if sigma_one <= 0 or sigma_two <= 0:
return "Error: sigma_one and sigma_two must be positive"
if mean_one > mean_two:
return "Error: Parameters must satisfy mean_one <= mean_two"
result = fuzz_gauss2mf(x_arr, mean_one, sigma_one, mean_two, sigma_two)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
GAUSSMF
Generates a Gaussian membership function for a given universe. The shape of the Gaussian is defined by two parameters: the center (mean) and the standard deviation (sigma).
The membership value is 1 at the mean and falls off symmetrically according to the standard deviation.
Excel Usage
=GAUSSMF(x, mean, sigma)
x(list[list], required): Array of independent universe variables.mean(float, required): Gaussian parameter for center (mean) value.sigma(float, required): Gaussian parameter for standard deviation.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Gaussian membership over a centered universe
Inputs:
| x | mean | sigma | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 2.5 | 1 |
Excel formula:
=GAUSSMF({0,1,2,3,4,5}, 2.5, 1)
Expected output:
| Result |
|---|
| 0.0439369 |
| 0.324652 |
| 0.882497 |
| 0.882497 |
| 0.324652 |
| 0.0439369 |
Example 2: Gaussian membership at the mean value
Inputs:
| x | mean | sigma |
|---|---|---|
| 1.5 | 1.5 | 0.75 |
Excel formula:
=GAUSSMF(1.5, 1.5, 0.75)
Expected output:
1
Example 3: Gaussian membership with a wide spread
Inputs:
| x | mean | sigma | ||||
|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 0 | 2 |
Excel formula:
=GAUSSMF({-2,-1,0,1,2}, 0, 2)
Expected output:
| Result |
|---|
| 0.606531 |
| 0.882497 |
| 1 |
| 0.882497 |
| 0.606531 |
Example 4: Gaussian membership centered at a negative mean
Inputs:
| x | mean | sigma | ||||
|---|---|---|---|---|---|---|
| -4 | -3 | -2 | -1 | 0 | -2 | 0.8 |
Excel formula:
=GAUSSMF({-4,-3,-2,-1,0}, -2, 0.8)
Expected output:
| Result |
|---|
| 0.0439369 |
| 0.457833 |
| 1 |
| 0.457833 |
| 0.0439369 |
Python Code
Show Code
import numpy as np
from skfuzzy import gaussmf as fuzz_gaussmf
def gaussmf(x, mean, sigma):
"""
Generate a Gaussian fuzzy membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.gaussmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
mean (float): Gaussian parameter for center (mean) value.
sigma (float): Gaussian parameter for standard deviation.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if sigma <= 0:
return "Error: sigma must be positive"
result = fuzz_gaussmf(x_arr, mean, sigma)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
GBELLMF
Generates a Generalized Bell fuzzy membership function. The function is defined by three parameters: width (a), slope (b), and center (c).
The equation is defined as: y(x) = 1 / (1 + abs([x - c] / a) ** [2 * b])
Excel Usage
=GBELLMF(x, a, b, c)
x(list[list], required): Array of independent universe variables.a(float, required): Bell function parameter controlling width.b(float, required): Bell function parameter controlling slope.c(float, required): Bell function parameter defining the center.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Generalized bell membership around the center
Inputs:
| x | a | b | c | |||||
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 2.5 |
Excel formula:
=GBELLMF({0,1,2,3,4,5}, 1, 2, 2.5)
Expected output:
| Result |
|---|
| 0.024961 |
| 0.164948 |
| 0.941176 |
| 0.941176 |
| 0.164948 |
| 0.024961 |
Example 2: Generalized bell membership at its center
Inputs:
| x | a | b | c |
|---|---|---|---|
| 2.5 | 1 | 2 | 2.5 |
Excel formula:
=GBELLMF(2.5, 1, 2, 2.5)
Expected output:
1
Example 3: Generalized bell with a broader width
Inputs:
| x | a | b | c | ||||
|---|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 2 | 2 | 0 |
Excel formula:
=GBELLMF({-2,-1,0,1,2}, 2, 2, 0)
Expected output:
| Result |
|---|
| 0.5 |
| 0.941176 |
| 1 |
| 0.941176 |
| 0.5 |
Example 4: Generalized bell centered on a negative value
Inputs:
| x | a | b | c | ||||
|---|---|---|---|---|---|---|---|
| -4 | -3 | -2 | -1 | 0 | 1.5 | 3 | -2 |
Excel formula:
=GBELLMF({-4,-3,-2,-1,0}, 1.5, 3, -2)
Expected output:
| Result |
|---|
| 0.151088 |
| 0.919294 |
| 1 |
| 0.919294 |
| 0.151088 |
Python Code
Show Code
import numpy as np
from skfuzzy import gbellmf as fuzz_gbellmf
def gbellmf(x, a, b, c):
"""
Generate a Generalized Bell fuzzy membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.gbellmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Bell function parameter controlling width.
b (float): Bell function parameter controlling slope.
c (float): Bell function parameter defining the center.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if a == 0:
return "Error: a must be nonzero"
result = fuzz_gbellmf(x_arr, a, b, c)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
PIECEMF
Piecewise linear membership function (particularly used in FIRE filters).
Piecewise definition: - y = 0 for x <= a - y = b(x - a)/c(b - a) for a <= x <= b - y = x/c for b <= x <= c - y = 1 for c <= x
Excel Usage
=PIECEMF(x, a, b, c)
x(list[list], required): Array of independent universe variables.a(float, required): First breakpoint of the piecewise function.b(float, required): Second breakpoint of the piecewise function.c(float, required): Third breakpoint of the piecewise function.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Piecewise membership with ordered breakpoints
Inputs:
| x | a | b | c | |||||
|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 |
Excel formula:
=PIECEMF({0,1,2,3,4,5}, 1, 2, 3)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.666667 |
| 1 |
| 1 |
| 1 |
Example 2: Piecewise membership on the upper plateau
Inputs:
| x | a | b | c |
|---|---|---|---|
| 3 | 1 | 2 | 3 |
Excel formula:
=PIECEMF(3, 1, 2, 3)
Expected output:
1
Example 3: Piecewise membership across the rising segment
Inputs:
| x | a | b | c | ||||
|---|---|---|---|---|---|---|---|
| 1 | 1.5 | 2 | 2.5 | 3 | 1 | 2 | 3 |
Excel formula:
=PIECEMF({1,1.5,2,2.5,3}, 1, 2, 3)
Expected output:
| Result |
|---|
| 0 |
| 0.333333 |
| 0.666667 |
| 0.833333 |
| 1 |
Example 4: Piecewise membership with wider support
Inputs:
| x | a | b | c | ||||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 1 | 3 | 5 |
Excel formula:
=PIECEMF({0,1,2,3,4,5,6}, 1, 3, 5)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.3 |
| 0.6 |
| 0.8 |
| 1 |
| 1 |
Python Code
Show Code
import numpy as np
from skfuzzy import piecemf as fuzz_piecemf
def piecemf(x, a, b, c):
"""
Generate a piecewise linear fuzzy membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.piecemf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): First breakpoint of the piecewise function.
b (float): Second breakpoint of the piecewise function.
c (float): Third breakpoint of the piecewise function.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if not (a <= b <= c):
return "Error: Parameters must satisfy a <= b <= c"
result = fuzz_piecemf(x_arr, [a, b, c])
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
PIMF
Pi-function fuzzy membership generator. Equivalently a product of the S-function (smf) and Z-function (zmf).
The function begins to climb from zero at the left ‘foot’ (a), levels off at 1 at the left ‘ceiling’ (b), begins falling from 1 at the right ‘ceiling’ (c), and reattains zero at the right ‘foot’ (d).
Excel Usage
=PIMF(x, a, b, c, d)
x(list[list], required): Array of independent universe variables.a(float, required): Left foot, where the function begins to climb from zero.b(float, required): Left ceiling, where the function levels off at 1.c(float, required): Right ceiling, where the function begins falling from 1.d(float, required): Right foot, where the function reattains zero.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Pi-function membership with a flat top
Inputs:
| x | a | b | c | d | |||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 |
Excel formula:
=PIMF({0,1,2,3,4,5}, 1, 2, 3, 4)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 1 |
| 1 |
| 0 |
| 0 |
Example 2: Pi-function membership inside the plateau
Inputs:
| x | a | b | c | d |
|---|---|---|---|---|
| 2.5 | 1 | 2 | 3 | 4 |
Excel formula:
=PIMF(2.5, 1, 2, 3, 4)
Expected output:
1
Example 3: Pi-function membership with wider transition regions
Inputs:
| x | a | b | c | d | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 1 | 2.5 | 3.5 | 5 |
Excel formula:
=PIMF({0,1,2,3,4,5,6}, 1, 2.5, 3.5, 5)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.777778 |
| 1 |
| 0.777778 |
| 0 |
| 0 |
Example 4: Pi-function membership over an asymmetric support
Inputs:
| x | a | b | c | d | |||||
|---|---|---|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 3 | -1 | 0 | 1.5 | 3 |
Excel formula:
=PIMF({-2,-1,0,1,2,3}, -1, 0, 1.5, 3)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 1 |
| 1 |
| 0.777778 |
| 0 |
Python Code
Show Code
import numpy as np
from skfuzzy import pimf as fuzz_pimf
def pimf(x, a, b, c, d):
"""
Generate a Pi-function fuzzy membership generator.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.pimf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Left foot, where the function begins to climb from zero.
b (float): Left ceiling, where the function levels off at 1.
c (float): Right ceiling, where the function begins falling from 1.
d (float): Right foot, where the function reattains zero.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if not (a <= b <= c <= d):
return "Error: Parameters must satisfy a <= b <= c <= d"
result = fuzz_pimf(x_arr, a, b, c, d)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
PSIGMF
Generates the product of two sigmoid membership functions. The shape of the curve is defined by multiplying two sigmoids together.
The equation is defined as y = f1(x) * f2(x) where f1 and f2 are sigmoid functions defined by parameters b1, c1 and b2, c2. For a smoothed rect-like function, choose c2 < 0 < c1. For its inverse, choose c1 < 0 < c2.
Excel Usage
=PSIGMF(x, b_one, c_one, b_two, c_two)
x(list[list], required): Array of independent universe variables.b_one(float, required): Center bias for the first sigmoid.c_one(float, required): Controls width of the first sigmoidal region.b_two(float, required): Center bias for the second sigmoid.c_two(float, required): Controls width of the second sigmoidal region.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Product of sigmoids forming a smooth window
Inputs:
| x | b_one | c_one | b_two | c_two | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 2 | 2 | 5 | -2 |
Excel formula:
=PSIGMF({0,1,2,3,4,5,6,7}, 2, 2, 5, -2)
Expected output:
| Result |
|---|
| 0.0179854 |
| 0.119163 |
| 0.498764 |
| 0.864955 |
| 0.864955 |
| 0.498764 |
| 0.119163 |
| 0.0179854 |
Example 2: Product of sigmoids forming an inverse window
Inputs:
| x | b_one | c_one | b_two | c_two | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 2 | -2 | 5 | 2 |
Excel formula:
=PSIGMF({0,1,2,3,4,5,6,7}, 2, -2, 5, 2)
Expected output:
| Result |
|---|
| 0.0000445813 |
| 0.000295375 |
| 0.00123631 |
| 0.00214401 |
| 0.00214401 |
| 0.00123631 |
| 0.000295375 |
| 0.0000445813 |
Example 3: Product of sigmoids at a scalar midpoint
Inputs:
| x | b_one | c_one | b_two | c_two |
|---|---|---|---|---|
| 3.5 | 2 | 2 | 5 | -2 |
Excel formula:
=PSIGMF(3.5, 2, 2, 5, -2)
Expected output:
0.907397
Example 4: Product of sigmoids shifted into a negative domain
Inputs:
| x | b_one | c_one | b_two | c_two | |||||
|---|---|---|---|---|---|---|---|---|---|
| -4 | -3 | -2 | -1 | 0 | 1 | -3 | 1.5 | 0 | -1.5 |
Excel formula:
=PSIGMF({-4,-3,-2,-1,0,1}, -3, 1.5, 0, -1.5)
Expected output:
| Result |
|---|
| 0.181974 |
| 0.494507 |
| 0.7788 |
| 0.7788 |
| 0.494507 |
| 0.181974 |
Python Code
Show Code
import numpy as np
from skfuzzy import psigmf as fuzz_psigmf
def psigmf(x, b_one, c_one, b_two, c_two):
"""
Generate the product of two sigmoid membership functions.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.psigmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
b_one (float): Center bias for the first sigmoid.
c_one (float): Controls width of the first sigmoidal region.
b_two (float): Center bias for the second sigmoid.
c_two (float): Controls width of the second sigmoidal region.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
result = fuzz_psigmf(x_arr, b_one, c_one, b_two, c_two)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
SIGMF
Generates a basic sigmoid membership function. The shape of the sigmoid is defined by its center point and width.
The equation for the sigmoid function is: y = 1 / (1. + exp[- c * (x - b)]). With c > 0, the left side approaches 0 and right side approaches 1. With c < 0, the opposite is true.
Excel Usage
=SIGMF(x, b, c)
x(list[list], required): Array of independent universe variables.b(float, required): Offset or bias. This is the center value of the sigmoid, where it equals 0.5.c(float, required): Controls width of the sigmoidal region (magnitude) and which side is open (sign).
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Increasing sigmoid membership profile
Inputs:
| x | b | c | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 2.5 | 1 |
Excel formula:
=SIGMF({0,1,2,3,4,5}, 2.5, 1)
Expected output:
| Result |
|---|
| 0.0758582 |
| 0.182426 |
| 0.377541 |
| 0.622459 |
| 0.817574 |
| 0.924142 |
Example 2: Decreasing sigmoid membership profile
Inputs:
| x | b | c | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 2.5 | -1 |
Excel formula:
=SIGMF({0,1,2,3,4,5}, 2.5, -1)
Expected output:
| Result |
|---|
| 0.924142 |
| 0.817574 |
| 0.622459 |
| 0.377541 |
| 0.182426 |
| 0.0758582 |
Example 3: Sigmoid membership at its midpoint
Inputs:
| x | b | c |
|---|---|---|
| 2.5 | 2.5 | 3 |
Excel formula:
=SIGMF(2.5, 2.5, 3)
Expected output:
0.5
Example 4: Sigmoid membership with a shallow slope
Inputs:
| x | b | c | ||||
|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 0 | 0.5 |
Excel formula:
=SIGMF({-2,-1,0,1,2}, 0, 0.5)
Expected output:
| Result |
|---|
| 0.268941 |
| 0.377541 |
| 0.5 |
| 0.622459 |
| 0.731059 |
Python Code
Show Code
import numpy as np
from skfuzzy import sigmf as fuzz_sigmf
def sigmf(x, b, c):
"""
Generate a basic sigmoid membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.sigmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
b (float): Offset or bias. This is the center value of the sigmoid, where it equals 0.5.
c (float): Controls width of the sigmoidal region (magnitude) and which side is open (sign).
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
result = fuzz_sigmf(x_arr, b, c)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
SMF
Generates an S-function fuzzy membership generator, named such because of its S-like shape.
The function begins to climb from zero at the ‘foot’ and levels off at 1 at the ‘ceiling’.
Excel Usage
=SMF(x, a, b)
x(list[list], required): Array of independent universe variables.a(float, required): Foot, where the function begins to climb from zero.b(float, required): Ceiling, where the function levels off at 1.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: S-function membership over a positive domain
Inputs:
| x | a | b | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 4 |
Excel formula:
=SMF({0,1,2,3,4,5}, 1, 4)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.222222 |
| 0.777778 |
| 1 |
| 1 |
Example 2: S-function membership after reaching the plateau
Inputs:
| x | a | b |
|---|---|---|
| 5 | 1 | 4 |
Excel formula:
=SMF(5, 1, 4)
Expected output:
1
Example 3: S-function membership with a wide transition band
Inputs:
| x | a | b | |||||
|---|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 3 | -1 | 2 |
Excel formula:
=SMF({-2,-1,0,1,2,3}, -1, 2)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.222222 |
| 0.777778 |
| 1 |
| 1 |
Example 4: S-function membership on a negative domain
Inputs:
| x | a | b | ||||
|---|---|---|---|---|---|---|
| -5 | -4 | -3 | -2 | -1 | -4 | -2 |
Excel formula:
=SMF({-5,-4,-3,-2,-1}, -4, -2)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 0.5 |
| 1 |
| 1 |
Python Code
Show Code
import numpy as np
from skfuzzy import smf as fuzz_smf
def smf(x, a, b):
"""
Generate an S-function fuzzy membership generator.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.smf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Foot, where the function begins to climb from zero.
b (float): Ceiling, where the function levels off at 1.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if a > b:
return "Error: Parameters must satisfy a <= b"
result = fuzz_smf(x_arr, a, b)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
TRAPMF
Generates a trapezoidal membership function for a given universe. The shape of the trapezoid is defined by four parameters: left foot, left ceiling, right ceiling, and right foot.
The membership value is 0 outside the feet, climbs linearly to 1 at the left ceiling, stays flat at 1 until the right ceiling, and falls linearly back to 0.
Excel Usage
=TRAPMF(x, a, b, c, d)
x(list[list], required): Array of independent universe variables.a(float, required): Left foot of the trapezoid (membership begins to climb from zero).b(float, required): Left ceiling of the trapezoid (membership attains 1).c(float, required): Right ceiling of the trapezoid (membership begins to fall).d(float, required): Right foot of the trapezoid (membership reattains zero).
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Trapezoidal membership with a flat top
Inputs:
| x | a | b | c | d | |||||
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 2 | 3 | 4 |
Excel formula:
=TRAPMF({0,1,2,3,4,5}, 1, 2, 3, 4)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 1 |
| 1 |
| 0 |
| 0 |
Example 2: Trapezoidal membership at a plateau point
Inputs:
| x | a | b | c | d |
|---|---|---|---|---|
| 2.5 | 1 | 2 | 3 | 4 |
Excel formula:
=TRAPMF(2.5, 1, 2, 3, 4)
Expected output:
1
Example 3: Trapezoidal membership across both sloped edges
Inputs:
| x | a | b | c | d | |||||
|---|---|---|---|---|---|---|---|---|---|
| 1 | 1.5 | 2 | 3 | 3.5 | 4 | 1 | 2 | 3 | 4 |
Excel formula:
=TRAPMF({1,1.5,2,3,3.5,4}, 1, 2, 3, 4)
Expected output:
| Result |
|---|
| 0 |
| 0.5 |
| 1 |
| 1 |
| 0.5 |
| 0 |
Example 4: Trapezoidal membership on a negative universe
Inputs:
| x | a | b | c | d | ||||
|---|---|---|---|---|---|---|---|---|
| -4 | -3 | -2 | -1 | 0 | -3 | -2 | -1 | 0 |
Excel formula:
=TRAPMF({-4,-3,-2,-1,0}, -3, -2, -1, 0)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 1 |
| 1 |
| 0 |
Python Code
Show Code
import numpy as np
from skfuzzy import trapmf as fuzz_trapmf
def trapmf(x, a, b, c, d):
"""
Generate a trapezoidal fuzzy membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.trapmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Left foot of the trapezoid (membership begins to climb from zero).
b (float): Left ceiling of the trapezoid (membership attains 1).
c (float): Right ceiling of the trapezoid (membership begins to fall).
d (float): Right foot of the trapezoid (membership reattains zero).
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if not (a <= b <= c <= d):
return "Error: Parameters must satisfy a <= b <= c <= d"
result = fuzz_trapmf(x_arr, [a, b, c, d])
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
TRIMF
Generates a triangular membership function for a given universe. The shape of the triangle is defined by three parameters: left foot, peak, and right foot.
The membership value is 0 outside the feet, climbs linearly to 1 at the peak, and falls linearly back to 0.
Excel Usage
=TRIMF(x, a, b, c)
x(list[list], required): Array of independent universe variables.a(float, required): Left foot of the triangle (membership begins to climb from zero).b(float, required): Peak of the triangle (membership equals 1).c(float, required): Right foot of the triangle (membership reattains zero).
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Triangular membership with a centered peak
Inputs:
| x | a | b | c | ||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 1 | 2 | 3 |
Excel formula:
=TRIMF({0,1,2,3,4}, 1, 2, 3)
Expected output:
| Result |
|---|
| 0 |
| 0 |
| 1 |
| 0 |
| 0 |
Example 2: Triangular membership at the peak point
Inputs:
| x | a | b | c |
|---|---|---|---|
| 2 | 1 | 2 | 3 |
Excel formula:
=TRIMF(2, 1, 2, 3)
Expected output:
1
Example 3: Triangular membership with a left shoulder
Inputs:
| x | a | b | c | ||||
|---|---|---|---|---|---|---|---|
| 0 | 0.5 | 1 | 1.5 | 2 | 0 | 0 | 2 |
Excel formula:
=TRIMF({0,0.5,1,1.5,2}, 0, 0, 2)
Expected output:
| Result |
|---|
| 1 |
| 0.75 |
| 0.5 |
| 0.25 |
| 0 |
Example 4: Triangular membership with a right shoulder
Inputs:
| x | a | b | c | |||
|---|---|---|---|---|---|---|
| 0 | 1 | 1.5 | 2 | 0 | 2 | 2 |
Excel formula:
=TRIMF({0,1,1.5,2}, 0, 2, 2)
Expected output:
| Result |
|---|
| 0 |
| 0.5 |
| 0.75 |
| 1 |
Python Code
Show Code
import numpy as np
from skfuzzy import trimf as fuzz_trimf
def trimf(x, a, b, c):
"""
Generate a triangular fuzzy membership function.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.trimf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Left foot of the triangle (membership begins to climb from zero).
b (float): Peak of the triangle (membership equals 1).
c (float): Right foot of the triangle (membership reattains zero).
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if not (a <= b <= c):
return "Error: Parameters must satisfy a <= b <= c"
result = fuzz_trimf(x_arr, [a, b, c])
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
ZMF
Generates a Z-function fuzzy membership generator, named such because of its Z-like shape.
The function begins falling from 1 at the ‘ceiling’ and reattains zero at the ‘foot’.
Excel Usage
=ZMF(x, a, b)
x(list[list], required): Array of independent universe variables.a(float, required): Ceiling, where the function begins falling from 1.b(float, required): Foot, where the function reattains zero.
Returns (list[list]): Array of membership values corresponding to the input universe.
Example 1: Z-function membership over a positive domain
Inputs:
| x | a | b | |||||
|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 1 | 4 |
Excel formula:
=ZMF({0,1,2,3,4,5}, 1, 4)
Expected output:
| Result |
|---|
| 1 |
| 1 |
| 0.777778 |
| 0.222222 |
| 0 |
| 0 |
Example 2: Z-function membership before the descent starts
Inputs:
| x | a | b |
|---|---|---|
| 0 | 1 | 4 |
Excel formula:
=ZMF(0, 1, 4)
Expected output:
1
Example 3: Z-function membership with a wide transition band
Inputs:
| x | a | b | |||||
|---|---|---|---|---|---|---|---|
| -2 | -1 | 0 | 1 | 2 | 3 | -1 | 2 |
Excel formula:
=ZMF({-2,-1,0,1,2,3}, -1, 2)
Expected output:
| Result |
|---|
| 1 |
| 1 |
| 0.777778 |
| 0.222222 |
| 0 |
| 0 |
Example 4: Z-function membership on a negative domain
Inputs:
| x | a | b | ||||
|---|---|---|---|---|---|---|
| -5 | -4 | -3 | -2 | -1 | -4 | -2 |
Excel formula:
=ZMF({-5,-4,-3,-2,-1}, -4, -2)
Expected output:
| Result |
|---|
| 1 |
| 1 |
| 0.5 |
| 0 |
| 0 |
Python Code
Show Code
import numpy as np
from skfuzzy import zmf as fuzz_zmf
def zmf(x, a, b):
"""
Generate a Z-function fuzzy membership generator.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.zmf
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Array of independent universe variables.
a (float): Ceiling, where the function begins falling from 1.
b (float): Foot, where the function reattains zero.
Returns:
list[list]: Array of membership values corresponding to the input universe.
"""
try:
def to1d(arr):
if isinstance(arr, list):
flat = []
for row in arr:
row_list = row if isinstance(row, list) else [row]
for val in row_list:
try:
flat.append(float(val))
except (TypeError, ValueError):
continue
return np.array(flat)
return np.array([float(arr)])
x_arr = to1d(x)
if len(x_arr) == 0:
return "Error: Input mapping array x cannot be empty"
if a > b:
return "Error: Parameters must satisfy a <= b"
result = fuzz_zmf(x_arr, a, b)
return [[float(val)] for val in result]
except Exception as e:
return f"Error: {str(e)}"Online Calculator