def main(argv): resultsFilename = 'results/integrationINapIKFig10_1_INapIKHighThreshold.npz' v0 = -60.00 t0 = 0.0 tf = 25.0 dt = 1e-5 nTSteps = round((tf - t0) / dt) times = np.empty(nTSteps + 1) i0 = 10 def i(t): return (i0) iNapIKModel = INapIKModel.getHighThresholdInstance() iNapIKModel.setI(i=i) n0 = iNapIKModel._nInf(v=v0) y0 = np.array([v0, n0]) res = integrateForward(deriv=iNapIKModel.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps) np.savez(resultsFilename, times=res['times'], ys=res['ys']) plt.plot(res['times'], res['ys'][0, :]) plt.xlabel("Time (sec)") plt.ylabel("Membrane Potential (mV)") plt.show()
def main(argv): epsilon = 0.1 i0 = 10 couplingStartTime = 99.04 duration = 100.0 dt = 1e-2 integrationWCOsFilename = "results/integrationWCoupledINapIKHighThresholdI0%.02fEpsilon%.06fCouplingStartTime%.02f.npz" % ( i0, epsilon, couplingStartTime) hFilenamePattern = "results/h%d%dINapIKHighThresholdI0%.02fEpsilon%.06fCouplingStart%.02f.npz" resultsFilename = "results/integrationPhasesDifferencesINapIKHighThresholdI0%.02fEpsilon%.05fCouplingStartTime%.02f.npz" % ( i0, epsilon, couplingStartTime) integrationWCOs = np.load(integrationWCOsFilename) def h(phaseDiff, phaseDiffs, hs, i, j): T = np.max(phaseDiffs) wrappedPhaseDiff = phaseDiff % T phaseDiffIndex = np.argmin(np.abs(wrappedPhaseDiff - phaseDiffs)) answer = hs[phaseDiffIndex] print("h%d%d[phaseDiff=%.04f]=%.04f" % (i, j, wrappedPhaseDiff, answer)) # plt.plot(phaseDiffs, hs); plt.title("h%d%d(%f)=%f"%(i, j, wrappedPhaseDiff, answer)); plt.axvline(x=wrappedPhaseDiff, color="gray"); plt.show() # pdb.set_trace() return (answer) h01IntRes = np.load(hFilenamePattern % (0, 1, i0, epsilon, couplingStartTime)) h01 = lambda phaseDiff: h(i=0, j=1, phaseDiff=phaseDiff, phaseDiffs=h01IntRes["phaseDiffs"], hs=h01IntRes["hValues"]) h10IntRes = np.load(hFilenamePattern % (1, 0, i0, epsilon, couplingStartTime)) h10 = lambda phaseDiff: h(i=1, j=0, phaseDiff=phaseDiff, phaseDiffs=h10IntRes["phaseDiffs"], hs=h10IntRes["hValues"]) zeroH = lambda phaseDiff: 0.0 hs = [[zeroH, h01], [h10, zeroH]] pdModel = MalkinsPhaseDeviationModelOfWeaklyCoupledOscillators( hs=hs, epsilon=epsilon) timesNeuron0 = integrationWCOs["times0Uncoupled"] voltagesNeuron0 = integrationWCOs["ys0Uncoupled"][0, :] resPhasesNeuron0 = getPhasesFromVoltages(times=timesNeuron0, voltages=voltagesNeuron0) phasesNeuron0 = resPhasesNeuron0["phases"] timePhasesNeuron0 = resPhasesNeuron0["times"] index = np.argmin(np.abs(couplingStartTime + 0.05 - timePhasesNeuron0)) phaseNeuron0AtCouplingStartTime = phasesNeuron0[index] timesNeuron1 = integrationWCOs["times1Uncoupled"] voltagesNeuron1 = integrationWCOs["ys1Uncoupled"][0, :] resPhasesNeuron1 = getPhasesFromVoltages(times=timesNeuron1, voltages=voltagesNeuron1) phasesNeuron1 = resPhasesNeuron1["phases"] timePhasesNeuron1 = resPhasesNeuron1["times"] index = np.argmin(np.abs(couplingStartTime + 0.05 - timePhasesNeuron1)) phaseNeuron1AtCouplingStartTime = phasesNeuron1[index] y0 = [phaseNeuron0AtCouplingStartTime, phaseNeuron1AtCouplingStartTime] t0 = couplingStartTime tf = t0 + duration nTSteps = int((tf - t0) / dt) intRes = integrateForward(deriv=pdModel.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps) np.savez(resultsFilename, times=intRes["times"], ys=intRes["ys"]) ax1 = plt.subplot(2, 1, 1) plt.plot(integrationWCOs["times0Uncoupled"], integrationWCOs["ys0Uncoupled"][0, :], color="red", label=r"$V_0$") plt.plot(integrationWCOs["times1Uncoupled"], integrationWCOs["ys1Uncoupled"][0, :], color="blue", label=r"$V_1$") plt.grid() plt.xlabel("Time (sec)") plt.ylabel("Membrane\nPotential (mV)") plt.axvline(x=couplingStartTime, color="red") plt.legend(loc="upper left") ax2 = plt.subplot(2, 1, 2, sharex=ax1) plt.plot(intRes["times"], intRes["ys"][0, :], color="red", label=r"$\phi_0$") plt.plot(intRes["times"], intRes["ys"][1, :], color="blue", label=r"$\phi_1$") plt.grid() plt.xlabel("Time (sec)") plt.ylabel("Phase Deviation") plt.legend(loc="upper left") plt.show() pdb.set_trace()
def main(argv): epsilon = 0.003 v00 = -25.91 # red n00 = 0.50 # red v01 = -62.56 # blue n01 = 0.13 # blue t0 = 0.0 tf = 500.0 dt = 1e-3 couplingStartTime = 100.44 nTSteps = int((tf - t0) / dt) times = np.empty(nTSteps + 1) i0 = 35.0 traceColNeuron1 = "blue" traceColNeuron2 = "red" linestyleCoupled = "-" linestyleUncoupled = ":" resultsFilename = "results/integrationWCoupledINapIKLowThresholdI0%.02fEpsilon%.06fCouplingStartTime%.02f.npz" % ( i0, epsilon, couplingStartTime) voltagesFigFilename = "figures/voltagesWCoupledINIKLowThresholdI0%.02fEpsilon%.06fCouplingStartTime%.02f.eps" % ( i0, epsilon, couplingStartTime) phaseSpaceFigFilename = "figures/phaseSpaceWCoupledINIKLowThresholdI0%.02fEpsilon%.06fCouplingStartTime%.02f.eps" % ( i0, epsilon, couplingStartTime) def i(t): return (i0) iNapIKModel1 = INapIKModel.getLowThresholdInstance() iNapIKModel1.setI(i=i) iNapIKModel2 = INapIKModel.getLowThresholdInstance() iNapIKModel2.setI(i=i) models = [iNapIKModel1, iNapIKModel2] # g_{ij}(x_i, x_j) is the coupling from neuron j to neuron i In # couplingFunc(x1, x2) x1==x_i (i.e., the state of the neuron receiving # the coupling) and x2==x_j (i.e., the state of the neuron sending the # coupling) uncoupledFunc = lambda x1, x2: np.array([0.0, 0.0]) coupledFunc = lambda x1, x2: np.array([x2[0] - x1[0], 0.0]) couplings = [[uncoupledFunc, coupledFunc], [coupledFunc, uncoupledFunc]] y0 = np.array([v00, n00, v01, n01]) coupledOscillatorsModel = WeaklyCoupledOscillatorsModel( models=models, couplings=couplings, epsilon=epsilon, couplingStartTime=couplingStartTime) res = integrateForward(deriv=coupledOscillatorsModel.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps) ysCoupled = res["ys"] timesCoupled = res["times"] y00 = np.array([v00, n00]) res = integrateForward(deriv=iNapIKModel1.deriv, t0=t0, y0=y00, dt=dt, nTSteps=nTSteps) ys0Uncoupled = res["ys"] times0Uncoupled = res["times"] y01 = np.array([v01, n01]) res = integrateForward(deriv=iNapIKModel2.deriv, t0=t0, y0=y01, dt=dt, nTSteps=nTSteps) ys1Uncoupled = res["ys"] times1Uncoupled = res["times"] np.savez(resultsFilename, timesCoupled=timesCoupled, ysCoupled=ysCoupled, times0Uncoupled=times0Uncoupled, ys0Uncoupled=ys0Uncoupled, times1Uncoupled=times1Uncoupled, ys1Uncoupled=ys1Uncoupled) plt.plot(timesCoupled, ysCoupled[0, :], color=traceColNeuron1, linestyle=linestyleCoupled, label="Coupled Neuron 1") plt.plot(timesCoupled, ysCoupled[2, :], color=traceColNeuron2, linestyle=linestyleCoupled, label="Coupled Neuron 2") plt.plot(times0Uncoupled, ys0Uncoupled[0, :], color=traceColNeuron1, linestyle=linestyleUncoupled, label="Uncoupled Neuron 1") plt.plot(times1Uncoupled, ys1Uncoupled[0, :], color=traceColNeuron2, linestyle=linestyleUncoupled, label="Uncoupled Neuron 2") plt.grid() plt.xlabel("Time (sec)") plt.ylabel("membrane potential (mV)") plt.axvline(x=couplingStartTime, color="red") plt.legend() plt.savefig(voltagesFigFilename) plt.figure() plt.plot(ysCoupled[0, :], ysCoupled[1, :], color=traceColNeuron1, linestyle=linestyleCoupled, label="Coupled Neuron 0") plt.plot(ysCoupled[2, :], ysCoupled[3, :], color=traceColNeuron2, linestyle=linestyleCoupled, label="Coupled Neuron 1") plt.plot(ys0Uncoupled[0, :], ys0Uncoupled[1, :], color=traceColNeuron1, linestyle=linestyleUncoupled, label="Uncoupled Neuron 0") plt.plot(ys1Uncoupled[0, :], ys1Uncoupled[1, :], color=traceColNeuron2, linestyle=linestyleUncoupled, label="Uncoupled Neuron 1") plt.grid() plt.ylabel("membrane potential (mV)") plt.ylabel("activation gate, n") plt.legend() plt.savefig(phaseSpaceFigFilename) plt.show() pdb.set_trace()
def main(argv): resultsFilename = "results/integrationINapIKFig10_10_2-1Sync.npz" v0 = -60.00 t0 = 0.0 tf = 198.0 dt = 1e-3 nTSteps = int(round((tf - t0) / dt)) times = np.empty(nTSteps + 1) # i0 = 4.7 i0 = 9.4 nTransientSpikes = 6 pulseStrength = 200.0 pulseWidth = 100 * dt Ts = 18.37 offset = 9.0 # offset = 14.0 def iDC(t): return (i0) iNapIKModelDC = INapIKModel.getHighThresholdInstance() iNapIKModelDC.setI(i=iDC) n0DC = iNapIKModelDC._nInf(v=v0) y0DC = np.array([v0, n0DC]) resDC = integrateForward(deriv=iNapIKModelDC.deriv, t0=t0, y0=y0DC, dt=dt, nTSteps=nTSteps) def iDCTrainPulses(t): r = (t - offset) % Ts if r < pulseWidth / 2 or Ts - pulseWidth / 2 < r: return (i0 + pulseStrength) return (i0) model = INapIKModel.getHighThresholdInstance() model.setI(i=iDCTrainPulses) n0 = model._nInf(v=v0) y0 = np.array([v0, n0]) resDCTrainPulses = integrateForward(deriv=model.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps) # peakIndices = getPeakIndices(v=resDCTrainPulses["ys"][0,:]) # resDCTrainPulses["ys"] = resDCTrainPulses["ys"][:,peakIndices[0]:] # resDCTrainPulses["times"] = resDCTrainPulses["times"][peakIndices[0]:]-\ # resDCTrainPulses["times"][peakIndices[0]] appliedIs = np.empty(resDCTrainPulses["times"].shape) for i in range(len(resDCTrainPulses["times"])): appliedIs[i] = iDCTrainPulses(t=resDCTrainPulses["times"][i]) # np.savez(resultsFilename, times=resDCTrainPulses["times"], # ys=resDCTrainPulses["ys"], # i0=i0, i=appliedIs, Ts=Ts, offset=offset) # np.savez(resultsFilename, # timesDC=resDC["times"], # ysDC=resDC["ys"], # timesDCTrainPulses=resDCTrainPulses["times"], # ysDCTrainPulses=resDCTrainPulses["ys"], # i0=i0, i=appliedIs, Ts=Ts, tPulse=tPulse) spikeIndices = getPeakIndices(v=resDC["ys"][0, :]) if len(spikeIndices) <= nTransientSpikes: raise ValueError("nTransientSpikes=%d is too large" % (nTransientSpikes)) spikeTimes = resDC["times"][spikeIndices] ts = spikeTimes[1:] - spikeTimes[:-1] T = np.mean(ts) print("T=%.02f" % (T)) plt.plot(resDCTrainPulses["times"], resDCTrainPulses["ys"][0, :], color="blue") plt.xlabel("Time (sec)") plt.ylabel("Membrane Potential (mV)") ax = plt.gca() ax2 = ax.twinx() ax2.plot(resDCTrainPulses["times"], appliedIs, color="red") ax2.set_ylabel("Input Current (mA)") plt.show()
def main(argv): resultsFilename = "results/integrationINapIKFig10_10_INapIKLowThreshold_2-1Sync.npz" v0 = -60.00 t0 = 0.0 tf = 800.0 dt = 1e-3 nTSteps = int(round((tf - t0) / dt)) times = np.empty(nTSteps + 1) i0 = 50.0 nTransientSpikes = 10 pulsePhase = 5.0 pulseStrength = 50.0 pulseWidthFactor = 100 Ts = 6.795 pulseWidth = pulseWidthFactor * dt def iDC(t): return (i0) iNapIKModelDC = INapIKModel.getLowThresholdInstance() iNapIKModelDC.setI(i=iDC) n0DC = iNapIKModelDC._nInf(v=v0) y0DC = np.array([v0, n0DC]) resDC = integrateForward(deriv=iNapIKModelDC.deriv, t0=t0, y0=y0DC, dt=dt, nTSteps=nTSteps) spikeIndices = getPeakIndices(v=resDC["ys"][0, :]) if len(spikeIndices) <= nTransientSpikes: raise ValueError("nTransientSpikes=%d is too large" % (nTransientSpikes)) spikeTimes = resDC["times"][spikeIndices] ts = spikeTimes[1:] - spikeTimes[:-1] T = np.mean(ts) print("T=%.02f" % (T)) pdb.set_trace() tPulse = spikeTimes[nTransientSpikes + 1] + pulsePhase def iDCTrainPulses(t): if t > tPulse: r = (t - tPulse) % Ts if r < pulseWidth / 2 or Ts - pulseWidth / 2 < r: return (i0 + pulseStrength) return (i0) model = INapIKModel.getLowThresholdInstance() model.setI(i=iDCTrainPulses) n0 = model._nInf(v=v0) y0 = np.array([v0, n0]) resDCTrainPulses = integrateForward(deriv=model.deriv, t0=t0, y0=y0, dt=dt, nTSteps=nTSteps) # peakIndices = getPeakIndices(v=resDCTrainPulses["ys"][0,:]) # resDCTrainPulses["ys"] = resDCTrainPulses["ys"][:,peakIndices[0]:] # resDCTrainPulses["times"] = resDCTrainPulses["times"][peakIndices[0]:]-\ # resDCTrainPulses["times"][peakIndices[0]] appliedIs = np.empty(resDCTrainPulses["times"].shape) for i in range(len(resDCTrainPulses["times"])): appliedIs[i] = iDCTrainPulses(t=resDCTrainPulses["times"][i]) np.savez(resultsFilename, timesDC=resDC["times"], ysDC=resDC["ys"], timesDCTrainPulses=resDCTrainPulses["times"], ysDCTrainPulses=resDCTrainPulses["ys"], i0=i0, i=appliedIs, Ts=Ts, tPulse=tPulse) plt.plot(resDC["times"], resDC["ys"][0, :], color="blue", label="DC stim") plt.plot(resDCTrainPulses["times"], resDCTrainPulses["ys"][0, :], color="magenta", label="Pulse stim") plt.xlabel("Time (sec)") plt.ylabel("Membrane Potential (mV)") plt.legend(loc="upper left") ax = plt.gca() ax2 = ax.twinx() ax2.plot(resDCTrainPulses["times"], appliedIs, color="lightgray") ax2.set_ylabel("Input Current (mA)") plt.show() pdb.set_trace()