Changeset 350
- Timestamp:
- 11/16/08 01:51:40 (2 months ago)
- Files:
-
- trunk/examples/sfn2008/sfn_example_parameterspace.py (modified) (3 diffs)
- trunk/examples/sfn2008/sfn_example_simulated_data.py (modified) (3 diffs)
- trunk/examples/sfn2008/sfn_example_stgen.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/sfn2008/sfn_example_parameterspace.py
r349 r350 4 4 Example to show off some capabilities of the parameters module. 5 5 6 - creates a ParameterSpace of c and jitter for the example shown in sfn_example_stgen.py 7 - the parameters c and jitter are scanned and the cc and the corrcoef are calculated 6 - creates a ParameterSpace of c and jitter for the example shown in 7 sfn_example_stgen.py 8 - the parameters c and jitter are scanned and the cc and the corrcoef 9 are calculated 8 10 - all the cc's are plotted 9 -10 11 11 12 Performed at the NeuroTools demo session, INCF booth, 12 13 SfN annual meeting 2008, Washington. DC. 13 14 """ 15 import numpy, pylab 16 14 17 import NeuroTools.stgen as stgen 15 18 sg = stgen.StGen() 16 # function of the example in sfn_example_stgen.py 19 20 from NeuroTools.parameters import ParameterSpace 21 from NeuroTools.parameters import ParameterRange 22 from NeuroTools.sandbox import make_name 23 24 # creating a ParameterSpace 25 p = ParameterSpace({}) 26 27 # adding fixed parameters 28 p.nu = 20. # rate [Hz] 29 p.duration = 1000. 30 31 # adding ParameterRanges 32 p.c = ParameterRange([0.0,0.01,0.1,0.5]) 33 p.jitter = ParameterRange([0.0,1.0,5.0,]) 34 35 # calculation of the ParameterSpace dimension and the labels of the parameters 36 # containing a range 37 dims, labels = p.parameter_space_dimension_labels() 38 print "dimensions: ", dims 39 print ' labels: ', labels 40 17 41 def calc_cc(p): 42 """ 43 Generate correlated spike trains from the ParameterSet. 44 45 Parameter: 46 p - ParameterSet containing parameters nu (rate), c (correlation), 47 duration (in ms), jitter (in ms). 48 49 Returns: (cc, time_axis_cc, corrcoef) 50 cc - correlation coefficient 51 time_axis_cc - time axis for cross-correlation (for plotting) 52 corrcoef - correlation coefficient between the two SpikeTrains 53 """ 18 54 rate_independent = (1-p.c)*p.nu 19 55 rate_shared = p.c*p.nu … … 34 70 35 71 36 # 37 from NeuroTools.parameters import ParameterSpace 38 from NeuroTools.parameters import ParameterRange 39 from NeuroTools.sandbox import make_name 40 # creating a ParameterSpace 41 p = ParameterSpace({}) 42 # adding paramters 43 p.nu = 20. # Hz 44 # adding a ParameterRange 45 p.c = ParameterRange([0.0,0.01,0.1,0.5]) 46 p.jitter = ParameterRange([0.0,1.0,5.0,]) 47 p.duration = 1000. 48 49 # calculation of the ParameterSpace dimension and the labels of the parameters containing a range 50 dims, labels = p.parameter_space_dimension_labels() 51 # creating a results arry, with the dimensions of the ParameterSpace 72 # creating a results array, with the dimensions of the ParameterSpace 52 73 corrcoef_results = numpy.empty(dims) 53 74 54 # scanning the Space75 # scanning the ParameterSpace 55 76 for experiment in p.iter_inner(): 56 77 # calculation of the index in the space … … 65 86 pylab.title(make_name(experiment,p.range_keys())) 66 87 pylab.xlim(-30,30.) 67 pylab.ylim(0,1 30.)88 pylab.ylim(0,10.) 68 89 69 90 70 91 # plot the results 71 92 pylab.matshow(corrcoef_results) 72 93 pylab.xticks(numpy.arange(0.5,dims[1]+0.5,1.0),[str(i) for i in p.jitter._values]) trunk/examples/sfn2008/sfn_example_simulated_data.py
r349 r350 1 import NeuroTools.signals as signals2 1 """ 3 2 Example to show off some capabilities of the signals module … … 12 11 SfN annual meeting 2008, Washington. DC. 13 12 """ 13 import NeuroTools.signals as signals 14 14 15 15 # loading spiking data … … 29 29 # isi distribution 30 30 hs = s.isi_hist() 31 pylab.figure() 31 32 pylab.plot(hs[1],hs[0]) 32 33 trunk/examples/sfn2008/sfn_example_stgen.py
r348 r350 43 43 st2.time_histogram(time_bin = 1.), 44 44 mode = 'same') 45 time_axis = numpy.linspace(cc.shape[0]/-2., cc.shape[0]/2, cc.shape[0]) 45 46 46 pylab.plot( cc, label = 'no correlation')47 pylab.plot(time_axis, cc, label = 'no correlation', alpha = 0.5) 47 48 48 49 # inject correlation into st1 and st2 49 st3 = sg.poisson_generator(rate =rate_shared, t_stop = duration)50 st3 = sg.poisson_generator(rate = rate_shared, t_stop = duration) 50 51 st1.merge(st3) 51 52 st2.merge(st3) … … 55 56 mode = 'same') 56 57 57 pylab.plot( cc2, label = '10% correlation')58 pylab.plot(time_axis, cc2, label = '10% correlation', alpha = 0.5) 58 59 pylab.legend() 59 60 pylab.show()

