# Path: cotede/fuzzy/fuzzy_core.py
# def fuzzyfy(data, features, output, require="all"):
#     """
#     Notes
#     -----
#     In the generalize this once the membership combining rules are defined
#     in the cfg, so I can decide to use mean or max.
#     """
#     features_list = list(features.keys())
# 
#     N = max([len(data[f]) for f in features_list])
# 
#     # The fuzzy set are usually: low, medium, high
#     # The membership of each fuzzy set are each feature scaled.
#     membership = {f: {} for f in output.keys()}
# 
#     mfuncs = {"smf": smf, "trimf": trimf, "trapmf": trapmf, "zmf": zmf}
#     for t in features_list:
#         for m in membership:
#             assert m in features[t], "Missing %s in %s" % (m, features[t])
#             f = mfuncs[features[t][m]["type"]]
#             membership[m][t] = f(np.asanyarray(data[t]), features[t][m]["params"])
# 
#     # Rule Set
#     rules = {}
#     # Low: u_low = mean(S_l(spike), S_l(clim)...)
#     # u_low = np.mean([weights['spike']['low'],
#     #    weights['woa_relbias']['low']], axis=0)
#     # Medium: u_medium = mean(S_l(spike), S_l(clim)...)
#     # u_medium = np.mean([weights['spike']['medium'],
#     #    weights['woa_relbias']['medium']], axis=0)
# 
#     for m in [m for m in membership if m != "high"]:
#         tmp = np.vstack([membership[m][f] for f in membership[m]])
#         if require == "any":
#             rules[m] = np.nanmean(tmp, axis=0)
#         else:
#             rules[m] = np.mean(tmp, axis=0)
# 
#     # High: u_high = max(S_l(spike), S_l(clim)...)
#     # u_high = np.max([weights['spike']['high'],
#     #    weights['woa_relbias']['high']], axis=0)
# 
#     tmp = np.vstack([membership["high"][f] for f in membership["high"]])
#     if require == "any":
#         rules["high"] = np.nanmax(tmp, axis=0)
#     else:
#         rules["high"] = np.max(tmp, axis=0)
# 
#     return rules


import numpy as np
from numpy.testing import assert_allclose
from cotede.fuzzy import fuzzyfy
        "low": {"type": "trimf", "params": [0.0, 0.225, 0.45]},
        "medium": {"type": "trimf", "params": [0.275, 0.5, 0.725]},
        "high": {"type": "smf", "params": [0.55, 0.775]},
    },
    "features": {
        "f1": {
            "weight": 1,
            "low": {"type": "zmf", "params": [0.07, 0.2]},
            "medium": {"type": "trapmf", "params": [0.07, 0.2, 2, 6]},
            "high": {"type": "smf", "params": [2, 6]},
        },
        "f2": {
            "weight": 1,
            "low": {"type": "zmf", "params": [3, 4]},
            "medium": {"type": "trapmf", "params": [3, 4, 5, 6]},
            "high": {"type": "smf", "params": [5, 6]},
        },
        "f3": {
            "weight": 1,
            "low": {"type": "zmf", "params": [0.5, 1.5]},
            "medium": {"type": "trapmf", "params": [0.5, 1.5, 3, 4]},
            "high": {"type": "smf", "params": [3, 4]},
        },
    },
}


def test_fuzzyfy():
    features = {"f1": np.array([1.0]), "f2": np.array([5.2]), "f3": np.array([0.9])}


# Path: cotede/fuzzy/fuzzy_core.py
# def fuzzyfy(data, features, output, require="all"):
#     """
#     Notes
#     -----
#     In the generalize this once the membership combining rules are defined
#     in the cfg, so I can decide to use mean or max.
#     """
#     features_list = list(features.keys())
# 
#     N = max([len(data[f]) for f in features_list])
# 
#     # The fuzzy set are usually: low, medium, high
#     # The membership of each fuzzy set are each feature scaled.
#     membership = {f: {} for f in output.keys()}
# 
#     mfuncs = {"smf": smf, "trimf": trimf, "trapmf": trapmf, "zmf": zmf}
#     for t in features_list:
#         for m in membership:
#             assert m in features[t], "Missing %s in %s" % (m, features[t])
#             f = mfuncs[features[t][m]["type"]]
#             membership[m][t] = f(np.asanyarray(data[t]), features[t][m]["params"])
# 
#     # Rule Set
#     rules = {}
#     # Low: u_low = mean(S_l(spike), S_l(clim)...)
#     # u_low = np.mean([weights['spike']['low'],
#     #    weights['woa_relbias']['low']], axis=0)
#     # Medium: u_medium = mean(S_l(spike), S_l(clim)...)
#     # u_medium = np.mean([weights['spike']['medium'],
#     #    weights['woa_relbias']['medium']], axis=0)
# 
#     for m in [m for m in membership if m != "high"]:
#         tmp = np.vstack([membership[m][f] for f in membership[m]])
#         if require == "any":
#             rules[m] = np.nanmean(tmp, axis=0)
#         else:
#             rules[m] = np.mean(tmp, axis=0)
# 
#     # High: u_high = max(S_l(spike), S_l(clim)...)
#     # u_high = np.max([weights['spike']['high'],
#     #    weights['woa_relbias']['high']], axis=0)
# 
#     tmp = np.vstack([membership["high"][f] for f in membership["high"]])
#     if require == "any":
#         rules["high"] = np.nanmax(tmp, axis=0)
#     else:
#         rules["high"] = np.max(tmp, axis=0)
# 
#     return rules


# Path: tests/fuzzy/test_fuzzyfy.py
import numpy as np
from numpy.testing import assert_allclose
from cotede.fuzzy import fuzzyfy

        "low": {"type": "trimf", "params": [0.0, 0.225, 0.45]},
        "medium": {"type": "trimf", "params": [0.275, 0.5, 0.725]},
        "high": {"type": "smf", "params": [0.55, 0.775]},
    },
    "features": {
        "f1": {
            "weight": 1,
            "low": {"type": "zmf", "params": [0.07, 0.2]},
            "medium": {"type": "trapmf", "params": [0.07, 0.2, 2, 6]},
            "high": {"type": "smf", "params": [2, 6]},
        },
        "f2": {
            "weight": 1,
            "low": {"type": "zmf", "params": [3, 4]},
            "medium": {"type": "trapmf", "params": [3, 4, 5, 6]},
            "high": {"type": "smf", "params": [5, 6]},
        },
        "f3": {
            "weight": 1,
            "low": {"type": "zmf", "params": [0.5, 1.5]},
            "medium": {"type": "trapmf", "params": [0.5, 1.5, 3, 4]},
            "high": {"type": "smf", "params": [3, 4]},
        },
    },
}


def test_fuzzyfy():
    features = {"f1": np.array([1.0]), "f2": np.array([5.2]), "f3": np.array([0.9])}


    rules = fuzzyfy(features, **CFG)