FUZZY_OR

Computes the fuzzy OR operator, representing the union of two fully defined fuzzy sets. As a soft maximum, it returns the point-wise maximum of membership values from both sets overlapping the same universe.

Excel Usage

=FUZZY_OR(x, mfx, y, mfy)
  • x (list[list], required): Universe variable for the first fuzzy set mfx.
  • mfx (list[list], required): Membership function values corresponding to x.
  • y (list[list], required): Universe variable for the second fuzzy set mfy.
  • mfy (list[list], required): Membership function values corresponding to y.

Returns (dict): Dictionary containing the combined universe points and the union membership values array.

Example 1: Fuzzy OR on matching universes

Inputs:

x mfx y mfy
1 2 3 0.5 0.8 1 1 2 3 0.2 0.9 0.5

Excel formula:

=FUZZY_OR({1,2,3}, {0.5,0.8,1}, {1,2,3}, {0.2,0.9,0.5})

Expected output:

{"type":"Double","basicValue":0.5,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.5}],[{"type":"Double","basicValue":0.9}],[{"type":"Double","basicValue":1}]]}}}

Example 2: Fuzzy OR with overlapping shifted universes

Inputs:

x mfx y mfy
0 1 2 0.1 0.7 1 1 2 3 0.4 0.9 0.2

Excel formula:

=FUZZY_OR({0,1,2}, {0.1,0.7,1}, {1,2,3}, {0.4,0.9,0.2})

Expected output:

{"type":"Double","basicValue":0.4,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":3}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.7}],[{"type":"Double","basicValue":1}],[{"type":"Double","basicValue":1}]]}}}

Example 3: Fuzzy OR for singleton fuzzy sets

Inputs:

x mfx y mfy
1 0.4 1 0.9

Excel formula:

=FUZZY_OR(1, 0.4, 1, 0.9)

Expected output:

{"type":"Double","basicValue":0.9,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.9}]]}}}

Example 4: Fuzzy OR of sparse membership profiles

Inputs:

x mfx y mfy
0 2 4 0 0.6 0.2 0 2 4 0.3 0.4 0.9

Excel formula:

=FUZZY_OR({0,2,4}, {0,0.6,0.2}, {0,2,4}, {0.3,0.4,0.9})

Expected output:

{"type":"Double","basicValue":0.3,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":0}],[{"type":"Double","basicValue":2}],[{"type":"Double","basicValue":4}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.3}],[{"type":"Double","basicValue":0.6}],[{"type":"Double","basicValue":0.9}]]}}}

Python Code

Show Code
import numpy as np
from skfuzzy import fuzzy_or as fuzz_or

def fuzzy_or(x, mfx, y, mfy):
    """
    Calculate the fuzzy OR operator (union) of two fuzzy sets.

    See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.fuzzy_or

    This example function is provided as-is without any representation of accuracy.

    Args:
        x (list[list]): Universe variable for the first fuzzy set `mfx`.
        mfx (list[list]): Membership function values corresponding to `x`.
        y (list[list]): Universe variable for the second fuzzy set `mfy`.
        mfy (list[list]): Membership function values corresponding to `y`.

    Returns:
        dict: Dictionary containing the combined universe points and the union membership values array.
    """
    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)
        mfx_arr = to1d(mfx)
        y_arr = to1d(y)
        mfy_arr = to1d(mfy)

        if len(x_arr) == 0 or len(mfx_arr) == 0 or len(y_arr) == 0 or len(mfy_arr) == 0:
            return "Error: Input arrays cannot be empty"

        if len(x_arr) != len(mfx_arr):
            return "Error: x and mfx must have the same number of elements"

        if len(y_arr) != len(mfy_arr):
            return "Error: y and mfy must have the same number of elements"

        z_arr, mfz_arr = fuzz_or(x_arr, mfx_arr, y_arr, mfy_arr)

        return {
            "type": "Double",
            "basicValue": float(mfz_arr[0]) if len(mfz_arr) > 0 else 0.0,
            "properties": {
                "z": {
                    "type": "Array",
                    "elements": [[{"type": "Double", "basicValue": float(val)}] for val in z_arr]
                },
                "mfz": {
                    "type": "Array",
                    "elements": [[{"type": "Double", "basicValue": float(val)}] for val in mfz_arr]
                }
            }
        }
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Universe variable for the first fuzzy set `mfx`.
Membership function values corresponding to `x`.
Universe variable for the second fuzzy set `mfy`.
Membership function values corresponding to `y`.