Old PLN Forward Chainer

From OpenCog

This describes the PLN forward chainer, as it worked in 2009.

A Rough Algorithmic Description

  1. Insert one or more user-given atoms to seed stack and optionally define a user-given target atom.
  2. Take the top-most atom from the seed stack and define it as seed atom. Clear the set_of_invalid_rules.
  3. Select random Rule R not in set_of_invalid_rules. If no such R exists, then pop the top-most atom from the seed stack and goto #2.
  4. Try to bind seed atom to one of the arg slots of R so that it satisfies the corresponding filter. If fails, set_of_invalid_rules.push(R) and goto #3.
  5. For each remaining arg slot of R, find an atom A with TV.confidence>min_confidence that satisfies the filter, where the probability of A being chosen is pS(A) if A is in the seed stack, and pN(A) if A is not in the seed stack but is in the atom table. Often we choose the functions so that pS(x1) > pN(x2) whenever x1 and x2 are similar in properties. If not all slots can be filled, set_of_invalid_rules.push(R) and goto #3.
  6. If the result of R.compute(with the said args) has confidence < min_confidence, then goto #5. Else, push it into the seed stack. If a target atom template exists and the result satisfies the target atom template or any other optional halt criteria are met, then halt. Else, goto #2.

Code level description

A simple code description of the forward chainer:

void fwtest()
{
    Handle seed = getAtomSpace()->addNode(CONCEPT_NODE,
        "test", new FirstPTLTruthValue(0.0f, 0.0f));
    DefaultVariableRuleProvider rp();

    Rule *r=rp[ rand()%rp.size() ];
    TV* tv=NULL;

    do
    {
        Handle nextH;
        do
        {
            nextH = getAtomSpace()->getRandomHandle();
            vector<Vertex> args;
            args.push_back(seed);
            args.push_back(nextH);
        }
        while (!r->validate(args));
        tv = r->compute(args);
    }
    while (!tv || tv->getConfidence() < MIN_CONF);

}

compute() sometimes returns NULL ifthe args were somehow false. So you can use both pre-filtering by validate() and post-filtering by NULL comparison to determine if the computation of the new TV was succesful or if we need to retry. Refer the algorithm description for more accurate way of doing these things.

Notes

  • Rule Input filters should be updated for many of the Rules.
  • Reuse decision formula for what node to use from PLN back inference?
    • 1 - epsilon
    • SOFTMAX (e^-pt)
  • Reuse finding rule inputs - currently random search. Weight by whether in seed pool and importance.
  • Use of Inference trails.