Help me to convert this fuzzy rules into Arduino IDE base on code i found on web

So i try to input my fuzzy rule into arduino ide

This is my code i use 3 input and 1 output

// Library fuzzy //

#include <Fuzzy.h>

Fuzzy *fuzzy = new Fuzzy(); // inisialisasi fuzzy objek

// fuzzy input 1
FuzzyInput *D = new FuzzyInput(1);

FuzzySet *DR = new FuzzySet (60 , 70 ,80); // Heart rate
D->addFuzzySet(DR);

FuzzySet *DT = new FuzzySet (70, 80, 90); 
D->addFuzzySet(DT);

FuzzySet *DC = new FuzzySet (80, 90, 100); 
D->addFuzzySet(DC);

FuzzySet *DS = new FuzzySet (90, 100, 110); 
D->addFuzzySet(DS);

fuzzy->addFuzzyInput(D);

// fuzzy input 2
Fuzzyinput *S = new FuzzyInput(2);

FuzzySet *SS = new FuzzySet (32, 33, 34); //Temp
S->addFuzzySet(SS);

FuzzySet *SC = new FuzzySet (33, 34, 35); 
S->addFuzzySet(SC);

FuzzySet *ST = new FuzzySet (34, 35, 36); 
S->addFuzzySet(ST);

FuzzySet *SR = new FuzzySet (35, 36, 37); 
S->addFuzzySet(SR);

fuzzy->addFuzzyInput(S);

// fuzzy input 3

Fuzzyinput *G = new FuzzyInput(3);

FuzzySet *GR = new FuzzySet (1, 2, 3); // GSR
G->addFuzzySet(GR);

FuzzySet *GT = new FuzzySet (2, 3, 4); 
G->addFuzzySet(GT);

FuzzySet *GC = new FuzzySet (3, 4, 5); 
G->addFuzzySet(GC);

FuzzySet *GS = new FuzzySet (4, 5, 7); 
G->addFuzzySet(GS);

fuzzy->addFuzzyInput(G);

// fuzzy OUTPUT

FuzzyOutput *kondisi = new FuzzyOutput(1);

FuzzySet *Rileks = new FuzzySet (0, 12.5, 25); // GSR
kondisi->addFuzzySet(Rileks);

FuzzySet *Tenang = new FuzzySet (25, 37.5, 50); 
kondisi->addFuzzySet(Tenang);

FuzzySet *Cemas= new FuzzySet (50, 62.5, 75); 
kondisi->addFuzzySet(Cemas);

FuzzySet *Stress = new FuzzySet (75, 87.5, 100); 
kondisi->addFuzzySet(Stress);```

So now iam trying to implement this code i found online but this code only use 1 input and 1 output

FuzzyRuleAntecedent *IfDistanceSmall = new FuzzyRuleAntecedent();
 IfDistanceSmall->joinSingle(small);

 FuzzyRuleConsequent*thenSpeedSlow = new FuzzyRuleConsequent();

 FuzzyRule *fuzzyRule01 = new FuzzyRule(1, IfDistanceSmall, thenSpeedSlow);
 fuzzy->addFuzzyRule(fuzzyRule01)

this is the code i found on youtube i try to implement my 3 input but i just dont understand how

And this is 3 example of my Rules

if G is GR and D is DR and S is SR then condition is Rileks

if G is GR and D is DR and S is ST then condition is Rileks

if G is GR and D is DR and S is SC then condition is Tenang

can you guys help me how to implement my rules into code that i found online

Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

thank you for the advice i just had some tech issues

just a joke:

Ask chatGPT. chatGPT is a specialist about "fuzzyness"
No don't do it.

Are you sure that the fuzzy.h is suited for arduino?Can you post the asource where you have the library from?

How about using one of these fuzzy-libraries?

Though the documentation of some of them is very consequent: fuzzy

best regards Stefan

1 Like
    if (G == GR && D == DR)  {
        if (S == SR || S == ST)
            Rileks
        else if (S == SC)
            Tenang
    }

i though fuzzy "logic" made decisions by weighting ranges of input values and combining the weighted values to help select choices where one input is slightly outside some selection range but the other far exceeds the selection range

When I try to convert fis to c language using makeproto , it's using weight as you say but I cant barely understand the code so it's hard to edit it

It's from YouTube that I watched here is the link

This is the code that is convert from fis to c language i still cant read it so i can edit it

//***********************************************************************
// Matlab .fis to arduino C converter v2.0.1.25122016                   
// - Karthik Nadig, USA                                                  
// Please report bugs to:                                                
// https://github.com/karthiknadig/ArduinoFIS/issues                     
// If you don't have a GitHub account mail to karthiknadig@gmail.com     
//***********************************************************************

#include "fis_header.h"

// Number of inputs to the fuzzy inference system
const int fis_gcI = 3;
// Number of outputs to the fuzzy inference system
const int fis_gcO = 1;
// Number of rules to the fuzzy inference system
const int fis_gcR = 64;

FIS_TYPE g_fisInput[fis_gcI];
FIS_TYPE g_fisOutput[fis_gcO];

// Setup routine runs once when you press reset:
void setup()
{
    // initialize the Analog pins for input.
    // Pin mode for Input: DETAK JANTUNG
    pinMode(0 , INPUT);
    // Pin mode for Input: SUHU
    pinMode(1 , INPUT);
    // Pin mode for Input: GSR
    pinMode(2 , INPUT);


    // initialize the Analog pins for output.
    // Pin mode for Output: KONDISI
    pinMode(3 , OUTPUT);

}

// Loop routine runs over and over again forever:
void loop()
{
    // Read Input: DETAK JANTUNG
    g_fisInput[0] = analogRead(0);
    // Read Input: SUHU
    g_fisInput[1] = analogRead(1);
    // Read Input: GSR
    g_fisInput[2] = analogRead(2);

    g_fisOutput[0] = 0;

    fis_evaluate();

    // Set output vlaue: KONDISI
    analogWrite(3 , g_fisOutput[0]);

}

//***********************************************************************
// Support functions for Fuzzy Inference System                          
//***********************************************************************
// Triangular Member Function
FIS_TYPE fis_trimf(FIS_TYPE x, FIS_TYPE* p)
{
    FIS_TYPE a = p[0], b = p[1], c = p[2];
    FIS_TYPE t1 = (x - a) / (b - a);
    FIS_TYPE t2 = (c - x) / (c - b);
    if ((a == b) && (b == c)) return (FIS_TYPE) (x == a);
    if (a == b) return (FIS_TYPE) (t2*(b <= x)*(x <= c));
    if (b == c) return (FIS_TYPE) (t1*(a <= x)*(x <= b));
    t1 = min(t1, t2);
    return (FIS_TYPE) max(t1, 0);
}

FIS_TYPE fis_min(FIS_TYPE a, FIS_TYPE b)
{
    return min(a, b);
}

FIS_TYPE fis_max(FIS_TYPE a, FIS_TYPE b)
{
    return max(a, b);
}

FIS_TYPE fis_array_operation(FIS_TYPE *array, int size, _FIS_ARR_OP pfnOp)
{
    int i;
    FIS_TYPE ret = 0;

    if (size == 0) return ret;
    if (size == 1) return array[0];

    ret = array[0];
    for (i = 1; i < size; i++)
    {
        ret = (*pfnOp)(ret, array[i]);
    }

    return ret;
}


//***********************************************************************
// Data for Fuzzy Inference System                                       
//***********************************************************************
// Pointers to the implementations of member functions
_FIS_MF fis_gMF[] =
{
    fis_trimf
};

// Count of member function for each Input
int fis_gIMFCount[] = { 4, 4, 4 };

// Count of member function for each Output 
int fis_gOMFCount[] = { 4 };

// Coefficients for the Input Member Functions
FIS_TYPE fis_gMFI0Coeff1[] = { 60, 70, 80 };
FIS_TYPE fis_gMFI0Coeff2[] = { 70, 80, 90 };
FIS_TYPE fis_gMFI0Coeff3[] = { 80, 90, 100 };
FIS_TYPE fis_gMFI0Coeff4[] = { 90, 100, 110 };
FIS_TYPE* fis_gMFI0Coeff[] = { fis_gMFI0Coeff1, fis_gMFI0Coeff2, fis_gMFI0Coeff3, fis_gMFI0Coeff4 };
FIS_TYPE fis_gMFI1Coeff1[] = { 32, 33, 34 };
FIS_TYPE fis_gMFI1Coeff2[] = { 33, 34, 35 };
FIS_TYPE fis_gMFI1Coeff3[] = { 34, 35, 36 };
FIS_TYPE fis_gMFI1Coeff4[] = { 35, 36, 37 };
FIS_TYPE* fis_gMFI1Coeff[] = { fis_gMFI1Coeff1, fis_gMFI1Coeff2, fis_gMFI1Coeff3, fis_gMFI1Coeff4 };
FIS_TYPE fis_gMFI2Coeff1[] = { 1, 2, 3 };
FIS_TYPE fis_gMFI2Coeff2[] = { 2, 3, 4 };
FIS_TYPE fis_gMFI2Coeff3[] = { 3, 4, 5 };
FIS_TYPE fis_gMFI2Coeff4[] = { 4, 5, 7 };
FIS_TYPE* fis_gMFI2Coeff[] = { fis_gMFI2Coeff1, fis_gMFI2Coeff2, fis_gMFI2Coeff3, fis_gMFI2Coeff4 };
FIS_TYPE** fis_gMFICoeff[] = { fis_gMFI0Coeff, fis_gMFI1Coeff, fis_gMFI2Coeff };

// Coefficients for the Output Member Functions
FIS_TYPE fis_gMFO0Coeff1[] = { 0, 12.5, 25 };
FIS_TYPE fis_gMFO0Coeff2[] = { 25, 37.5, 50 };
FIS_TYPE fis_gMFO0Coeff3[] = { 50, 62.5, 75 };
FIS_TYPE fis_gMFO0Coeff4[] = { 75, 87.5, 100 };
FIS_TYPE* fis_gMFO0Coeff[] = { fis_gMFO0Coeff1, fis_gMFO0Coeff2, fis_gMFO0Coeff3, fis_gMFO0Coeff4 };
FIS_TYPE** fis_gMFOCoeff[] = { fis_gMFO0Coeff };

// Input membership function set
int fis_gMFI0[] = { 0, 0, 0, 0 };
int fis_gMFI1[] = { 0, 0, 0, 0 };
int fis_gMFI2[] = { 0, 0, 0, 0 };
int* fis_gMFI[] = { fis_gMFI0, fis_gMFI1, fis_gMFI2};

// Output membership function set
int fis_gMFO0[] = { 0, 0, 0, 0 };
int* fis_gMFO[] = { fis_gMFO0};

// Rule Weights
FIS_TYPE fis_gRWeight[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

// Rule Type
int fis_gRType[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };

// Rule Inputs
int fis_gRI0[] = { 1, 1, 1 };
int fis_gRI1[] = { 2, 1, 1 };
int fis_gRI2[] = { 3, 1, 1 };
int fis_gRI3[] = { 4, 1, 1 };
int fis_gRI4[] = { 1, 2, 1 };
int fis_gRI5[] = { 2, 2, 1 };
int fis_gRI6[] = { 3, 2, 1 };
int fis_gRI7[] = { 4, 2, 1 };
int fis_gRI8[] = { 1, 3, 1 };
int fis_gRI9[] = { 2, 3, 1 };
int fis_gRI10[] = { 3, 3, 1 };
int fis_gRI11[] = { 4, 3, 1 };
int fis_gRI12[] = { 1, 4, 1 };
int fis_gRI13[] = { 2, 4, 1 };
int fis_gRI14[] = { 3, 4, 1 };
int fis_gRI15[] = { 4, 4, 1 };
int fis_gRI16[] = { 1, 1, 2 };
int fis_gRI17[] = { 2, 1, 2 };
int fis_gRI18[] = { 3, 1, 2 };
int fis_gRI19[] = { 4, 1, 2 };
int fis_gRI20[] = { 1, 2, 2 };
int fis_gRI21[] = { 2, 2, 2 };
int fis_gRI22[] = { 3, 2, 2 };
int fis_gRI23[] = { 4, 2, 2 };
int fis_gRI24[] = { 1, 3, 2 };
int fis_gRI25[] = { 2, 3, 2 };
int fis_gRI26[] = { 3, 3, 2 };
int fis_gRI27[] = { 4, 3, 2 };
int fis_gRI28[] = { 1, 4, 2 };
int fis_gRI29[] = { 2, 4, 2 };
int fis_gRI30[] = { 3, 4, 2 };
int fis_gRI31[] = { 4, 4, 2 };
int fis_gRI32[] = { 1, 1, 3 };
int fis_gRI33[] = { 2, 1, 3 };
int fis_gRI34[] = { 3, 1, 3 };
int fis_gRI35[] = { 4, 1, 3 };
int fis_gRI36[] = { 1, 2, 3 };
int fis_gRI37[] = { 2, 2, 3 };
int fis_gRI38[] = { 3, 2, 3 };
int fis_gRI39[] = { 4, 2, 3 };
int fis_gRI40[] = { 1, 3, 3 };
int fis_gRI41[] = { 2, 3, 3 };
int fis_gRI42[] = { 3, 3, 3 };
int fis_gRI43[] = { 4, 3, 3 };
int fis_gRI44[] = { 1, 4, 3 };
int fis_gRI45[] = { 2, 4, 3 };
int fis_gRI46[] = { 3, 4, 3 };
int fis_gRI47[] = { 4, 4, 3 };
int fis_gRI48[] = { 1, 1, 4 };
int fis_gRI49[] = { 2, 1, 4 };
int fis_gRI50[] = { 3, 1, 4 };
int fis_gRI51[] = { 4, 1, 4 };
int fis_gRI52[] = { 1, 2, 4 };
int fis_gRI53[] = { 2, 2, 4 };
int fis_gRI54[] = { 3, 2, 4 };
int fis_gRI55[] = { 4, 2, 4 };
int fis_gRI56[] = { 1, 3, 4 };
int fis_gRI57[] = { 2, 3, 4 };
int fis_gRI58[] = { 3, 3, 4 };
int fis_gRI59[] = { 4, 3, 4 };
int fis_gRI60[] = { 1, 4, 4 };
int fis_gRI61[] = { 2, 4, 4 };
int fis_gRI62[] = { 3, 4, 4 };
int fis_gRI63[] = { 4, 4, 4 };
int* fis_gRI[] = { fis_gRI0, fis_gRI1, fis_gRI2, fis_gRI3, fis_gRI4, fis_gRI5, fis_gRI6, fis_gRI7, fis_gRI8, fis_gRI9, fis_gRI10, fis_gRI11, fis_gRI12, fis_gRI13, fis_gRI14, fis_gRI15, fis_gRI16, fis_gRI17, fis_gRI18, fis_gRI19, fis_gRI20, fis_gRI21, fis_gRI22, fis_gRI23, fis_gRI24, fis_gRI25, fis_gRI26, fis_gRI27, fis_gRI28, fis_gRI29, fis_gRI30, fis_gRI31, fis_gRI32, fis_gRI33, fis_gRI34, fis_gRI35, fis_gRI36, fis_gRI37, fis_gRI38, fis_gRI39, fis_gRI40, fis_gRI41, fis_gRI42, fis_gRI43, fis_gRI44, fis_gRI45, fis_gRI46, fis_gRI47, fis_gRI48, fis_gRI49, fis_gRI50, fis_gRI51, fis_gRI52, fis_gRI53, fis_gRI54, fis_gRI55, fis_gRI56, fis_gRI57, fis_gRI58, fis_gRI59, fis_gRI60, fis_gRI61, fis_gRI62, fis_gRI63 };

// Rule Outputs
int fis_gRO0[] = { 1 };
int fis_gRO1[] = { 1 };
int fis_gRO2[] = { 1 };
int fis_gRO3[] = { 1 };
int fis_gRO4[] = { 1 };
int fis_gRO5[] = { 1 };
int fis_gRO6[] = { 1 };
int fis_gRO7[] = { 1 };
int fis_gRO8[] = { 1 };
int fis_gRO9[] = { 1 };
int fis_gRO10[] = { 1 };
int fis_gRO11[] = { 1 };
int fis_gRO12[] = { 1 };
int fis_gRO13[] = { 1 };
int fis_gRO14[] = { 1 };
int fis_gRO15[] = { 1 };
int fis_gRO16[] = { 1 };
int fis_gRO17[] = { 1 };
int fis_gRO18[] = { 1 };
int fis_gRO19[] = { 1 };
int fis_gRO20[] = { 1 };
int fis_gRO21[] = { 1 };
int fis_gRO22[] = { 1 };
int fis_gRO23[] = { 1 };
int fis_gRO24[] = { 1 };
int fis_gRO25[] = { 1 };
int fis_gRO26[] = { 1 };
int fis_gRO27[] = { 1 };
int fis_gRO28[] = { 1 };
int fis_gRO29[] = { 1 };
int fis_gRO30[] = { 1 };
int fis_gRO31[] = { 1 };
int fis_gRO32[] = { 1 };
int fis_gRO33[] = { 1 };
int fis_gRO34[] = { 1 };
int fis_gRO35[] = { 1 };
int fis_gRO36[] = { 1 };
int fis_gRO37[] = { 1 };
int fis_gRO38[] = { 1 };
int fis_gRO39[] = { 1 };
int fis_gRO40[] = { 1 };
int fis_gRO41[] = { 1 };
int fis_gRO42[] = { 1 };
int fis_gRO43[] = { 1 };
int fis_gRO44[] = { 1 };
int fis_gRO45[] = { 1 };
int fis_gRO46[] = { 1 };
int fis_gRO47[] = { 1 };
int fis_gRO48[] = { 1 };
int fis_gRO49[] = { 1 };
int fis_gRO50[] = { 1 };
int fis_gRO51[] = { 1 };
int fis_gRO52[] = { 1 };
int fis_gRO53[] = { 1 };
int fis_gRO54[] = { 1 };
int fis_gRO55[] = { 1 };
int fis_gRO56[] = { 1 };
int fis_gRO57[] = { 1 };
int fis_gRO58[] = { 1 };
int fis_gRO59[] = { 1 };
int fis_gRO60[] = { 1 };
int fis_gRO61[] = { 1 };
int fis_gRO62[] = { 1 };
int fis_gRO63[] = { 1 };
int* fis_gRO[] = { fis_gRO0, fis_gRO1, fis_gRO2, fis_gRO3, fis_gRO4, fis_gRO5, fis_gRO6, fis_gRO7, fis_gRO8, fis_gRO9, fis_gRO10, fis_gRO11, fis_gRO12, fis_gRO13, fis_gRO14, fis_gRO15, fis_gRO16, fis_gRO17, fis_gRO18, fis_gRO19, fis_gRO20, fis_gRO21, fis_gRO22, fis_gRO23, fis_gRO24, fis_gRO25, fis_gRO26, fis_gRO27, fis_gRO28, fis_gRO29, fis_gRO30, fis_gRO31, fis_gRO32, fis_gRO33, fis_gRO34, fis_gRO35, fis_gRO36, fis_gRO37, fis_gRO38, fis_gRO39, fis_gRO40, fis_gRO41, fis_gRO42, fis_gRO43, fis_gRO44, fis_gRO45, fis_gRO46, fis_gRO47, fis_gRO48, fis_gRO49, fis_gRO50, fis_gRO51, fis_gRO52, fis_gRO53, fis_gRO54, fis_gRO55, fis_gRO56, fis_gRO57, fis_gRO58, fis_gRO59, fis_gRO60, fis_gRO61, fis_gRO62, fis_gRO63 };

// Input range Min
FIS_TYPE fis_gIMin[] = { 60, 32, 1 };

// Input range Max
FIS_TYPE fis_gIMax[] = { 110, 37, 7 };

// Output range Min
FIS_TYPE fis_gOMin[] = { 0 };

// Output range Max
FIS_TYPE fis_gOMax[] = { 100 };

//***********************************************************************
// Data dependent support functions for Fuzzy Inference System           
//***********************************************************************
FIS_TYPE fis_MF_out(FIS_TYPE** fuzzyRuleSet, FIS_TYPE x, int o)
{
    FIS_TYPE mfOut;
    int r;

    for (r = 0; r < fis_gcR; ++r)
    {
        int index = fis_gRO[r][o];
        if (index > 0)
        {
            index = index - 1;
            mfOut = (fis_gMF[fis_gMFO[o][index]])(x, fis_gMFOCoeff[o][index]);
        }
        else if (index < 0)
        {
            index = -index - 1;
            mfOut = 1 - (fis_gMF[fis_gMFO[o][index]])(x, fis_gMFOCoeff[o][index]);
        }
        else
        {
            mfOut = 0;
        }

        fuzzyRuleSet[0][r] = fis_min(mfOut, fuzzyRuleSet[1][r]);
    }
    return fis_array_operation(fuzzyRuleSet[0], fis_gcR, fis_max);
}

FIS_TYPE fis_defuzz_centroid(FIS_TYPE** fuzzyRuleSet, int o)
{
    FIS_TYPE step = (fis_gOMax[o] - fis_gOMin[o]) / (FIS_RESOLUSION - 1);
    FIS_TYPE area = 0;
    FIS_TYPE momentum = 0;
    FIS_TYPE dist, slice;
    int i;

    // calculate the area under the curve formed by the MF outputs
    for (i = 0; i < FIS_RESOLUSION; ++i){
        dist = fis_gOMin[o] + (step * i);
        slice = step * fis_MF_out(fuzzyRuleSet, dist, o);
        area += slice;
        momentum += slice*dist;
    }

    return ((area == 0) ? ((fis_gOMax[o] + fis_gOMin[o]) / 2) : (momentum / area));
}

//***********************************************************************
// Fuzzy Inference System                                                
//***********************************************************************
void fis_evaluate()
{
    FIS_TYPE fuzzyInput0[] = { 0, 0, 0, 0 };
    FIS_TYPE fuzzyInput1[] = { 0, 0, 0, 0 };
    FIS_TYPE fuzzyInput2[] = { 0, 0, 0, 0 };
    FIS_TYPE* fuzzyInput[fis_gcI] = { fuzzyInput0, fuzzyInput1, fuzzyInput2, };
    FIS_TYPE fuzzyOutput0[] = { 0, 0, 0, 0 };
    FIS_TYPE* fuzzyOutput[fis_gcO] = { fuzzyOutput0, };
    FIS_TYPE fuzzyRules[fis_gcR] = { 0 };
    FIS_TYPE fuzzyFires[fis_gcR] = { 0 };
    FIS_TYPE* fuzzyRuleSet[] = { fuzzyRules, fuzzyFires };
    FIS_TYPE sW = 0;

    // Transforming input to fuzzy Input
    int i, j, r, o;
    for (i = 0; i < fis_gcI; ++i)
    {
        for (j = 0; j < fis_gIMFCount[i]; ++j)
        {
            fuzzyInput[i][j] =
                (fis_gMF[fis_gMFI[i][j]])(g_fisInput[i], fis_gMFICoeff[i][j]);
        }
    }

    int index = 0;
    for (r = 0; r < fis_gcR; ++r)
    {
        if (fis_gRType[r] == 1)
        {
            fuzzyFires[r] = FIS_MAX;
            for (i = 0; i < fis_gcI; ++i)
            {
                index = fis_gRI[r][i];
                if (index > 0)
                    fuzzyFires[r] = fis_min(fuzzyFires[r], fuzzyInput[i][index - 1]);
                else if (index < 0)
                    fuzzyFires[r] = fis_min(fuzzyFires[r], 1 - fuzzyInput[i][-index - 1]);
                else
                    fuzzyFires[r] = fis_min(fuzzyFires[r], 1);
            }
        }
        else
        {
            fuzzyFires[r] = FIS_MIN;
            for (i = 0; i < fis_gcI; ++i)
            {
                index = fis_gRI[r][i];
                if (index > 0)
                    fuzzyFires[r] = fis_max(fuzzyFires[r], fuzzyInput[i][index - 1]);
                else if (index < 0)
                    fuzzyFires[r] = fis_max(fuzzyFires[r], 1 - fuzzyInput[i][-index - 1]);
                else
                    fuzzyFires[r] = fis_max(fuzzyFires[r], 0);
            }
        }

        fuzzyFires[r] = fis_gRWeight[r] * fuzzyFires[r];
        sW += fuzzyFires[r];
    }

    if (sW == 0)
    {
        for (o = 0; o < fis_gcO; ++o)
        {
            g_fisOutput[o] = ((fis_gOMax[o] + fis_gOMin[o]) / 2);
        }
    }
    else
    {
        for (o = 0; o < fis_gcO; ++o)
        {
            g_fisOutput[o] = fis_defuzz_centroid(fuzzyRuleSet, o);
        }
    }
}

As far as I understand fuzzy logic. The main thing is to have a few fuzzy rules and all the rest is done in the backround.

So IMHO you either accept the black-box given by the fis to c++-converter and work with it as is
or you have to become a super-specialist in how to write code for fuzzy-logic itself. I mean the base that runs in the background.
(not a real option)

You haven't described what the final purpose of your project is.
If you describe your project maybe a different approach is better suited.

might be.
But did you "download" the fuzzy.h-library out of the video?
Surely not. You are the one who wants help. You should take the effort to support a link to where the fuzzy.h-library can be downloaded.
With googling everybody will find dozens of fuzzy-logic libraries.
Do you expect the voluntary helpers here that they search through them all?

Which fuzzy.h is that one that you are using?

You seem to greatly underestimate the effort it takes to make such a project working.
Maybe you should change to using Alexa and some kind of automation service that can be configured by shouting: "Alexa do ........"

best regards Stefan

sorry stefan i didnt mean that way ,so this is the library link

and this is the example code i find i will try to study about this code first

#include <Fuzzy.h>

// For scope, instantiate all objects you will need to access in loop()
// It may be just one Fuzzy, but for demonstration, this sample will print
// all FuzzySet pertinence

// Fuzzy
Fuzzy *fuzzy = new Fuzzy();

// FuzzyInput
FuzzySet *near = new FuzzySet(0, 20, 20, 40);
FuzzySet *safe = new FuzzySet(30, 50, 50, 70);
FuzzySet *distant = new FuzzySet(60, 80, 100, 100);

// FuzzyInput
FuzzySet *stopedInput = new FuzzySet(0, 0, 0, 0);
FuzzySet *slowInput = new FuzzySet(1, 10, 10, 20);
FuzzySet *normalInput = new FuzzySet(15, 30, 30, 50);
FuzzySet *quickInput = new FuzzySet(45, 60, 70, 70);

// FuzzyInput
FuzzySet *cold = new FuzzySet(-30, -30, -20, -10);
FuzzySet *good = new FuzzySet(-15, 0, 0, 15);
FuzzySet *hot = new FuzzySet(10, 20, 30, 30);

// FuzzyOutput
FuzzySet *minimum = new FuzzySet(0, 20, 20, 40);
FuzzySet *average = new FuzzySet(30, 50, 50, 70);
FuzzySet *maximum = new FuzzySet(60, 80, 80, 100);

// FuzzyOutput
FuzzySet *stopedOutput = new FuzzySet(0, 0, 0, 0);
FuzzySet *slowOutput = new FuzzySet(1, 10, 10, 20);
FuzzySet *normalOutput = new FuzzySet(15, 30, 30, 50);
FuzzySet *quickOutput = new FuzzySet(45, 60, 70, 70);

void setup()
{
  // Set the Serial output
  Serial.begin(9600);
  // Set a random seed
  randomSeed(analogRead(0));

  // Every setup must occur in the function setup()

  // FuzzyInput
  FuzzyInput *distance = new FuzzyInput(1);

  distance->addFuzzySet(near);
  distance->addFuzzySet(safe);
  distance->addFuzzySet(distant);
  fuzzy->addFuzzyInput(distance);

  // FuzzyInput
  FuzzyInput *speedInput = new FuzzyInput(2);

  speedInput->addFuzzySet(stopedInput);
  speedInput->addFuzzySet(slowInput);
  speedInput->addFuzzySet(normalInput);
  speedInput->addFuzzySet(quickInput);
  fuzzy->addFuzzyInput(speedInput);

  // FuzzyInput
  FuzzyInput *temperature = new FuzzyInput(3);

  temperature->addFuzzySet(cold);
  temperature->addFuzzySet(good);
  temperature->addFuzzySet(hot);
  fuzzy->addFuzzyInput(temperature);

  // FuzzyOutput
  FuzzyOutput *risk = new FuzzyOutput(1);

  risk->addFuzzySet(minimum);
  risk->addFuzzySet(average);
  risk->addFuzzySet(maximum);
  fuzzy->addFuzzyOutput(risk);

  // FuzzyOutput
  FuzzyOutput *speedOutput = new FuzzyOutput(2);

  speedOutput->addFuzzySet(stopedOutput);
  speedOutput->addFuzzySet(slowOutput);
  speedOutput->addFuzzySet(normalOutput);
  speedOutput->addFuzzySet(quickOutput);
  fuzzy->addFuzzyOutput(speedOutput);

  // Building FuzzyRule
  FuzzyRuleAntecedent *distanceNearAndSpeedQuick = new FuzzyRuleAntecedent();
  distanceNearAndSpeedQuick->joinWithAND(near, quickInput);
  FuzzyRuleAntecedent *temperatureCold = new FuzzyRuleAntecedent();
  temperatureCold->joinSingle(cold);
  FuzzyRuleAntecedent *ifDistanceNearAndSpeedQuickOrTemperatureCold = new FuzzyRuleAntecedent();
  ifDistanceNearAndSpeedQuickOrTemperatureCold->joinWithOR(distanceNearAndSpeedQuick, temperatureCold);

  FuzzyRuleConsequent *thenRisMaximumAndSpeedSlow = new FuzzyRuleConsequent();
  thenRisMaximumAndSpeedSlow->addOutput(maximum);
  thenRisMaximumAndSpeedSlow->addOutput(slowOutput);

  FuzzyRule *fuzzyRule1 = new FuzzyRule(1, ifDistanceNearAndSpeedQuickOrTemperatureCold, thenRisMaximumAndSpeedSlow);
  fuzzy->addFuzzyRule(fuzzyRule1);

  // Building FuzzyRule
  FuzzyRuleAntecedent *distanceSafeAndSpeedNormal = new FuzzyRuleAntecedent();
  distanceSafeAndSpeedNormal->joinWithAND(safe, normalInput);
  FuzzyRuleAntecedent *ifDistanceSafeAndSpeedNormalOrTemperatureGood = new FuzzyRuleAntecedent();
  ifDistanceSafeAndSpeedNormalOrTemperatureGood->joinWithOR(distanceSafeAndSpeedNormal, good);

  FuzzyRuleConsequent *thenRiskAverageAndSpeedNormal = new FuzzyRuleConsequent();
  thenRiskAverageAndSpeedNormal->addOutput(average);
  thenRiskAverageAndSpeedNormal->addOutput(normalOutput);

  FuzzyRule *fuzzyRule2 = new FuzzyRule(2, ifDistanceSafeAndSpeedNormalOrTemperatureGood, thenRiskAverageAndSpeedNormal);
  fuzzy->addFuzzyRule(fuzzyRule2);

  // Building FuzzyRule
  FuzzyRuleAntecedent *distanceDistantAndSpeedSlow = new FuzzyRuleAntecedent();
  distanceDistantAndSpeedSlow->joinWithAND(distant, slowInput);
  FuzzyRuleAntecedent *ifDistanceDistantAndSpeedSlowOrTemperatureHot = new FuzzyRuleAntecedent();
  ifDistanceDistantAndSpeedSlowOrTemperatureHot->joinWithOR(distanceDistantAndSpeedSlow, hot);

  FuzzyRuleConsequent *thenRiskMinimumSpeedQuick = new FuzzyRuleConsequent();
  thenRiskMinimumSpeedQuick->addOutput(minimum);
  thenRiskMinimumSpeedQuick->addOutput(quickOutput);

  FuzzyRule *fuzzyRule3 = new FuzzyRule(3, ifDistanceDistantAndSpeedSlowOrTemperatureHot, thenRiskMinimumSpeedQuick);
  fuzzy->addFuzzyRule(fuzzyRule3);
}

void loop()
{
  // get random entrances
  int input1 = random(0, 100);
  int input2 = random(0, 70);
  int input3 = random(-30, 30);

  Serial.println("\n\n\nEntrance: ");
  Serial.print("\t\t\tDistance: ");
  Serial.print(input1);
  Serial.print(", Speed: ");
  Serial.print(input2);
  Serial.print(", and Temperature: ");
  Serial.println(input3);

  fuzzy->setInput(1, input1);
  fuzzy->setInput(2, input2);
  fuzzy->setInput(3, input3);

  fuzzy->fuzzify();

  Serial.println("Input: ");
  Serial.print("\tDistance: Near-> ");
  Serial.print(near->getPertinence());
  Serial.print(", Safe-> ");
  Serial.print(safe->getPertinence());
  Serial.print(", Distant-> ");
  Serial.println(distant->getPertinence());

  Serial.print("\tSpeed: Stoped-> ");
  Serial.print(stopedInput->getPertinence());
  Serial.print(",  Slow-> ");
  Serial.print(slowInput->getPertinence());
  Serial.print(",  Normal-> ");
  Serial.print(normalInput->getPertinence());
  Serial.print(",  Quick-> ");
  Serial.println(quickInput->getPertinence());

  Serial.print("\tTemperature: Cold-> ");
  Serial.print(cold->getPertinence());
  Serial.print(", Good-> ");
  Serial.print(good->getPertinence());
  Serial.print(", Hot-> ");
  Serial.println(hot->getPertinence());

  float output1 = fuzzy->defuzzify(1);
  float output2 = fuzzy->defuzzify(2);

  Serial.println("Output: ");
  Serial.print("\tRisk: Minimum-> ");
  Serial.print(minimum->getPertinence());
  Serial.print(", Average-> ");
  Serial.print(average->getPertinence());
  Serial.print(", Maximum-> ");
  Serial.println(maximum->getPertinence());

  Serial.print("\tSpeed: Stoped-> ");
  Serial.print(stopedOutput->getPertinence());
  Serial.print(",  Slow-> ");
  Serial.print(slowOutput->getPertinence());
  Serial.print(",  Normal-> ");
  Serial.print(normalOutput->getPertinence());
  Serial.print(",  Quick-> ");
  Serial.println(quickOutput->getPertinence());

  Serial.println("Result: ");
  Serial.print("\t\t\tRisk: ");
  Serial.print(output1);
  Serial.print(", and Speed: ");
  Serial.println(output2);

  // wait 12 seconds
  delay(12000);
}
1 Like

what are you intending to apply fuzzy rules to?

to mimick this tabel for my project , so i have 3 input from my 3 sensors and what i want the output its condition (kondisi)

and base on this tabel there are 64 rules

1. If GSR is rileks and Detak is rileks and Suhu is rileks then HASIL is rileks 
2. If GSR is rileks and Detak is rileks and Suhu is tenang then HASIL is rileks
3. If GSR is rileks and Detak is rileks and Suhu is cemas then HASIL is tenang 
4. If GSR is rileks and Detak is rileks and Suhu is stress then HASIL is cemas 
5. If GSR is rileks and Detak is tenang and Suhu is rileks then HASIL is rileks 
6. If GSR is rileks and Detak is tenang and Suhu is tenang then HASIL is tenang 
7. If GSR is rileks and Detak is tenang and Suhu is cemas then HASIL is tenang
8. If GSR is rileks and Detak is tenang and Suhu is stress then HASIL is cemas 
9. If GSR is rileks and Detak is cemas and Suhu is rileks then HASIL is tenang
10. If GSR is rileks and Detak is cemas and Suhu is tenang then HASIL is tenang
11. If GSR is rileks and Detak is cemas and Suhu is cemas then HASIL is cemas 
12. If GSR is rileks and Detak is cemas and Suhu is stress then HASIL is cemas
13. If GSR is rileks and Detak is stress and Suhu is rileks then HASIL is tenang
14. If GSR is rileks and Detak is stress and Suhu is tenang then HASIL is tenang
15. If GSR is rileks and Detak is stress and Suhu is cemas then HASIL is cemas 
16. If GSR is rileks and Detak is stress and Suhu is stress then HASIL is cemas 
17. If GSR is tenang and Detak is rileks and Suhu is rileks then HASIL is rileks 
18. If GSR is tenang and Detak is rileks and Suhu is tenang then HASIL is tenang 
19. If GSR is tenang and Detak is rileks and Suhu is cemas then HASIL is tenang
20. If GSR is tenang and Detak is rileks and Suhu is stress then HASIL is tenang
21. If GSR is tenang and Detak is tenang and Suhu is rileks then HASIL is tenang
22. If GSR is tenang and Detak is tenang and Suhu is tenang then HASIL is
tenang
23. If GSR is tenang and Detak is tenang and Suhu is cemas then HASIL is
tenang
24. If GSR is tenang and Detak is tenang and Suhu is stress then HASIL is cemas
25. If GSR is tenang and Detak is cemas and Suhu is rileks then HASIL is cemas
26. If GSR is tenang and Detak is cemas and Suhu is tenang then HASIL is
tenang
27. If GSR is tenang and Detak is cemas and Suhu is cemas then HASIL is cemas
28. If GSR is tenang and Detak is cemas and Suhu is stress then HASIL is cemas
29. If GSR is tenang and Detak is stress and Suhu is rileks then HASIL is tenang
30. If GSR is tenang and Detak is stress and Suhu is tenang then HASIL is cemas
31. If GSR is tenang and Detak is stress and Suhu is cemas then HASIL is cemas
32. If GSR is tenang and Detak is stress and Suhu is stress then HASIL is cemas
33. If GSR is cemas and Detak is rileks and Suhu is rileks then HASIL is tenang
34. If GSR is cemas and Detak is rileks and Suhu is tenang then HASIL is tenang
35. If GSR is cemas and Detak is rileks and Suhu is cemas then HASIL is cemas
36. If GSR is cemas and Detak is rileks and Suhu is stress then HASIL is cemas
37. If GSR is cemas and Detak is tenang and Suhu is rileks then HASIL is tenang
38. If GSR is cemas and Detak is tenang and Suhu is tenang then HASIL is
tenang
39. If GSR is cemas and Detak is tenang and Suhu is cemas then HASIL is cemas
40. If GSR is cemas and Detak is tenang and Suhu is stress then HASIL is cemas
41. If GSR is cemas and Detak is cemas and Suhu is rileks then HASIL is cemas
42. If GSR is cemas and Detak is cemas and Suhu is tenang then HASIL is cemas
43. If GSR is cemas and Detak is cemas and Suhu is cemas then HASIL is cemas
44. If GSR is cemas and Detak is cemas and Suhu is stress then HASIL is cemas
45. If GSR is cemas and Detak is stress and Suhu is rileks then HASIL is cemas
46. If GSR is cemas and Detak is stress and Suhu is tenang then HASIL is cemas
47. If GSR is cemas and Detak is stress and Suhu is cemas then HASIL is cemas
48. If GSR is cemas and Detak is stress and Suhu is stress then HASIL is stress
49. If GSR is stress and Detak is rileks and Suhu is rileks then HASIL is tenang
50. If GSR is stress and Detak is rileks and Suhu is tenang then HASIL is tenang
51. If GSR is stress and Detak is rileks and Suhu is cemas then HASIL is cemas
52. If GSR is stress and Detak is rileks and Suhu is stress then HASIL is cemas
53. If GSR is stress and Detak is tenang and Suhu is rileks then HASIL is tenang
54. If GSR is stress and Detak is tenang and Suhu is tenang then HASIL is cemas
55. If GSR is stress and Detak is tenang and Suhu is cemas then HASIL is cemas
56. If GSR is stress and Detak is tenang and Suhu is stress then HASIL is cemas
57. If GSR is stress and Detak is cemas and Suhu is rileks then HASIL is cemas
58. If GSR is stress and Detak is cemas and Suhu is tenang then HASIL is cemas
59. If GSR is stress and Detak is cemas and Suhu is cemas then HASIL is cemas
60. If GSR is stress and Detak is cemas and Suhu is stress then HASIL is stress
61. If GSR is stress and Detak is stress and Suhu is rileks then HASIL is cemas
62. If GSR is stress and Detak is stress and Suhu is tenang then HASIL is cemas
63. If GSR is stress and Detak is stress and Suhu is cemas then HASIL is stress
64. If GSR is stress and Detak is stress and Suhu is stress then HASIL is stress

You could probably simplify the 64 cases using something similar to a Karnaugh map

You could also represent the state of each sensor on 2 bits and combine those bits in a byte (using the 6 low bits - 64 values possible) and have a 64 entries array giving you the answer in one easy index.

Using Fuzzy logic for this (or machine learning) is possibly not the best idea…

I would go for the 64 entries array.

Thank you Jackson for the answer, cmiiw but karnaugh map output it's 0 or 1 right? I need the fuzzy output to determine some output

yeah, that's why I said something similar to, may be that could be simplified.

but the array approach is straightforward.

say you code the states in an enum like this

enum t_state : byte {rileks = 0b00, tenang = 0b01, cemas = 0b10, stress = 0b11}; // values are unnecessary just here for making it clear

then your decision table is like this

# GSR DETAK SUHU => HASIL GSR DETAK SUHU INDEX => HASIL
1 rileks rileks rileks => rileks 00 00 00 0b00000000 => 00
2 rileks rileks tenang => rileks 00 00 01 0b00000001 => 00
3 rileks rileks cemas => tenang 00 00 10 0b00000010 => 01
4 rileks rileks stress => cemas 00 00 11 0b00000011 => 10
5 rileks tenang rileks => rileks 00 01 00 0b00000100 => 00
6 rileks tenang tenang => tenang 00 01 01 0b00000101 => 01
7 rileks tenang cemas => tenang 00 01 10 0b00000110 => 01
8 rileks tenang stress => cemas 00 01 11 0b00000111 => 10
9 rileks cemas rileks => tenang 00 10 00 0b00001000 => 01
10 rileks cemas tenang => tenang 00 10 01 0b00001001 => 01
11 rileks cemas cemas => cemas 00 10 10 0b00001010 => 10
12 rileks cemas stress => cemas 00 10 11 0b00001011 => 10
13 rileks stress rileks => tenang 00 11 00 0b00001100 => 01
14 rileks stress tenang => tenang 00 11 01 0b00001101 => 01
15 rileks stress cemas => cemas 00 11 10 0b00001110 => 10
16 rileks stress stress => cemas 00 11 11 0b00001111 => 10
17 tenang rileks rileks => rileks 01 00 00 0b00010000 => 00
18 tenang rileks tenang => tenang 01 00 01 0b00010001 => 01
19 tenang rileks cemas => tenang 01 00 10 0b00010010 => 01
20 tenang rileks stress => tenang 01 00 11 0b00010011 => 01
21 tenang tenang rileks => tenang 01 01 00 0b00010100 => 01
22 tenang tenang tenang => tenang 01 01 01 0b00010101 => 01
23 tenang tenang cemas => tenang 01 01 10 0b00010110 => 01
24 tenang tenang stress => cemas 01 01 11 0b00010111 => 10
25 tenang cemas rileks => cemas 01 10 00 0b00011000 => 10
26 tenang cemas tenang => tenang 01 10 01 0b00011001 => 01
27 tenang cemas cemas => cemas 01 10 10 0b00011010 => 10
28 tenang cemas stress => cemas 01 10 11 0b00011011 => 10
29 tenang stress rileks => tenang 01 11 00 0b00011100 => 01
30 tenang stress tenang => cemas 01 11 01 0b00011101 => 10
31 tenang stress cemas => cemas 01 11 10 0b00011110 => 10
32 tenang stress stress => cemas 01 11 11 0b00011111 => 10
33 cemas rileks rileks => tenang 10 00 00 0b00100000 => 01
34 cemas rileks tenang => tenang 10 00 01 0b00100001 => 01
35 cemas rileks cemas => cemas 10 00 10 0b00100010 => 10
36 cemas rileks stress => cemas 10 00 11 0b00100011 => 10
37 cemas tenang rileks => tenang 10 01 00 0b00100100 => 01
38 cemas tenang tenang => tenang 10 01 01 0b00100101 => 01
39 cemas tenang cemas => cemas 10 01 10 0b00100110 => 10
40 cemas tenang stress => cemas 10 01 11 0b00100111 => 10
41 cemas cemas rileks => cemas 10 10 00 0b00101000 => 10
42 cemas cemas tenang => cemas 10 10 01 0b00101001 => 10
43 cemas cemas cemas => cemas 10 10 10 0b00101010 => 10
44 cemas cemas stress => cemas 10 10 11 0b00101011 => 10
45 cemas stress rileks => cemas 10 11 00 0b00101100 => 10
46 cemas stress tenang => cemas 10 11 01 0b00101101 => 10
47 cemas stress cemas => cemas 10 11 10 0b00101110 => 10
48 cemas stress stress => stress 10 11 11 0b00101111 => 11
49 stress rileks rileks => tenang 11 00 00 0b00110000 => 01
50 stress rileks tenang => tenang 11 00 01 0b00110001 => 01
51 stress rileks cemas => cemas 11 00 10 0b00110010 => 10
52 stress rileks stress => cemas 11 00 11 0b00110011 => 10
53 stress tenang rileks => tenang 11 01 00 0b00110100 => 01
54 stress tenang tenang => cemas 11 01 01 0b00110101 => 10
55 stress tenang cemas => cemas 11 01 10 0b00110110 => 10
56 stress tenang stress => cemas 11 01 11 0b00110111 => 10
57 stress cemas rileks => cemas 11 10 00 0b00111000 => 10
58 stress cemas tenang => cemas 11 10 01 0b00111001 => 10
59 stress cemas cemas => cemas 11 10 10 0b00111010 => 10
60 stress cemas stress => stress 11 10 11 0b00111011 => 11
61 stress stress rileks => cemas 11 11 00 0b00111100 => 10
62 stress stress tenang => cemas 11 11 01 0b00111101 => 10
63 stress stress cemas => stress 11 11 10 0b00111110 => 11
64 stress stress stress => stress 11 11 11 0b00111111 => 11
1 Like

so I would do something like this


enum t_state : byte {rileks = 0b00, tenang = 0b01, cemas = 0b10, stress = 0b11, error = 0b11111111}; // values are unnecessary just here for making it clear

const t_state hasilState[] = { // index is gsr detak suhu combined in binary
  rileks, rileks, tenang, cemas, rileks, tenang, tenang, cemas,
  tenang, tenang, cemas, cemas, tenang, tenang, cemas, cemas,
  rileks, tenang, tenang, tenang, tenang, tenang, tenang, cemas,
  cemas, tenang, cemas, cemas, tenang, cemas, cemas, cemas,
  tenang, tenang, cemas, cemas, tenang, tenang, cemas, cemas,
  cemas, cemas, cemas, cemas, cemas, cemas, cemas, stress,
  tenang, tenang, cemas, cemas, tenang, cemas, cemas, cemas,
  cemas, cemas, cemas, stress, cemas, cemas, stress, stress,
};

t_state hasilValue(t_state gsr, t_state detak, t_state suhu) {
  if (gsr == error || detak == error || suhu == error) return error;
  byte index = (gsr << 4) | (detak << 2) | suhu;
  return hasilState[index];
}

const char * state2str(t_state aState) {
  switch (aState) {
    case rileks: return "rileks";
    case tenang: return "tenang";
    case cemas:  return "cemas";
    case stress: return "stress";
    default:     return "unknown";
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println(state2str(hasilValue(rileks, rileks, rileks)));
}

void loop() {}

fully untested :slight_smile:

➜ based on the table you shared previously

to get your status for each variable, you would code a small function like this

t_state gsrValue(int s) { // or float, not sure what's the type of your GSR unit
  if (s < 2)       return rileks;
  else if (s <= 4) return tenang;
  else if (s <= 6) return cemas;
  return stress;
}

EDIT:

I noted from your first code that you would get the sampled values from an analogRead (don't do the pinMode on pins 0, 1 and 2 in set-up you'll mess up the Serial communication. no need for pinMode to perform an analogRead)

detak = analogRead(A0);
suhu = analogRead(A1);
gsr = analogRead(A2);

so you'll have to adjust a bit the code for the formulas to take into account the mapping of your sensor source into a sampled voltage. say that for GSR 2 the sampled value is 40, 4 is 80, 6 is 120 then the code could be

t_state gsrValue() {
  int gsr;
  gsr = analogRead(A2);
  gsr = analogRead(A2); // double reading for analog stability

  if (gsr < 40)        return rileks;
  else if (gsr <= 80)  return tenang;
  else if (gsr <= 120) return cemas;
  return stress;
}
1 Like

what about the cases outside the above ranges?

  • HR < 60
  • H&T > 37

why do you think this need fuzzy rules?

I guess it could be useful if you want a more descriptive answer like "you are "calm" but on very close to "tense". Make sure to keep an eye on your heartbeat"

➜ gives you a sense where you are in the 3D space and the mapping to the various states or what could influence outcome

fuzzy logic may have a role in this by considering overlapping ranges of value

a fuzzy value is from 0-1 where within some range, the value scales from 0-1 and outside that range the value is either 0 or 1

for HR, it could be 0 for <60, 1 > 100 and from 0-1 from 60-100. 70 would be 0.25, 80 0.5, 90, 0.75

similarly for h&t, the scale is 0-1 for 37-35

multiplying the scales gives another value in the range of 0-1

there may be an issue if either value is 1, or maybe it doesn't matter if either is 0

but there's also a threshold between 0-1where an issue is recognized where the product of the scaled values exceeds some threshold -- hr is relatively high while h&t is not zero

  prod   hr        h&t
  0.00   95 0.88   38 0.00
  0.00  100 1.00   38 0.00
  0.03   65 0.12   36 0.25
  0.06   70 0.25   36 0.25
  0.09   65 0.12   34 0.75
  0.09   75 0.38   36 0.25
  0.12   65 0.12   32 1.00
  0.12   80 0.50   36 0.25
  0.16   85 0.62   36 0.25
  0.19   70 0.25   34 0.75
  0.19   90 0.75   36 0.25
  0.22   95 0.88   36 0.25
  0.25   70 0.25   32 1.00
  0.25  100 1.00   36 0.25
  0.28   75 0.38   34 0.75
  0.38   75 0.38   32 1.00
  0.38   80 0.50   34 0.75
  0.47   85 0.62   34 0.75
  0.50   80 0.50   32 1.00
  0.56   90 0.75   34 0.75
  0.62   85 0.62   32 1.00
  0.66   95 0.88   34 0.75
  0.75   90 0.75   32 1.00
  0.75  100 1.00   34 0.75
  0.88   95 0.88   32 1.00
  1.00  100 1.00   32 1.00

This is interesting I will try understand this first