Giter Club home page Giter Club logo

Comments (7)

grizonic avatar grizonic commented on August 11, 2024

I think I'm running into similar issues with a different example - the greet example of the docs. I noticed that if I explicitly set priority via salience, then there are no issues. If not, I run into issues on both examples.

In the greet example I managed to find that activations are being wrongly removed from the list in the _update_agenda method in strategies.py, because the keys seem to be the same for different activations (when salience not specified!).

Basically, I see that the location question is popped from the list to be fired and then _update_agenda removes the name question from the list, mistakenly. Also, I didn't manage to understand why it is popping activations and then deleting them in the _update_agenda. I'm sure there's a reason for that, but I can't see it.

Commenting out the del statement in _update_agenda makes the greet example work fine as well. Let me know if you think that they are different issues. I can create another one. I'll leave the greet code here, as it might be helpful:

from experta import *

class Greetings(KnowledgeEngine):
    @DefFacts()
    def _initial_action(self):
        yield Fact(action="greet")

    @Rule(Fact(action='greet'),
          NOT(Fact(name=W())))
    def ask_name(self):
        self.declare(Fact(name=input("What's your name? ")))

    @Rule(Fact(action='greet'))
    def ask_test(self):
        self.declare(Fact(test=input("What's your test? ")))

    @Rule(Fact(action='greet'),
          NOT(Fact(location=W())))
    def ask_location(self):
        self.declare(Fact(location=input("Where are you? ")))

    @Rule(Fact(action='greet'),
          Fact(name=MATCH.name),
          Fact(location=MATCH.location))
    def greet(self, name, location):
        print("Hi %s! How is the weather in %s?" % (name, location))

engine = Greetings()
engine.reset()  # Prepare the engine for the execution.
engine.run()  # Run it!

from experta.

grizonic avatar grizonic commented on August 11, 2024

I just installed directly from github now (was running 1.9.2 installed with pip) and the bug @orenwangtencent reported has been fixed. I can't reproduce it anymore and I see that the activations' keys are now different :) I will check the greetings example again and if I find something I'll report on a different issue.

from experta.

loseraitc avatar loseraitc commented on August 11, 2024

Oh thank u a lot, @grizonic . I tried to install from the develop branch of the GitHub, yet still no luck. But assigning a randint for salience definitely do the trick. I am trying to figure out the activation keys now!

from experta.

nilp0inter avatar nilp0inter commented on August 11, 2024

HI! Sorry for the delay and thank you for reporting this.

I am working on it and will be fix soon.

from experta.

nilp0inter avatar nilp0inter commented on August 11, 2024

I've just published v1.9.4, the random behavior should be fixed now. Please check if this works for you.

On the other hand, the new tests that I wrote to fix this issue arose two new issues #12 and #13.

#12 in particular causes that the order of execution between runs can be undefined when the strategy doesn't have strict rules. This will be the case for example with your code if you remove the declare statement. If you do so both rules will match but with the current implementation the order in which red_light and yellow_light get run can be different between different executions of the Python interpreter.

from experta.

loseraitc avatar loseraitc commented on August 11, 2024

Yeah it worked normally now, both the example above and my own code. @nilp0inter thx very much! BTW Really Good library, to learn from and integrate into projects.

from experta.

nilp0inter avatar nilp0inter commented on August 11, 2024

Glad to hear that! Thank you both @orenwangtencent and @grizonic .

from experta.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.