import skfuzzy as fuzz
from skfuzzy import control as ctrl
import matplotlib.pyplot as plt
import numpy as np
def Diagram(data):
data.view()
Inputs
First Presentation
pres1 = ctrl.Antecedent(np.arange(0, 4), "First Presentation")
pres1["A1"] = fuzz.trimf(pres1.universe, [0, 0, 1])
pres1["A2"] = fuzz.trimf(pres1.universe, [0, 1, 2])
pres1["A3"] = fuzz.trimf(pres1.universe, [1, 2, 3])
pres1["A4"] = fuzz.trimf(pres1.universe, [2, 3, 3])
Diagram(pres1)
Second Presentation
pres2 = ctrl.Antecedent(np.arange(0, 8), "Second Presentation")
pres2["B1"] = fuzz.trimf(pres2.universe, [0, 0, 3])
pres2["B2"] = fuzz.trimf(pres2.universe, [2, 4, 6])
pres2["B3"] = fuzz.trimf(pres2.universe, [5, 7, 7])
Diagram(pres2)
Project
project = ctrl.Antecedent(np.arange(0, 6), "Project")
project["C1"] = fuzz.trimf(project.universe, [0, 0, 3])
project["C2"] = fuzz.trimf(project.universe, [3, 4, 5])
project["C3"] = fuzz.trimf(project.universe, [4, 5, 5])
Diagram(project)
Final
final = ctrl.Antecedent(np.arange(0, 6), "Final")
final["D1"] = fuzz.trimf(final.universe, [0, 0, 1])
final["D2"] = fuzz.trimf(final.universe, [1, 2, 3])
final["D3"] = fuzz.trimf(final.universe, [3, 4, 4])
final["D4"] = fuzz.trimf(final.universe, [4, 5, 5])
Diagram(final)
Output
Total Score
score = ctrl.Consequent(np.arange(0, 21), "Total Score")
score["E1"] = fuzz.trimf(score.universe, [0, 0, 12])
score["E2"] = fuzz.trimf(score.universe, [10, 13, 15])
score["E3"] = fuzz.trimf(score.universe, [14, 16, 17])
score["E4"] = fuzz.trimf(score.universe, [16, 20, 20])
Diagram(score)
Rules
r1 = ctrl.Rule(pres1["A1"] & pres2["B1"] & project["C1"] & final["D1"], score["E1"])
r2 = ctrl.Rule(pres1["A2"] & pres2["B2"] & project["C2"] & final["D2"], score["E2"])
r3 = ctrl.Rule(pres1["A3"] & pres2["B2"] & project["C2"] & final["D3"], score["E3"])
r4 = ctrl.Rule(pres1["A4"] & pres2["B2"] & project["C2"] & final["D4"], score["E3"])
r5 = ctrl.Rule(pres1["A4"] & pres2["B3"] & project["C3"] & final["D4"], score["E4"])
r6 = ctrl.Rule(pres1["A1"] & pres2["B2"] & project["C3"] & final["D4"], score["E3"])
r7 = ctrl.Rule(pres1["A2"] & pres2["B3"] & project["C3"] & final["D4"], score["E4"])
r8 = ctrl.Rule(pres1["A3"] & pres2["B3"] & project["C2"] & final["D2"], score["E3"])
r9 = ctrl.Rule(pres1["A3"] & pres2["B2"] & project["C2"] & final["D4"], score["E4"])
r10 = ctrl.Rule(pres1["A2"] & pres2["B3"] & project["C2"] & final["D3"], score["E3"])
r11 = ctrl.Rule(pres1["A3"] & pres2["B2"] & project["C2"] & final["D2"], score["E2"])
rules = []
for i in range(1,12):
rules.append(eval("r" + str(i)))
fuzzy_ctrl = ctrl.ControlSystem(rules)
Results
compute = ctrl.ControlSystemSimulation(fuzzy_ctrl)
def compute_score(first_pres, sec_pres, project, final):
inputs = {
'First Presentation': first_pres,
'Second Presentation': sec_pres,
'Project': project,
'Final': final
}
compute.inputs(inputs)
compute.compute()
print('Inputs: ', inputs)
print('Total Score is:', compute.output['Total Score'])
score.view(sim=compute)
compute_score(0, 0, 0, 0)
compute_score(3, 7, 5, 5)
compute_score(2, 3, 4, 4)
compute_score(0.5, 0.5, 0.5, 0.5)
compute_score(2, 3, 4, 5)