memoization+persistence

The mis-named “tabling” module (should really be called “memoize”) now allows for persisting memoized calls to a file. See:

http://github.com/cmungall/blipkit/blob/master/packages/blipcore/tabling.pro

(docs up on the pldoc server soon).

To see how this works, consider the transitive closure of the subclass/2 fact, as defined in the ontol_db schema:


subclassT(X,Y):- subclass(X,Y).
subclassT(X,Y):- subclass(X,Z),subclassT(Z,Y).

if you end up using a predicate such as this frequently in one session, you can do this at the start of the session


:- use_module(bio(tabling)).

init :- table_pred(ontol_db:subclassT/2).

This rewrites subclassT/2 behind the scenes. See the code for details.

After loading some subclass/2 facts (e.g. from GO), you then call:


forall(subclassT('GO:0006915',X), writeln(X)). % all ancestors of apoptosis

The first time you call this, the original code is called. The second time you call this, it checks to see if it knows the answer for ‘GO:0006915’ – it does – it then returns the previously calculated results, which have been asserted to memory.

However, this caching is lost when the prolog db is destroyed at the end of the session. Now you can persist this:


persistent_table_pred(ontol_db:subclassT/2, 'my_cache.pl').

The first time this is called, cache.pl is created. All results of subclassT/2 calls are saved there.

After the session the file is retained. In future sessions, if this is called again, the cache is loaded into memory and appended with the results of future calls.

In future, the module may also be extended to be made ‘hookable’, with hooks provided for caching to a relational database.

Post a comment or leave a trackback: Trackback URL.

Comments

  • Samuel Lampa  On June 19, 2010 at 12:38 pm

    I’m wondering about the dots around “tabling” … are there any principal differences between this functionality and the tabling found in typical RDF/RDFS/OWL reasoners?

    • blipkit  On June 19, 2010 at 11:49 pm

      Hi Samuel

      OWL reasoners typically use tableaux methods, which AFAIK isn’t really related to tabling other than terminological / conceptual metaphor coincidence. A more accurate comparison is between prolog/deductive database systems such as Yap and XSB – these implement true tabling whereas the blip module really implements memoization.

Leave a reply to blipkit Cancel reply