singnet / opencog

A framework for integrated Artificial Intelligence & Artificial General Intelligence (AGI)
http://wiki.opencog.org/w/Development
Other
14 stars 3 forks source link

Remove useless warnings from URE pattern miner and optimize count calculation #11

Closed ngeiswei closed 5 years ago

ngeiswei commented 6 years ago

Issue description

The URE pattern miner easily produces warnings such as

[WARN] No type restrictions! Your code has a bug in it!
[WARN] Offending variable=(VariableNode "$X-1") ; [7925133672396084461][4036]

[WARN] Offending clauses=(VariableNode "$X-1") ; [7925133672396084461][4036]

That happens when the pattern has an unconstrained variable like Variable "$X-1" in

      (LambdaLink
        (VariableList
          (VariableNode "$PM-7adfc8ae") ; [6619014796412716190][1]
          (VariableNode "$PM-648d8b51") ; [3929278926326560509][1]
          (VariableNode "$X-1") ; [7925133672396084461][1]
        ) ; [14380031784774046701][1]
        (AndLink
          (VariableNode "$X-1") ; [7925133672396084461][1]
          (InheritanceLink
            (VariableNode "$PM-7adfc8ae") ; [6619014796412716190][1]
            (VariableNode "$PM-648d8b51") ; [3929278926326560509][1]
          ) ; [12555164482694371291][1]
        ) ; [17555328375829165888][1]
      ) ; [11446648929752136218][1]

Not only that but such a count is trivially equal to the size of the texts. The URE pattern miner code should be inspected to clean and optimize these inefficiencies. It is expected that the fix would occur in support in miner-utils.scm https://github.com/singnet/opencog/blob/master/opencog/learning/miner/miner-utils.scm#L183

How to reproduce

Run MinerUTest

cd <OPENCOG_ROOT>/<BUILD_DIR>/tests/learning/miner/; make -j4 MinerUTest && ./MinerUTest

in particular MinerUTest::test_2conjuncts_3(), and more specifically the URE pattern miner run, should produce these warnings.

ngeiswei commented 6 years ago

I've labeled it as good first issue because it is fairly well defined and self-contained, but it does require some amount of understanding of the pattern matcher and pattern miner to be addressed, so it is a hard good first issue.

ngeiswei commented 6 years ago

A bit more details: it is expected that the fix will be to generalize the first conditional of support

  (if (equal? pat (top))

so that not only the top pattern but any one containing one or more clauses as single variables would return the cardinality of texts.

ngeiswei commented 6 years ago

Perhaps an even better solution would be to create some scheme binding for Miner::freq https://github.com/singnet/opencog/blob/master/opencog/learning/miner/Miner.h#L247 (which would require that a version without any heuristic be made public and static), and have support call it.

ngeiswei commented 5 years ago

Fix