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

Array of independent universe variables.
Gaussian parameter for center (mean) value of left-side Gaussian. Requires mean_one <= mean_two.
Standard deviation of left Gaussian.
Gaussian parameter for center (mean) value of right-side Gaussian. Requires mean_two >= mean_one.
Standard deviation of right Gaussian.