Documentation
Tools for embedded systems
Loading...
Searching...
No Matches
qFIS

API for the qFIS Fuzzy Inference System Engine. More...

Data Structures

struct  qFIS_Input_t
 A FIS Input object. More...
 
struct  qFIS_Output_t
 A FIS Output object. More...
 
struct  qFIS_MF_t
 A FIS Membership Function. More...
 
struct  qFIS_t
 A FIS(Fuzzy Inference System) object. More...
 

Macros

#define FIS_RULE_ITEM_SIZE
 
#define FIS_RULES_MIN_VALUE
 
#define QFIS_RULES_BEGIN
 Start a Fuzzy rule set. The QFIS_RULES_BEGIN statement is used to declare the starting point of a FIS rule set. It should be placed at the start of the rules enumeration. QFIS_RULES_END declare the end of the FIS rule set.
 
#define QFIS_RULES_END
 Ends a Fuzzy rule set. The QFIS_RULES_END statement is used to finalize the declaration of a FIS rule set. It should be placed at the end of the rules enumeration. QFIS_RULES_BEGIN declare the start point of the FIS rule set.
 
#define IF
 Rule statement to begin a rule sentence.
 
#define AND
 Rule statement to represent the AND connector.
 
#define OR
 Rule statement to represent the OR connector.
 
#define THEN
 Rule statement to represent the implication.
 
#define IS
 Rule statement to represent a premise.
 
#define IS_NOT
 Rule statement to represent a negated premise.
 
#define END
 Rule statement to end a rule sentence.
 

Typedefs

typedef int16_t qFIS_Rules_t
 Type definition to instantiate a set of fuzzy rules.
 

Enumerations

enum  qFIS_MF_Name_t {
  custommf , trimf , trapmf , gbellmf ,
  gaussmf , gauss2mf , sigmf , dsigmf ,
  psigmf , pimf , smf , zmf ,
  singletonmf , concavemf , spikemf , linsmf ,
  linzmf , rectmf , cosmf , constantmf ,
  linearmf , tlinsmf , tlinzmf , tconcavemf ,
  tsigmf , tsmf , tzmf
}
 An enum with all the possible values to specify a membership function. More...
 
enum  qFIS_DeFuzz_Method_t {
  centroid , bisector , mom , lom ,
  som , wtaver , wtsum
}
 An enum with all the possible de-Fuzzyfication methods. More...
 
enum  qFIS_ParamValue_t {
  qFIS_MIN , qFIS_PROD , qFIS_MAX , qFIS_PROBOR ,
  qFIS_SUM
}
 An enum with the supported parameter values. More...
 
enum  qFIS_Parameter_t {
  qFIS_Implication , qFIS_Aggregation , qFIS_AND , qFIS_OR ,
  qFIS_EvalPoints
}
 An enum with the allowed parameters that can be set on a FIS instance. More...
 
enum  qFIS_Type_t { Mamdani , Sugeno , Tsukamoto }
 An enum with the inference system types supported by qFIS. More...
 

Functions

int qFIS_SetParameter (qFIS_t *const f, const qFIS_Parameter_t p, const qFIS_ParamValue_t x)
 Set parameters of the FIS instance.
 
int qFIS_SetDeFuzzMethod (qFIS_t *const f, qFIS_DeFuzz_Method_t m)
 Change the default de-Fuzzification method of the FIS instance.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
int qFIS_Fuzzify (qFIS_t *const f)
 Perform the fuzzification operation over the crisp inputs on the requested FIS object.
 
int qFIS_Inference (qFIS_t *const f)
 Perform the inference process on the requested FIS object.
 
int qFIS_DeFuzzify (qFIS_t *const f)
 Perform the de-Fuzzification operation to compute the crisp outputs.
 
int qFIS_SetRuleWeights (qFIS_t *const f, float *rWeights)
 Set weights to the rules of the inference system.
 

Detailed Description

API for the qFIS Fuzzy Inference System Engine.

For a brief description of this module, please read Fuzzy Inference System Engine

Macro Definition Documentation

◆ QFIS_RULES_BEGIN

#define QFIS_RULES_BEGIN

Start a Fuzzy rule set. The QFIS_RULES_BEGIN statement is used to declare the starting point of a FIS rule set. It should be placed at the start of the rules enumeration. QFIS_RULES_END declare the end of the FIS rule set.

See also
QFIS_RULES_END
Warning
Only one segment is allowed inside a fuzzy rule set.
Note
It must always be used together with a matching QFIS_RULES_END statement. Example:
static const qFIS_Rules_t rules[] = {
};
int16_t qFIS_Rules_t
Type definition to instantiate a set of fuzzy rules.
Definition qfis.h:219
#define QFIS_RULES_END
Ends a Fuzzy rule set. The QFIS_RULES_END statement is used to finalize the declaration of a FIS rule...
Definition qfis.h:315
#define QFIS_RULES_BEGIN
Start a Fuzzy rule set. The QFIS_RULES_BEGIN statement is used to declare the starting point of a FIS...
Definition qfis.h:295

◆ QFIS_RULES_END

#define QFIS_RULES_END

Ends a Fuzzy rule set. The QFIS_RULES_END statement is used to finalize the declaration of a FIS rule set. It should be placed at the end of the rules enumeration. QFIS_RULES_BEGIN declare the start point of the FIS rule set.

See also
QFIS_RULES_BEGIN
Warning
Only one segment is allowed inside a fuzzy rule set.
Note
It must always be used together with a matching QFIS_RULES_BEGIN statement. Example:
static const qFIS_Rules_t rules[] = {
};

Typedef Documentation

◆ qFIS_Rules_t

typedef int16_t qFIS_Rules_t

Type definition to instantiate a set of fuzzy rules.

Rules are defined by combining I/O and membership function tags with the following statements:

QFIS_RULES_BEGIN, IF, IS, IS_NOT, AND, OR, THEN, END and QFIS_RULES_END

Example:

static const qFIS_Rules_t rules[] = {
IF service IS service_poor OR food IS food_rancid THEN tip IS tip_cheap END
IF service IS service_good THEN tip IS tip_average END
IF service IS service_excellent OR food IS food_delicious THEN tip IS tip_generous END
};
#define END
Rule statement to end a rule sentence.
Definition qfis.h:330
#define OR
Rule statement to represent the OR connector.
Definition qfis.h:322
#define IF
Rule statement to begin a rule sentence.
Definition qfis.h:318
#define IS
Rule statement to represent a premise.
Definition qfis.h:326
#define THEN
Rule statement to represent the implication.
Definition qfis.h:324

Enumeration Type Documentation

◆ qFIS_DeFuzz_Method_t

An enum with all the possible de-Fuzzyfication methods.

Enumerator
centroid 

Center of gravity of the fuzzy set along the x-axis [ Only for Mamdani FIS ]

bisector 

Vertical line that divides the fuzzy set into two sub-regions of equal area [ Only for Mamdani FIS ]

mom 

Middle of Maximum [ Only for Mamdani FIS ]

lom 

Largest of Maximum [ Only for Mamdani FIS ]

som 

Smallest of Maximum [ Only for Mamdani FIS ]

wtaver 

Weighted average of all rule outputs [ Only for Sugeno and Tsukamoto FIS ]

wtsum 

Weighted sum of all rule outputs [ Only for Sugeno FIS ]

◆ qFIS_MF_Name_t

An enum with all the possible values to specify a membership function.

Enumerator
custommf 

Custom user-defined Membership function

trimf 

Triangular Membership function f(a,b,c)

trapmf 

Trapezoidal Membership function f(a,b,c,d)

gbellmf 

Generalized bell-shaped Membership function f(a,b,c)

gaussmf 

Gaussian Membership function f(s,c)

gauss2mf 

Gaussian combination Membership function f(s1,c1,s2,c2)

sigmf 

Sigmoidal Membership function f(a,c)

dsigmf 

Difference between two sigmoidal Membership functions f(a1,c1,a2,c2)

psigmf 

Product of two sigmoidal membership functions f(a1,c1,a2,c2)

pimf 

Pi-shaped membership function f(a,b,c,d)

smf 

S-shaped membership function f(a,b)

zmf 

Z-shaped membership function f(a,b)

singletonmf 

Singleton Membership Function f(a)

concavemf 

Concave Membership Function f(i,e)

spikemf 

Spike Membership Function f(w,c)

linsmf 

Linear s-shaped saturation membership function f(a,b)

linzmf 

Linear z-shaped saturation membership function f(a,b)

rectmf 

Rectangle Membership Function f(s,e)

cosmf 

Cosine Membership Function f(c,w)

constantmf 

Constant membership function f(a) [Only for Sugeno FIS ]

linearmf 

Linear membership function f(...) [Only for Sugeno FIS ]

tlinsmf 

Tsukamoto s-shaped saturation membership function f(a,b) [Only for Tsukamoto FIS ]

tlinzmf 

Tsukamoto linzmf membership function f(a,b) [ Only for Tsukamoto FIS ]

tconcavemf 

Tsukamoto z-shaped saturation membership function f(i,e) [Only for Tsukamoto FIS ]

tsigmf 

Tsukamoto Sigmoid membership function f(a,c) [ Only for Tsukamoto FIS ]

tsmf 

Tsukamoto S-Shape membership function f(a,b) [ Only for Tsukamoto FIS ]

tzmf 

Tsukamoto Z-Shape membership function f(a,b) [ Only for Tsukamoto FIS ]

◆ qFIS_Parameter_t

An enum with the allowed parameters that can be set on a FIS instance.

Enumerator
qFIS_Implication 

Only qFIS_MIN and qFIS_PROD supported

qFIS_Aggregation 

Only qFIS_MAX, qFIS_PROBOR and qFIS_SUM supported

qFIS_AND 

Only qFIS_MIN and qFIS_PROD supported

qFIS_OR 

Only qFIS_MAX and qFIS_PROBOR supported

qFIS_EvalPoints 

The number of points for de-fuzzification

◆ qFIS_ParamValue_t

An enum with the supported parameter values.

Enumerator
qFIS_MIN 

Minimal value

qFIS_PROD 

Product

qFIS_MAX 

Maximum value

qFIS_PROBOR 

Probabilistic OR

qFIS_SUM 

Sum

◆ qFIS_Type_t

An enum with the inference system types supported by qFIS.

Enumerator
Mamdani 

Mamdani inference system. The output of each rule its a fuzzy logic set.

Sugeno 

Takagi-Sugeno inference system. The output of each rule its a function either linear or constant.

Tsukamoto 

Mamdani inference system. The output of each rule its a fuzzy logic set represented with a monotonic membership function.

Function Documentation

◆ qFIS_DeFuzzify()

int qFIS_DeFuzzify ( qFIS_t *const f)

Perform the de-Fuzzification operation to compute the crisp outputs.

Precondition
The instance should have already invoked the inference process successfully with qFIS_Inference()
Note
By default, this function, this API uses the Centroid method on Mamdani type FIS and weight-average on Sugeno type FIS. To change the default settings use the qFIS_SetDeFuzzMethod() function.
Parameters
[in]fA pointer to the Fuzzy Inference System instance.
Returns
1 on success, otherwise return 0.

◆ qFIS_Fuzzify()

int qFIS_Fuzzify ( qFIS_t *const f)

Perform the fuzzification operation over the crisp inputs on the requested FIS object.

Precondition
I/Os and fuzzy sets must be previously initialized by qFIS_InputSetup(), qFIS_OutputSetup(), qFIS_SetMF() and qFIS_Setup() respectively.
Parameters
[in]fA pointer to the Fuzzy Inference System instance.
Returns
1 on success, otherwise return 0.

◆ qFIS_GetOutput()

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.

Parameters
[in]vAn array with the FIS inputs as a qFIS_Output_t array.
[in]tThe output tag
Returns
The requested de-fuzzified crips value.

◆ qFIS_Inference()

int qFIS_Inference ( qFIS_t *const f)

Perform the inference process on the requested FIS object.

Precondition
The instance should have already invoked the fuzzification operation successfully with qFIS_Fuzzify()
Parameters
[in]fA pointer to the Fuzzy Inference System instance.
Returns
1 on success, otherwise return 0.

◆ qFIS_InputSetup()

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.

Parameters
[in]vAn array with the FIS inputs as a qFIS_Input_t array.
[in]tThe input tag
[in]minMinimum allowed value for this input
[in]maxMax allowed value for this input
Returns
1 on success, otherwise return 0.

◆ qFIS_OutputSetup()

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.

Note
limits do not apply in Sugeno outputs
Parameters
[in]vAn array with the FIS outputs as a qFIS_Output_t array.
[in]tThe output tag
[in]minMinimum allowed value for this output
[in]maxMax allowed value for this output
Returns
1 on success, otherwise return 0.

◆ qFIS_SetDeFuzzMethod()

int qFIS_SetDeFuzzMethod ( qFIS_t *const f,
qFIS_DeFuzz_Method_t m )

Change the default de-Fuzzification method of the FIS instance.

Parameters
[in]fA pointer to the Fuzzy Inference System instance.
[in]mThe de-fuzzification method: use one of the following : centroid, bisector, mom, lom, som, wtaver, wtsum
Note
centroid, bisector, mom, lom and som only apply for a Mamdani FIS
wtaver and wtsum only apply for a Sugeno FIS.
wtaver only apply for a Tsukamoto FIS
Returns
1 on success, otherwise return 0.

◆ qFIS_SetInput()

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.

Parameters
[in]vAn array with the FIS inputs as a qFIS_Input_t array.
[in]tThe input tag
[in]valueThe crisp value to set
Returns
1 on success, otherwise return 0.

◆ qFIS_SetMF()

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.

Parameters
[in]mAn array with the required membership functions as qFIS_MF_t objects.
[in]ioThe I/O tag related with this membership function
[in]mfThe user-defined tag for this membership function
[in]sThe wanted shape/form for this membership function, can be one of the following: trimf, trapmf, gbellmf, gaussmf, gauss2mf, sigmf, dsigmf, psigmf, pimf, smf, zmf, singletonmf, concavemf, spikemf, linsmf, linzmf, rectmf, cosmf.
Note
For Sugeno FIS, an output membership function should be one of the following: constantmf, linearmf.
For Tsukamoto FIS, an output membership function should be one the following monotonic functions : tlinsmf, tlinzmf, tsmf, tzmf, tconcavemf
To set a custom user-defined membership function, set this argument as custommf and pass a pointer to the desired function on the custom_mf argument.
Parameters
[in]custom_mfCustom user-defined membership function. To ignore pass NULL as argument.
[in]cpPoints or coefficients of the membership function.
[in]hHeight of the membership function.
Note
Height parameter h does not apply for output membership functions on Sugeno and Tsukamoto inference systems. [ 0 <= h <= 1]
Returns
1 on success, otherwise return 0.

◆ qFIS_SetParameter()

int qFIS_SetParameter ( qFIS_t *const f,
const qFIS_Parameter_t p,
const qFIS_ParamValue_t x )

Set parameters of the FIS instance.

Parameters
[in]fA pointer to the Fuzzy Inference System instance.
[in]pThe requested parameter to change/set.
[in]xThe value of the parameter to set.
Returns
1 on success, otherwise return 0.

◆ qFIS_SetRuleWeights()

int qFIS_SetRuleWeights ( qFIS_t *const f,
float * rWeights )

Set weights to the rules of the inference system.

Precondition
I/Os and fuzzy sets must be previously initialized by qFIS_InputSetup(), qFIS_OutputSetup(), qFIS_SetMF() and qFIS_Setup() respectively.
Parameters
[in]fA pointer to the Fuzzy Inference System instance.
[in]rWeightsAn array with the values of every rule weight;
Returns
1 on success, otherwise return 0.

◆ qFIS_Setup()

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.

Note
Default configuration : AND = Min, OR = Max, Implication = Min Aggregation = Max, EvalPoints = 100
Parameters
[in]fA pointer to the Fuzzy Inference System instance.
[in]tType of inference Mamdani, Sugeno or Tsukamoto.
[in]inputsAn array with all the system inputs as qFIS_Input_t objects.
[in]niThe number of bytes used by inputs. Use the sizeof operator.
[in]outputsAn array with all the system outputs as qFIS_Output_t objects.
[in]noThe number of bytes used by outputs. Use the sizeof operator.
[in]mf_inputsAn array with all the membership functions related to the inputs. This should be an array of qFIS_MF_t objects.
[in]nmiThe number of bytes used by mf_inputs. Use the sizeof operator.
[in]mf_outputsAn array with all the membership functions related to the outputs. This should be an array of qFIS_MF_t objects.
[in]nmoThe number of bytes used by mf_outputs. Use the sizeof operator.
[in]rThe rules set.
[in]wiAn array of size n were the rule strengths will be stored.
[in]nNumber of rules
Returns
1 on success, otherwise return 0.

◆ qFIS_StoreAggregatedRegion()

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.

Note
This feature only applies to Mamdani systems.
Warning
Array size of x and y should be greater or equal to the number of evaluation points of the FIS instance.
Precondition
The FIS instance and the output should be previously configured initialized with qFIS_Setup() and qFIS_OutputSetup() respectively.
Parameters
[in]oAn array of type qFIS_Output_t with the FIS outputs.
[in]tThe output tag
[in]xArray where the x-axis points of the aggregated output will be stored
[in]yArray where the y-axis points of the aggregated output will be stored
[in]nNumber of elements in x or y.
Returns
1 on success, otherwise return 0.