def Dempsters_rule(a: BA, b: BA) -> BA: c = conjunctive_rule(a, b) k = 1 - c.empty t = c.true / k f = c.false / k u = c.unknown / k return BA(t, f, u)
def get_sample_BAPS() -> BA: x, y, z = np.random.rand(3).tolist() if y + z > 1: y, z = 1.0 - y, 1.0 - z if x + z > 1: x, z = 1.0 - x, 1.0 - y - z if x + y + z > 1: x, y = 1.0 - z - x, 1.0 - z - y return BA(x, y, z)
def conjunctive_rule(a: BA, b: BA) -> BA: ts, fs, us, _ = unwrapPairValues(a, b) t = cross(ts, us) + norm(ts) f = cross(fs, us) + norm(fs) u = norm(us) return BA(t, f, u)
def Dubois_Prades_rule(a: BA, b: BA) -> BA: ts, fs, us, _ = unwrapPairValues(a, b) t = cross(ts, us) + norm(ts) f = cross(fs, us) + norm(fs) u = norm(us) + cross(ts, fs) return BA(t, f, u)
def Yagers_rule(a: BA, b: BA) -> BA: c = conjunctive_rule(a, b) t = c.true f = c.false u = c.unknown + c.empty return BA(t, f, u)
def disjunctive_rule(a: BA, b: BA) -> BA: ts, fs, us, _ = unwrapPairValues(a, b) t = norm(ts) f = norm(fs) u = 1 - t - f return BA(t, f, u)
from PyDSmT.BinarySet.BinaryAssignment import BA from PyDSmT.BinarySet.BAPSCRBasic import conjunctive_rule, disjunctive_rule, Dempsters_rule # Part 1 a = BA(0.1, 0.2) b = BA(0.3, 0.2) c = BA(0.25, 0.7) print(disjunctive_rule(a, c)) print(conjunctive_rule(a, c)) print(Dempsters_rule(b, c)) # Part 2 BA.set_comb_rule(Dempsters_rule) print( BA(0.1, 0.3) * BA(0.5, 0.4) * BA(0.2, 0.2) * BA(0.6, 0.3) * BA(0.8, 0.1) * BA(0.7, 0.2) * BA(0.6, 0.1) * BA(0.01, 0.95))