SystemyRozmyteProjekt/FuzzySystemFunctions.py
2023-01-17 21:56:21 +01:00

79 lines
5.5 KiB
Python

from simpful import *
def create_fuzzy_system():
FS = FuzzySystem(show_banner=False)
# ADVANTAGE_STANDINGS
adv_standings_negative = TriangleFuzzySet(5, 5, 50, term="negative")
adv_standings_neutral = TriangleFuzzySet(10, 50, 90, term="neutral")
adv_standings_positive = TriangleFuzzySet(50, 95, 95, term="positive")
FS.add_linguistic_variable("ADVANTAGE_STANDINGS",
LinguisticVariable([adv_standings_negative,
adv_standings_neutral,
adv_standings_positive],
universe_of_discourse=[0, 100]))
# ADVANTAGE_FORM
adv_form_negative = TriangleFuzzySet(5, 5, 50, term="negative")
adv_form_neutral = TriangleFuzzySet(10, 50, 90, term="neutral")
adv_form_positive = TriangleFuzzySet(50, 95, 95, term="positive")
FS.add_linguistic_variable("ADVANTAGE_FORM",
LinguisticVariable([adv_form_negative,
adv_form_neutral,
adv_form_positive],
universe_of_discourse=[0, 100]))
# ADVANTAGE_PERFORMANCE
adv_performance_negative = TriangleFuzzySet(5, 5, 50, term="negative")
adv_performance_neutral = TriangleFuzzySet(10, 50, 90, term="neutral")
adv_performance_positive = TriangleFuzzySet(50, 95, 95, term="positive")
FS.add_linguistic_variable("ADVANTAGE_PERFORMANCE",
LinguisticVariable([adv_performance_negative,
adv_performance_neutral,
adv_performance_positive],
universe_of_discourse=[0, 100]))
# RESULT
team_b_surely_wins = TriangleFuzzySet(10, 10, 25, term="team_b_surely_wins")
team_b_most_likely_wins = TrapezoidFuzzySet(17, 27, 37, 47, term="team_b_most_likely_wins")
draw = TrapezoidFuzzySet(37, 47, 53, 63, term="draw")
team_a_most_likely_wins = TrapezoidFuzzySet(53, 63, 73, 83, term="team_a_most_likely_wins")
team_a_surely_wins = TriangleFuzzySet(75, 90, 90, term="team_a_surely_wins")
FS.add_linguistic_variable("RESULT",
LinguisticVariable([team_b_surely_wins,
team_b_most_likely_wins,
draw,
team_a_most_likely_wins,
team_a_surely_wins],
universe_of_discourse=[0, 100]))
RULE1 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_surely_wins)"
RULE2 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_surely_wins)"
RULE3 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_a_most_likely_wins)"
RULE4 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_b_most_likely_wins)"
RULE5 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE6 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE7 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS draw)"
RULE8 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_surely_wins)"
RULE9 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_surely_wins)"
RULE10 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS positive) THEN (RESULT IS team_a_most_likely_wins)"
RULE11 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS negative) THEN (RESULT IS team_b_most_likely_wins)"
RULE12 = "IF (ADVANTAGE_STANDINGS IS positive) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_most_likely_wins)"
RULE13 = "IF (ADVANTAGE_STANDINGS IS negative) AND (ADVANTAGE_FORM IS neutral) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_most_likely_wins)"
RULE14 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS positive) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_a_most_likely_wins)"
RULE15 = "IF (ADVANTAGE_STANDINGS IS neutral) AND (ADVANTAGE_FORM IS negative) AND (ADVANTAGE_PERFORMANCE IS neutral) THEN (RESULT IS team_b_most_likely_wins)"
FS.add_rules([RULE1, RULE2, RULE3, RULE4, RULE5, RULE6, RULE7, RULE8, RULE9, RULE10, RULE11, RULE12, RULE13, RULE14, RULE15])
return FS
def make_inference(FS, standings, form, performance):
FS.set_variable("ADVANTAGE_STANDINGS", standings)
FS.set_variable("ADVANTAGE_FORM", form)
FS.set_variable("ADVANTAGE_PERFORMANCE", performance)
return FS.inference(["RESULT"])