Browse Source

And formula fixed

Maksim Melnik 7 years ago
parent
commit
b5126c3e2c
2 changed files with 28 additions and 18 deletions
  1. 28 18
      CertainTrust.py
  2. 0 0
      app-sec.py

+ 28 - 18
CertainTrust.py

@@ -63,23 +63,31 @@ class Opinion:
         :param o_B: opinion
         :return: opinion as described above
         """
-        r_f = o_A.f * o_B.f
+        t1 = o_A.t
+        c1 = o_A.c
+        f1 = o_A.f
+        t2 = o_B.t
+        c2 = o_B.c
+        f2 = o_B.f
+
+        if np.isclose(f1*f2, 1):
+            f1 = 0.999
+            f2 = 0.999
+        r_f = f1*f2
+
+
+
 
         if not np.isclose(r_f, 1):
-            # resC = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+c1*t1*(1-c2)*(1-f2)) / (1 - resF);
-            r_c = o_A.c + o_B.c - o_A.c * o_B.c - (o_B.c*o_B.t*(1-o_A.c)*(1-o_A.f)+o_A.c*o_A.t*(1-o_B.c)*(1-o_B.f)) / (1 - r_f)
+            r_c = c1 + c2 - c1*c2 - (c2*t2*(1-c1)*(1-f1)+(c1*t1*(1-c2)*(1-f2))) / (1 - r_f);
         else:
-            r_c = o_A.c + o_B.c - o_A.c * o_B.c
+            r_c = c1 + c2 - c1 * c2
 
         #FIXME: js implementation of this comparison is different from paper, using js variant now
         if np.isclose(r_c, 0):
             r_t = 0.5
-        elif np.isclose(r_f, 1):
-            # resT = (1/resC) *  (c1*t1*c2*t2)
-            r_t = (1/r_c) * (o_A.c*o_A.t*o_B.c*o_B.t)
         else:
-            # resT = (1/resC) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - resF));
-            r_t = (1/r_c) * ((o_A.c*o_A.t*o_B.c*o_B.t) + (o_A.c*o_B.f*o_A.t*(1-o_B.c)*(1-o_A.f)+o_B.c*o_A.f*o_B.t*(1-o_A.c)*(1-o_B.f)) / (1 - r_f))
+            r_t = (1/r_c) *  ((c1*t1*c2*t2) + (c1*f2*t1*(1-c2)*(1-f1)+c2*f1*t2*(1-c1)*(1-f2)) / (1 - r_f));
 
         r_t = Opinion._adjust_value(r_t)
         r_c = Opinion._adjust_value(r_c)
@@ -102,7 +110,11 @@ class Opinion:
 
     @staticmethod
     def _cum_or(opar):
-        # TODO PUT INTO ANOTHER FILE
+        """
+        For a list of opinions, compute a cummulated OR opinion.
+        :param opar:
+        :return: ORO-cummulated opinion
+        """
         res = opar[0]
         for o in opar[1:]:
             res = Opinion._single_or(res, o)
@@ -110,22 +122,21 @@ class Opinion:
 
     @staticmethod
     def _cum_and(opar):
-        # TODO PUT INTO ANOTHER FILE
+        """
+        For a list of opinions, compute a cummulated AND opinion.
+        :param opar:
+        :return: AND-cummulated opinion
+        """
         res = opar[0]
         for o in opar[1:]:
             res = Opinion._single_and(res, o)
         return res
 
-    @staticmethod
-    def _initialize():
-        #TODO PUT INTO ANOTHER FILE
-        return
-
     @staticmethod
     def _internal_fusion(args, weights, doc=1.0):
         """
         An internal implementation of fusion function.
-        Is called by _weighted_fusion and cFusion
+        Is called by _weighted_fusion and cFusion.
         :param args: list of opinions
         :param weights: list of weights
         :param doc: degree of conflict (float)
@@ -260,4 +271,3 @@ print(Opinion._internal_fusion(os, w, 1))
 
 print(Opinion._conflicted_fusion(os, w))
 """
-

+ 0 - 0
app-sec.py