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
Array of independent universe variables.
Gaussian parameter for center (mean) value.
Gaussian parameter for standard deviation.