fuzzylite / help

A place to ask for help with the FuzzyLite Libraries
https://fuzzylite.com
0 stars 1 forks source link

Problem with unassigned input variables #6

Closed wilsonts01 closed 3 years ago

wilsonts01 commented 3 years ago

Hi Juan, I am attempting to create a fuzzy model with multiple outputs but have run into a problem which it took me quite a while to find a solution to. I was unable to find this issue documented anywhere. My model works fine in the Fuzzylite GUI which by the way I find very nice to use . When I call it from my code which accesses the C++ Fuzzylite library, the call to the output returns a nan. I finally figured out that all input variables in the model, even ones that aren't assigned to the output that is being called seem to have to be assigned a value. I tried many different ways of locking and unlocking inputs and outputs but it seemed to make no difference. I also notice that the linear variables that I am using in my Takagi-Sugeno style output variables have terms fields in them for all variables in the model, whether they are used in that output variable or not. I found this very confusing and when you have a large number of input variables, the gui interface gets very congested.

The following code returns an error (NAN) from the call to GetOutputVal

SetInputValue("distanceToProfitStop", glvTradeData.distanceToProfitStop);

SetInputValue("recentGradient", glvTradeData.scaledRecentGrad);

calcStatus = CalcFuzzyOutput();

if (calcStatus == SUCCESS)
{
       fuzzyResult =GetOutputVal("letProfitsRunAction");
        ........
}  

The following code returns a valid number

SetInputValue("distanceToProfitStop", glvTradeData.distanceToProfitStop);

SetInputValue("recentGradient", glvTradeData.scaledRecentGrad);

SetInputValue("profitGivenBack", 0);  // This value is not used in the "letProfitsRunAction" but is required to prevent error

calcStatus = CalcFuzzyOutput();

if (calcStatus == SUCCESS)
{
     fuzzyResult =GetOutputVal("letProfitsRunAction");
      ........
} 

A cut down version of the fll file that will reproduce the problem is attached in a zip file. Test2.zip

Regards Tim Wilson

jcrada commented 3 years ago

Hi Tim,

thanks for your post and for using the FuzzyLite Libraries.

You mentioned that it all works fine in the QtFuzzyLite app, which is great.

Unfortunately, it seems you may have created some wrapper around fuzzylite, which may have introduced a bug. For example, SetInputValue, CalcFuzzyOutput and GetOutputVal are not fuzzylite functions. You may want to either remove the wrapper and work directly with fuzzylite objects, or review the code of your functions. I find removing the wrapper would be the easiest option.

The QtFuzzyLite app uses the fuzzylite library so any fuzzy engine in the app will behave exactly the same as they would in the library.

I am closing this issue because I believe the bug is in the wrapper functions you created. Feel free to reopen if you remove the wrapper and still get unexpected values.