Skip to content

Commit

Permalink
xcorr func :) spikes only main thang done (bad perf vs VI (: )
Browse files Browse the repository at this point in the history
  • Loading branch information
tfiers committed Apr 18, 2024
1 parent 585e89e commit ac2cf06
Show file tree
Hide file tree
Showing 6 changed files with 1,497 additions and 50 deletions.
114 changes: 68 additions & 46 deletions nb/2024-04-10__Overview-figure.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"id": "02610716",
"id": "b55548c7",
"metadata": {},
"source": [
"# 2024-04-10 · Overview figure"
Expand All @@ -11,7 +11,7 @@
{
"cell_type": "code",
"execution_count": 80,
"id": "37046b52",
"id": "350435d7",
"metadata": {},
"outputs": [
{
Expand All @@ -30,7 +30,7 @@
},
{
"cell_type": "markdown",
"id": "7f41c0d2",
"id": "084901d0",
"metadata": {},
"source": [
"## Sim"
Expand All @@ -39,7 +39,7 @@
{
"cell_type": "code",
"execution_count": 15,
"id": "355d9ab2",
"id": "b3a0c29e",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -51,7 +51,7 @@
{
"cell_type": "code",
"execution_count": 16,
"id": "8d6e9c69",
"id": "c2560239",
"metadata": {},
"outputs": [
{
Expand All @@ -69,7 +69,7 @@
{
"cell_type": "code",
"execution_count": 44,
"id": "88a2caef",
"id": "4efffc64",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -79,7 +79,7 @@
{
"cell_type": "code",
"execution_count": 45,
"id": "0dfacc8c",
"id": "f40b147d",
"metadata": {},
"outputs": [
{
Expand All @@ -100,7 +100,7 @@
{
"cell_type": "code",
"execution_count": 49,
"id": "e2acc0a1",
"id": "a86541e5",
"metadata": {},
"outputs": [
{
Expand All @@ -126,7 +126,7 @@
{
"cell_type": "code",
"execution_count": 66,
"id": "aa66d86b",
"id": "530b9ce6",
"metadata": {},
"outputs": [
{
Expand All @@ -148,7 +148,7 @@
{
"cell_type": "code",
"execution_count": 67,
"id": "50da60ce",
"id": "3bdbc747",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -158,7 +158,7 @@
{
"cell_type": "code",
"execution_count": 68,
"id": "7dfe4d9f",
"id": "b2b4ff04",
"metadata": {},
"outputs": [
{
Expand All @@ -183,15 +183,15 @@
},
{
"cell_type": "markdown",
"id": "8f6eb707",
"id": "99e37fd0",
"metadata": {},
"source": [
"---"
]
},
{
"cell_type": "markdown",
"id": "f6c87a43",
"id": "64430f0f",
"metadata": {},
"source": [
"Aside: Otsu-like method to find spike / clipping threshold?"
Expand All @@ -200,7 +200,7 @@
{
"cell_type": "code",
"execution_count": 55,
"id": "99b92ac0",
"id": "c313b675",
"metadata": {},
"outputs": [
{
Expand All @@ -225,31 +225,31 @@
},
{
"cell_type": "markdown",
"id": "f3dcd6ce",
"id": "0c58e222",
"metadata": {},
"source": [
"So yes it seems possible (given that our percentile is ± right..). But let's skip here and take fixed pctile value as threshold."
]
},
{
"cell_type": "markdown",
"id": "18b40cf6",
"id": "0a7c2571",
"metadata": {},
"source": [
"Although: setting all those ceiled values to e.g. 0mV is still not good (They're still peaks, so still lotsa noise added). Better if they're set to e.g. the mean (around -58 mV) or somehow excluded."
]
},
{
"cell_type": "markdown",
"id": "db92d42c",
"id": "92240923",
"metadata": {},
"source": [
"----"
]
},
{
"cell_type": "markdown",
"id": "fa267359",
"id": "18317bc0",
"metadata": {},
"source": [
"## Test"
Expand All @@ -258,35 +258,50 @@
{
"cell_type": "code",
"execution_count": 94,
"id": "97b47c47",
"id": "f869f1bd",
"metadata": {},
"outputs": [],
"source": [
"highest_firing_inputs = get_trains_to_test(sim, Nₜ=10);"
"highest_firing_inputs = get_trains_to_test(sim, Nₜ = 10);"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "c2ca7860",
"id": "ee8df68c",
"metadata": {},
"outputs": [],
"source": [
"linefit_method = ConnectionTests.FitUpstroke(\n",
" winsize=100, # 10 ms\n",
" offset=0,\n",
" winsize = 100, # 10 ms\n",
" offset = 0,\n",
")\n",
"linefit_test(sig, spiketimes) = test_conn(linefit_method, sig, spiketimes);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "688aef2a",
"metadata": {},
"outputs": [],
"source": [
"function spike_corr_test(post_spikes, pre_spikes)\n",
" # weird arg order is remnant of voltage based conntests function signature:\n",
" # `test(sig, spikes)` ('big arg first' convention)\n",
" \n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "be6fbc0b",
"id": "cfac1ded",
"metadata": {},
"outputs": [],
"source": [
"conntest_methods = [\n",
" (\"Spikes-only\", spike_corr_test),\n",
" (\"STA height\", STA_test),\n",
" (\"Line fit\", linefit_test),\n",
"];"
Expand All @@ -295,7 +310,7 @@
{
"cell_type": "code",
"execution_count": 103,
"id": "b8f96c20",
"id": "1f39102e",
"metadata": {},
"outputs": [
{
Expand All @@ -312,47 +327,47 @@
},
{
"cell_type": "code",
"execution_count": 104,
"id": "1c05517a",
"execution_count": 109,
"id": "c1a365ed",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[32mexc 100%|████████████████████████████████████████████████| Time: 0:00:03\u001b[39m\n",
"\u001b[32mexc 100%|████████████████████████████████████████████████| Time: 0:00:04\u001b[39m\n",
"\u001b[32minh 100%|████████████████████████████████████████████████| Time: 0:00:02\u001b[39m\n",
"\u001b[32munc 100%|████████████████████████████████████████████████| Time: 0:00:02\u001b[39m\n",
"\u001b[32mexc 100%|████████████████████████████████████████████████| Time: 0:00:01\u001b[39m\n",
"\u001b[32minh 100%|████████████████████████████████████████████████| Time: 0:00:00\u001b[39m\n",
"\u001b[32munc 100%|████████████████████████████████████████████████| Time: 0:00:00\u001b[39m\n"
"\u001b[32minh 100%|████████████████████████████████████████████████| Time: 0:00:01\u001b[39m\n",
"\u001b[32munc 100%|████████████████████████████████████████████████| Time: 0:00:01\u001b[39m\n"
]
},
{
"data": {
"text/html": [
"<div><div style = \"float: left;\"><span>2×3 DataFrame</span></div><div style = \"clear: both;\"></div></div><div class = \"data-frame\" style = \"overflow-x: scroll;\"><table class = \"data-frame\" style = \"margin-bottom: 6px;\"><thead><tr class = \"header\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">Row</th><th style = \"text-align: left;\">method</th><th style = \"text-align: left;\">AUC</th><th style = \"text-align: left;\">F1max</th></tr><tr class = \"subheader headerLastRow\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\"></th><th title = \"String\" style = \"text-align: left;\">String</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th></tr></thead><tbody><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">1</td><td style = \"text-align: left;\">STA height</td><td style = \"text-align: right;\">0.5</td><td style = \"text-align: right;\">0.714</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">2</td><td style = \"text-align: left;\">Line fit</td><td style = \"text-align: right;\">0.805</td><td style = \"text-align: right;\">0.833</td></tr></tbody></table></div>"
"<div><div style = \"float: left;\"><span>2×4 DataFrame</span></div><div style = \"clear: both;\"></div></div><div class = \"data-frame\" style = \"overflow-x: scroll;\"><table class = \"data-frame\" style = \"margin-bottom: 6px;\"><thead><tr class = \"header\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">Row</th><th style = \"text-align: left;\">method</th><th style = \"text-align: left;\">AUC</th><th style = \"text-align: left;\">F1max</th><th style = \"text-align: left;\">compute_time</th></tr><tr class = \"subheader headerLastRow\"><th class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\"></th><th title = \"String\" style = \"text-align: left;\">String</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th><th title = \"Float64\" style = \"text-align: left;\">Float64</th></tr></thead><tbody><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">1</td><td style = \"text-align: left;\">STA height</td><td style = \"text-align: right;\">0.5</td><td style = \"text-align: right;\">0.714</td><td style = \"text-align: right;\">9.62</td></tr><tr><td class = \"rowNumber\" style = \"font-weight: bold; text-align: right;\">2</td><td style = \"text-align: left;\">Line fit</td><td style = \"text-align: right;\">0.805</td><td style = \"text-align: right;\">0.833</td><td style = \"text-align: right;\">3.6</td></tr></tbody></table></div>"
],
"text/latex": [
"\\begin{tabular}{r|ccc}\n",
"\t& method & AUC & F1max\\\\\n",
"\\begin{tabular}{r|cccc}\n",
"\t& method & AUC & F1max & compute\\_time\\\\\n",
"\t\\hline\n",
"\t& String & Float64 & Float64\\\\\n",
"\t& String & Float64 & Float64 & Float64\\\\\n",
"\t\\hline\n",
"\t1 & STA height & 0.5 & 0.714 \\\\\n",
"\t2 & Line fit & 0.805 & 0.833 \\\\\n",
"\t1 & STA height & 0.5 & 0.714 & 9.62 \\\\\n",
"\t2 & Line fit & 0.805 & 0.833 & 3.6 \\\\\n",
"\\end{tabular}\n"
],
"text/plain": [
"\u001b[1m2×3 DataFrame\u001b[0m\n",
"\u001b[1m Row \u001b[0m│\u001b[1m method \u001b[0m\u001b[1m AUC \u001b[0m\u001b[1m F1max \u001b[0m\n",
"\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼──────────────────────────────\n",
" 1 │ STA height 0.5 0.714\n",
" 2 │ Line fit 0.805 0.833"
"\u001b[1m2×4 DataFrame\u001b[0m\n",
"\u001b[1m Row \u001b[0m│\u001b[1m method \u001b[0m\u001b[1m AUC \u001b[0m\u001b[1m F1max \u001b[0m\u001b[1m compute_time \u001b[0m\n",
"\u001b[90m String \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\u001b[90m Float64 \u001b[0m\n",
"─────┼────────────────────────────────────────────\n",
" 1 │ STA height 0.5 0.714 9.62\n",
" 2 │ Line fit 0.805 0.833 3.6"
]
},
"execution_count": 104,
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -361,8 +376,14 @@
"rows = []\n",
"\n",
"for (method, f) in conntest_methods\n",
" println(method)\n",
" if f == spike_corr_test\n",
" post_sig = sim.spiketimes\n",
" else\n",
" post_sig = sigc\n",
" end\n",
" t0 = time()\n",
" spiketrain_rows = test_inputs(sim, sigc, highest_firing_inputs, f)\n",
" spiketrain_rows = test_inputs(sim, post_sig, highest_firing_inputs, f)\n",
" compute_time = time() - t0\n",
" df = DataFrame(spiketrain_rows)\n",
" sweep = sweep_threshold(df)\n",
Expand All @@ -373,6 +394,7 @@
" compute_time,\n",
" )\n",
" push!(rows, row)\n",
" println()\n",
"end\n",
"\n",
"df = DataFrame(rows)"
Expand All @@ -381,7 +403,7 @@
{
"cell_type": "code",
"execution_count": 108,
"id": "fbd504d7",
"id": "693b7b77",
"metadata": {},
"outputs": [
{
Expand All @@ -408,7 +430,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "13af93c0",
"id": "36c8c2f4",
"metadata": {},
"outputs": [],
"source": []
Expand Down
24 changes: 20 additions & 4 deletions nb/2024-04-10__Overview-figure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ hist(sig[sig .> -42.1mV] / mV, xlabel="mV");

# ## Test

highest_firing_inputs = get_trains_to_test(sim, Nₜ=10);
highest_firing_inputs = get_trains_to_test(sim, Nₜ = 10);

linefit_method = ConnectionTests.FitUpstroke(
winsize=100, # 10 ms
offset=0,
winsize = 100, # 10 ms
offset = 0,
)
linefit_test(sig, spiketimes) = test_conn(linefit_method, sig, spiketimes);

# +
function spike_corr_test(post_spikes, pre_spikes)
# weird arg order is remnant of voltage based conntests function signature:
# `test(sig, spikes)` ('big arg first' convention)

end
# -

conntest_methods = [
("Spikes-only", spike_corr_test),
("STA height", STA_test),
("Line fit", linefit_test),
];
Expand All @@ -71,8 +80,14 @@ include("lib/df.jl")
rows = []

for (method, f) in conntest_methods
println(method)
if f == spike_corr_test
post_sig = sim.spiketimes
else
post_sig = sigc
end
t0 = time()
spiketrain_rows = test_inputs(sim, sigc, highest_firing_inputs, f)
spiketrain_rows = test_inputs(sim, post_sig, highest_firing_inputs, f)
compute_time = time() - t0
df = DataFrame(spiketrain_rows)
sweep = sweep_threshold(df)
Expand All @@ -83,6 +98,7 @@ for (method, f) in conntest_methods
compute_time,
)
push!(rows, row)
println()
end

df = DataFrame(rows)
Expand Down
Loading

0 comments on commit ac2cf06

Please sign in to comment.