Exemplo n.º 1
0
def main(argv):
    a = -1.0
    b = 1.0
    c = 2.0
    x0 = -0.7
    y0 = 1.0
    t0 = 0.0
    tf = 15.0
    dt = 1e-5
    xBounds = [-10, 10]
    yBounds = [-10, 10]
    resultsFilename = "results/integrationA%fB%fC%fX0%fY0%f.npz" % (a, b, c,
                                                                    x0, y0)

    def deriv(t, z):
        x = z[0]
        y = z[1]
        f = lambda x, y: a + x**2 - y
        g = lambda x, y: b * x - c * y
        xDot = f(x=x, y=y)
        yDot = g(x=x, y=y)
        return (np.array([xDot, yDot]))

    integrator = ode(deriv).set_integrator('vode')

    z0 = np.array([x0, y0])
    integrator.set_initial_value(z0, t0)
    zs = [z0]
    times = [t0]

    step = 0
    t = t0
    z = z0
    successfulIntegration = True
    while successfulIntegration and t<tf and \
          xBounds[0]<=z[0] and z[0]<=xBounds[1] and\
          yBounds[0]<=z[1] and z[1]<=yBounds[1]:
        step = step + 1
        if step % 10000 == 0:
            print('Processing time %.05f out of %.02f (%.02f, %.02f)' %
                  (t, tf, z[0], z[1]))
            sys.stdout.flush()
        integrator.integrate(t + dt)
        t = integrator.t
        z = integrator.y
        times.append(t)
        zs.append(z.tolist())
    timesArray = np.array(times)
    zsArray = buildMatrixFromArraysList(arraysList=zs)

    np.savez(resultsFilename, times=timesArray, zs=zsArray)
def main(argv):
    if len(argv) != 5:
        print("Usage %s <I> <label> <v0> <n0>" % argv[0])
        return

    i0 = float(argv[1])
    label = argv[2]
    v0 = float(argv[3])
    n0 = float(argv[4])
    t0 = 0.0
    t1 = 5.0
    tf = 40.0
    dt = 1e-5
    resultsFilename = 'results/integrationINapIKFig4-37%s.npz' % label

    iPulseStrength = 0.0
    iPulseWidth = 1 * dt

    def i(t):
        if t1 - iPulseWidth / 2 < t and t <= t1 + iPulseWidth / 2:
            return (i0 + iPulseStrength)
        return (i0)

    iNapIKModel = INapIKModel.getLowThresholdInstance(i=i)
    integrator = ode(iNapIKModel.deriv).set_integrator('vode')

    y0 = [v0, n0]
    integrator.set_initial_value(y0, t0)
    ys = [y0]
    times = [t0]

    step = 0
    t = t0
    y = y0
    successfulIntegration = True
    while successfulIntegration and t < tf:
        step = step + 1
        if step % 10000 == 0:
            print('Processing time %.05f out of %.02f (%.02f, %.02f)' %
                  (t, tf, y[0], y[1]))
            sys.stdout.flush()
        integrator.integrate(t + dt)
        t = integrator.t
        y = integrator.y
        times.append(t)
        ys.append(y.tolist())
    timesArray = np.array(times)
    ysArray = buildMatrixFromArraysList(arraysList=ys)

    np.savez(resultsFilename, times=timesArray, ys=ysArray)
Exemplo n.º 3
0
def main(argv):
    v0 = -73.00
    n0 = 0.0
    t0 = 0.0
    tf = 100.0
    current0 = 40.0
    currentf = 400.0
    dt = 1e-3
    resultsFilename = 'results/integrationINapIKFig4-37Ramp.npz'

    iSlope = 360.0 / 100.0

    def i(t, iSlope=iSlope):
        return (current0 + iSlope * t)

    iNapIKModel = INapIKModel.getLowThresholdInstance(i=i)
    # integrator = ode(iNapIKModel.deriv).set_integrator('vode', max_step=dt)
    integrator = ode(iNapIKModel.deriv).set_integrator('vode')

    y0 = [v0, n0]
    integrator.set_initial_value(y0, t0)
    ys = [y0]
    times = [t0]
    currents = [i(t0)]

    step = 0
    t = t0
    y = y0
    successfulIntegration = True
    while successfulIntegration and t < tf:
        step = step + 1
        if step % 10000 == 0:
            print('Processing time %.05f out of %.02f (%.02f, %.02f)' %
                  (t, tf, y[0], y[1]))
            sys.stdout.flush()
        integrator.integrate(t + dt)
        t = integrator.t
        y = integrator.y
        times.append(t)
        ys.append(y.tolist())
        currents.append(i(t))
    timesArray = np.array(times)
    ysArray = buildMatrixFromArraysList(arraysList=ys)
    currentsArray = np.array(currents)
    np.savez(resultsFilename,
             times=timesArray,
             ys=ysArray,
             currents=currentsArray)
def main(argv):
    a = 7.0 / 8.0
    b = 2.0
    c = 1.0
    x0 = 0.6
    y0 = 1.2
    t0 = 0.0
    tf = 15.0
    dt = 1e-5
    resultsFilenamePattern = "results/integrationA%fB%fC%fX0%fY0%f.npz"%\
                              (a, b, c, x0, y0)

    def deriv(self, t, y):
        x = y[0]
        y = y[1]
        f = lambda x, y: a + x**2 - y
        g = lambda x, y: b * x - c * y
        xDot = f(x=x, y=y)
        yDot = f(x=x, y=y)
        return (np.array([xDot, yDot]))

    integrator = ode(deriv).set_integrator('vode')

    y0 = np.array([x0, y0])
    integrator.set_initial_value(y0, t0)
    ys = [y0]
    times = [t0]

    step = 0
    t = t0
    y = y0
    successfulIntegration = True
    while successfulIntegration and t < tf:
        step = step + 1
        if step % 10000 == 0:
            print('Processing time %.05f out of %.02f (%.02f, %.02f)' %
                  (t, tf, y[0], y[1]))
            sys.stdout.flush()
        integrator.integrate(t + dt)
        t = integrator.t
        y = integrator.y
        times.append(t)
        ys.append(y.tolist())
    timesArray = np.array(times)
    ysArray = buildMatrixFromArraysList(arraysList=ys)

    np.savez(resultsFilename, times=timesArray, ys=ysArray)
def main(argv):
    i0 = 10.0

    v0 = -60.00
    n0 = 0.0008
    t0 = 0.0
    tf = 140.0
    dt = 1e-4
    current0 = 0.0
    timeWinToSearchForUnstableFocus = (10, 80)

    iSlope = 30.0 / 100.0

    def i(t, iSlope=iSlope):
        return (current0 + iSlope * t)

    iNapIKModel = INapIKModel.getLowThresholdInstance(i=i)
    integrator = ode(iNapIKModel.deriv).set_integrator('vode', max_step=dt)

    y0 = [v0, n0]
    integrator.set_initial_value(y0, t0)
    ys = [y0]
    times = [t0]
    stabilityType, eigenValues, jacobian = \
     iNapIKModel.checkStability(v0=v0, n0=n0)
    stabilityTypes = [stabilityType]
    eigenValuesList = [eigenValues.tolist()]
    jacobiansList = [jacobian.flatten().tolist()]
    step = 0
    t = t0
    y = y0
    successfulIntegration = True
    while successfulIntegration and t < tf:
        step = step + 1
        if step % 10 == 0:
            print('Processing time %.05f out of %.02f (i=%.02f)' %
                  (t, tf, i(t=t)))
            sys.stdout.flush()
        integrator.integrate(t + dt)
        t = integrator.t
        y = integrator.y
        times.append(t)
        ys.append(y.tolist())
        v = y[0]
        n = y[1]
        stabilityType, eigenValues, jacobian = \
         iNapIKModel.checkStability(v0=v, n0=n)
        stabilityTypes.append(stabilityType)
        eigenValuesList.append(eigenValues.tolist())
        jacobiansList.append(jacobian.flatten().tolist())
    timesArray = np.array(times)
    ysArray = buildMatrixFromArraysList(arraysList=ys)
    eigenValuesArray = buildMatrixFromArraysList(arraysList=eigenValuesList)
    stabilityTypesArray = np.array(stabilityTypes)
    unstableFocusIndices = np.where(
        stabilityTypesArray == iNapIKModel.UNSTABLE_FOCUS)[0]
    timeWinIndices = np.where(
        np.logical_and(timeWinToSearchForUnstableFocus[0] <= timesArray,
                       timesArray <= timeWinToSearchForUnstableFocus[1]))[0]
    validUnstableFocusIndices = np.intersect1d(ar1=unstableFocusIndices,
                                               ar2=timeWinIndices)
    bifurcationIndex = validUnstableFocusIndices[0]
    iAtBifurcation = i(t=timesArray[bifurcationIndex])
    jacobianAtBifurcation = np.reshape(a=jacobiansList[bifurcationIndex],
                                       newshape=(2, 2))
    print("Input current at bifurcation: %.08f" % iAtBifurcation)
    print("V at bifurcation: %.08f" % (ysArray[0, bifurcationIndex]))
    print("n at bifurcation: %.08f" % ysArray[1, bifurcationIndex])
    print("Jacobian at bifurcation: [[%.08f,%.08f],[%.08f,%.08f]]" %
          (jacobianAtBifurcation[0, 0], jacobianAtBifurcation[0, 1],
           jacobianAtBifurcation[1, 0], jacobianAtBifurcation[1, 1]))
    print("Eigenvalues at bifurcation: %.08f+j%.08f, %.08f+j%.08f" %
          (eigenValuesArray[0, bifurcationIndex].real,
           eigenValuesArray[0, bifurcationIndex].imag,
           eigenValuesArray[1, bifurcationIndex].real,
           eigenValuesArray[1, bifurcationIndex].imag))

    plt.plot(i(timesArray), eigenValuesArray[0, :].real)
    plt.xlabel("Input Current")
    plt.ylabel("Real Part of Eigenvalues")
    plt.axhline(y=0, color="grey")
    plt.axvline(x=iAtBifurcation, color="grey")
    plt.show()
    pdb.set_trace()