Creating bc_rule on the fly

  • krishna dubba

    krishna dubba - 2009-04-27

    I want to create bc_rule on the fly and add it to the rule_base instead of listing them in a krb file. Is there a way to do it? From the file, it takes lot of arguments and I am not able to correspond them to the example bc_rules.

    Say, I want to create the following bc_rule:

        use father_son($father, $son, ())
            family.son_of($son, $father)

    and bc_rule takes the following arguments:

    def __init__(self, name, rule_base, goal_name, bc_fn, plan_fn,
                      goal_arg_patterns, plan_vars, patterns):

    I am not able to correspond the arguments properly to the pieces in the given example bc_rule.

    Can someone help me put.

    Thanks in advance,

    • Bruce Frederiksen

      The bc_rules (.krb files) are compiled by Pyke into Python source (.py) files and then imported.

      The compiler emits code to call the bc_rule.__init__ functions with the proper parameters, which includes the compiled bc_fn and plan_fn.  The goal_arg_patterns, plan_vars, and patterns parameters are tables of patterns referenced within the bc_fn and plan_fns.

      To create your own bc_rules, you would need to write them in .krb syntax and feed them to the Pyke compiler to be translated into Python functions suitable for use within the Pyke runtime system.

      If you are generating the bc_rules prior to calling Pyke, then it should be easy to generate .krb files before you create your engine object.  They will automatically be compiled and included in that engine instance.  When you are done with that engine, you can del(ete) it, create a new set of bc_rules in a new set of .krb files and repeat the process.  The only problem that I can foresee here is that you might see some memory growth if you don't use the same .krb filenames and rule names, but I would expect that you would have to do this thousands of times to notice it.

      If you are wanting to generate bc_rules while Pyke is trying to prove a goal (i.e., while Pyke is running other bc_rules), then you are in for more work.  The easiest way to do this would be to put all of the new rules in a new rule_base (i.e., in their own .krb file) and then manually run the Pyke compiler on that file to compile and import the new rule_base.  You'd then have to activate the rule_base to make the rules available to the already running bc_rules.  This would have a limitation of not being able to deactivate the rule_base during that same proof.  So if you want to create new bc_rules several times during one proof, you would have to think about how to do that.

      In either case, if you are wanting to add rules for the same goals that you already have rules for, you would have to derive the new rule_base from the permanent rule_base.  Then the new rules will be tried before the permanent rules that you already have.  With no way to deactivate rule_bases, it would be difficult to do this more than once during a single proof (unless it was to different permanent rule_bases).

      In either case, Pyke lets you store .krb files in multiple directories, so you could place the permanent .krb files in one directory and the temporary .krb files in another directory to make it easier to keep track of them.


    • krishna dubba

      krishna dubba - 2009-04-29

      Basically I want to write a Inductive Logic Programming system. We will have data (fact base) and have to find rules that satisfies this fact base.

      >> If you are generating the bc_rules prior to calling Pyke ...
      I cannot generate them prior to starting pyke because I generate possible candidate rules based on the performance of previous candidates. So its dynamic.

      This problem is computationally demanding so I want to completely avoid file read/write tasks because the rules generated can be very very high (sometimes tens of thousands :-(.

      I will see if I can change the way rules are used for proving and will let you know.

      Thanks for the quick suggestions.

      - dksr


Log in to post a comment.