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
Array of independent universe variables.
First breakpoint of the piecewise function.
Second breakpoint of the piecewise function.
Third breakpoint of the piecewise function.