Finding Closest Rule Matches

Help
Cerin
2010-09-18
2013-04-25
  • Cerin
    Cerin
    2010-09-18

    This is related to me earlier "Partial Rule Matches" question. What is the most efficient way to find the first K-nearest rules partially matching the current facts? For example, if a rule has 2 patterns, and only one pattern matches the current facts, then that rule would be assigned a fitness of 1/2.

    Ideally, I'd like to do something like:
    e.g.
    (defrule rule-1
        (myfact ?value1)
        (otherfact ?value2)
        (mylastfact ?value3)
        =>
        (assert (sumfact (+ ?value1 ?value2 ?value3)))
    )
    (defrule rule-2
        (myfact ?value1)
        (otherfact ?value2)
        =>
        (assert (sumfact (+ ?value1 ?value2 ?value3)))
    )
    (deffacts startup (myfact 123))
    (reset)
    (run)
    (find-k-nearest-matches 5)
    => (rule-2 0.5 rule-1 0.333333)

    Obviously, I could use the (matches rule-1) function, and parse the results to get the match fitness. However, in order to find the K-nearest, I'd need to do this to every rule in existence, which would be prohibitively expensive. Is there any way to take advantage of Clips internal representation of the rules (via RETE), to do this search more efficiently?

     
  • The point is that CLIPS isn't designed to do this. And the power of CLIPS as a library, is actually in hiding the internal representation of rules. If the creation of rules in my program were automatic, I would split the created rules into simpler ones in order to partially achieve the same result, but it's not your case, I guess.

    If you want to investigate this, I think that the best option is to subscribe to the CLIPS discussion group (CLIPSESG) and see if this can be done in CLIPS without directly accessing the raw objects in CLIPS memory (and thus find a way to implement it in PyCLIPS), or if it's possible to tweak the CLIPS code in order to investigate the dynamics of rule matching in every step of the RETE algorythm - which is far beyond the scope of PyCLIPS.

    F.