prototype fuzzy system engine

This commit is contained in:
Mateusz Tylka 2022-12-17 16:47:45 +01:00
commit 69c93e95a3
3 changed files with 5886 additions and 0 deletions

54
engine.py Normal file
View File

@ -0,0 +1,54 @@
from simpful import *
FS = FuzzySystem()
# Define fuzzy sets for the variable # Define fuzzy sets for the variable
# RELEASE_YEAR
release_year_newer = FuzzySet(points=[[-68.0, 0.0], [68.0, 1.0]], term="newer")
release_year_similar = FuzzySet(points=[[-68.0, 0.0], [0.0, 1.0], [68.0, 0.0]], term="similar")
release_year_older = FuzzySet(points=[[-68.0, 1.0], [68.0, 0.0]], term="older")
FS.add_linguistic_variable("RELEASE_YEAR", LinguisticVariable( [release_year_newer, release_year_similar, release_year_older] ))
# RUNTIME
runtime_shorter = FuzzySet(points=[[-238.0, 0.0], [238.0, 1.0]], term="shorter")
runtime_similar = FuzzySet(points=[[-238.0, 0.0], [0.0, 1.0], [238.0, 0.0]], term="similar")
runtime_longer = FuzzySet(points=[[-238.0, 1.0], [238.0, 0]], term="longer")
FS.add_linguistic_variable("RUNTIME", LinguisticVariable( [runtime_shorter, runtime_similar, runtime_longer] ))
# SEASONS
seasons_less = FuzzySet(points=[[-42.0, 0.0], [42.0, 1.0]], term="less")
seasons_similar = FuzzySet(points=[[-42.0, 0.0], [0.0, 1.0], [42.0, 0.0]], term="similar")
seasons_more = FuzzySet(points=[[-42.0, 1.0], [42.0, 0.0]], term="more")
FS.add_linguistic_variable("SEASONS", LinguisticVariable( [seasons_less, seasons_similar, seasons_more] ))
# GENRES
genres_different = FuzzySet(points=[[-100.0, 0.0], [100.0, 1.0]], term="different")
genres_similar = FuzzySet(points=[[-100.0, 0.0], [0.0, 1.0], [100.0, 0.0]], term="similar")
genres_same = FuzzySet(points=[[-100.0, 1.0], [100.0, 0.0]], term="same")
FS.add_linguistic_variable("GENRES", LinguisticVariable( [genres_different, genres_similar, genres_same] ))
# EMOTIONS
emotions_different = FuzzySet(points=[[-4.0, 0.0], [4.0, 1.0]], term="different")
emotions_similar = FuzzySet(points=[[-4.0, 0.0], [0.0, 1.0], [4.0, 0.0]], term="similar")
emotions_same = FuzzySet(points=[[-4.0, 1.0], [4.0, 0.0]], term="same")
FS.add_linguistic_variable("EMOTIONS", LinguisticVariable( [emotions_different, emotions_similar, emotions_same] ))
FS.set_crisp_output_value("low_recomendation", 0)
FS.set_crisp_output_value("medium_recomendation", 50)
FS.set_crisp_output_value("high_recomendation", 100)
RULE1 = "IF (RELEASE_YEAR IS older) AND (RUNTIME IS longer) AND (SEASONS IS more) THEN (RECOMENDATION IS low_recomendation)"
RULE2 = "IF (EMOTIONS IS different) AND (GENRES IS different) THEN (RECOMENDATION IS low_recomendation)"
RULE3 = "IF (RELEASE_YEAR IS newer) AND (RUNTIME IS similar) AND (SEASONS IS less) THEN (RECOMENDATION IS medium_recomendation)"
RULE4 = "IF (EMOTIONS IS similar) AND (GENRES IS similar) THEN (RECOMENDATION IS medium_recomendation)"
RULE5 = "IF (RELEASE_YEAR IS similar) AND (RUNTIME IS similar) AND (SEASONS IS similar) AND (EMOTIONS IS same) AND (GENRES IS same) THEN (RECOMENDATION IS high_recomendation)"
FS.add_rules([RULE1, RULE2, RULE3, RULE4, RULE5])
FS.set_variable("RELEASE_YEAR", -12.0)
FS.set_variable("RUNTIME", -10.0)
FS.set_variable("SEASONS", -2.0)
FS.set_variable("GENRES", 50.0)
FS.set_variable("EMOTIONS", 1.0)
print(FS.Sugeno_inference(["RECOMENDATION"]))

107
notes.txt Normal file
View File

@ -0,0 +1,107 @@
rok: 1999
czas_trwania: 25
sezony: 4
gatunek: komedia, dramat
emocje: funny 50, Sad 50
nowszy, dluzszy, wiecej, podobny, podobne
ROK PREMIERY
nowszy =
taki_sam_jak_wybrany =
starszy =
CZAS TRWANIA
krotszy =
taki_sam_jak_wybrany =
dluzszy =
SEZONY
mniej =
podobnie_jak_wybrane =
wiecej =
GATUNEK
inny =
podobny =
taki_sam_jak_wybrany =
EMOCJE
inne =
podobne =
takie_same_jak_wybrane =
OCENA - sortuje
OUTPUT rekomendacja -
(DEFUZZIFY srodek ciezkosci)
wysoka =
srednia =
mala =
RULE 1: IF rok_premiery IS starszy AND czas_trwania IS dluzszy AND sezony IS wiecej THEN rekomendacja IS mala;
RULE 2: IF emocje IS inne AND gatunek IS inny THEN rekomendacja IS mala;
RULE 3: IF rok_premiery IS nowszy AND sezony IS mniej AND czas_trwania IS taki_sam_jak_wybrany THEN rekomendacja IS srednia;
RULE 4: IF emocje IS podobne AND gatunek IS podobny THEN rekomendacja IS srednia;
RULE 5: IF emocje IS takie_same_jak_wybrane AND gatunek IS taki_sam_jak_wybrany AND sezony IS podobnie_jak_wybrane
AND czas_trwania IS taki_sam_jak_wybrany AND rok_premiery IS taki_sam_jak_wybrany THEN rekomendacja IS wysoka;
rok: 1999
czas_trwania: 25
sezony: 4
gatunek: komedia, dramat
emocje: funny 50, Sad 50
nowszy, dluzszy, wiecej, podobny, podobne
ROK PREMIERY
nowszy =
taki_sam_jak_wybrany =
starszy =
CZAS TRWANIA
krotszy =
taki_sam_jak_wybrany =
dluzszy =
SEZONY
mniej =
podobnie_jak_wybrane =
wiecej =
GATUNEK
inny =
podobny =
taki_sam_jak_wybrany =
EMOCJE
inne =
podobne =
takie_same_jak_wybrane =
OCENA - sortuje
OUTPUT rekomendacja -
(DEFUZZIFY srodek ciezkosci)
wysoka =
srednia =
mala =
RULE 1: IF rok_premiery IS starszy AND czas_trwania IS dluzszy AND sezony IS wiecej THEN rekomendacja IS mala;
RULE 2: IF emocje IS inne AND gatunek IS inny THEN rekomendacja IS mala;
RULE 3: IF rok_premiery IS nowszy AND sezony IS mniej AND czas_trwania IS taki_sam_jak_wybrany THEN rekomendacja IS srednia;
RULE 4: IF emocje IS podobne AND gatunek IS podobny THEN rekomendacja IS srednia;
RULE 5: IF emocje IS takie_same_jak_wybrane AND gatunek IS taki_sam_jak_wybrany AND sezony IS podobnie_jak_wybrane
AND czas_trwania IS taki_sam_jak_wybrany AND rok_premiery IS taki_sam_jak_wybrany THEN rekomendacja IS wysoka;

5725
processed_data.csv Normal file

File diff suppressed because it is too large Load Diff