-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimized learning and response functions for GCAL model with modified CFProjection #678
Comments
Right; CFPLF_Plugin and CFPRF_Plugin make it easy to write custom learning and response functions, but they will be much slower. Nowadays I'd probably use Numba or at least Cython to do optimized functions, but we haven't set that up in Topgraphica, and so unless you want to go into uncharted territory, if you want to speed things up you'll need to copy those two optimized components, rename the copies, and try to adapt them to your needs. Unfortunately, they are quite difficult to follow, as they are written in very low-level C code, but if you patiently work through them comparing the optimized code to the non-optimized version that we provide for reference, you should be able to see how the optimized code implements the same operation but at a much lower level that works much faster. If you don't know C, you'll probably want to get some help from someone who does. Or you can try to resurrect the Cython versions of the optimized components that are probably somewhere in the Topographica repository; those versions should be nearly as fast and vastly easier to understand and modify. If you want to go that route @ceball can probably find where the latest Cython versions were. |
I wouldn't call it resurrecting, they are in perfect working order and are just as fast (or faster) than the previous C extensions. When I was still working on Topographica I used them exclusively. You'll be able to find them in the optimized module. |
Oh, excellent! Glad they didn't die out. :-) Those should be much easier to work with than the C-optimized versions. Good luck! |
Hi, I didn't see what are the big differences between CFPRF_DotProduct_cython and CFPRF_DotProduct_opt, why did you think the cython classes are much easier to modify ? @jbednar @philippjfr |
If I need to modify, e.g. dot_product function, I should modify that in optimized.h, then compile the files by using command "python setup.py build_ext", right ? |
We have a lot of versions of this crucial object:
I think (4) is the one that Philipp used in practice, so it should be in good shape, and that one should be a good starting point, as it has good performance (unlike 1) and is reasonably readable and maintainable (unlike 2 and 3). Hope that helps! |
I still don't see what you mean; CFPRF_DotProduct_cython and CFPRF_DotProduct_opt really aren't very similar (click on the links above to see); one of them is pages of very specific pointer-based C code, and the other is a short bit of Pythonic code with types (not C). |
You'll see that |
If I were writing this stuff today I'd probably just replace these functions with Numba. |
Ah, I thought the Definitely, Numba would be the way to go now. But I wouldn't want to try mixing Numba, Cython, and Weave in the same codebase, the way the code is currently organized; instead I'd disable or delete all but the unoptimized, then see if Numba can optimize that directly with similar or better performance. If only we had had Numba at the time we wrote this in 1993! |
Hi, I want to implement a modified CFProjection class for GCAL model. I changed some code for e.g. learning function and response function and connection fields. The learning function uses modified
class CFPLF_Plugin(CFPLearningFn)
. The response function uses modifiedclass CFPRF_Plugin(CFPResponseFn)
.Then the modified GCAL model can work for non-optimized components but the problem is the running is very slow. I checked that GCAL model uses e.g.responsefn.optimized.CFPRF_DotProduct_opt()
andlearningfn.optimized.CFPLF_Hebbian_opt()
to speed up the code. So I suppose I also need to modified these optimized functions for the modified connection field settings. Can you give some suggestions for the necessary changes ?The text was updated successfully, but these errors were encountered: