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
Array of independent universe variables.
Ceiling, where the function begins falling from 1.
Foot, where the function reattains zero.