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
Array of independent universe variables.
Foot, where the function begins to climb from zero.
Ceiling, where the function levels off at 1.