Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qfis.h
1
9#ifndef QFIS_H
10#define QFIS_H
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
16 #include <stdlib.h>
17 #include <stdint.h>
18 #include <limits.h>
19
61
65 typedef enum {
74 _NUM_DFUZZ //skipcq: CXX-E2000
77
88
99
103 typedef enum {
106 Tsukamoto
108
110 typedef enum {
111 DeFuzz_Init,
112 DeFuzz_Compute,
113 DeFuzz_End
114 } qFIS_DeFuzzState_t;
117 /*cstat -MISRAC2012-Dir-4.8*/
118
120 typedef struct
121 {
122 float min, max, value;
123 } qFIS_IO_Base_t;
131 typedef struct
132 {
134 qFIS_IO_Base_t b;
136 } qFIS_Input_t;
137
143 typedef struct
144 {
146 qFIS_IO_Base_t b;
147 void *owner;
148 float *xag, *yag;
149 float res, x, y, data[ 4 ];
152
153 /*cstat +MISRAC2012-Dir-4.8*/
154
156 typedef float (*qFIS_MF_Fcn_t)( const qFIS_IO_Base_t * const in, const float *p, const size_t n );
164 typedef struct
165 {
167 qFIS_MF_Fcn_t shape;
168 const float *points;
169 float fx, h;
170 size_t index;
172 } qFIS_MF_t;
173
174 #define FIS_RULE_ITEM_SIZE 1
175
176 #if ( FIS_RULE_ITEM_SIZE == 1 )
177
197 typedef int8_t qFIS_Rules_t;
198 #define FIS_RULES_MIN_VALUE INT8_MIN
199 #else
219 typedef int16_t qFIS_Rules_t;
220 #define FIS_RULES_MIN_VALUE INT16_MIN
221 #endif
222
224 typedef int qFIS_Tag_t;
225 typedef float (*qFIS_DeFuzz_Fcn_t)( qFIS_Output_t * const o, const qFIS_DeFuzzState_t stage );
233 typedef struct _qFIS_s //skipcq: CXX-E2000
234 {
236 qFIS_Input_t *input;
237 qFIS_Output_t *output;
238 qFIS_MF_t *inMF, *outMF;
239 float (*andOp)( const float a, const float b );
240 float (*orOp)( const float a, const float b );
241 float (*implicate)( const float a, const float b );
242 float (*aggregate)( const float a, const float b );
243 size_t (*inferenceState)( struct _qFIS_s * const f, size_t i );
244 size_t (*aggregationState)( struct _qFIS_s * const f, size_t i );
245 qFIS_DeFuzz_Fcn_t deFuzz;
246 float *ruleWeight;
247 float *wi;
248 const qFIS_Rules_t *rules;
249 size_t rule_cols;
250 size_t nInputs, nOutputs;
251 size_t nMFInputs, nMFOutputs;
252 size_t nPoints;
253 size_t nRules, ruleCount;
254 float rStrength;
255 qFIS_Rules_t lastConnector;
256 qFIS_Type_t type;
258 } qFIS_t;
259
261 #define _QFIS_RULES_END ( FIS_RULES_MIN_VALUE + 1 ) //skipcq: CXX-E2000
262 #define _QFIS_AND ( FIS_RULES_MIN_VALUE + 2 ) //skipcq: CXX-E2000
263 #define _QFIS_OR ( FIS_RULES_MIN_VALUE + 3 ) //skipcq: CXX-E2000
264 #define _QFIS_THEN ( FIS_RULES_MIN_VALUE + 4 ) //skipcq: CXX-E2000
265
266 #define _QFIS_IF_STATEMENT , //skipcq: CXX-E2000
267 #define _QFIS_AND_STATEMENT +1),_QFIS_AND, //skipcq: CXX-E2000
268 #define _QFIS_OR_STATEMENT +1),_QFIS_OR, //skipcq: CXX-E2000
269 #define _QFIS_THEN_STATEMENT +1),_QFIS_THEN, //skipcq: CXX-E2000
270 #define _QFIS_IS_STATEMENT ,( //skipcq: CXX-E2000
271 #define _QFIS_IS_NOT_STATEMENT ,-( //skipcq: CXX-E2000
272 #define _QFIS_END_STATEMENT +1) //skipcq: CXX-E2000
275 /*Rules build keywords*/
276
295 #define QFIS_RULES_BEGIN ( FIS_RULES_MIN_VALUE )
296
315 #define QFIS_RULES_END ,_QFIS_RULES_END
316
318 #define IF _QFIS_IF_STATEMENT
320 #define AND _QFIS_AND_STATEMENT
322 #define OR _QFIS_OR_STATEMENT
324 #define THEN _QFIS_THEN_STATEMENT
326 #define IS _QFIS_IS_STATEMENT
328 #define IS_NOT _QFIS_IS_NOT_STATEMENT
330 #define END _QFIS_END_STATEMENT
331
339 int qFIS_SetParameter( qFIS_t * const f,
340 const qFIS_Parameter_t p,
341 const qFIS_ParamValue_t x );
342
354 int qFIS_SetDeFuzzMethod( qFIS_t * const f,
356
382 int qFIS_Setup( qFIS_t * const f,
383 const qFIS_Type_t t,
384 qFIS_Input_t * const inputs,
385 const size_t ni,
386 qFIS_Output_t * const outputs,
387 const size_t no,
388 qFIS_MF_t * const mf_inputs,
389 const size_t nmi,
390 qFIS_MF_t * const mf_outputs,
391 const size_t nmo,
392 const qFIS_Rules_t * const r,
393 float *wi,
394 const size_t n
395 );
396
405 int qFIS_InputSetup( qFIS_Input_t * const v,
406 const qFIS_Tag_t t,
407 const float min,
408 const float max );
409
419 int qFIS_OutputSetup( qFIS_Output_t * const v,
420 const qFIS_Tag_t t,
421 const float min,
422 const float max );
423
431 int qFIS_SetInput( qFIS_Input_t * const v,
432 const qFIS_Tag_t t,
433 const float value );
434
442 float qFIS_GetOutput( const qFIS_Output_t * const v,
443 const qFIS_Tag_t t );
444
472 int qFIS_SetMF( qFIS_MF_t * const m,
473 const qFIS_Tag_t io,
474 const qFIS_Tag_t mf,
475 const qFIS_MF_Name_t s,
476 qFIS_MF_Fcn_t custom_mf,
477 const float *cp,
478 const float h );
479
497 const qFIS_Tag_t t,
498 float *x,
499 float *y,
500 const size_t n );
501
510 int qFIS_Fuzzify( qFIS_t * const f );
511
519 int qFIS_Inference( qFIS_t * const f );
520
531 int qFIS_DeFuzzify( qFIS_t * const f );
532
541 int qFIS_SetRuleWeights( qFIS_t * const f,
542 float *rWeights );
543
546#ifdef __cplusplus
547}
548#endif
549
550#endif
int16_t qFIS_Rules_t
Type definition to instantiate a set of fuzzy rules.
Definition qfis.h:219
qFIS_Type_t
An enum with the inference system types supported by qFIS.
Definition qfis.h:103
int qFIS_StoreAggregatedRegion(qFIS_Output_t *const o, const qFIS_Tag_t t, float *x, float *y, const size_t n)
Set location to store the aggregated region for supplied FIS output.
Definition qfis.c:376
float qFIS_GetOutput(const qFIS_Output_t *const v, const qFIS_Tag_t t)
Get the de-fuzzified crisp value from the the output with the specified tag.
Definition qfis.c:323
int qFIS_Inference(qFIS_t *const f)
Perform the inference process on the requested FIS object.
Definition qfis.c:859
qFIS_ParamValue_t
An enum with the supported parameter values.
Definition qfis.h:81
qFIS_MF_Name_t
An enum with all the possible values to specify a membership function.
Definition qfis.h:29
int qFIS_DeFuzzify(qFIS_t *const f)
Perform the de-Fuzzification operation to compute the crisp outputs.
Definition qfis.c:792
int qFIS_SetDeFuzzMethod(qFIS_t *const f, qFIS_DeFuzz_Method_t m)
Change the default de-Fuzzification method of the FIS instance.
Definition qfis.c:191
int qFIS_InputSetup(qFIS_Input_t *const v, const qFIS_Tag_t t, const float min, const float max)
Setup the input with the specified tag and set limits for it.
Definition qfis.c:269
qFIS_Parameter_t
An enum with the allowed parameters that can be set on a FIS instance.
Definition qfis.h:92
int qFIS_Setup(qFIS_t *const f, const qFIS_Type_t t, qFIS_Input_t *const inputs, const size_t ni, qFIS_Output_t *const outputs, const size_t no, qFIS_MF_t *const mf_inputs, const size_t nmi, qFIS_MF_t *const mf_outputs, const size_t nmo, const qFIS_Rules_t *const r, float *wi, const size_t n)
Setup and initialize the FIS instance.
Definition qfis.c:217
int qFIS_SetMF(qFIS_MF_t *const m, const qFIS_Tag_t io, const qFIS_Tag_t mf, const qFIS_MF_Name_t s, qFIS_MF_Fcn_t custom_mf, const float *cp, const float h)
Set the IO tag and points for the specified membership function.
Definition qfis.c:336
int qFIS_SetRuleWeights(qFIS_t *const f, float *rWeights)
Set weights to the rules of the inference system.
Definition qfis.c:846
int qFIS_SetInput(qFIS_Input_t *const v, const qFIS_Tag_t t, const float value)
Set a crisp value of the input with the specified tag.
Definition qfis.c:309
int qFIS_OutputSetup(qFIS_Output_t *const v, const qFIS_Tag_t t, const float min, const float max)
Setup the output with the specified tag and set limits for it.
Definition qfis.c:285
qFIS_DeFuzz_Method_t
An enum with all the possible de-Fuzzyfication methods.
Definition qfis.h:65
int qFIS_SetParameter(qFIS_t *const f, const qFIS_Parameter_t p, const qFIS_ParamValue_t x)
Set parameters of the FIS instance.
Definition qfis.c:137
int qFIS_Fuzzify(qFIS_t *const f)
Perform the fuzzification operation over the crisp inputs on the requested FIS object.
Definition qfis.c:426
@ Sugeno
Definition qfis.h:105
@ Tsukamoto
Definition qfis.h:106
@ Mamdani
Definition qfis.h:104
@ qFIS_SUM
Definition qfis.h:86
@ qFIS_PROD
Definition qfis.h:83
@ qFIS_MIN
Definition qfis.h:82
@ qFIS_MAX
Definition qfis.h:84
@ qFIS_PROBOR
Definition qfis.h:85
@ tsigmf
Definition qfis.h:54
@ zmf
Definition qfis.h:41
@ linsmf
Definition qfis.h:45
@ smf
Definition qfis.h:40
@ sigmf
Definition qfis.h:36
@ constantmf
Definition qfis.h:49
@ pimf
Definition qfis.h:39
@ linearmf
Definition qfis.h:50
@ tconcavemf
Definition qfis.h:53
@ gauss2mf
Definition qfis.h:35
@ linzmf
Definition qfis.h:46
@ singletonmf
Definition qfis.h:42
@ custommf
Definition qfis.h:30
@ tsmf
Definition qfis.h:55
@ rectmf
Definition qfis.h:47
@ trapmf
Definition qfis.h:32
@ tlinzmf
Definition qfis.h:52
@ trimf
Definition qfis.h:31
@ concavemf
Definition qfis.h:43
@ psigmf
Definition qfis.h:38
@ gbellmf
Definition qfis.h:33
@ spikemf
Definition qfis.h:44
@ tlinsmf
Definition qfis.h:51
@ cosmf
Definition qfis.h:48
@ gaussmf
Definition qfis.h:34
@ tzmf
Definition qfis.h:56
@ dsigmf
Definition qfis.h:37
@ qFIS_EvalPoints
Definition qfis.h:97
@ qFIS_OR
Definition qfis.h:96
@ qFIS_Implication
Definition qfis.h:93
@ qFIS_Aggregation
Definition qfis.h:94
@ qFIS_AND
Definition qfis.h:95
@ wtsum
Definition qfis.h:72
@ lom
Definition qfis.h:69
@ bisector
Definition qfis.h:67
@ centroid
Definition qfis.h:66
@ wtaver
Definition qfis.h:71
@ mom
Definition qfis.h:68
@ som
Definition qfis.h:70
A FIS Input object.
Definition qfis.h:132
A FIS Membership Function.
Definition qfis.h:165
A FIS Output object.
Definition qfis.h:144
A FIS(Fuzzy Inference System) object.
Definition qfis.h:234