opencog / moses

MOSES Machine Learning: Meta-Optimizing Semantic Evolutionary Search. See also AS-MOSES https://github.com/opencog/asmoses but kept to guaranty backward compatibility.
https://wiki.opencog.org/w/Meta-Optimizing_Semantic_Evolutionary_Search
Other
127 stars 83 forks source link

Add a few operators for Python output #48

Closed ntoxeg closed 7 years ago

ntoxeg commented 7 years ago

Alleviates #47 to a satisfactory extent. Not all operators got implemented.

ntoxeg commented 7 years ago

Welp, some tests fail because when using Python bindings output programs get clipped for some reason.

linas commented 7 years ago

Its CythonMoses that is failing. Looking at the output, I see the below printed. Looks to me like maybe there is some fixed buffer length that is truncating the output, or that maybe the output needs to be flushed and closed. Maybe some explicit close() is needed ??


test_moses.TestMOSES.test_run_xor_python ... ERROR

======================================================================
ERROR: test_moses.TestMOSES.test_run_majority_python
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/moses/tests/cython/moses/test_moses.py", line 43, in test_run_majority_python
    assert not model([0, 1, 0, 1, 0])
  File "pymoses.pyx", line 82, in opencog.pymoses.MosesCandidate.eval (/moses/build/moses/cython/opencog/pymoses.cpp:1426)
  File "<string>", line 10
    def pdiv(a
             ^
SyntaxError: invalid syntax

======================================================================
ERROR: test_moses.TestMOSES.test_run_xor_python
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/moses/tests/cython/moses/test_moses.py", line 21, in test_run_xor_python
    assert not model([0, 0])
  File "pymoses.pyx", line 82, in opencog.pymoses.MosesCandidate.eval (/moses/build/moses/cython/opencog/pymoses.cpp:1426)
  File "<string>", line 10
    def pdiv(a
             ^
SyntaxError: invalid syntax

----------------------------------------------------------------------
Ran 5 tests in 7.280s

FAILED (errors=2)
In run_majority_python, the program is:
#!/usr/bin/env python

#score: 0
import operator as op
from functools import reduce
from math import log, exp, sin
def l0(i): return 0 < i
def adds(*args): return sum(args)
def muls(*args): return reduce(op.mul, args)
def pdiv(a
In run_xor_combo, the program is:and(or(!$1 !$2) or($1 $2)) 
In run_xor_python, the program is:
#!/usr/bin/env python

#score: 0
import operator as op
from functools import reduce
from math import log, exp, sin
def l0(i): return 0 < i
def adds(*args): return sum(args)
def muls(*args): return reduce(op.mul, args)
def pdiv(a
<end of output>
Test time =   7.44 sec
----------------------------------------------------------
Test Failed.
"CythonMoses" end time: May 03 20:07 UTC
"CythonMoses" time elapsed: 00:00:07
----------------------------------------------------------

End testing: May 03 20:07 UTC
ntoxeg commented 7 years ago

There is this fragment of code in pymoses.pyx:

# @todo Fix moses/comboreduct/combo/iostream_combo.h
# (ostream_combo_it) to remove the unneeded trailing comma
# that is inserted by the Python formatter
if ',' in program:
    program = program.rpartition(',')[0]

Guess what, that boilerplate pdiv function takes two arguments... which are separated by a comma. I'll see what I can do about it.

ntoxeg commented 7 years ago

It turns out iostream_combo.h code is working fine - the workaround from pymoses.pyx is not needed. The tests should pass now.

ntoxeg commented 7 years ago

It also seems that your code in iostream_combo.h can handle infix operators with more than two arguments to apply them to. I could reduce the boilerplate in Python output with that knowledge but I don't know if it is really worth it.

linas commented 7 years ago

looks good to me. Whether something is "worth it" depends on how much it annoys you. :-)