Debian Codegraph @

examples/takagi-sugeno/octave/cubic_approximator.R

raw
1 #Code automatically generated with fuzzylite 6.0.
2
3 library(ggplot2);
4
5 engine.name = "cubic_approximator"
6 engine.fll = "Engine: cubic_approximator
7 InputVariable: X
8 enabled: true
9 range: -5.000 5.000
10 lock-range: false
11 term: AboutNegFive Triangle -6.000 -5.000 -4.000
12 term: AboutNegFour Triangle -5.000 -4.000 -3.000
13 term: AboutNegThree Triangle -4.000 -3.000 -2.000
14 term: AboutNegTwo Triangle -3.000 -2.000 -1.000
15 term: AboutNegOne Triangle -2.000 -1.000 0.000
16 term: AboutZero Triangle -1.000 0.000 1.000
17 term: AboutOne Triangle 0.000 1.000 2.000
18 term: AboutTwo Triangle 1.000 2.000 3.000
19 term: AboutThree Triangle 2.000 3.000 4.000
20 term: AboutFour Triangle 3.000 4.000 5.000
21 term: AboutFive Triangle 4.000 5.000 6.000
22 OutputVariable: ApproxXCubed
23 enabled: true
24 range: -5.000 5.000
25 lock-range: false
26 aggregation: none
27 defuzzifier: WeightedAverage TakagiSugeno
28 default: nan
29 lock-previous: false
30 term: TangentatNegFive Linear 75.000 250.000
31 term: TangentatNegFour Linear 48.000 128.000
32 term: TangentatNegThree Linear 27.000 54.000
33 term: TangentatNegTwo Linear 12.000 16.000
34 term: TangentatNegOne Linear 3.000 2.000
35 term: TangentatZero Linear 0.000 0.000
36 term: TangentatOne Linear 3.000 -2.000
37 term: TangentatTwo Linear 12.000 -16.000
38 term: TangentatThree Linear 27.000 -54.000
39 term: TangentatFour Linear 48.000 -128.000
40 term: TangentatFive Linear 75.000 -250.000
41 RuleBlock:
42 enabled: true
43 conjunction: none
44 disjunction: none
45 implication: none
46 activation: General
47 rule: if X is AboutNegFive then ApproxXCubed is TangentatNegFive
48 rule: if X is AboutNegFour then ApproxXCubed is TangentatNegFour
49 rule: if X is AboutNegThree then ApproxXCubed is TangentatNegThree
50 rule: if X is AboutNegTwo then ApproxXCubed is TangentatNegTwo
51 rule: if X is AboutNegOne then ApproxXCubed is TangentatNegOne
52 rule: if X is AboutZero then ApproxXCubed is TangentatZero
53 rule: if X is AboutOne then ApproxXCubed is TangentatOne
54 rule: if X is AboutTwo then ApproxXCubed is TangentatTwo
55 rule: if X is AboutThree then ApproxXCubed is TangentatThree
56 rule: if X is AboutFour then ApproxXCubed is TangentatFour
57 rule: if X is AboutFive then ApproxXCubed is TangentatFive"
58
59 engine.fldFile = "cubic_approximator.fld"
60 if (require(data.table)) {
61 engine.df = data.table::fread(engine.fldFile, sep="auto", header="auto")
62 } else {
63 engine.df = read.table(engine.fldFile, header=TRUE)
64 }
65
66 engine.plot.i1_o1 = ggplot(engine.df, aes(X, ApproxXCubed)) +
67 geom_line(aes(color=ApproxXCubed), size=3, lineend="round", linejoin="mitre") +
68 scale_color_gradient(low="yellow", high="red") +
69 ggtitle("X vs ApproxXCubed")
70
71 engine.plot.o1_i1 = ggplot(engine.df, aes(X, ApproxXCubed)) +
72 geom_line(aes(color=ApproxXCubed), size=3, lineend="round", linejoin="mitre") +
73 scale_color_gradient(low="yellow", high="red") +
74 coord_flip() +
75 ggtitle("ApproxXCubed vs X")
76
77 if (require(gridExtra)) {
78 engine.plots = arrangeGrob(engine.plot.i1_o1, engine.plot.o1_i1, ncol=2, top=engine.name)
79 ggsave(paste0(engine.name, ".pdf"), engine.plots)
80 if (require(grid)) {
81 grid.newpage()
82 grid.draw(engine.plots)
83 }
84 }