MOZI-AI / annotation-scheme

Human Gene annotation service backend
GNU General Public License v3.0
3 stars 4 forks source link

memoize-function-call doesn't work as expected #193

Closed Habush closed 4 years ago

Habush commented 4 years ago

Hi @linas, I am adding new functions to support STRING and I'm trying to use the caching utitlity function you added, i.e memoize-function-call. However, instead of the returning a result, it is returning a procedure that accepts a single atom. Here is the code I wrote

;;the function to be cached
(define (do-find-ggi input-set)
   (append-map (lambda (interaction)
      (run-query (Bind (EvaluationLink 
            (PredicateNode (cog-name interaction))
            (SetLink
               (gar input-set)
               (Variable "$x")
            )
         )
         (EvaluationLink 
            (PredicateNode (cog-name interaction))
            (SetLink 
               (gar input-set)
               (Variable "$x")
            ))))
   ) (cog-outgoing-set (gdr input-set)))

)

(define-public (cache-find-ggi s-atom)
   (memoize-function-call do-find-ggi)
)

Now, calling (cache-find-ggi (Set (Gene "A") (List (Concept "B")))) returns a procedure instead of the result of do-find-ggi. What is missing here?

linas commented 4 years ago

Hi, OK, for starters, consult the documentation:

,d make-afunc-cache

or

,describe make-afunc-cache

which explains that, given a function, returns a caching version of that function. (But it works only for functions that can take one Atom as the argument) It is the non-thread-safe variant of memoize-function-call function .. which also has documentation.

The fix, for you is this:

(define-public cache-find-ggi  (memoize-function-call do-find-ggi))

So ... now cache-find-ggi is a function . that takes one atom as argument, and returns the same thing that do-find-ggi would have returned.

linas commented 4 years ago

BTW, are you using cytopscape for visualization, or gephi? I've started writing a export-to-gml function, so that I can use these to visualize some of the graphs... but it occurs to me that it would be nice to have a generic atomspace-to-js plugin that could work with cytoscape ...

Habush commented 4 years ago

Thanks @linas! It works now.

BTW, are you using cytopscape for visualization, or gephi?

We are using cytoscape for visualization. But the issue with cytoscape is its performance over large graphs, even those with 1000 nodes. And most of the results returned from the service have 1000+ nodes and 2000+ edges and cytoscape has been performing poorly. I recently discovered ngraph and it is crazy fast! Check out the benchmark video on the README. It is also has path search algorithms and clustering algorithms (which we are implementing manually in cytoscape). The downside maybe it requires you to do a bit of extra groundwork (like rendering the graph yourself) but tbf that isn't much compared to the performance gain.

EDIT:

It also supports gephi and DOT file serialization