Implement the MYCIN certainty-factor algebra: AND=min, premise×rule strength for a rule CF (0.8 AND 0.6, strength 1.0), then combine that rule with a second rule of CF 0.6. Print "rule CF" and "combined CF".
Implement the MYCIN certainty-factor algebra: AND=min, premise×rule strength for a rule CF (0.8 AND 0.6, strength 1.0), then combine that rule with a second rule of CF 0.6. Print "rule CF" and "combined CF".
Answer
def cf_and(*cfs): return min(cfs) # AND premise = weakest link def cf_or(*cfs): return max(cfs) # OR premise = strongest evidence def rule_cf(premise_cf, rule_strength): return premise_cf * rule_strength def combine(cf1, cf2): # two rules concluding the same fact if cf1 >= 0 and cf2 >= 0: return cf1 + cf2 - cf1 * cf2 if cf1 < 0 and cf2 < 0: return cf1 + cf2 + cf1 * cf2 return (cf1 + cf2) / (1 - min(abs(cf1), abs(cf2))) # Rule R1: IF p1 (CF 0.8) AND p2 (CF 0.6) THEN conclusion, strength 1.0 premise = cf_and(0.8, 0.6) r1 = rule_cf(premise, 1.0) print(f"rule CF = {round(r1, 2)}") # Rule R2 (CF 0.6) supports the same conclusion; combine. combined = combine(r1, 0.6) print(f"combined CF = {round(combined, 2)}")