We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 67fe25d commit fc9c10cCopy full SHA for fc9c10c
src/fuzzylogic/defuzz.py
@@ -20,7 +20,10 @@ def cog(target_weights: list[tuple[Set, float]]) -> float:
20
• xᵢ is the corresponding value for the iᵗʰ element in the output domain.
21
22
"""
23
+
24
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.")
27
sum_weighted_cogs = sum(then_set.center_of_gravity() * weight for then_set, weight in target_weights)
28
return sum_weighted_cogs / sum_weights
29
0 commit comments