summaryrefslogtreecommitdiff
path: root/examples/takagi-sugeno/octave/linear_tip_calculator.R
blob: e6a7058068a39884d6dd544d797c5b43891081c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#Code automatically generated with fuzzylite 6.0.

library(ggplot2);

engine.name = "linear_tip_calculator"
engine.fll = "Engine: linear_tip_calculator
InputVariable: FoodQuality
  enabled: true
  range: 1.000 10.000
  lock-range: false
  term: Bad Trapezoid 0.000 1.000 3.000 7.000
  term: Good Trapezoid 3.000 7.000 10.000 11.000
InputVariable: Service
  enabled: true
  range: 1.000 10.000
  lock-range: false
  term: Bad Trapezoid 0.000 1.000 3.000 7.000
  term: Good Trapezoid 3.000 7.000 10.000 11.000
OutputVariable: Tip
  enabled: true
  range: 10.000 20.000
  lock-range: false
  aggregation: none
  defuzzifier: WeightedAverage TakagiSugeno
  default: nan
  lock-previous: false
  term: TenPercent Linear 0.000 0.000 10.000
  term: FifteenPercent Linear 0.000 0.000 15.000
  term: TwentyPercent Linear 0.000 0.000 20.000
RuleBlock: 
  enabled: true
  conjunction: Minimum
  disjunction: none
  implication: none
  activation: General
  rule: if FoodQuality is Bad and Service is Bad then Tip is TenPercent
  rule: if FoodQuality is Bad and Service is Good then Tip is FifteenPercent
  rule: if FoodQuality is Good and Service is Bad then Tip is FifteenPercent
  rule: if FoodQuality is Good and Service is Good then Tip is TwentyPercent"

engine.fldFile = "linear_tip_calculator.fld"
if (require(data.table)) {
    engine.df = data.table::fread(engine.fldFile, sep="auto", header="auto")
} else {
    engine.df = read.table(engine.fldFile, header=TRUE)
}

engine.plot.i1i2_o1 = ggplot(engine.df, aes(FoodQuality, Service)) + 
    geom_tile(aes(fill=Tip)) + 
    scale_fill_gradient(low="yellow", high="red") + 
    stat_contour(aes(x=FoodQuality, y=Service, z=Tip), color="black") + 
    ggtitle("(FoodQuality, Service) = Tip")

engine.plot.i2i1_o1 = ggplot(engine.df, aes(Service, FoodQuality)) + 
    geom_tile(aes(fill=Tip)) + 
    scale_fill_gradient(low="yellow", high="red") + 
    stat_contour(aes(x=Service, y=FoodQuality, z=Tip), color="black") + 
    ggtitle("(Service, FoodQuality) = Tip")

if (require(gridExtra)) {
    engine.plots = arrangeGrob(engine.plot.i1i2_o1, engine.plot.i2i1_o1, ncol=2, top=engine.name)
    ggsave(paste0(engine.name, ".pdf"), engine.plots)
    if (require(grid)) {
        grid.newpage()
        grid.draw(engine.plots)
    }
}