# Example

In [ ]:
Copied!

    import diffrax as dfx
    import jax
    import jax.numpy as jnp
    import jax.random as jrand
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    from eventpropjax.evnn import FFEvNN

    from felice.neuron_models import FHN

import diffrax as dfx import jax import jax.numpy as jnp import jax.random as jrand import matplotlib as mpl import matplotlib.pyplot as plt from eventpropjax.evnn import FFEvNN from felice.neuron_models import FHN
In [2]:
Copied!

    key = jrand.key(0)
    max_time = 200

    snn = FFEvNN(
        layers=[1],
        in_size=1,
        neuron_model=FHN,
        solver=dfx.Dopri5(),
        max_solver_time=max_time,
        key=key,
        max_event_steps=1000000,
        solver_stepsize=0.1,
        init_weights=2.0,
    )

key = jrand.key(0) max_time = 200 snn = FFEvNN( layers=[1], in_size=1, neuron_model=FHN, solver=dfx.Dopri5(), max_solver_time=max_time, key=key, max_event_steps=1000000, solver_stepsize=0.1, init_weights=2.0, )
In [3]:
Copied!

    v_range = jnp.arange(-3.1, 3, 0.1)
    VI_inst = jax.vmap(snn.neuron_model.IV_inst)(v_range)
    VI_fast = jax.vmap(snn.neuron_model.IV_fast)(v_range)
    VI_slow = jax.vmap(snn.neuron_model.IV_slow)(v_range)

    with mpl.style.context("boilerplot.ieeetran"):
        fig, ax = plt.subplots(1, 3, figsize=(6.9, 2.3), dpi=200.0, sharey=True)
        ax[0].plot(v_range, VI_inst)
        ax[1].plot(v_range, VI_fast)
        ax[2].plot(v_range, VI_slow)
        plt.show()

v_range = jnp.arange(-3.1, 3, 0.1) VI_inst = jax.vmap(snn.neuron_model.IV_inst)(v_range) VI_fast = jax.vmap(snn.neuron_model.IV_fast)(v_range) VI_slow = jax.vmap(snn.neuron_model.IV_slow)(v_range) with mpl.style.context("boilerplot.ieeetran"): fig, ax = plt.subplots(1, 3, figsize=(6.9, 2.3), dpi=200.0, sharey=True) ax[0].plot(v_range, VI_inst) ax[1].plot(v_range, VI_fast) ax[2].plot(v_range, VI_slow) plt.show()
In [4]:
Copied!

    in_spikes = jnp.asarray([[0.00]])
    comp_times = jnp.linspace(0.0, max_time, 500)
    state = snn.state_at_t(in_spikes, comp_times)
    spikes = snn.spikes_until_t(in_spikes, max_time)

in_spikes = jnp.asarray([[0.00]]) comp_times = jnp.linspace(0.0, max_time, 500) state = snn.state_at_t(in_spikes, comp_times) spikes = snn.spikes_until_t(in_spikes, max_time)
In [5]:
Copied!

    with mpl.style.context("boilerplot.ieeetran"):
        fig, ax = plt.subplots(1, 2, figsize=(6.9, 2.6), dpi=200)
        ax[0].plot(comp_times, state[0, :, 0])
        ax[0].plot(comp_times, state[0, :, 1], "--")
        # ax[0].plot(comp_times, state[0, :, 2], "-.")
        [ax[0].axvline(s, alpha=0.2, color="g", linestyle="--") for s in jnp.unique(spikes)]
        ax[0].set_xlabel("Time (ms)")
        ax[0].legend(["v", "vslow", "syn", "Spike"])

        ax[1].plot(state[0, :, 0], state[0, :, 1])
        ax[1].plot(state[0, 0, 0], state[0, 0, 1], ".", label="start")
        ax[1].plot(state[0, -1, 0], state[0, -1, 1], ".", label="end")
        ax[1].set_xlabel("v")
        ax[1].set_ylabel("v fast")
        ax[1].legend()
        plt.show()

with mpl.style.context("boilerplot.ieeetran"): fig, ax = plt.subplots(1, 2, figsize=(6.9, 2.6), dpi=200) ax[0].plot(comp_times, state[0, :, 0]) ax[0].plot(comp_times, state[0, :, 1], "--") # ax[0].plot(comp_times, state[0, :, 2], "-.") [ax[0].axvline(s, alpha=0.2, color="g", linestyle="--") for s in jnp.unique(spikes)] ax[0].set_xlabel("Time (ms)") ax[0].legend(["v", "vslow", "syn", "Spike"]) ax[1].plot(state[0, :, 0], state[0, :, 1]) ax[1].plot(state[0, 0, 0], state[0, 0, 1], ".", label="start") ax[1].plot(state[0, -1, 0], state[0, -1, 1], ".", label="end") ax[1].set_xlabel("v") ax[1].set_ylabel("v fast") ax[1].legend() plt.show()
In [ ]:
Copied!