Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fuzzy overlay #381

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions eis_toolkit/prediction/fuzzy_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 data.sum(axis=0) - np.prod(data, axis=0)
product_term = np.prod(1 - data, axis=0)
fuzzy_sum = 1 - product_term
return fuzzy_sum


@beartype
Expand All @@ -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 = data.sum(axis=0) - product
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
Loading