|
@@ -3,8 +3,8 @@ import numpy as np
|
|
class Opinion:
|
|
class Opinion:
|
|
"""
|
|
"""
|
|
This class represents opinion.
|
|
This class represents opinion.
|
|
- c - certainty
|
|
|
|
t - average rating
|
|
t - average rating
|
|
|
|
+ c - certainty
|
|
f - initial expectation value
|
|
f - initial expectation value
|
|
doc - degree of conflict
|
|
doc - degree of conflict
|
|
"""
|
|
"""
|
|
@@ -18,11 +18,9 @@ class Opinion:
|
|
def __str__(self):
|
|
def __str__(self):
|
|
return "Opinion{t: "+str(self.t)+", c: "+str(self.c)+", f: "+str(self.f)+"}"
|
|
return "Opinion{t: "+str(self.t)+", c: "+str(self.c)+", f: "+str(self.f)+"}"
|
|
|
|
|
|
- @staticmethod
|
|
|
|
- def _adjust_value(val):
|
|
|
|
- return max(min(val, 1), 0)
|
|
|
|
|
|
+ def expectation_value(self):
|
|
|
|
+ return self.c * self.t + ( 1 - self.c ) * self.f
|
|
|
|
|
|
- @staticmethod
|
|
|
|
def _single_or(o_A, o_B):
|
|
def _single_or(o_A, o_B):
|
|
"""
|
|
"""
|
|
Computes OR function of two Opinion objects. Result is returned as a new object,
|
|
Computes OR function of two Opinion objects. Result is returned as a new object,
|
|
@@ -124,13 +122,13 @@ class Opinion:
|
|
return
|
|
return
|
|
|
|
|
|
@staticmethod
|
|
@staticmethod
|
|
- def _internal_fusion(args, weights, doc):
|
|
|
|
|
|
+ def _internal_fusion(args, weights, doc=1.0):
|
|
"""
|
|
"""
|
|
An internal implementation of fusion function.
|
|
An internal implementation of fusion function.
|
|
Is called by _weighted_fusion and cFusion
|
|
Is called by _weighted_fusion and cFusion
|
|
- :param args:
|
|
|
|
- :param weights:
|
|
|
|
- :param doc:
|
|
|
|
|
|
+ :param args: list of opinions
|
|
|
|
+ :param weights: list of weights
|
|
|
|
+ :param doc: degree of conflict (float)
|
|
:return:
|
|
:return:
|
|
"""
|
|
"""
|
|
allOne = True;
|
|
allOne = True;
|
|
@@ -162,7 +160,7 @@ class Opinion:
|
|
r_t = 0
|
|
r_t = 0
|
|
else:
|
|
else:
|
|
for i in range(0,arrLength):
|
|
for i in range(0,arrLength):
|
|
- numeratorT += weights[i] * args[i].getT()
|
|
|
|
|
|
+ numeratorT += weights[i] * args[i].t
|
|
denominatorT += weights[i]
|
|
denominatorT += weights[i]
|
|
else:
|
|
else:
|
|
if atLeastOne1:
|
|
if atLeastOne1:
|
|
@@ -242,6 +240,12 @@ class Opinion:
|
|
else:
|
|
else:
|
|
raise Exception("_conflicted_fusion is not allowed for these arguments")
|
|
raise Exception("_conflicted_fusion is not allowed for these arguments")
|
|
|
|
|
|
|
|
+ @staticmethod
|
|
|
|
+ def _adjust_value(val):
|
|
|
|
+ return max(min(val, 1), 0)
|
|
|
|
+
|
|
|
|
+"""
|
|
|
|
+// TESTS
|
|
os = [Opinion(0.7,0.9,0.9), Opinion(0.4,0.7,1),Opinion(0.7,0.7,1),Opinion(0.2,0.9,1),Opinion(0.55,0.8,1)]
|
|
os = [Opinion(0.7,0.9,0.9), Opinion(0.4,0.7,1),Opinion(0.7,0.7,1),Opinion(0.2,0.9,1),Opinion(0.55,0.8,1)]
|
|
w = [1, 0.3, 0.2, 1, 0.5]
|
|
w = [1, 0.3, 0.2, 1, 0.5]
|
|
print(Opinion._single_or(os[0],os[1]))
|
|
print(Opinion._single_or(os[0],os[1]))
|
|
@@ -255,7 +259,5 @@ print(Opinion._cum_and(os))
|
|
print(Opinion._internal_fusion(os, w, 1))
|
|
print(Opinion._internal_fusion(os, w, 1))
|
|
|
|
|
|
print(Opinion._conflicted_fusion(os, w))
|
|
print(Opinion._conflicted_fusion(os, w))
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+"""
|
|
|
|
|