opencog / asmoses

MOSES Machine Learning: Meta-Optimizing Semantic Evolutionary Search for the AtomSpace (https://github.com/opencog/atomspace)

Home Page:https://wiki.opencog.org/w/Meta-Optimizing_Semantic_Evolutionary_Search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

implement an interpreter for atomese programs

Bitseat opened this issue · comments

The task here is to implement an atomese interpreter program to execute such programs (Plus (Schema "i1") (Schema "i2")) (times (Schema "i1") (Schema "i2")) etc and represent the result.

given an input-table of

(Similarity (stv 1 1)
  (List (Schema "o") (Schema "i1") (Schema "i2"))
  (Set
    (List (Node "r1") (List (Number 1) (Number 0) (Number 1)))
    (List (Node "r2") (List (Number 1) (Number 1) (Number 0)))
    (List (Node "r3") (List (Number 0) (Number 0) (Number 0)))))

present the result of

(cog-execute! (Plus "Schema-i1" "Schema-i2")))

in the format

(Set
  (List (Node "r1") (Number 1))
  (List (Node "r2") (Number 1))
  (List (Node "r3") (Number 0)))

Proposed approach

define a plus/times function which takes two arguments (two specified schemas)

(define (plus x y)
  (Put
    (Variable "$R")
    (List
    	;gives the row names in the result set
      	(ExecutionOutput
        	(GroundedSchemaNode "scm:row")
        	(List (Variable "$R"))
      	)
      	(Plus
      		(ExecutionOutputLink
      			(GroundedSchemaNode (string-append "scm:" x))
      			(List (Variable "$R"))
          	)
          	(ExecutionOutputLink
          		(GroundedSchemaNode  (string-append "scm:" y))
          		(List (Variable "$R"))
          	)
      	)
    )
  input-table))

A program that auto generates a program for each feature variables.

(define (featureVariables problemData)
    ....)

The above program is expected to generate programs like

`(define (schema-1 atom)
	...)

(define (schema-2 atom)
	...)

(define (schema-3 atom)
	...)`

which return the specified schema value for each row.
an attempt has been made by defining a function for the number of featurevariables. Both approaches don't seem to be efficient though.

problems with the proposed approach
The program can handle any two schemas but not three or four. For example
(cog-execute! (Plus "Schema-i1" "Schema-i2" "Schema-i3")))
can not be handled.

Questions
Is there any way to define a function with unknown number of arguments?
Are programs like (cog-execute! (Plus "Schema-i1" (Times "Schema-i2" "Schema-i3"))) are expected to work?

@Bitseat I appreciate you taking the steps to writing that issue, however I think we'll begin with a different road, that I'll explain below. But first let me make a few corrections

  1. I suppose by (cog-execute! (Plus "Schema-i1" "Schema-i2"))) you mean (cog-execute! (Plus (Schema "i1" (Schema "i2")))), right?
  2. To handle multiple arguments you'd use (define (plus . args) ...

So now with my simpler suggestion:

Directly write the interpreter in C++, define in a recursive manner, in the spirit of the Combo' boolean_interpreter and such, or Instantiator::execute() (but much simpler since you don't need to support the whole Atomese vocabulary, say only Plus, Times, And, Or, Not for starter).

Instead of using the representation

(Set
  (List (Node "r1") (Number 1))
  (List (Node "r2") (Number 1))
  (List (Node "r3") (Number 0)))

use directly the list of output values using the proto atom FloatValue, as suggested in #17 .

I know that this somewhat contradictory to what I had suggested before, and it is because it ignores the reasoning aspect. However I think it's a better road to take. First it will give us a very efficient Atomese interpreter (possibly even more efficient than Combo's if subprogram memoization is enabled), and reasoning capabilities can be added later on (using the kind of representation I have initially suggested) when the port has reached the desired level of maturity.

I was particularly concerned about the reasoning aspect because I wanted to be sure the decisions we take today are compatible with the long term vision, I see things more clearly now thus the change of plan for the interpreter.

Thank you Nil. @kasimebrahim I hope this will give you some insight into the code you're writing.