2022-10-04 • Use faster curve fit for connection inference

2022-10-04 • Use faster curve fit for connection inference

As we saw in the previous notebook, we can get away with way fewer Levenberg-Marquardt steps (see here for more on that algo) to get a decent fit: the difference in fit quality between 10 and the default ~350 iterations is not that big.

Imports

#
using MyToolbox
@time_imports using VoltoMapSim
[ Info: Precompiling VoltoMapSim [f713100b-c48c-421a-b480-5fcb4c589a9e]
[ Info: Skipping precompilation since __precompile__(false). Importing VoltoMapSim [f713100b-c48c-421a-b480-5fcb4c589a9e].
[ Info: Precompiling Sciplotlib [61be95e5-9550-4d5f-a203-92a5acbc3116]
[ Info: Running Sciplotlib._precompile_
   1072.4 ms  Unitful
   1752.6 ms  Sciplotlib 51.23% compilation time
[ Info: Precompiling LsqFit [2fda8390-95c7-5789-9bda-21331edee243]
     25.5 ms  FiniteDiff 34.90% compilation time
     14.9 ms  NLSolversBase
      6.2 ms  LsqFit

The faster modelling code has been consolidated in the codebase (src/infer/model_STA.jl).

Params

p = get_params(
    duration = 10minutes,
    p_conn = 0.04,
    g_EE = 1, g_EI = 1, g_IE = 4, g_II = 4,
    ext_current = Normal(-0.5 * pA/√seconds, 5 * pA/√seconds),
    E_inh = -80 * mV,
    record_v = [1:40; 801:810],
);

Load STA’s

Load all STA’s

Skip this section if you want just one.

out = cached_STAs(p);
Loading cached output from `C:\Users\tfiers\.phdcache\calc_all_STAs\b9353bdd11d8b8cb.jld2` … done (16.9 s)
(ct, STAs, shuffled_STAs) = out;
α = 0.05 
conns = ct.pre .=> ct.post
example_conn(typ) = conns[findfirst(ct.conntype .== typ)]
conn = example_conn(:exc)  # 139 => 1
139 => 1
STA = copy(STAs[conn]);

Load 1 STA

path = cachepath("2022-10-04__inspect_curve_fit", "STA");
# savecache(path, STA);
# using SnoopCompile
# tinf = @snoopi_deep loadcache(path);
@time STA = loadcache(path);

Test one

fit, model = STA_modelling_funcs(p);
@time fit(STA, maxIter=10);  # compile
 27.393178 seconds (23.28 M allocations: 1.119 GiB, 14.36% gc time, 99.67% compilation time: 0% of which was recompilation)
fitfunc = fit $ (; maxIter = 10)
testfunc = modelfit_test $ (; modelling_funcs = (fitfunc, model))
test_conn(testfunc, STAs[conn], shuffled_STAs[conn])
(predtype = :exc, pval = 0.01, pval_type = "<", Eness = 0.379)
@time test_conn(testfunc, STAs[conn], shuffled_STAs[conn]);
  0.394131 seconds (10.52 k allocations: 19.963 MiB, 11.45% gc time)

This used to be 5.8 seconds (or even 50 seconds).

Test sample

samplesize = 100
resetrng!(1234)
i = sample(1:nrow(ct), samplesize, replace = false)
ctsample = ct[i, :];
summarize_conns_to_test(ctsample)
We test 100 putative input connections to 45 neurons.
32 of those connections are excitatory, 15 are inhibitory, and the remaining 53 are non-connections.
tc = test_conns(testfunc, ctsample, STAs, shuffled_STAs, α = 0.05);
Testing connections: 100%|██████████████████████████████| Time: 0:00:40
perftable(tc)
Tested connections: 100                                                                                
┌───────Real type───────┐Precision
unconnexcinh
unconn4412276%
Predicted typeexc320087%
inh601368%
Sensitivity83%62%87%
tc[(tc.conntype .== :exc), :] 
32×8 DataFrame
7 rows omitted
Rowposttypepostpreconntypepredtypepvalpval_typeEness
SymbolInt64Int64SymbolSymbolFloat64StringFloat64
1exc17207excexc0.01<2
2exc35171excexc0.01<2
3exc29682excunconn0.11=0.075
4exc7161excexc0.01<0.885
5exc39178excexc0.02=0.284
6exc19515excexc0.02=0.108
7exc36648excunconn0.59=0.0565
8inh803757excexc0.01<0.705
9exc39352excunconn0.19=0.0613
10exc14781excunconn0.33=0.263
11exc2820excunconn0.95=0.0152
12inh81098excunconn0.59=0.164
13exc36760excexc0.01<1.1
&vellip;&vellip;&vellip;&vellip;&vellip;&vellip;&vellip;&vellip;&vellip;
21exc29760excunconn0.28=0.32
22exc174excunconn0.33=0.0108
23exc1447excexc0.01<1.59
24exc26516excexc0.01<2
25inh80633excexc0.01<0.719
26exc19282excunconn0.69=0.242
27inh805502excexc0.01<0.644
28exc25237excexc0.04=0.148
29exc2779excexc0.01<0.831
30exc18770excunconn0.62=-0.127
31inh801206excexc0.01<2
32exc6451excexc0.01<0.737
(julia.exe:20956): Gdk-CRITICAL **: 23:49:46.013: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed

(julia.exe:20956): Gdk-CRITICAL **: 23:49:46.942: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed

(julia.exe:20956): Gdk-CRITICAL **: 23:49:46.991: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed

(julia.exe:20956): Gdk-CRITICAL **: 11:26:25.302: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed

(julia.exe:20956): Gdk-CRITICAL **: 11:26:26.472: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed

(julia.exe:20956): Gdk-CRITICAL **: 11:26:26.626: gdk_seat_default_remove_tool: assertion 'tool != NULL' failed
plotsig(STAs[20=>28] / mV, p);
plotsig(STAs[451=>6] / mV, p);
plotsig(STAs[770=>18] / mV, p);
plotsig(STAs[33=>806] / mV, p);
../_images/2022-10-07__Conntest_with_faster_curve_fit_33_0.png

oh ow, is this the nonlinearity of Izhikevich at play? (Weaker excitation at lower voltages). Hm or is that sth else (nb).