ShuhuaGao / geppy

A framework for gene expression programming (an evolutionary algorithm) in Python
https://geppy.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
208 stars 76 forks source link

how to perform multi dimensioned GEP #10

Closed waynezw0618 closed 5 years ago

waynezw0618 commented 5 years ago

Hello I’d like to use geppy to calculate a formula where the output is a tensor and the inputs are several tensors and scalars, is there any tutorial to show how to do that?

Yours Sincerely

ShuhuaGao commented 5 years ago

I haven't try that yet. However, I think it can be done similarly once you have set up the proper primitive set (terminals + functions). Just be sure that your function node can operate normally on all the possible inputs and intermediate values.

For example, if your input is a tensor, then the ADD function should also be tensor version, that can accept two tensors, or one tensor plus one scalar. I guess general libraries like PyTorch has support for that already. If not, you need to implement your own ADD function by checking the actual parameter types internally.

waynezw0618 commented 5 years ago

Hi Thanks for replying. where I can find the list of the function? I'd like to know if there is dot, cross, these operator for the tensor?

waynezw0618 commented 5 years ago

Besides, I meet the error message during the installation. it says : .... deap/tools/_hypervolume/hv.cpp:24:10: fatal error: 'cstdlib' file not found

include

     ^~~~~~~~~

... I am trying to install geppy in my MacBook Pro with python2.7

bolzzzz commented 5 years ago

Hi Thanks for replying. where I can find the list of the function? I'd like to know if there is dot, cross, these operator for the tensor?

Hi, I think you can find these in PyTorch's document. For example: dot operation: https://pytorch.org/docs/stable/torch.html#torch.dot, cross: https://pytorch.org/docs/stable/torch.html#torch.cross

bolzzzz commented 5 years ago

Besides, I meet the error message during the installation. it says : .... deap/tools/_hypervolume/hv.cpp:24:10: fatal error: 'cstdlib' file not found

include

^~~~~ ... I am trying to install geppy in my MacBook Pro with python2.7

looks like it's about deap. You may try pip install deap to manually install deap first

ShuhuaGao commented 5 years ago

Thanks for your help @bolz213 .

@waynezw0618 : I am afraid you have misunderstood the function concept in geppy. This package geppy only defines a function wrapper essentially, which requires a true function that can do the work and the number of arguments needed by this function. That is, you can provide it with any function you like. Please check the examples for some inspiration.

waynezw0618 commented 5 years ago

@bolz213 @ShuhuaGao thanks for both I did not notice that I have to install deep manually before geppy(as I suppose it will automatically install the dependency). but now I manually reinstall deap. and later rebuild and install geppy. still have problem to use geppy properly. here is the error message:

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^ SyntaxError: invalid syntax

bolzzzz commented 5 years ago

you don't have to manually install deap, I just offered a possible solution. Now the problem is on geppy I think.


From: Wei Zhang notifications@github.com Sent: Wednesday, April 10, 2019 8:48:10 PM To: ShuhuaGao/geppy Cc: bolz213; Mention Subject: Re: [ShuhuaGao/geppy] how to perform multi dimensioned GEP (#10)

@bolz213https://github.com/bolz213 @ShuhuaGaohttps://github.com/ShuhuaGao thanks for both I did not notice that I have to install deep manually before geppy(as I suppose it will automatically install the dependency). but now I manually reinstall deap. and later rebuild and install geppy. still have problem to use geppy properly. here is the error message:

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^ SyntaxError: invalid syntax

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/ShuhuaGao/geppy/issues/10#issuecomment-481640503, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AJHycnZ5-obx4qmXYJFPkUU91sOBpX8Oks5vfcFqgaJpZM4cl0fs.

bolzzzz commented 5 years ago

@bolz213 @ShuhuaGao thanks for both I did not notice that I have to install deep manually before geppy(as I suppose it will automatically install the dependency). but now I manually reinstall deap. and later rebuild and install geppy. still have problem to use geppy properly. here is the error message:

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^ SyntaxError: invalid syntax

Hi the author of geppy documents that it requires python3.5 and afterwards. See the "Requirements" in the readme

waynezw0618 commented 5 years ago

@bolz213 thanks, that works now!

waynezw0618 commented 5 years ago

@ShuhuaGao @bolz213 Sorry again seems my installation is not stable. I have installed geppy on MacBook with Mac OS 14.0 I have installed python3.7 manually with numpy-1.16.2,graphviz-0.10.1,sympy-1.4. as mentioned before, geppy works after installation.
and now the problems, I works only after I install geppy. Once I quit python. I can't even import geppy properly. see below:

[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^

bolzzzz commented 5 years ago

@ShuhuaGao @bolz213 Sorry again seems my installation is not stable. I have installed geppy on MacBook with Mac OS 14.0 I have installed python3.7 manually with numpy-1.16.2,graphviz-0.10.1,sympy-1.4. as mentioned before, geppy works after installation. and now the problems, I works only after I install geppy. Once I quit python. I can't even import geppy properly. see below:

[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^

It's still about the python version. Could you try "python --version" and see its version?

In addition, for convenience of trying something, I recommend you to use conda and create an environment which is isolated and you can try anything inside it. The cool thing is that in this isolated environment you can install packages of certain versions and won't affect other environments.

bolzzzz commented 5 years ago

@ShuhuaGao @bolz213 Sorry again seems my installation is not stable. I have installed geppy on MacBook with Mac OS 14.0 I have installed python3.7 manually with numpy-1.16.2,graphviz-0.10.1,sympy-1.4. as mentioned before, geppy works after installation. and now the problems, I works only after I install geppy. Once I quit python. I can't even import geppy properly. see below:

[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin Type "help", "copyright", "credits" or "license" for more information.

import geppy Traceback (most recent call last): File "", line 1, in File "geppy/init.py", line 37, in from .core.entity import * File "geppy/core/entity.py", line 415 nonlocal n_rnc ^

The default python version of Mac 14.0 seems python2. You may need to use python3 to invoke python3 (and maybe you need use pip3 install ... to install geppy for python3). Or a better way is to use conda environment.

ShuhuaGao commented 5 years ago

@waynezw0618 I guess you are new to Python. Apart from using an environment manager, as said by @bolz213 , you can set the default Python to the 3.7 version. See this stackoverflow How to set Python's default version to 3.x on OS X?.

waynezw0618 commented 5 years ago

Hello Again @ShuhuaGao @bolz213

I am trying geppy to fit N 3X3 tensor Bij with two scalar list I1,I2 of size N and two 3X3 tensor list V1,V2 with fitness defined as tensorDot(Bij, PBij)/(tensordot(Bij,Bji)*tensordot(PBij, PBji)). but I get errors in my evaluation function like this: [[ATraceback (most recent call last): File "testGEPPY_DNS.py", line 109, in stats=stats, hall_of_fame=hof, verbose=True) File "/Users/weizhang/software/backup/geppy-master/geppy/algorithms/basic.py", line 100, in gep_simple for ind, fit in zip(invalid_individuals, fitnesses): File "testGEPPY_DNS.py", line 71, in evaluate Rp_i=np.array([[Yp[i,1],Yp[i,2],Yp[i,3]],[Yp[i,2],Yp[i,4],Yp[i,5]],[Yp[i,3],Yp[i,5],Yp[i,:6]]]) IndexError: too many indices for array

here is my evaluation function: ` def evaluate(individual): """Evalute the fitness of an individual: MSE (mean squared error)""" func = toolbox.compile(individual) Yp = np.array(list(map(func,T1,T2,T3))) # predictions with the GEP model

#print (np.shape(Yp),Yp)
a=0
b=0
c=0
for i in range(size):
   Ri=np.array([[bij[i,1],bij[i,2],bij[i,3]],[bij[i,2],bij[i,4],bij[i,5]],[bij[i,3],bij[i,5],bij[i,6]]])
   Rp_i=np.array([[Yp[i,1],Yp[i,2],Yp[i,3]],[Yp[i,2],Yp[i,4],Yp[i,5]],[Yp[i,3],Yp[i,5],Yp[i,6]]])
#   print (Ri,np.shape(Ri))
   a=a+np.tensordot(Rp_i,Ri)
   b=a+np.tensordot(Ri,Ri.T) 
   c=c+np.tensordot(Rp_i,Rp_i.T) 

return a/(b*c),

` I tried to print the PB, seems give me a array of(N,1) rather than expected (N,3,3) can you please give me some suggestion