home Forums # Technical Support Nan in the output variable

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #2334
    Unknown
    Member

    Hi, I’m working on a fuzzy control system with fuzzylite. I design the system with octave and export it to a .fis file. Then in the C++ code I load it with fl :: FisImporter (). FromFile (…) and work correctly.
    But after making some changes to the fis file, the fuzzy system sometimes returns nan.
    What could be the problem ?
    These are the codes I am using:

    C++ code:

    fl::Engine* engine = fl::FisImporter().fromFile(“/home/ruben/ros_ws/src/greenbot/src/fuzzy.fis”)

    engine->getInputVariable(0)->setInputValue(Error);
    engine->getInputVariable(1)->setInputValue(D_error);

    engine->process();

    fl::OutputVariable* output = engine->getOutputVariable(“Angulo”);

    Octave code (which generates the fis file):

    clc
    clear all
    close all
    pkg load fuzzy-logic-toolkit

    fis = newfis(‘Direccion-Controlador’);

    % Variables de entrada
    fis = addvar(fis, ‘input’, ‘Error’, [-64,64]);
    fis = addmf(fis, ‘input’, 1, ‘Izquierda’, ‘gaussmf’, [35.2 -64]);
    fis = addmf(fis, ‘input’, 1, ‘Centro’, ‘gaussmf’, [15.2 0]);
    fis = addmf(fis, ‘input’, 1, ‘Derecha’, ‘gaussmf’, [35.2 64]);

    fis = addvar(fis, ‘input’,’D-Error’,[-50,50]);
    fis = addmf(fis, ‘input’, 2, ‘Negativo’, ‘gaussmf’, [30 -50]);
    fis = addmf(fis, ‘input’, 2, ‘Centro’, ‘gaussmf’, [10 0]);
    fis = addmf(fis, ‘input’, 2, ‘Positivo’, ‘gaussmf’, [30 50]);

    % Variables de salida
    fis = addvar(fis, ‘output’,’Angulo’,[-45,45]);
    fis = addmf(fis, ‘output’,1,’M-izq’,’trapmf’,[-46 -45 -10 -5]);
    fis = addmf(fis, ‘output’,1,’Izq’,’trimf’,[-10 -5 0]);
    fis = addmf(fis, ‘output’,1,’Centro’,’trimf’,[-2 0 2]);
    fis = addmf(fis, ‘output’,1,’Der’,’trimf’,[0 5 10]);
    fis = addmf(fis, ‘output’,1,’M-der’,’trapmf’,[5 10 45 46]);

    % Matriz de Reglas
    %Error Derivada Angulo Peso Conector
    % E D A P C
    reglas = [1 1 5 1 1;
    1 2 4 1 1;
    1 3 4 1 1;
    2 1 4 1 1;
    2 2 3 1 1;
    2 3 2 1 1;
    3 1 2 1 1;
    3 2 2 1 1;
    3 3 1 1 1];

    fis file:
    [System]
    Name=’Direccion-Controlador’
    Type=’mamdani’
    Version=1.0
    NumInputs=2
    NumOutputs=1
    NumRules=9
    AndMethod=’min’
    OrMethod=’max’
    ImpMethod=’min’
    AggMethod=’max’
    DefuzzMethod=’centroid’

    [Input1]
    Name=’Error’
    Range=[-64 64]
    NumMFs=3
    MF1=’Izquierda’:’gaussmf’,[35.2 -64]
    MF2=’Centro’:’gaussmf’,[15.2 0]
    MF3=’Derecha’:’gaussmf’,[35.2 64]

    [Input2]
    Name=’D-Error’
    Range=[-50 50]
    NumMFs=3
    MF1=’Negativo’:’gaussmf’,[30 -50]
    MF2=’Centro’:’gaussmf’,[10 0]
    MF3=’Positivo’:’gaussmf’,[30 50]

    [Output1]
    Name=’Angulo’
    Range=[-45 45]
    NumMFs=5
    MF1=’M-izq’:’trapmf’,[-46 -45 -10 -5]
    MF2=’Izq’:’trimf’,[-10 -5 0]
    MF3=’Centro’:’trimf’,[-2 0 2]
    MF4=’Der’:’trimf’,[0 5 10]
    MF5=’M-der’:’trapmf’,[5 10 45 46]

    [Rules]
    1 1, 5 (1) : 1
    1 2, 4 (1) : 1
    1 3, 4 (1) : 1
    2 1, 4 (1) : 1
    2 2, 3 (1) : 1
    2 3, 2 (1) : 1
    3 1, 2 (1) : 1
    3 2, 2 (1) : 1
    3 3, 1 (1) : 1

    thank you very much

    #2335

    Hi,

    Thanks for your post.

    Your case is a perfect example for which QtFuzzyLite will help you determine what is wrong in your engine.

    Please, download QtFuzzyLite, import your file, and you will solve your problem, whatever it is. You can either buy a license of QtFuzzyLite or use the Community version for free.

    If your problem persists, please post again using the FLL code for your engine, which you can extract using FllExporter().toString(engine);

    Cheers.

    #2336
    Unknown
    Member

    I find the problem. By distracted I was using another fis file and the system returned nan because the input variable was outside the defined range. Indeed, qtfuzzylite helped me to find this problem and better tune the fuzzy system.

    I take this opportunity to congratulate you for the enormous work you are doing.

    Thank you.

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