Changeset 347
- Timestamp:
- 11/16/08 00:29:16 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/examples/sfn2008/sfn_example_stgen.py
- Property svn:mergeinfo set
- Property svn:keywords set to Id
r345 r347 1 """ 2 $Id$ 3 4 Example to show off some capabilities of the stgen module 5 and the SpikeTrain class. 6 7 Performed at the NeuroTools demo session, INCF booth, 8 SfN annual meeting 2008, Washington. DC. 9 """ 1 10 import NeuroTools.stgen as stgen 2 11 sg = stgen.StGen() 3 12 duration = 10000. 4 nu = 20. 5 c = 0.0 # correlation 6 rate_independent = (1-c)*nu 7 rate_shared = c*nu 13 rate_independent = 100. #Hz 14 rate_shared = 10. #Hz, 10 % correlation 8 15 9 16 st1 = sg.poisson_generator(rate=rate_independent, t_stop = duration) … … 22 29 import numpy 23 30 cc = numpy.correlate(st1.time_histogram(time_bin = 1.), 24 st2.time_histogram(time_bin = 1.),25 mode = 'same')31 st2.time_histogram(time_bin = 1.), 32 mode = 'same') 26 33 27 34 import pylab 28 35 pylab.plot(cc) 29 36 30 # inject correlation into st1 and st2 37 # inject correlation into st1 and st2 (only if correlation is > 0) 31 38 st3 = sg.poisson_generator(rate=rate_shared, t_stop = duration) 32 39 st1.merge(st3) … … 34 41 35 42 cc2 = numpy.correlate(st1.time_histogram(time_bin = 1.), 36 st2.time_histogram(time_bin = 1.),37 mode = 'same')43 st2.time_histogram(time_bin = 1.), 44 mode = 'same') 38 45 39 46 import pylab 40 47 pylab.plot(cc2) 41 48 42 # shot noise49 #generate shot noise from st1 43 50 st1_shot = stgen.shotnoise_fromspikes(st1, 44 q = 1.0,45 tau = 10.,46 t_start = st1.t_start,47 t_stop = st1.t_stop)51 q = 1.0, 52 tau = 10., 53 t_start = st1.t_start, 54 t_stop = st1.t_stop) 48 55 pylab.figure() 49 56 pylab.plot(st1_shot.signal) … … 53 60 54 61 55 # example parameter space range etc.56 # parameter scan, c vs. jitter57 58 59 def calc_cc(p):60 rate_independent = (1-p.c)*p.nu61 rate_shared = p.c*p.nu62 63 st1 = sg.poisson_generator(rate=rate_independent, t_stop = p.duration)64 st2 = sg.poisson_generator(rate=rate_independent, t_stop = p.duration)65 if p.c >0:66 st3 = sg.poisson_generator(rate=rate_shared, t_stop = duration)67 st1.merge(st3.jitter(p.jitter))68 st2.merge(st3.jitter(p.jitter))69 70 cc = numpy.correlate(st1.time_histogram(time_bin = 1.0),st2.time_histogram(time_bin = 1.),mode = 'same')71 corrcoef = numpy.corrcoef(st1.time_histogram(time_bin = 1.0),st2.time_histogram(time_bin = 1.))72 return cc, corrcoef[0][1]73 74 75 76 from NeuroTools.parameters import ParameterSpace77 from NeuroTools.parameters import ParameterRange78 from NeuroTools.sandbox import make_name79 80 p = ParameterSpace({})81 p.nu = 20. # Hz82 p.c = ParameterRange([0.0,0.01,0.1,0.5])83 p.jitter = ParameterRange([0.0,1.0,5.0,])84 p.duration = 1000.85 86 dims, labels = p.parameter_space_dimension_labels()87 88 corrcoef_results = numpy.empty(dims)89 90 for experiment in p.iter_inner():91 index = p.parameter_space_index(experiment)92 cc, corrcoef = calc_cc(experiment)93 time_axis = numpy.linspace(-cc.shape[0]/2.,cc.shape[0]/2.,cc.shape[0])94 corrcoef_results[index] = corrcoef95 subplot_index = (dims[1]*index[0])+index[1]96 pylab.subplot(dims[0],dims[1],subplot_index+1)97 pylab.plot(time_axis,cc)98 pylab.title(make_name(experiment,p.range_keys()))99 pylab.xlim(-30,30.)100 pylab.ylim(0,130.)101 102 103

