source: cpp/frams/neuro/impl/neuroimpl-fuzzy.h @ 791

Last change on this file since 791 was 791, checked in by Maciej Komosinski, 6 years ago

Code formatting

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// This file is a part of Framsticks SDK.  http://www.framsticks.com/
2// Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
3// See LICENSE.txt for details.
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
14extern ParamEntry NI_FuzzyNeuro_tab[];
15
16/** Does the fuzzyfication process (of inputs) and defuzzyfication proces (of outpurs) - represents fuzzy rules
17*/
18class NI_FuzzyNeuro : public NeuroImpl
19{
20private:
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
40protected:
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
48public:
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
Note: See TracBrowser for help on using the repository browser.