From 9a5e7a07a34bd39a07177a5455dcf50c4992fcc8 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Sun, 28 Apr 2024 21:05:03 +0300 Subject: [PATCH 1/2] fix(fuzzy_overlay): fix sum overlay and sum term in gamma overlay --- eis_toolkit/prediction/fuzzy_overlay.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eis_toolkit/prediction/fuzzy_overlay.py b/eis_toolkit/prediction/fuzzy_overlay.py index b289f496..3d02421d 100644 --- a/eis_toolkit/prediction/fuzzy_overlay.py +++ b/eis_toolkit/prediction/fuzzy_overlay.py @@ -94,7 +94,7 @@ def sum_overlay(data: Union[Sequence[np.ndarray], np.ndarray]) -> np.ndarray: InvalidParameterValueException: If data values are not in range [0, 1]. """ data = _prepare_data_for_fuzzy_overlay(data) - return data.sum(axis=0) - np.prod(data, axis=0) + return 1 - np.prod(1 - data, axis=0) @beartype @@ -121,5 +121,5 @@ def gamma_overlay(data: Union[Sequence[np.ndarray], np.ndarray], gamma: float = raise InvalidParameterValueException("The gamma parameter must be in range [0, 1]") product = np.prod(data, axis=0) - sum = data.sum(axis=0) - product + sum = 1 - np.prod(1 - data, axis=0) return product ** (1 - gamma) * sum**gamma From 76b07f836f4722c9bae3a15d53af72659e923dd5 Mon Sep 17 00:00:00 2001 From: Niko Aarnio Date: Mon, 29 Apr 2024 08:58:47 +0300 Subject: [PATCH 2/2] refactor(fuzzy_overlay) --- eis_toolkit/prediction/fuzzy_overlay.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/eis_toolkit/prediction/fuzzy_overlay.py b/eis_toolkit/prediction/fuzzy_overlay.py index 3d02421d..d896edf3 100644 --- a/eis_toolkit/prediction/fuzzy_overlay.py +++ b/eis_toolkit/prediction/fuzzy_overlay.py @@ -94,7 +94,9 @@ def sum_overlay(data: Union[Sequence[np.ndarray], np.ndarray]) -> np.ndarray: InvalidParameterValueException: If data values are not in range [0, 1]. """ data = _prepare_data_for_fuzzy_overlay(data) - return 1 - np.prod(1 - data, axis=0) + product_term = np.prod(1 - data, axis=0) + fuzzy_sum = 1 - product_term + return fuzzy_sum @beartype @@ -120,6 +122,7 @@ def gamma_overlay(data: Union[Sequence[np.ndarray], np.ndarray], gamma: float = if gamma < 0 or gamma > 1: raise InvalidParameterValueException("The gamma parameter must be in range [0, 1]") - product = np.prod(data, axis=0) - sum = 1 - np.prod(1 - data, axis=0) - return product ** (1 - gamma) * sum**gamma + fuzzy_product = np.prod(data, axis=0) + product_term_for_sum = np.prod(1 - data, axis=0) + fuzzy_sum = 1 - product_term_for_sum + return fuzzy_product ** (1 - gamma) * fuzzy_sum**gamma