ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

graphs of GUI are quite different to result from calculation #561

Closed kalok87 closed 10 years ago

kalok87 commented 10 years ago

Dear Developers,

It is a very strange phenomenon here. Using GUI with gcal.ty, I got a very nice fft of map which is shown here:

fft_plot _v1_orientation_preference_at_time_003545 40

It is a nice pattern with 2 modes. However, I tried to save the numerical data via commands: from topo.command.analysis import measure_sine_pref import numpy as np import pylab as pl

measure_or_pref() p = topo.sim.V1.views.maps.OrientationPreference.last.data s = topo.sim.V1.views.maps.OrientationSelectivity.last.data

map = s_np.exp(2j_p) power = abs(pl.fft2(map))**2 pl.imshow(pl.fftshift(power)) pl.colorbar() pl.show()

I got this graph which is quite different to the first one (not ring-shape, 4 dominant modes). figure_1

Could you help me to figure out the reason for this?

jbednar commented 10 years ago

The OrientationPreference data is on a scale from 0 to pi, based on the range of possible orientations of a symmetric pattern. I would try rescaling it to a range 0 to 1.0, by dividing p by pi, as the GUI does.

kalok87 commented 10 years ago

Dear James,

After rescaling, the result is even strange (one mode in the middle, but the result of GUI has 2 modes and ring-shape.) figure_2 The code I was using to generate this graph is: from topo.command.analysis import measure_sine_pref import numpy as np import pylab as pl

measure_or_pref() p = topo.sim.V1.views.maps.OrientationPreference.last.data s = topo.sim.V1.views.maps.OrientationSelectivity.last.data

p_new = p/np.pi map = s_np.exp(2j_p_new) power = abs(pl.fft2(map))**2 pl.imshow(pl.fftshift(power)) pl.colorbar() pl.show()

I have no idea how it comes. Can you help me to figure it out?

kalok87 commented 10 years ago

I forget to mention that I use RunProgress().run(1000) to run the simulation, is that possibly the reason?

jbednar commented 10 years ago

Unfortunately, I'm not currently able to try to debug your code, but the code we are using in the GUI is (from templateplotgrouppanel.py):

topo.command.pylabplot.fftplot(m, title="FFT Plot: " + description)

where m is the Orientation preference matrix from 0..1.0.

The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.

kalok87 commented 10 years ago

Thank you James, the result is same once I use the definition in your code to calculate the fft. But I also want to compute the power-spectrum of the map which means I also take selectivity into account. The power-spectrum from my calculation shows no ring-shape that is opposite to the graph of GUI shows. So I guess there may be an error in my code. I will re-do my simulation and see whether it works.

But I still have two questions: 1) I used ipython-notebook which you provided to perform the simulation. But because I want to run it without interaction, I copy all the contents ( without those graphs showing commands) of gcal.ipnb to a template 'simu.ty' and try use topographica to run this script (using command: "topographica tsimu.ty" ). But here I meet a problem, a line in gcal.ipnb:

from topo.misc.ipython import export_notebook diff = export_notebook('./gcal.ipnb', 'gcal.ty', identifier='GCAL_TY')

It writes all the defined parameters to gcal.ty. But this command is only for notebook. How can I modify it in order to let topographica read the parameters I defined in the script and write it to gcal.ty ?

2) Once I use topographica to run my script, an error occurs: 'RunProgress' object has no attribute 'run'. But the 'RunPrograss' commands works in notebook. What is the reason for this error?

jbednar commented 10 years ago

I'm not sure precisely what you are asking about export_notebook, but the intent of that function is to automatically create a file 'gcal.ty' out of the contents of your notebook. So you don't have any need to copy all the contents manually; instead gcal.ty should be created automatically when you run the notebook. It will only have the code cells that start out with "GCAL_TY", which you can use to make sure that the generated .ty file has only the bits you want (and not e.g. the export_notebook command itself, which doesn't go into the .ty file).

Regarding RunProgress, it should work either inside or outside a notebook. Without the actual command you used it's not clear what the trouble would be; presumably the right syntax is something like from topo.misc.ipython import RunProgress ; RunProgress()(1000). But you also don't need it if you don't want a progress bar; you can simply do topo.sim.run(1000), or load it into the GUI and hit Run.

Jim

The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.

kalok87 commented 10 years ago

James, sorry for my poor English. What I want to do is trying to use topo to run a script instead of notebook. So I copy everything from gcal.ipnb to my script. And I also change 2 lines of your code:

1) I change the code " response = prompt('Would you like to explore the GCAL model with the Topographica GUI?', 'n', ['y','n']) if response == 'y': misc.open_gui() if os.path.isfile('gcal.ty'): execfile('gcal.ty') else: print "GCAL not loaded: 'gcal.ty' file not found!" " To " execfile('gcal.ty')".

2) I deleted " from topo.misc.ipython import export_notebook diff = export_notebook('./gcal.ipynb', 'gcal.ty', identifier='GCAL_TY') "

And then I run this script using "RunProgress().run(1000)".

I then run the script using ' topographica myscript.ty'. I do not know why, but compared to the result I got from the gcal.ipnb, the result form myscript.ty is much worse. Because I try to run the simulation in cluster (it did not support ipython notebook), I must use XXX.ty instead of notebook.

Could you help me to figure it out? My script is almost the same as gcal.ipnb except those 2 places and the lat part:

for time in range(5000): print time RunProgress().run(1000) measure_or_pref() save_plotgroup('Activity') p = topo.sim.V1.views.maps.OrientationPreference.last.data s = topo.sim.V1.views.maps.OrientationSelectivity.last.data b = topo.sim.V1.views.maps.OrientationSelectivity.last.ylim n = time + 1 filename = str(n).rjust(4, '0') save_data.save(p,s,b,filename+'.txt','result/')

here I save the data in each 1000 iteration.

jbednar commented 10 years ago

If you want to run on a cluster that doesn't support notebooks, simply use the gcal.ty file we provide with topographica in the examples/ directory, which should be essentially the same as the one automatically generated by gcal.ipynb and saved as gcal.ty in whatever directory you ran the notebook in. I.e., there's no need to convert the notebook into a .ty file, because we already supply a .ty file that works well on clusters, and moreover the gcal.ipynb file already generates another .ty file with the same content. We can't really debug your code any more than that; Topographica is just a modelling framework for you to use for your own work, not a commercial package with paid support.