Debian Codegraph @

examples/takagi-sugeno/octave/sugeno_tip_calculator.R

raw
1 #Code automatically generated with fuzzylite 6.0.
2
3 library(ggplot2);
4
5 engine.name = "sugeno_tip_calculator"
6 engine.fll = "Engine: sugeno_tip_calculator
7 InputVariable: FoodQuality
8 enabled: true
9 range: 1.000 10.000
10 lock-range: false
11 term: Bad Trapezoid 0.000 1.000 3.000 7.000
12 term: Good Trapezoid 3.000 7.000 10.000 11.000
13 InputVariable: Service
14 enabled: true
15 range: 1.000 10.000
16 lock-range: false
17 term: Bad Trapezoid 0.000 1.000 3.000 7.000
18 term: Good Trapezoid 3.000 7.000 10.000 11.000
19 OutputVariable: CheapTip
20 enabled: true
21 range: 5.000 25.000
22 lock-range: false
23 aggregation: none
24 defuzzifier: WeightedAverage TakagiSugeno
25 default: nan
26 lock-previous: false
27 term: Low Constant 10.000
28 term: Medium Constant 15.000
29 term: High Constant 20.000
30 OutputVariable: AverageTip
31 enabled: true
32 range: 5.000 25.000
33 lock-range: false
34 aggregation: none
35 defuzzifier: WeightedAverage TakagiSugeno
36 default: nan
37 lock-previous: false
38 term: Low Constant 10.000
39 term: Medium Constant 15.000
40 term: High Constant 20.000
41 OutputVariable: GenerousTip
42 enabled: true
43 range: 5.000 25.000
44 lock-range: false
45 aggregation: none
46 defuzzifier: WeightedAverage TakagiSugeno
47 default: nan
48 lock-previous: false
49 term: Low Constant 10.000
50 term: Medium Constant 15.000
51 term: High Constant 20.000
52 RuleBlock:
53 enabled: true
54 conjunction: EinsteinProduct
55 disjunction: none
56 implication: none
57 activation: General
58 rule: if FoodQuality is extremely Bad and Service is extremely Bad then CheapTip is extremely Low and AverageTip is very Low and GenerousTip is Low
59 rule: if FoodQuality is Good and Service is extremely Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium
60 rule: if FoodQuality is very Good and Service is very Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High
61 rule: if FoodQuality is Bad and Service is Bad then CheapTip is Low and AverageTip is Low and GenerousTip is Medium
62 rule: if FoodQuality is Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is High
63 rule: if FoodQuality is extremely Good and Service is Bad then CheapTip is Low and AverageTip is Medium and GenerousTip is very High
64 rule: if FoodQuality is Bad and Service is Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High
65 rule: if FoodQuality is Good and Service is Good then CheapTip is Medium and AverageTip is Medium and GenerousTip is very High
66 rule: if FoodQuality is very Bad and Service is very Good then CheapTip is Low and AverageTip is Medium and GenerousTip is High
67 rule: if FoodQuality is very very Good and Service is very very Good then CheapTip is High and AverageTip is very High and GenerousTip is extremely High"
68
69 engine.fldFile = "sugeno_tip_calculator.fld"
70 if (require(data.table)) {
71 engine.df = data.table::fread(engine.fldFile, sep="auto", header="auto")
72 } else {
73 engine.df = read.table(engine.fldFile, header=TRUE)
74 }
75
76 engine.plot.i1i2_o1 = ggplot(engine.df, aes(FoodQuality, Service)) +
77 geom_tile(aes(fill=CheapTip)) +
78 scale_fill_gradient(low="yellow", high="red") +
79 stat_contour(aes(x=FoodQuality, y=Service, z=CheapTip), color="black") +
80 ggtitle("(FoodQuality, Service) = CheapTip")
81
82 engine.plot.i2i1_o1 = ggplot(engine.df, aes(Service, FoodQuality)) +
83 geom_tile(aes(fill=CheapTip)) +
84 scale_fill_gradient(low="yellow", high="red") +
85 stat_contour(aes(x=Service, y=FoodQuality, z=CheapTip), color="black") +
86 ggtitle("(Service, FoodQuality) = CheapTip")
87
88 engine.plot.i1i2_o2 = ggplot(engine.df, aes(FoodQuality, Service)) +
89 geom_tile(aes(fill=AverageTip)) +
90 scale_fill_gradient(low="yellow", high="red") +
91 stat_contour(aes(x=FoodQuality, y=Service, z=AverageTip), color="black") +
92 ggtitle("(FoodQuality, Service) = AverageTip")
93
94 engine.plot.i2i1_o2 = ggplot(engine.df, aes(Service, FoodQuality)) +
95 geom_tile(aes(fill=AverageTip)) +
96 scale_fill_gradient(low="yellow", high="red") +
97 stat_contour(aes(x=Service, y=FoodQuality, z=AverageTip), color="black") +
98 ggtitle("(Service, FoodQuality) = AverageTip")
99
100 engine.plot.i1i2_o3 = ggplot(engine.df, aes(FoodQuality, Service)) +
101 geom_tile(aes(fill=GenerousTip)) +
102 scale_fill_gradient(low="yellow", high="red") +
103 stat_contour(aes(x=FoodQuality, y=Service, z=GenerousTip), color="black") +
104 ggtitle("(FoodQuality, Service) = GenerousTip")
105
106 engine.plot.i2i1_o3 = ggplot(engine.df, aes(Service, FoodQuality)) +
107 geom_tile(aes(fill=GenerousTip)) +
108 scale_fill_gradient(low="yellow", high="red") +
109 stat_contour(aes(x=Service, y=FoodQuality, z=GenerousTip), color="black") +
110 ggtitle("(Service, FoodQuality) = GenerousTip")
111
112 if (require(gridExtra)) {
113 engine.plots = arrangeGrob(engine.plot.i1i2_o1, engine.plot.i2i1_o1, engine.plot.i1i2_o2, engine.plot.i2i1_o2, engine.plot.i1i2_o3, engine.plot.i2i1_o3, ncol=2, top=engine.name)
114 ggsave(paste0(engine.name, ".pdf"), engine.plots)
115 if (require(grid)) {
116 grid.newpage()
117 grid.draw(engine.plots)
118 }
119 }