FRsūtil̲s
A fuzzy-rough reasoning utilities library
 
Loading...
Searching...
No Matches
implicators.py
Go to the documentation of this file.
1"""
2Collection of fuzzy implicator functions.
3
4This module provides a set of standard fuzzy logic implicators.
5Each function takes two fuzzy truth values (floats in the range [0.0, 1.0])
6and returns the result of the corresponding implicator.
7"""
8
9import numpy as np
10
11def imp_gaines(a: float, b: float) -> float:
12 """
13 Gaines fuzzy implicator.
14
15 Returns 1.0 if a <= b.
16 Returns b / a if a > b and a > 0.
17 Returns 0.0 if a == 0 and b < a.
18
19 @param a: Antecedent value in the range [0.0, 1.0].
20 @param b: Consequent value in the range [0.0, 1.0].
21 @return: Result of Gaines' implicator.
22 @throws ValueError: If either input is outside the range [0.0, 1.0].
23 """
24 if not (0.0 <= a <= 1.0 and 0.0 <= b <= 1.0):
25 raise ValueError("Inputs must be in range [0.0, 1.0].")
26 if a <= b:
27 return 1.0
28 elif a > 0:
29 return b / a
30 else:
31 return 0.0
32
33def imp_goedel(a: float, b: float) -> float:
34 """
35 Gödel fuzzy implicator.
36
37 Returns 1.0 if a <= b, otherwise returns b.
38
39 @param a: Antecedent value in the range [0.0, 1.0].
40 @param b: Consequent value in the range [0.0, 1.0].
41 @return: Result of Gödel's implicator.
42 @throws ValueError: If either input is outside the range [0.0, 1.0].
43 """
44 if not (0.0 <= a <= 1.0 and 0.0 <= b <= 1.0):
45 raise ValueError("Inputs must be in range [0.0, 1.0].")
46 return 1.0 if a <= b else b
47
48def imp_kleene_dienes(a: float, b: float) -> float:
49 """
50 Kleene-Dienes fuzzy implicator.
51
52 Computes max(1 - a, b).
53
54 @param a: Antecedent value in the range [0.0, 1.0].
55 @param b: Consequent value in the range [0.0, 1.0].
56 @return: Result of Kleene-Dienes implicator.
57 @throws ValueError: If either input is outside the range [0.0, 1.0].
58 """
59 if not (0.0 <= a <= 1.0 and 0.0 <= b <= 1.0):
60 raise ValueError("Inputs must be in range [0.0, 1.0].")
61 return max(1.0 - a, b)
62
63def imp_reichenbach(a: float, b: float) -> float:
64 """
65 Reichenbach fuzzy implicator.
66
67 Computes 1 - a + a * b.
68
69 @param a: Antecedent value in the range [0.0, 1.0].
70 @param b: Consequent value in the range [0.0, 1.0].
71 @return: Result of Reichenbach implicator.
72 @throws ValueError: If either input is outside the range [0.0, 1.0].
73 """
74 if not (0.0 <= a <= 1.0 and 0.0 <= b <= 1.0):
75 raise ValueError("Inputs must be in range [0.0, 1.0].")
76 return 1.0 - a + a * b
77
78def imp_lukasiewicz(a: float, b: float) -> float:
79 """
80 Łukasiewicz fuzzy implicator.
81
82 Computes min(1, 1 - a + b).
83
84 @param a: Antecedent value in the range [0.0, 1.0].
85 @param b: Consequent value in the range [0.0, 1.0].
86 @return: Result of Łukasiewicz implicator.
87 @throws ValueError: If either input is outside the range [0.0, 1.0].
88 """
89 if not (0.0 <= a <= 1.0 and 0.0 <= b <= 1.0):
90 raise ValueError("Inputs must be in range [0.0, 1.0].")
91 return min(1.0, 1.0 - a + b)
float imp_kleene_dienes(float a, float b)
float imp_gaines(float a, float b)
float imp_reichenbach(float a, float b)
float imp_goedel(float a, float b)
float imp_lukasiewicz(float a, float b)