Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc9c10c

Browse files
fix: handle zero total weight in cog function with ValueError
1 parent 67fe25d commit fc9c10c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

‎src/fuzzylogic/defuzz.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ def cog(target_weights: list[tuple[Set, float]]) -> float:
2020
• xi is the corresponding value for the ith element in the output domain.
2121
2222
"""
23+
2324
sum_weights = sum(weight for _, weight in target_weights)
25+
if sum_weights == 0:
26+
raise ValueError("Total weight is zero. Cannot compute center-of-gravity.")
2427
sum_weighted_cogs = sum(then_set.center_of_gravity() * weight for then_set, weight in target_weights)
2528
return sum_weighted_cogs / sum_weights
2629

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /