def test_FrequencyModulationWithPhaseResponseCurve(self): data = RungeKutta45IntegratorData(8, 0.0) iaf = IntegrateAndFire() iaf.phaseEfectivenessCurve = phaseEfectivenessCurveSH fireNotifier = FiringTimesNotifier() iaf.Notify = fireNotifier.Notify npoints = 1000 period = 20.0 seriesNotifier = SeriesNotifier(8, npoints) allTimes = np.linspace(0.0, npoints * iaf.SamplingTime, npoints) for t in allTimes: data.t = t data.y[5] = 2.0 * iaf.r * (1.0 + np.cos(2 * np.pi * t / period)) data.y[6] = iaf.Phase + phaseEfectivenessCurveSH(iaf.Phase) iaf.ApplyDrive(data) # will open or not. #print("%lf\t%lf" % (iaf.Phase,data.y[6])) logging.debug(data) seriesNotifier.Notify(data) #Print dots at firing times spikes = np.ones(len(fireNotifier.firingTimes)) #print("Firing times: %s" % str(fireNotifier.firingTimes)) fig = plt.figure() plt.subplot(2, 1, 1) #plt.ylim(-12.0,12.0) plt.plot(allTimes, seriesNotifier.GetVar(5)) #effective rate plt.subplot(2, 1, 2) plt.plot(allTimes, seriesNotifier.GetVar(4), "g") plt.plot(allTimes, seriesNotifier.GetVar(6), "r") plt.plot(fireNotifier.firingTimes, spikes, "ro") fname = sys._getframe().f_code.co_name + ".png" print("Test result in %s" % fname) plt.savefig(fname)
def test_PhaseResponseCurve(self): data = RungeKutta45IntegratorData(8,0.0) iaf = IntegrateAndFire() iaf.phaseEfectivenessCurve = phaseEfectivenessCurveSH fireNotifier = FiringTimesNotifier() iaf.Notify = fireNotifier.Notify npoints = 1000 #allPhasesCircle = np.linspace(0.0,2.0*np.pi,npoints) allPhases = np.linspace(0.0,1.0,npoints) allPRC = np.linspace(0.0,1.0,npoints) for i,t in enumerate(allPhases): allPRC[i] = phaseEfectivenessCurveSH(t) fig = plt.figure() plt.subplot(2,1,1) plt.plot(allPhases,allPRC) plt.axhline(y=0.0,color='k',linestyle='-') ax = plt.subplot(2,1,2, projection='polar') ax.plot(allPhases*2.0*np.pi,0.1*np.ones(npoints),'b') ax.plot(allPhases*2.0*np.pi,0.1+allPRC,'r') ax.set_rmax(0.3) ax.set_rticks([0.1, 0.2, 0.3]) # less radial ticks ax.set_rlabel_position(22.5) # get radial labels away from plotted line ax.grid(True) # ax.set_aspect('equal', 'datalim') # plt.plot(0.5*np.cos(2.0*np.pi*allPhases), # 0.5*np.sin(2.0*np.pi*allPhases), # linewidth=1,color='k') # plt.plot((0.5 + phaseEfectivenessCurveSH(allPhases)) * np.cos(2.0*np.pi*allPhases), # (0.5 + phaseEfectivenessCurveSH(allPhases)) * np.sin(2.0*np.pi*allPhases), # linewidth=1,color='r') # plt.axhline(y=0.0,color='k',linestyle='-') # plt.axvline(x=0.0,color='k',linestyle='-') fname = sys._getframe().f_code.co_name + ".png" print("Test result in %s" % fname) plt.savefig(fname)