home Forums # Technical Support Equivalent of fismain.c from MATLAB distribution

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #868
    Unknown
    Member

    Dear Juan,

    Would you mind describing in a few points steps necessary to build a console application reading values of inputs and returning the output values for the inputs? It is not

    fuzzylite -i model.fis -of fld -max 1024

    because I don’t want 1024 values covering the universe of all input values. Instead I want to know e.g. the tip for service 3 and food 7. The MATLAB toolkit includes two files: fis.h and fismain.c to do exactly this task. I guess with fuzzylite I need to export the model to a C++ file and build it with some other files (which ones? all from the fl directory?). The C++ file has the main function, but only to create necessary objects. I suppose there is a function to call the engine with defined input values – could you point me to the place it is? What is its syntax?

    Best regards and thank you,

    Witold

    #871

    Dear Witold,

    Another person recently requested the same feature in the forums. I will definitely incorporate such a simple function in the next version. I had no idea about it because I have rarely used Matlab for fuzzy logic control, or anything else for that matter.

    Anyway, what you require is not too hard and you do not need to build fuzzylite from source to achieve so.

    Roughly, in SomeFile.cpp:

    
    #include <fl/Headers.h>
    
    int main(int argc, char** argv){
       std::string fisEngine = readFromSomeFile("xxx.fis");
       std::vector<std::vector<fl::scalar> > inputs = readFromSomeFileAndParse("xxx.dat");
       fl::Engine* engine = FisImporter().fromString(fisEngine);
       for (std::size_t i = 0 ; i < inputs.size(); ++i){
           for (std::size_t x = 0 ; x < inputs.at(i).size(); ++x){
                engine->getInputVariable(x)->setInputValue(inputs.at(i).at(x));
           }
           engine->process();
           for (int i = 0 ; i < engine->numberOfOutputVariables(); ++i){
              fl::scalar output = engine->getOutputVariable(i)->defuzzify(); 
              writeToSomeFile(output + " ");
           }
           writeToSomeFile(output + "\n");
    }
    

    You have to implement yourself the read and write functions and fix some details.

    g++ SomeFile.cpp -I/path/to/fuzzylite/fuzzylite -L/path/to/fuzzylite/fuzzylite/bin -lfuzzylite

    #876
    Unknown
    Member

    Dear Juan,

    I believe what you have written is the solution in this case.

    To make you sure about MATLAB’s fismain, let me explain. If you compile fismain.c (including fis.h) you get a ready to use controller. You have to call fismain with two parameters: the name of the fis file and the name of a txt file with input data – one line is a single set of input data. The program sends lines of outputs to stdout. The advantage of this is that you can have your first controller running on your preferable hardware immediately. Programmers dealing with controllers don’t pay so much attention to graphics and nice “feel” of the software, but rather want to have the source code as short, easy and non-extravant as possible. Fismain fulfills this desire.

    Best regards,

    Witold

    #877

    Dear Witold,

    thank you for your information. I have finished its implementation today and it is looking pretty neat. The usage is:

    fuzzylite -i engine.fll -d inputs.fld -o outputs.fld

    The output is:

    #@Engine: name; @InputVariable: name; ... @OutputVariable: name;
    inputValue1 inputValue2 ... outputValue1 outputValue2
    .
    .
    .
    

    I was unsure whether to only export the values of the output variables, but I guess it does not make sense to only export the output values without their respective input values. Could you confirm the output I mention is satisfactory?

    I expect to release version 4.1 in the upcoming weeks, and this feature will be included.

    Cheers,

    Juan.

    #911
    Unknown
    Member

    Dear Juan,

    It’s nice you have reacted so fast. The proposed solution is the step in right direction, however, I would propose the following changes:

    1. Don’t duplicate the input values. The application which generates the query knows what it is asking for, so the input values in the output file will be discarded. Only additional hassle.

    2. Instead of the output file use the standard output. If the user wants to have a file he will use the stream redirection fuzzylite -i engine.fll -d inputs.fld > output.fld. It is how the MATLAB stuff works. However, I don’t know if it works also under Windows, but if it doesn’t then you can have the -o option and the standard output, if no file was defined. Obviously, to the standard output you should not send the header with the description.

    The decision is yours, I can use any setup.

    Best regards,

    Witold

    #918

    Dear Witold,

    thank you for your review, the example, and your feedback on the output that you expect. I greatly appreciate the time you took to provide very useful feedback. I will fix the current implementation to show the output that you want. I expect to release v4.1 early February.

    Cheers,

    Juan.

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