<jupyter_start><jupyter_text>Model output<jupyter_code>tsample = 0.005 / 1000
stim = p2p.stimuli.PulseTrain(tsample, freq=20, amp=150, pulse_dur=0.45 / 1000, dur=0.5)
ecm = np.array([1, 1]).reshape((2, 1))
layers = ['GCL']
use_jit = True

nanduri = p2p.retina.Nanduri2012(tsample=tsample)
nanduri_out = nanduri.model_cascade(ecm, [stim.data], layers, use_jit)
nanduri_t = tsample * np.arange(len(nanduri_out.data))

legacy = LegacyNanduri2012(tsample=tsample)
legacy_out = legacy.model_cascade(ecm, [stim.data], layers, use_jit)
legacy_t = tsample * np.arange(len(legacy_out.data))
finite_diff_t, finite_diff_out = finite_diff(stim, nanduri)
cython_t, cython_out = cythoncascade(stim, nanduri)
plt.figure(figsize=(10, 5))
plt.plot(legacy_t, legacy_out.data, linewidth=10, label='Nanduri 2012 (Legacy)')
plt.plot(nanduri_t, nanduri_out.data, linewidth=5, label='Nanduri 2012 (Cython)')
plt.plot(cython_t, cython_out, linewidth=2, label='Finite difference (Cython)')
plt.legend(loc='lower right')<jupyter_output><empty_output><jupyter_text>Accuracy<jupyter_code>np.allclose(legacy_out.data, nanduri_out.data, atol=5e-3)
np.allclose(cython_out, nanduri_out.data, atol=5e-3)<jupyter_output><empty_output><jupyter_text>Speed Convolutions (pure Python):<jupyter_code>%timeit out = legacy.model_cascade(ecm, [stim.data], layers, use_jit)<jupyter_output>584 ms ± 17.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)<jupyter_text>Finite difference model (pure Python):<jupyter_code>%timeit out = finite_diff(stim, nanduri)<jupyter_output>698 ms ± 5.94 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)<jupyter_text>Finite difference model (naive Cython):<jupyter_code>%timeit out_R4 = cythoncascade(stim, nanduri)<jupyter_output>163 ms ± 844 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)<jupyter_text>Finite difference model (pulse2percept):<jupyter_code>%timeit out = nanduri.model_cascade(ecm, [stim.data], layers, use_jit)<jupyter_output>2.9 ms ± 15 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
{'fraction_non_alphanumeric': 0.13811881188118813, 'fraction_numerical': 0.04455445544554455, 'mean_word_length': 7.456066945606694, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '613265', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 918, 'n_tokens_neox': 828, 'n_words': 168, 'path': 'examples/notebooks/internal-0.3-finite-difference.ipynb', 'repo_name': 'jonluntzel/pulse2percept', 'size': '2020'}