1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #ifndef _NEUROIMPLFUZZY_H_ |
---|
6 | #define _NEUROIMPLFUZZY_H_ |
---|
7 | |
---|
8 | #include <stdlib.h> |
---|
9 | #include <math.h> |
---|
10 | |
---|
11 | #include <frams/neuro/neuroimpl.h> |
---|
12 | #include <frams/util/sstring.h> |
---|
13 | |
---|
14 | extern ParamEntry NI_FuzzyNeuro_tab[]; |
---|
15 | |
---|
16 | /** Does the fuzzyfication process (of inputs) and defuzzyfication proces (of outpurs) - represents fuzzy rules |
---|
17 | */ |
---|
18 | class NI_FuzzyNeuro : public NeuroImpl |
---|
19 | { |
---|
20 | private: |
---|
21 | |
---|
22 | double *fuzzySets; /// list of four digits which represents fuzzy sets: [0]-l, [1]-m, [2]-n, [3]-r, ... fuzzySet[4*i] = left, fuzzySet[4*i + 1] = midleft, fuzzySet[4*i + 2] = midright, fuzzySet[4*i + 3] = right |
---|
23 | |
---|
24 | /** Determines, which fuzzy set is connected with each input of neuron. For instance third rule: |
---|
25 | * 'IF input3 = fuzzy set #3 AND input5 = fuzzy set #1 then output2 = fuzzy set #6 AND output7 = fuzzy set #5' |
---|
26 | * the variables shoul have values as shown below: |
---|
27 | * RulesDef[4]=2; RulesDef[5]=2; //rule 3: 2 inputs, 2 outputs |
---|
28 | * Rules[2][0]=3, Rules[2][1]=3, Rules[2][2]=5, Rules[2][3]=1, Rules[2][4]=2, Rules[2][5]=6, Rules[2][6]=7, Rules[2][3]=5 |
---|
29 | */ |
---|
30 | int *rulesDef; ///list of rules definitions: nr of inputs in rule 1, nr of outputs in rule 1, ... and so on for each rule |
---|
31 | int **rules; ///list of rules body: input nr, fuzzy set nr, ... , output nr, fuzzy set nr, ... and so on for each rule |
---|
32 | |
---|
33 | /** |
---|
34 | * Sets defuzzyfication parameters: determines - for each rule - cut level <0;1> (minimum membership function of current rule). |
---|
35 | * In fact, defuzzParam remembers the values from 'first layer' - fuzzyfication layer (see neuron at documentation) |
---|
36 | * i.e. rule 1: defuzzParam[0] = 0.3522 |
---|
37 | */ |
---|
38 | double *defuzzParam; /// i.e.: defuzParam[5] = 0.455 means that rule #6 has got a minimum membership function (of given inputs set for this rule) at value 0.455 (it's cut level) |
---|
39 | |
---|
40 | protected: |
---|
41 | |
---|
42 | ///Fuzzy functions |
---|
43 | double TrapeziumFuzz(int which_fuzzy_set, double input_val); |
---|
44 | int Fuzzyfication(); |
---|
45 | int Defuzzyfication(); |
---|
46 | int GetFuzzySetParam(int set_nr, double &left, double &midleft, double &midright, double &right); |
---|
47 | |
---|
48 | public: |
---|
49 | |
---|
50 | int fuzzySetsNr; /// number of fuzzy sets |
---|
51 | int rulesNr; ///number of rules |
---|
52 | SString fuzzySetString; /// strings containing all fuzzy sets given in f0 |
---|
53 | SString fuzzyRulesString; /// strings containing all fuzzy rules given in f0 |
---|
54 | |
---|
55 | NI_FuzzyNeuro() {paramentries=NI_FuzzyNeuro_tab; fuzzySets=defuzzParam=NULL; rulesDef=NULL; rules=NULL;} |
---|
56 | ~NI_FuzzyNeuro(); |
---|
57 | NeuroImpl* makeNew() { return new NI_FuzzyNeuro(); }; |
---|
58 | void go(); |
---|
59 | int lateinit(); |
---|
60 | /** Function build model based on given genotype and conts number of neurons connected with fuzzy neuro, |
---|
61 | also checks number of fuzzy neuron inputs. |
---|
62 | \param genotype genotype to be scanned |
---|
63 | \param inputs number of fuzzy neuron inputs |
---|
64 | \param output number of fuzzy neuron outputs (= number of neurons connected to fuzzy neuron) |
---|
65 | @return success or failure |
---|
66 | **/ |
---|
67 | static int countOuts(const Model *m, const Neuro *fuzzy); |
---|
68 | |
---|
69 | }; |
---|
70 | |
---|
71 | #endif |
---|