home Forums # Technical Support Pipe output of one fuzzy model into another fuzzy model using QTFuzzylite

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6219
    Avatarsenabhishek
    Participant

    Hi there,

    We have 2 Fuzzy models where model 1’s output will be fed into model 2.

    The question I have is:
    – How can we pipe in the output of model 1 into model 2 using QTFuzzyLite?
    – Can we pipe an output variable as an input variable to another rule block in the same Fuzzy model (also via QTFuzzyLite)?

    Would be very helpful if you could get back with some more details on how to do this.

    Best,
    Abhishek.

    #6220

    Hi,

    thanks for your questions.

    You can merge the two models into a single engine (just append the contents of one FLL into the other without the Engine tag). This merge assumes you have different names for Variables and RuleBlocks.

    Once merged, you could add in your relevant rule block a rule using the output variable in the antecedent.

    Check this example: https://github.com/fuzzylite/fuzzylite/blob/release/examples/mamdani/SimpleDimmerChained.fll

    Just make sure that the order of rules execution updates the output variable (to be used as input) before the rule.

    Also, have in mind that this approach is not exactly piping. Piping to me means that you defuzzify your output and use it as input in an input variable, thereby losing information in the process. The approach I am suggesting uses the fuzzy output directly, without defuzzification, thereby not losing information in the process.

    If this approach does not work for you, I am afraid that piping as you want it is not currently possible in QtFuzzyLite, but would be pretty easy to set up programmatically using the libraries.

    Cheers.

    #6221
    Avatarsenabhishek
    Participant

    Hi Juan,

    Thanks very much for getting back. I’ve tried your approach and am now testing it out by following the example in the SimpleDimmerChained solution.

    A follow-up question: One of the inputs to the fuzzy model is a machine-learned model for activity recognition (stationary, walking, running etc.). Now, if I simply take the highest confidence value from the output of the machine-learned model (e.g. stationary with 0.75) and pass it in as the input to the fuzzy model, I obviously lose a significant degree of precision where the other activity confidence degrees (e.g. walking 0.2, running 0.05) are not represented in the input variable to the fuzzy model.

    How can I achieve this in fuzzylite i.e. how can I pass in a membership function (e.g. stationary 0.75, walking 0.2, running 0.05) as an input variable? What membership function would accurately represent this type of an input?

    Best,
    Abhishek.

    #6222

    Interesting question.

    I think the easiest is to create an output variable that you construct and use as input variable. For example, create output variable output_state, your rules in the form “if output_state is walking then …”.

    The trick is that you are going to manipulate the fuzzy value of output_state. Every time that you get your set of three values, you are going to do something like:

    
    output_state = engine.output_variable("output_state")
    
    walking = output_state.terms[0]
    running = output_state.terms[1]
    stationary = output_state.terms[2]
    
    output_state.clear()
    
    implication = engine.rule_block[0].implication
    output_state.fuzzy.terms.append(Activated(walking, walking_value, implication))
    output_state.fuzzy.terms.append(Activated(running, running_value, implication))
    output_state.fuzzy.terms.append(Activated(stationary, stationary_value, implication))
    

    (The code above is Python, but should give you an idea to do so in C++/Java)

    You will also need to process the engine manually because in engine.process() all the output variables are cleared, and you do not want this output_state cleared.

    #6230
    Avatarsenabhishek
    Participant

    Hi Juan,

    Thanks for getting back.

    If I understand this correctly:
    – Everytime an activity vector arrives (walking 0.75, running 0.2, stationary, 0.05), I don’t understand how output_state gets populated:
    `output_state = engine.output_variable(“output_state”)
    – Is there anything that needs to be created in the Fuzzy Model (using QTFuzzyLite) or will this be done programmatically at runtime? How does output_state get populated?
    – When you say the engine needs to be manually processed, do you mean that specific rule blocks need to be activated that are connected to this activity state, the output gets processed and defuzzified, and then the rest of the blocks need to be activated and defuzzified?
    – What is the point of the ‘implication’ in your comment? Is this setting it up for the subsequent processing of rule blocks that are dependent on the activity state?

    Or am I missing something?

    Abhishek.

    #6234

    Hi,

    sorry for the delay.

    What I mentioned is meant to be done programmatically in the fuzzylite libraries for Java, C++ or Python, not within QtFuzzyLite.

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