FUZZY_AND
Computes the fuzzy AND operator, representing the intersection of two fully defined fuzzy sets. As a soft minimum, it returns the point-wise minimum of membership values from both sets overlapping the same universe.
Excel Usage
=FUZZY_AND(x, mfx, y, mfy)
x(list[list], required): Universe variable for the first fuzzy setmfx.mfx(list[list], required): Membership function values corresponding tox.y(list[list], required): Universe variable for the second fuzzy setmfy.mfy(list[list], required): Membership function values corresponding toy.
Returns (dict): Dictionary containing the combined universe points and the intersection membership values array.
Example 1: Fuzzy AND 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_AND({1,2,3}, {0.5,0.8,1}, {1,2,3}, {0.2,0.9,0.5})
Expected output:
{"type":"Double","basicValue":0.2,"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.2}],[{"type":"Double","basicValue":0.8}],[{"type":"Double","basicValue":0.5}]]}}}
Example 2: Fuzzy AND 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_AND({0,1,2}, {0.1,0.7,1}, {1,2,3}, {0.4,0.9,0.2})
Expected output:
{"type":"Double","basicValue":0.1,"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.1}],[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.9}],[{"type":"Double","basicValue":0.2}]]}}}
Example 3: Fuzzy AND for singleton fuzzy sets
Inputs:
| x | mfx | y | mfy |
|---|---|---|---|
| 1 | 0.4 | 1 | 0.9 |
Excel formula:
=FUZZY_AND(1, 0.4, 1, 0.9)
Expected output:
{"type":"Double","basicValue":0.4,"properties":{"z":{"type":"Array","elements":[[{"type":"Double","basicValue":1}]]},"mfz":{"type":"Array","elements":[[{"type":"Double","basicValue":0.4}]]}}}
Example 4: Fuzzy AND 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_AND({0,2,4}, {0,0.6,0.2}, {0,2,4}, {0.3,0.4,0.9})
Expected output:
{"type":"Double","basicValue":0,"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}],[{"type":"Double","basicValue":0.4}],[{"type":"Double","basicValue":0.2}]]}}}
Python Code
Show Code
import numpy as np
from skfuzzy import fuzzy_and as fuzz_and
def fuzzy_and(x, mfx, y, mfy):
"""
Calculate the fuzzy AND operator (intersection) of two fuzzy sets.
See: https://pythonhosted.org/scikit-fuzzy/api/skfuzzy.html#skfuzzy.fuzzy_and
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 intersection 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_and(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)}"