home Forums # Technical Support Converting Matlab .fis file to C code

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2276
    Unknown
    Member

    I would like to convert a matlab file with extension .fis, can you explain me how to do this using Fuzylite?

    Thanks

    Mash

    #2277
    Unknown
    Member

    Hi, I’m new from here and frist thank to Juan for fuzzylite it is great job.

    I’m working in a example that could help you but I have a problem to defuzzify the output variable.

    1) I’m ussing fuzzylite 5.0 (C++).
    2) I have a fis file (created with octave), called fuzzy.fis.

    [System]
    Name='Direccion-Controlador'
    Type='mamdani'
    Version=1.0
    NumInputs=2
    NumOutputs=1
    NumRules=6
    AndMethod='min'
    OrMethod='max'
    ImpMethod='min'
    AggMethod='max'
    DefuzzMethod='centroid'
    
    [Input1]
    Name='Error'
    Range=[-64 64]
    NumMFs=3
    MF1='Izquierda':'gaussmf',[35 -64]
    MF2='Centro':'gaussmf',[25 0]
    MF3='Derecha':'gaussmf',[35 64]
    
    [Input2]
    Name='D-Error'
    Range=[-1 1]
    NumMFs=2
    MF1='Negativo':'gaussmf',[1 -1]
    MF2='Positivo':'gaussmf',[1 1]
    
    [Output1]
    Name='Angulo'
    Range=[-45 45]
    NumMFs=5
    MF1='M-izq':'trapmf',[-46 -45 -30 -15]
    MF2='Izq':'trimf',[-30 -15 0]
    MF3='Centro':'trimf',[-15 0 15]
    MF4='Der':'trimf',[0 15 30]
    MF5='M-der':'trapmf',[15 30 45 46]
    
    [Rules]
    1 1, 2 (1) : 1
    1 2, 1 (1) : 1
    2 1, 3 (1) : 1
    2 2, 3 (1) : 1
    3 1, 5 (1) : 1
    3 2, 4 (1) : 1

    3) I want to evaluate some input values.

    #include <fl/Headers.h>
    #include <sstream>
    #include <stdio.h>
    
    int main(int argc, char **argv)
    {
        fl::Engine* engine = fl::FisImporter().fromFile("/home/ruben/fuzzy.fis");
    	
        engine->getInputVariable(0)->setInputValue(15);
        engine->getInputVariable(1)->setInputValue(0.32);
    
        engine->process();
    
        //engine->defuzzify();
    
        fl::OutputVariable* output = engine->getOutputVariable("Angulo");
        
        FL_LOG(output->toString());
    
        FL_LOG(output->fuzzyOutputValue());
        
        FL_LOG(output->fuzzify(output->getOutputValue()));
    
    }

    I have been seaching and trying with different ways but I can’t get the crisp output’s value in float format.

    ejemplo.cpp [19]:0.078/Mizq + 0.078/Izq + 0.794/Centro + 0.375/Der + 0.375/Mder
    ejemplo.cpp [21]:0.000/Mizq + 0.000/Izq + 0.357/Centro + 0.643/Der + 0.000/Mder
    ejemplo.cpp [24]:OutputVariable: Angulo
    enabled: true
    range: -45.000 45.000
    accumulation: Maximum
    defuzzifier: Centroid 200
    default: nan
    lock-previous: false
    lock-range: false
    term: Mizq Trapezoid -46.000 -45.000 -30.000 -15.000
    term: Izq Triangle -30.000 -15.000 0.000
    term: Centro Triangle -15.000 0.000 15.000
    term: Der Triangle 0.000 15.000 30.000
    term: Mder Trapezoid 15.000 30.000 45.000 46.000

    If I include the line “engine->defuzzify();” I get error’s compiler message:

    error: ‘class fl::Engine’ has no member named ‘defuzzify’
    engine->defuzzify();

    when I run the fuzzy system in octave with 15 and 0.32, ( evalfis([15,0.32],fis) ) I get 9.6498.

    Juan, could you help me?

    Thank.

    #2278
    Unknown
    Member

    i find the solution, it was too easy:

    int main(int argc, char **argv)
    {
        fl::Engine* engine = fl::FisImporter().fromFile("/home/ruben/fuzzy.fis");
    	
        engine->getInputVariable(0)->setInputValue(15);
        engine->getInputVariable(1)->setInputValue(0.32);
    
        engine->process();
    
        fl::OutputVariable* output = engine->getOutputVariable("Angulo");
    
        printf("%f\n",output->getOutputValue());
    }

    I get 9.649305 vs 9.6498 (by octave) very good I think.

    #2279

    Hi,

    thank you for your posts and kind words.

    Mash to convert fis to C++ you can do:

    //Import from FIS
    Engine* engine = fl::FisImporter().fromFile("/path/to/yourfile.fis");
    //Export to C++ file
    fl::CppExporter().toFile(engine, "/path/to/yourfile.cpp");
    
    #2280

    Ruben,

    about the difference in results, fuzzylite is more accurate than octave because the resolution of fuzzylite is 200 to compute the centroid, whereas octave uses 100. If you change the centroid defuzzification method in fuzzylite to use 100, the results should be even closer.

    Cheers.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.