-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoFuzzy.h
62 lines (49 loc) · 1.5 KB
/
AutoFuzzy.h
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
// AutoFuzzy.h
#ifndef AutoFuzzy_h
#define AutoFuzzy_h
#include "Arduino.h"
#define MAX_VARS 10
#define MAX_MEMBERSHIP_FUNCTIONS 5
#define MAX_RULES 50
class AutoFuzzy {
public:
AutoFuzzy();
// Input/Output variable management
void addInput(const char* name, float min, float max);
void addOutput(const char* name, float min, float max);
// Membership functions
void addTriangularMF(const char* varName, const char* mfName, float a, float b, float c);
void addTrapezoidalMF(const char* varName, const char* mfName, float a, float b, float c, float d);
// Rule management
void addRule(const char* ifVar, const char* ifMF, const char* thenVar, const char* thenMF);
// Automated optimization
void autoOptimize(int iterations = 100);
float evaluate(float* inputs);
private:
struct MembershipFunction {
char name[20];
uint8_t type; // 0 for triangular, 1 for trapezoidal
float params[4];
};
struct Variable {
char name[20];
bool isInput;
float min;
float max;
MembershipFunction mfs[MAX_MEMBERSHIP_FUNCTIONS];
uint8_t mfCount;
};
struct Rule {
uint8_t ifVar;
uint8_t ifMF;
uint8_t thenVar;
uint8_t thenMF;
};
Variable vars[MAX_VARS];
uint8_t varCount;
Rule rules[MAX_RULES];
uint8_t ruleCount;
float calculateMembership(MembershipFunction& mf, float value);
void optimizeParameters(float* trainingInputs, float* trainingOutputs, int dataSize);
};
#endif