diff --git a/doc/dev/index.rst b/doc/dev/index.rst index 17d4db34b9c8d6f3776ee3ecd9c4ed85823f621f..25fbb8f140c5e1175a4c485272d7f92c61d78336 100644 --- a/doc/dev/index.rst +++ b/doc/dev/index.rst @@ -27,4 +27,4 @@ Here we document internal components of Arbor. These pages can be useful if you' mechanism_abi util version -.. numerics + numerics diff --git a/doc/dev/numerics.rst b/doc/dev/numerics.rst index 1523aadda614fac31d5d23905d9908a54f630150..c4cd5bd3bd9116efaf3e268f36e8a61e73e143a0 100644 --- a/doc/dev/numerics.rst +++ b/doc/dev/numerics.rst @@ -18,3 +18,5 @@ Mechanisms Exponential Euler `cnexp`. Implicit Euler `sparse`. + +Euler-Maruyama (explicit Euler) `stochastic` diff --git a/doc/tutorial/calcium_stdp.svg b/doc/tutorial/calcium_stdp.svg new file mode 100644 index 0000000000000000000000000000000000000000..d9bea02d3e9bbdfe6194626e4b3e00c02e5962b0 --- /dev/null +++ b/doc/tutorial/calcium_stdp.svg @@ -0,0 +1,1204 @@ +<?xml version="1.0" encoding="utf-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="434.953987pt" height="346.979688pt" viewBox="0 0 434.953987 346.979688" xmlns="http://www.w3.org/2000/svg" version="1.1"> + <metadata> + <rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> + <cc:Work> + <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/> + <dc:date>2022-11-22T13:35:54.885511</dc:date> + <dc:format>image/svg+xml</dc:format> + <dc:creator> + <cc:Agent> + <dc:title>Matplotlib v3.6.2, https://matplotlib.org/</dc:title> + </cc:Agent> + </dc:creator> + </cc:Work> + </rdf:RDF> + </metadata> + <defs> + <style type="text/css">*{stroke-linejoin: round; stroke-linecap: butt}</style> + </defs> + <g id="figure_1"> + <g id="patch_1"> + <path d="M 0 346.979688 +L 434.953987 346.979688 +L 434.953987 0 +L 0 0 +z +" style="fill: #ffffff"/> + </g> + <g id="axes_1"> + <g id="patch_2"> + <path d="M 49.807188 304.02 +L 333.299988 304.02 +L 333.299988 7.2 +L 49.807188 7.2 +z +" style="fill: #eaeaf2"/> + </g> + <g id="matplotlib.axis_1"> + <g id="xtick_1"> + <g id="line2d_1"> + <path d="M 62.693224 304.02 +L 62.693224 7.2 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_1"> + <!-- −100 --> + <g style="fill: #262626" transform="translate(47.586271 321.878281) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-2212" d="M 678 2272 +L 4684 2272 +L 4684 1741 +L 678 1741 +L 678 2272 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-31" d="M 794 531 +L 1825 531 +L 1825 4091 +L 703 3866 +L 703 4441 +L 1819 4666 +L 2450 4666 +L 2450 531 +L 3481 531 +L 3481 0 +L 794 0 +L 794 531 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-30" d="M 2034 4250 +Q 1547 4250 1301 3770 +Q 1056 3291 1056 2328 +Q 1056 1369 1301 889 +Q 1547 409 2034 409 +Q 2525 409 2770 889 +Q 3016 1369 3016 2328 +Q 3016 3291 2770 3770 +Q 2525 4250 2034 4250 +z +M 2034 4750 +Q 2819 4750 3233 4129 +Q 3647 3509 3647 2328 +Q 3647 1150 3233 529 +Q 2819 -91 2034 -91 +Q 1250 -91 836 529 +Q 422 1150 422 2328 +Q 422 3509 836 4129 +Q 1250 4750 2034 4750 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-2212"/> + <use xlink:href="#DejaVuSans-31" x="83.789062"/> + <use xlink:href="#DejaVuSans-30" x="147.412109"/> + <use xlink:href="#DejaVuSans-30" x="211.035156"/> + </g> + </g> + </g> + <g id="xtick_2"> + <g id="line2d_2"> + <path d="M 127.123406 304.02 +L 127.123406 7.2 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_2"> + <!-- −50 --> + <g style="fill: #262626" transform="translate(115.515828 321.878281) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-35" d="M 691 4666 +L 3169 4666 +L 3169 4134 +L 1269 4134 +L 1269 2991 +Q 1406 3038 1543 3061 +Q 1681 3084 1819 3084 +Q 2600 3084 3056 2656 +Q 3513 2228 3513 1497 +Q 3513 744 3044 326 +Q 2575 -91 1722 -91 +Q 1428 -91 1123 -41 +Q 819 9 494 109 +L 494 744 +Q 775 591 1075 516 +Q 1375 441 1709 441 +Q 2250 441 2565 725 +Q 2881 1009 2881 1497 +Q 2881 1984 2565 2268 +Q 2250 2553 1709 2553 +Q 1456 2553 1204 2497 +Q 953 2441 691 2322 +L 691 4666 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-2212"/> + <use xlink:href="#DejaVuSans-35" x="83.789062"/> + <use xlink:href="#DejaVuSans-30" x="147.412109"/> + </g> + </g> + </g> + <g id="xtick_3"> + <g id="line2d_3"> + <path d="M 191.553588 304.02 +L 191.553588 7.2 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_3"> + <!-- 0 --> + <g style="fill: #262626" transform="translate(188.054213 321.878281) scale(0.11 -0.11)"> + <use xlink:href="#DejaVuSans-30"/> + </g> + </g> + </g> + <g id="xtick_4"> + <g id="line2d_4"> + <path d="M 255.983769 304.02 +L 255.983769 7.2 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_4"> + <!-- 50 --> + <g style="fill: #262626" transform="translate(248.985019 321.878281) scale(0.11 -0.11)"> + <use xlink:href="#DejaVuSans-35"/> + <use xlink:href="#DejaVuSans-30" x="63.623047"/> + </g> + </g> + </g> + <g id="xtick_5"> + <g id="line2d_5"> + <path d="M 320.413951 304.02 +L 320.413951 7.2 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_5"> + <!-- 100 --> + <g style="fill: #262626" transform="translate(309.915826 321.878281) scale(0.11 -0.11)"> + <use xlink:href="#DejaVuSans-31"/> + <use xlink:href="#DejaVuSans-30" x="63.623047"/> + <use xlink:href="#DejaVuSans-30" x="127.246094"/> + </g> + </g> + </g> + <g id="text_6"> + <!-- lag time difference (ms) --> + <g style="fill: #262626" transform="translate(119.2639 337.284063) scale(0.12 -0.12)"> + <defs> + <path id="DejaVuSans-6c" d="M 603 4863 +L 1178 4863 +L 1178 0 +L 603 0 +L 603 4863 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-61" d="M 2194 1759 +Q 1497 1759 1228 1600 +Q 959 1441 959 1056 +Q 959 750 1161 570 +Q 1363 391 1709 391 +Q 2188 391 2477 730 +Q 2766 1069 2766 1631 +L 2766 1759 +L 2194 1759 +z +M 3341 1997 +L 3341 0 +L 2766 0 +L 2766 531 +Q 2569 213 2275 61 +Q 1981 -91 1556 -91 +Q 1019 -91 701 211 +Q 384 513 384 1019 +Q 384 1609 779 1909 +Q 1175 2209 1959 2209 +L 2766 2209 +L 2766 2266 +Q 2766 2663 2505 2880 +Q 2244 3097 1772 3097 +Q 1472 3097 1187 3025 +Q 903 2953 641 2809 +L 641 3341 +Q 956 3463 1253 3523 +Q 1550 3584 1831 3584 +Q 2591 3584 2966 3190 +Q 3341 2797 3341 1997 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-67" d="M 2906 1791 +Q 2906 2416 2648 2759 +Q 2391 3103 1925 3103 +Q 1463 3103 1205 2759 +Q 947 2416 947 1791 +Q 947 1169 1205 825 +Q 1463 481 1925 481 +Q 2391 481 2648 825 +Q 2906 1169 2906 1791 +z +M 3481 434 +Q 3481 -459 3084 -895 +Q 2688 -1331 1869 -1331 +Q 1566 -1331 1297 -1286 +Q 1028 -1241 775 -1147 +L 775 -588 +Q 1028 -725 1275 -790 +Q 1522 -856 1778 -856 +Q 2344 -856 2625 -561 +Q 2906 -266 2906 331 +L 2906 616 +Q 2728 306 2450 153 +Q 2172 0 1784 0 +Q 1141 0 747 490 +Q 353 981 353 1791 +Q 353 2603 747 3093 +Q 1141 3584 1784 3584 +Q 2172 3584 2450 3431 +Q 2728 3278 2906 2969 +L 2906 3500 +L 3481 3500 +L 3481 434 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-20" transform="scale(0.015625)"/> + <path id="DejaVuSans-74" d="M 1172 4494 +L 1172 3500 +L 2356 3500 +L 2356 3053 +L 1172 3053 +L 1172 1153 +Q 1172 725 1289 603 +Q 1406 481 1766 481 +L 2356 481 +L 2356 0 +L 1766 0 +Q 1100 0 847 248 +Q 594 497 594 1153 +L 594 3053 +L 172 3053 +L 172 3500 +L 594 3500 +L 594 4494 +L 1172 4494 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-69" d="M 603 3500 +L 1178 3500 +L 1178 0 +L 603 0 +L 603 3500 +z +M 603 4863 +L 1178 4863 +L 1178 4134 +L 603 4134 +L 603 4863 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-6d" d="M 3328 2828 +Q 3544 3216 3844 3400 +Q 4144 3584 4550 3584 +Q 5097 3584 5394 3201 +Q 5691 2819 5691 2113 +L 5691 0 +L 5113 0 +L 5113 2094 +Q 5113 2597 4934 2840 +Q 4756 3084 4391 3084 +Q 3944 3084 3684 2787 +Q 3425 2491 3425 1978 +L 3425 0 +L 2847 0 +L 2847 2094 +Q 2847 2600 2669 2842 +Q 2491 3084 2119 3084 +Q 1678 3084 1418 2786 +Q 1159 2488 1159 1978 +L 1159 0 +L 581 0 +L 581 3500 +L 1159 3500 +L 1159 2956 +Q 1356 3278 1631 3431 +Q 1906 3584 2284 3584 +Q 2666 3584 2933 3390 +Q 3200 3197 3328 2828 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-65" d="M 3597 1894 +L 3597 1613 +L 953 1613 +Q 991 1019 1311 708 +Q 1631 397 2203 397 +Q 2534 397 2845 478 +Q 3156 559 3463 722 +L 3463 178 +Q 3153 47 2828 -22 +Q 2503 -91 2169 -91 +Q 1331 -91 842 396 +Q 353 884 353 1716 +Q 353 2575 817 3079 +Q 1281 3584 2069 3584 +Q 2775 3584 3186 3129 +Q 3597 2675 3597 1894 +z +M 3022 2063 +Q 3016 2534 2758 2815 +Q 2500 3097 2075 3097 +Q 1594 3097 1305 2825 +Q 1016 2553 972 2059 +L 3022 2063 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-64" d="M 2906 2969 +L 2906 4863 +L 3481 4863 +L 3481 0 +L 2906 0 +L 2906 525 +Q 2725 213 2448 61 +Q 2172 -91 1784 -91 +Q 1150 -91 751 415 +Q 353 922 353 1747 +Q 353 2572 751 3078 +Q 1150 3584 1784 3584 +Q 2172 3584 2448 3432 +Q 2725 3281 2906 2969 +z +M 947 1747 +Q 947 1113 1208 752 +Q 1469 391 1925 391 +Q 2381 391 2643 752 +Q 2906 1113 2906 1747 +Q 2906 2381 2643 2742 +Q 2381 3103 1925 3103 +Q 1469 3103 1208 2742 +Q 947 2381 947 1747 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-66" d="M 2375 4863 +L 2375 4384 +L 1825 4384 +Q 1516 4384 1395 4259 +Q 1275 4134 1275 3809 +L 1275 3500 +L 2222 3500 +L 2222 3053 +L 1275 3053 +L 1275 0 +L 697 0 +L 697 3053 +L 147 3053 +L 147 3500 +L 697 3500 +L 697 3744 +Q 697 4328 969 4595 +Q 1241 4863 1831 4863 +L 2375 4863 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-72" d="M 2631 2963 +Q 2534 3019 2420 3045 +Q 2306 3072 2169 3072 +Q 1681 3072 1420 2755 +Q 1159 2438 1159 1844 +L 1159 0 +L 581 0 +L 581 3500 +L 1159 3500 +L 1159 2956 +Q 1341 3275 1631 3429 +Q 1922 3584 2338 3584 +Q 2397 3584 2469 3576 +Q 2541 3569 2628 3553 +L 2631 2963 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-6e" d="M 3513 2113 +L 3513 0 +L 2938 0 +L 2938 2094 +Q 2938 2591 2744 2837 +Q 2550 3084 2163 3084 +Q 1697 3084 1428 2787 +Q 1159 2491 1159 1978 +L 1159 0 +L 581 0 +L 581 3500 +L 1159 3500 +L 1159 2956 +Q 1366 3272 1645 3428 +Q 1925 3584 2291 3584 +Q 2894 3584 3203 3211 +Q 3513 2838 3513 2113 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-63" d="M 3122 3366 +L 3122 2828 +Q 2878 2963 2633 3030 +Q 2388 3097 2138 3097 +Q 1578 3097 1268 2742 +Q 959 2388 959 1747 +Q 959 1106 1268 751 +Q 1578 397 2138 397 +Q 2388 397 2633 464 +Q 2878 531 3122 666 +L 3122 134 +Q 2881 22 2623 -34 +Q 2366 -91 2075 -91 +Q 1284 -91 818 406 +Q 353 903 353 1747 +Q 353 2603 823 3093 +Q 1294 3584 2113 3584 +Q 2378 3584 2631 3529 +Q 2884 3475 3122 3366 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-28" d="M 1984 4856 +Q 1566 4138 1362 3434 +Q 1159 2731 1159 2009 +Q 1159 1288 1364 580 +Q 1569 -128 1984 -844 +L 1484 -844 +Q 1016 -109 783 600 +Q 550 1309 550 2009 +Q 550 2706 781 3412 +Q 1013 4119 1484 4856 +L 1984 4856 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-73" d="M 2834 3397 +L 2834 2853 +Q 2591 2978 2328 3040 +Q 2066 3103 1784 3103 +Q 1356 3103 1142 2972 +Q 928 2841 928 2578 +Q 928 2378 1081 2264 +Q 1234 2150 1697 2047 +L 1894 2003 +Q 2506 1872 2764 1633 +Q 3022 1394 3022 966 +Q 3022 478 2636 193 +Q 2250 -91 1575 -91 +Q 1294 -91 989 -36 +Q 684 19 347 128 +L 347 722 +Q 666 556 975 473 +Q 1284 391 1588 391 +Q 1994 391 2212 530 +Q 2431 669 2431 922 +Q 2431 1156 2273 1281 +Q 2116 1406 1581 1522 +L 1381 1569 +Q 847 1681 609 1914 +Q 372 2147 372 2553 +Q 372 3047 722 3315 +Q 1072 3584 1716 3584 +Q 2034 3584 2315 3537 +Q 2597 3491 2834 3397 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-29" d="M 513 4856 +L 1013 4856 +Q 1481 4119 1714 3412 +Q 1947 2706 1947 2009 +Q 1947 1309 1714 600 +Q 1481 -109 1013 -844 +L 513 -844 +Q 928 -128 1133 580 +Q 1338 1288 1338 2009 +Q 1338 2731 1133 3434 +Q 928 4138 513 4856 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-6c"/> + <use xlink:href="#DejaVuSans-61" x="27.783203"/> + <use xlink:href="#DejaVuSans-67" x="89.0625"/> + <use xlink:href="#DejaVuSans-20" x="152.539062"/> + <use xlink:href="#DejaVuSans-74" x="184.326172"/> + <use xlink:href="#DejaVuSans-69" x="223.535156"/> + <use xlink:href="#DejaVuSans-6d" x="251.318359"/> + <use xlink:href="#DejaVuSans-65" x="348.730469"/> + <use xlink:href="#DejaVuSans-20" x="410.253906"/> + <use xlink:href="#DejaVuSans-64" x="442.041016"/> + <use xlink:href="#DejaVuSans-69" x="505.517578"/> + <use xlink:href="#DejaVuSans-66" x="533.300781"/> + <use xlink:href="#DejaVuSans-66" x="568.505859"/> + <use xlink:href="#DejaVuSans-65" x="603.710938"/> + <use xlink:href="#DejaVuSans-72" x="665.234375"/> + <use xlink:href="#DejaVuSans-65" x="704.097656"/> + <use xlink:href="#DejaVuSans-6e" x="765.621094"/> + <use xlink:href="#DejaVuSans-63" x="829"/> + <use xlink:href="#DejaVuSans-65" x="883.980469"/> + <use xlink:href="#DejaVuSans-20" x="945.503906"/> + <use xlink:href="#DejaVuSans-28" x="977.291016"/> + <use xlink:href="#DejaVuSans-6d" x="1016.304688"/> + <use xlink:href="#DejaVuSans-73" x="1113.716797"/> + <use xlink:href="#DejaVuSans-29" x="1165.816406"/> + </g> + </g> + </g> + <g id="matplotlib.axis_2"> + <g id="ytick_1"> + <g id="line2d_6"> + <path d="M 49.807188 290.690246 +L 333.299988 290.690246 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_7"> + <!-- 0.7 --> + <g style="fill: #262626" transform="translate(22.81375 294.869386) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-2e" d="M 684 794 +L 1344 794 +L 1344 0 +L 684 0 +L 684 794 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-37" d="M 525 4666 +L 3525 4666 +L 3525 4397 +L 1831 0 +L 1172 0 +L 2766 4134 +L 525 4134 +L 525 4666 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-30"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-37" x="95.410156"/> + </g> + </g> + </g> + <g id="ytick_2"> + <g id="line2d_7"> + <path d="M 49.807188 242.071081 +L 333.299988 242.071081 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_8"> + <!-- 0.8 --> + <g style="fill: #262626" transform="translate(22.81375 246.250222) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-38" d="M 2034 2216 +Q 1584 2216 1326 1975 +Q 1069 1734 1069 1313 +Q 1069 891 1326 650 +Q 1584 409 2034 409 +Q 2484 409 2743 651 +Q 3003 894 3003 1313 +Q 3003 1734 2745 1975 +Q 2488 2216 2034 2216 +z +M 1403 2484 +Q 997 2584 770 2862 +Q 544 3141 544 3541 +Q 544 4100 942 4425 +Q 1341 4750 2034 4750 +Q 2731 4750 3128 4425 +Q 3525 4100 3525 3541 +Q 3525 3141 3298 2862 +Q 3072 2584 2669 2484 +Q 3125 2378 3379 2068 +Q 3634 1759 3634 1313 +Q 3634 634 3220 271 +Q 2806 -91 2034 -91 +Q 1263 -91 848 271 +Q 434 634 434 1313 +Q 434 1759 690 2068 +Q 947 2378 1403 2484 +z +M 1172 3481 +Q 1172 3119 1398 2916 +Q 1625 2713 2034 2713 +Q 2441 2713 2670 2916 +Q 2900 3119 2900 3481 +Q 2900 3844 2670 4047 +Q 2441 4250 2034 4250 +Q 1625 4250 1398 4047 +Q 1172 3844 1172 3481 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-30"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-38" x="95.410156"/> + </g> + </g> + </g> + <g id="ytick_3"> + <g id="line2d_8"> + <path d="M 49.807188 193.451916 +L 333.299988 193.451916 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_9"> + <!-- 0.9 --> + <g style="fill: #262626" transform="translate(22.81375 197.631057) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-39" d="M 703 97 +L 703 672 +Q 941 559 1184 500 +Q 1428 441 1663 441 +Q 2288 441 2617 861 +Q 2947 1281 2994 2138 +Q 2813 1869 2534 1725 +Q 2256 1581 1919 1581 +Q 1219 1581 811 2004 +Q 403 2428 403 3163 +Q 403 3881 828 4315 +Q 1253 4750 1959 4750 +Q 2769 4750 3195 4129 +Q 3622 3509 3622 2328 +Q 3622 1225 3098 567 +Q 2575 -91 1691 -91 +Q 1453 -91 1209 -44 +Q 966 3 703 97 +z +M 1959 2075 +Q 2384 2075 2632 2365 +Q 2881 2656 2881 3163 +Q 2881 3666 2632 3958 +Q 2384 4250 1959 4250 +Q 1534 4250 1286 3958 +Q 1038 3666 1038 3163 +Q 1038 2656 1286 2365 +Q 1534 2075 1959 2075 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-30"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-39" x="95.410156"/> + </g> + </g> + </g> + <g id="ytick_4"> + <g id="line2d_9"> + <path d="M 49.807188 144.832752 +L 333.299988 144.832752 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_10"> + <!-- 1.0 --> + <g style="fill: #262626" transform="translate(22.81375 149.011892) scale(0.11 -0.11)"> + <use xlink:href="#DejaVuSans-31"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-30" x="95.410156"/> + </g> + </g> + </g> + <g id="ytick_5"> + <g id="line2d_10"> + <path d="M 49.807188 96.213587 +L 333.299988 96.213587 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_11"> + <!-- 1.1 --> + <g style="fill: #262626" transform="translate(22.81375 100.392728) scale(0.11 -0.11)"> + <use xlink:href="#DejaVuSans-31"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-31" x="95.410156"/> + </g> + </g> + </g> + <g id="ytick_6"> + <g id="line2d_11"> + <path d="M 49.807188 47.594423 +L 333.299988 47.594423 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #ffffff; stroke-linecap: round"/> + </g> + <g id="text_12"> + <!-- 1.2 --> + <g style="fill: #262626" transform="translate(22.81375 51.773563) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-32" d="M 1228 531 +L 3431 531 +L 3431 0 +L 469 0 +L 469 531 +Q 828 903 1448 1529 +Q 2069 2156 2228 2338 +Q 2531 2678 2651 2914 +Q 2772 3150 2772 3378 +Q 2772 3750 2511 3984 +Q 2250 4219 1831 4219 +Q 1534 4219 1204 4116 +Q 875 4013 500 3803 +L 500 4441 +Q 881 4594 1212 4672 +Q 1544 4750 1819 4750 +Q 2544 4750 2975 4387 +Q 3406 4025 3406 3419 +Q 3406 3131 3298 2873 +Q 3191 2616 2906 2266 +Q 2828 2175 2409 1742 +Q 1991 1309 1228 531 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-31"/> + <use xlink:href="#DejaVuSans-2e" x="63.623047"/> + <use xlink:href="#DejaVuSans-32" x="95.410156"/> + </g> + </g> + </g> + <g id="text_13"> + <!-- change in synaptic strenght (after/before) --> + <g style="fill: #262626" transform="translate(16.318125 281.545313) rotate(-90) scale(0.12 -0.12)"> + <defs> + <path id="DejaVuSans-68" d="M 3513 2113 +L 3513 0 +L 2938 0 +L 2938 2094 +Q 2938 2591 2744 2837 +Q 2550 3084 2163 3084 +Q 1697 3084 1428 2787 +Q 1159 2491 1159 1978 +L 1159 0 +L 581 0 +L 581 4863 +L 1159 4863 +L 1159 2956 +Q 1366 3272 1645 3428 +Q 1925 3584 2291 3584 +Q 2894 3584 3203 3211 +Q 3513 2838 3513 2113 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-79" d="M 2059 -325 +Q 1816 -950 1584 -1140 +Q 1353 -1331 966 -1331 +L 506 -1331 +L 506 -850 +L 844 -850 +Q 1081 -850 1212 -737 +Q 1344 -625 1503 -206 +L 1606 56 +L 191 3500 +L 800 3500 +L 1894 763 +L 2988 3500 +L 3597 3500 +L 2059 -325 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-70" d="M 1159 525 +L 1159 -1331 +L 581 -1331 +L 581 3500 +L 1159 3500 +L 1159 2969 +Q 1341 3281 1617 3432 +Q 1894 3584 2278 3584 +Q 2916 3584 3314 3078 +Q 3713 2572 3713 1747 +Q 3713 922 3314 415 +Q 2916 -91 2278 -91 +Q 1894 -91 1617 61 +Q 1341 213 1159 525 +z +M 3116 1747 +Q 3116 2381 2855 2742 +Q 2594 3103 2138 3103 +Q 1681 3103 1420 2742 +Q 1159 2381 1159 1747 +Q 1159 1113 1420 752 +Q 1681 391 2138 391 +Q 2594 391 2855 752 +Q 3116 1113 3116 1747 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-2f" d="M 1625 4666 +L 2156 4666 +L 531 -594 +L 0 -594 +L 1625 4666 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-62" d="M 3116 1747 +Q 3116 2381 2855 2742 +Q 2594 3103 2138 3103 +Q 1681 3103 1420 2742 +Q 1159 2381 1159 1747 +Q 1159 1113 1420 752 +Q 1681 391 2138 391 +Q 2594 391 2855 752 +Q 3116 1113 3116 1747 +z +M 1159 2969 +Q 1341 3281 1617 3432 +Q 1894 3584 2278 3584 +Q 2916 3584 3314 3078 +Q 3713 2572 3713 1747 +Q 3713 922 3314 415 +Q 2916 -91 2278 -91 +Q 1894 -91 1617 61 +Q 1341 213 1159 525 +L 1159 0 +L 581 0 +L 581 4863 +L 1159 4863 +L 1159 2969 +z +" transform="scale(0.015625)"/> + <path id="DejaVuSans-6f" d="M 1959 3097 +Q 1497 3097 1228 2736 +Q 959 2375 959 1747 +Q 959 1119 1226 758 +Q 1494 397 1959 397 +Q 2419 397 2687 759 +Q 2956 1122 2956 1747 +Q 2956 2369 2687 2733 +Q 2419 3097 1959 3097 +z +M 1959 3584 +Q 2709 3584 3137 3096 +Q 3566 2609 3566 1747 +Q 3566 888 3137 398 +Q 2709 -91 1959 -91 +Q 1206 -91 779 398 +Q 353 888 353 1747 +Q 353 2609 779 3096 +Q 1206 3584 1959 3584 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-63"/> + <use xlink:href="#DejaVuSans-68" x="54.980469"/> + <use xlink:href="#DejaVuSans-61" x="118.359375"/> + <use xlink:href="#DejaVuSans-6e" x="179.638672"/> + <use xlink:href="#DejaVuSans-67" x="243.017578"/> + <use xlink:href="#DejaVuSans-65" x="306.494141"/> + <use xlink:href="#DejaVuSans-20" x="368.017578"/> + <use xlink:href="#DejaVuSans-69" x="399.804688"/> + <use xlink:href="#DejaVuSans-6e" x="427.587891"/> + <use xlink:href="#DejaVuSans-20" x="490.966797"/> + <use xlink:href="#DejaVuSans-73" x="522.753906"/> + <use xlink:href="#DejaVuSans-79" x="574.853516"/> + <use xlink:href="#DejaVuSans-6e" x="634.033203"/> + <use xlink:href="#DejaVuSans-61" x="697.412109"/> + <use xlink:href="#DejaVuSans-70" x="758.691406"/> + <use xlink:href="#DejaVuSans-74" x="822.167969"/> + <use xlink:href="#DejaVuSans-69" x="861.376953"/> + <use xlink:href="#DejaVuSans-63" x="889.160156"/> + <use xlink:href="#DejaVuSans-20" x="944.140625"/> + <use xlink:href="#DejaVuSans-73" x="975.927734"/> + <use xlink:href="#DejaVuSans-74" x="1028.027344"/> + <use xlink:href="#DejaVuSans-72" x="1067.236328"/> + <use xlink:href="#DejaVuSans-65" x="1106.099609"/> + <use xlink:href="#DejaVuSans-6e" x="1167.623047"/> + <use xlink:href="#DejaVuSans-67" x="1231.001953"/> + <use xlink:href="#DejaVuSans-68" x="1294.478516"/> + <use xlink:href="#DejaVuSans-74" x="1357.857422"/> + <use xlink:href="#DejaVuSans-20" x="1397.066406"/> + <use xlink:href="#DejaVuSans-28" x="1428.853516"/> + <use xlink:href="#DejaVuSans-61" x="1467.867188"/> + <use xlink:href="#DejaVuSans-66" x="1529.146484"/> + <use xlink:href="#DejaVuSans-74" x="1562.601562"/> + <use xlink:href="#DejaVuSans-65" x="1601.810547"/> + <use xlink:href="#DejaVuSans-72" x="1663.333984"/> + <use xlink:href="#DejaVuSans-2f" x="1704.447266"/> + <use xlink:href="#DejaVuSans-62" x="1738.138672"/> + <use xlink:href="#DejaVuSans-65" x="1801.615234"/> + <use xlink:href="#DejaVuSans-66" x="1863.138672"/> + <use xlink:href="#DejaVuSans-6f" x="1898.34375"/> + <use xlink:href="#DejaVuSans-72" x="1959.525391"/> + <use xlink:href="#DejaVuSans-65" x="1998.388672"/> + <use xlink:href="#DejaVuSans-29" x="2059.912109"/> + </g> + </g> + </g> + <g id="PolyCollection_1"> + <defs> + <path id="me45bea305e" d="M 62.693224 -205.226149 +L 62.693224 -186.418636 +L 69.136242 -187.399122 +L 75.57926 -183.347525 +L 82.022278 -179.616004 +L 88.465297 -174.109884 +L 94.908315 -176.212663 +L 101.351333 -178.643621 +L 107.794351 -174.596076 +L 114.237369 -174.267896 +L 120.680388 -150.768633 +L 127.123406 -145.748705 +L 133.566424 -123.870081 +L 140.009442 -111.873302 +L 146.45246 -105.228683 +L 152.895478 -81.733471 +L 159.338497 -56.451506 +L 165.781515 -70.87114 +L 172.224533 -104.418363 +L 178.667551 -137.321383 +L 185.110569 -165.034307 +L 191.553588 -195.174137 +L 197.996606 -308.942982 +L 204.439624 -292.09239 +L 210.882642 -283.989196 +L 217.32566 -271.672341 +L 223.768678 -262.272636 +L 230.211697 -237.314798 +L 236.654715 -239.583692 +L 243.097733 -233.425265 +L 249.540751 -227.262786 +L 255.983769 -216.408557 +L 262.426788 -208.953619 +L 268.869806 -206.036469 +L 275.312824 -200.036054 +L 281.755842 -201.490577 +L 288.19886 -191.612783 +L 294.641878 -196.14652 +L 301.084897 -190.802464 +L 307.527915 -195.336201 +L 313.970933 -196.312636 +L 320.413951 -191.288656 +L 320.413951 -210.092117 +L 320.413951 -210.092117 +L 313.970933 -214.463791 +L 307.527915 -214.954034 +L 301.084897 -210.25013 +L 294.641878 -214.787918 +L 288.19886 -211.064501 +L 281.755842 -220.460154 +L 275.312824 -218.839516 +L 268.869806 -225.160007 +L 262.426788 -228.081208 +L 255.983769 -235.045904 +L 249.540751 -246.714503 +L 243.097733 -252.872931 +L 236.654715 -260.976125 +L 230.211697 -257.572783 +L 223.768678 -282.372609 +L 217.32566 -290.799931 +L 210.882642 -302.46853 +L 204.439624 -311.053864 +L 197.996606 -326.287869 +L 191.553588 -213.977599 +L 185.110569 -185.292292 +L 178.667551 -157.097228 +L 172.224533 -121.933417 +L 165.781515 -88.382142 +L 159.338497 -74.278533 +L 152.895478 -99.722562 +L 146.45246 -124.032145 +L 140.009442 -129.866444 +L 133.566424 -143.155683 +L 127.123406 -164.876294 +L 120.680388 -169.896223 +L 114.237369 -191.774847 +L 107.794351 -192.909294 +L 101.351333 -197.933275 +L 94.908315 -194.696049 +L 88.465297 -192.585167 +L 82.022278 -198.103442 +L 75.57926 -203.281383 +L 69.136242 -206.198533 +L 62.693224 -205.226149 +z +" style="stroke: #4c72b0; stroke-opacity: 0.2"/> + </defs> + <g clip-path="url(#pbda4021e28)"> + <use xlink:href="#me45bea305e" x="0" y="346.979688" style="fill: #4c72b0; fill-opacity: 0.2; stroke: #4c72b0; stroke-opacity: 0.2"/> + </g> + </g> + <g id="PolyCollection_2"/> + <g id="line2d_12"> + <path d="M 62.693224 150.667052 +L 69.136242 150.342924 +L 75.57926 153.260074 +L 82.022278 158.284054 +L 88.465297 163.95629 +L 94.908315 161.687396 +L 101.351333 159.418501 +L 107.794351 163.145971 +L 114.237369 164.118354 +L 120.680388 186.645233 +L 127.123406 191.50715 +L 133.566424 212.899582 +L 140.009442 225.378501 +L 146.45246 232.347248 +L 152.895478 256.170639 +L 159.338497 281.938796 +L 165.781515 267.515111 +L 172.224533 233.805823 +L 178.667551 199.934472 +L 185.110569 172.383612 +L 191.553588 142.23973 +L 197.996606 28.957076 +L 204.439624 45.325528 +L 210.882642 53.75285 +L 217.32566 65.745577 +L 223.768678 74.983219 +L 230.211697 99.292801 +L 236.654715 96.375651 +L 243.097733 103.668526 +L 249.540751 109.826953 +L 255.983769 120.685233 +L 262.426788 128.626364 +L 268.869806 131.219386 +L 275.312824 136.891622 +L 281.755842 135.595111 +L 288.19886 145.15688 +L 294.641878 141.753538 +L 301.084897 146.453391 +L 307.527915 141.915602 +L 313.970933 142.077666 +L 320.413951 146.453391 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #4c72b0; stroke-width: 1.5; stroke-linecap: round"/> + </g> + <g id="line2d_13"> + <path d="M 62.693224 154.857322 +L 69.136242 153.722752 +L 75.57926 148.125507 +L 82.022278 153.393502 +L 88.465297 163.270994 +L 94.908315 159.978497 +L 101.351333 168.538989 +L 107.794351 173.806985 +L 114.237369 177.428731 +L 120.680388 186.318474 +L 127.123406 198.500713 +L 133.566424 192.244969 +L 140.009442 229.779436 +L 146.45246 233.730432 +L 152.895478 258.753411 +L 159.338497 282.13014 +L 165.781515 262.375157 +L 172.224533 242.949424 +L 178.667551 201.463961 +L 185.110569 174.465484 +L 191.553588 148.356704 +L 197.996606 30.352162 +L 204.439624 35.192855 +L 210.882642 59.228084 +L 217.32566 54.289339 +L 223.768678 71.410324 +L 230.211697 83.592563 +L 236.654715 86.226561 +L 243.097733 105.323044 +L 249.540751 109.93254 +L 255.983769 126.395026 +L 262.426788 125.736527 +L 268.869806 133.63852 +L 275.312824 122.444029 +L 281.755842 125.078027 +L 288.19886 132.321521 +L 294.641878 144.17451 +L 301.084897 138.906515 +L 307.527915 144.17451 +L 313.970933 140.223514 +L 320.413951 148.784006 +" clip-path="url(#pbda4021e28)" style="fill: none; stroke: #dd8452; stroke-width: 1.5; stroke-linecap: round"/> + </g> + <g id="line2d_14"/> + <g id="line2d_15"/> + <g id="patch_3"> + <path d="M 49.807188 304.02 +L 49.807188 7.2 +" style="fill: none; stroke: #ffffff; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> + </g> + <g id="patch_4"> + <path d="M 49.807188 304.02 +L 333.299988 304.02 +" style="fill: none; stroke: #ffffff; stroke-width: 1.25; stroke-linejoin: miter; stroke-linecap: square"/> + </g> + </g> + <g id="legend_1"> + <g id="line2d_16"> + <path d="M 338.86555 164.602188 +L 349.86555 164.602188 +L 360.86555 164.602188 +" style="fill: none; stroke: #4c72b0; stroke-width: 1.5; stroke-linecap: round"/> + </g> + <g id="text_14"> + <!-- Arbor --> + <g style="fill: #262626" transform="translate(369.66555 168.452188) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-41" d="M 2188 4044 +L 1331 1722 +L 3047 1722 +L 2188 4044 +z +M 1831 4666 +L 2547 4666 +L 4325 0 +L 3669 0 +L 3244 1197 +L 1141 1197 +L 716 0 +L 50 0 +L 1831 4666 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-41"/> + <use xlink:href="#DejaVuSans-72" x="68.408203"/> + <use xlink:href="#DejaVuSans-62" x="109.521484"/> + <use xlink:href="#DejaVuSans-6f" x="172.998047"/> + <use xlink:href="#DejaVuSans-72" x="234.179688"/> + </g> + </g> + <g id="line2d_17"> + <path d="M 338.86555 180.748125 +L 349.86555 180.748125 +L 360.86555 180.748125 +" style="fill: none; stroke: #dd8452; stroke-width: 1.5; stroke-linecap: round"/> + </g> + <g id="text_15"> + <!-- Reference --> + <g style="fill: #262626" transform="translate(369.66555 184.598125) scale(0.11 -0.11)"> + <defs> + <path id="DejaVuSans-52" d="M 2841 2188 +Q 3044 2119 3236 1894 +Q 3428 1669 3622 1275 +L 4263 0 +L 3584 0 +L 2988 1197 +Q 2756 1666 2539 1819 +Q 2322 1972 1947 1972 +L 1259 1972 +L 1259 0 +L 628 0 +L 628 4666 +L 2053 4666 +Q 2853 4666 3247 4331 +Q 3641 3997 3641 3322 +Q 3641 2881 3436 2590 +Q 3231 2300 2841 2188 +z +M 1259 4147 +L 1259 2491 +L 2053 2491 +Q 2509 2491 2742 2702 +Q 2975 2913 2975 3322 +Q 2975 3731 2742 3939 +Q 2509 4147 2053 4147 +L 1259 4147 +z +" transform="scale(0.015625)"/> + </defs> + <use xlink:href="#DejaVuSans-52"/> + <use xlink:href="#DejaVuSans-65" x="64.982422"/> + <use xlink:href="#DejaVuSans-66" x="126.505859"/> + <use xlink:href="#DejaVuSans-65" x="161.710938"/> + <use xlink:href="#DejaVuSans-72" x="223.234375"/> + <use xlink:href="#DejaVuSans-65" x="262.097656"/> + <use xlink:href="#DejaVuSans-6e" x="323.621094"/> + <use xlink:href="#DejaVuSans-63" x="387"/> + <use xlink:href="#DejaVuSans-65" x="441.980469"/> + </g> + </g> + </g> + </g> + <defs> + <clipPath id="pbda4021e28"> + <rect x="49.807188" y="7.2" width="283.4928" height="296.82"/> + </clipPath> + </defs> +</svg> diff --git a/doc/tutorial/calcium_stdp_curve.rst b/doc/tutorial/calcium_stdp_curve.rst new file mode 100644 index 0000000000000000000000000000000000000000..899925cc873ac0dd1b6efb4e030d328068d4dbd1 --- /dev/null +++ b/doc/tutorial/calcium_stdp_curve.rst @@ -0,0 +1,192 @@ +.. _tutorial_calcium_stpd_curve: + +Spike Timing-dependent Plasticity Curve +======================================= + +This tutorial uses a single cell and reproduces `this Brian2 example +<https://brian2.readthedocs.io/en/latest/examples/frompapers.Graupner_Brunel_2012.html>`_. We aim +to reproduce a spike timing-dependent plastivity curve which arises from stochastic calcium-based +synapse dynamics described in Graupner and Brunel [1]_. + +The synapse is modeled as synaptic efficacy variable, :math:`\rho`, which is a function of the +calcium concentration, :math:`c(t)`. There are two stable states at :math:`\rho=0` (DOWN) and +:math:`\rho=1` (UP), while :math:`\rho=\rho^\ast=0.5` represents a third unstable state between the +two stable states. The calcium concentration dynamics are represented by a simplified model which +uses a linear sum of individual calcium transients elicited by trains of pre- and postsynaptic +action potentials: + +.. math:: + + \begin{align*} + c^\prime (t) &= - \frac{1}{\tau_{Ca}}c + + C_{pre} \sum_i \delta(t-t_i-D) + + C_{post} \sum_j \delta(t-t_j), \\ + \rho^\prime(t) &= - \frac{1}{\tau}\left [ + \rho (1 - \rho) (\rho^\ast - \rho) + -\gamma_p (1-\rho) H\left(c - \theta_p \right) + + \gamma_d \rho H\left(c - \theta_d \right) \right ] + + N, \\ + N &= \frac{\sigma}{\sqrt{\tau}} \sqrt{H\left( c - \theta_p \right) + + H\left( c - \theta_d \right)} W. + \end{align*} + +Here, the sums over :math:`i` and :math:`j` represent the contributions from all pre and +postsynaptic spikes, respectively, with :math:`C_{pre}` and :math:`C_{pre}` denoting the jumps in +concentration after a spike. The jump after the presynaptic spike is delayed by :math:`D`. The +calcium decay time is assumed to be much faster than the synaptic time scale, +:math:`\tau_{Ca} \ll \tau`. The subscripts :math:`p` and :math:`d` represent potentiation (increase +in synaptic efficacy) and depression (decrease in synaptic efficacy), respectively, with +:math:`\gamma` and :math:`\theta` being the corresponding rates and thresholds. :math:`H(x)` is the +right-continuous heaviside step function (:math:`H(0)=1`). + +This mechanism is stochastic, :math:`W` represents a white noise process, and therefore our +simulation needs to + +- use a stochastic synapse mechanism, +- accumulate statistics over a large enough ensemble of initial states. + + +Implementation of a Stochastic Mechanism +---------------------------------------- + +Implementing a stochastic mechanism which is given by a stochastic differential equation (SDE) as +above is straightforward to implement in :ref:`Arbor's NMODL dialect <format-sde>`. Let's examine +the mechanism code in the `Arbor repository +<https://github.com/arbor-sim/arbor/mechanisms/stochastic/calcium_based_synapse.mod>`_. + +The main difference compared to a deterministic (ODE) description is the additional `WHITE_NOISE` +block, + +.. code:: none + + WHITE_NOISE { + W + } + +which declares the white noise process :math:`W`, and the specification of the `stochastic` solver +method, + +.. code:: none + + BREAKPOINT { + SOLVE state METHOD stochastic + } + +This is sufficient to inform Arbor about the stochasticity of the mechanism. For more information +about Arbor's strategy to solve SDEs, please consult :ref:`this overview <mechanisms-sde>`, while +details about the numerical solver can be found in the :ref:`developers guide <sde>`. + + +The Model +--------- + +In this tutorial, the neuron model itself is simple with only +passive (leaky) membrane dynamics, and it receives regular synaptic current +input in one arbitrary chosen control volume (CV) to trigger regular spikes. + +First we import some required modules: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 13-18 + +Next we set the simulation parameters in order to reproduce the plasticity curve: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 20-41 + +The time lag resolution, together with the maximum time lag, determine the number of cases we want +to simulate. For each such case, however, we need to run many simulations in order to get a +statistically meaningful result. The number of simulations per case is given by the ensemble size +and the initial conditions. In our case, we have two inital states, :math:`\rho(0)=0` and +:math:`\rho(0)=1`, and for each initial state we want to run :math:`100` simulations. We note, that +the stochastic synapse mechanism does not alter the state of the cell, but couples one-way only by +reacting to spikes. Therefore, we are allowed to simply place :math:`100` synapses per initial state +onto the cell without worrying about interference. Moreover, this has the benefit of exposing +parallelism that Arbor can take advantage of. + +Thus, we create a simple cell with a midpoint at which we place our mechanisms: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 44-67 + +Since our stochastic mechanism `calcium_based_synapse` is not within Arbor's default set of +mechanism, we need to extend the mechanism catalogue within the cable cell properties: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 70-74 + +Our cell and cell properties can then later be used to create a simple recipe: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 77-103 + +Note, that the recipe takes a cell, cell properties and a list of event generators as constructor +arguments and returns them with its corresponding methods. Furthermore, the recipe also returns a +list of probes which contains only one item: A query for our mechanism's state variable +:math:`\rho`. Since we placed a number of these mechanisms on our cell, we will receive a vector of +values when probing. + +Next we set up the simulation logic: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 106-134 + +The pre- and postsynaptic events are generated at explicit schedules, where the presynaptic event +is shifted in time by :math:`D -\text{time lag}` with respect to the presynaptic event, which in +turn is generated regularly with the frequency :math:`f`. The postsynaptic events are driven by the +deterministic synapse with weight `1.0`, while the presynaptic events are generated at the +stochastic calcium synapses. The postsynaptic weight can be set arbitrarily as long as it is large +enough to trigger the spikes. + +Thus, we have all ingredients to create the recipe + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 136-137 + +Now, we need to initialize the simulation, register a probe and run the simulation: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 139-154 + +Since we are interested in the long-term average value, we only query the probe at the end of the +simulation. + +After the simulation is finished, we calculate the change in synaptic strength by evaluating the +transition probabilies from initial DOWN state to final UP state and vice versa. + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 156-174 + +Since we need to run our simulation for each time lag case anew, we spawn a bunch of threads to +carry out the work in parallel: + +.. literalinclude:: ../../python/example/calcium_stdp.py + :language: python + :lines: 177-178 + +The collected results can then be plotted: + +.. figure:: calcium_stdp.svg + :width: 1600 + :align: center + + Comparison of this simulation with reference simulation [1]_; for a simulation duration + of 60 spikes at 1 Hertz, ensemble size of 2000 per initial state and time step dt=0.01 ms. + The shaded region indicates the 95\% confidence interval. + +The full code +------------- +You can find the full code of the example at ``python/examples/calcium_stdp.py``. + +References +---------- +.. [1] Graupner and Brunel, PNAS 109 (10): 3991-3996 (2012); `<https://doi.org/10.1073/pnas.1109359109>`_, `<https://www.pnas.org/doi/10.1073/pnas.1220044110>`_. diff --git a/doc/tutorial/index.rst b/doc/tutorial/index.rst index 629e81c95e9799b38e33378399005c53bb501cb3..9bbcaeac5b284ec8b4de1cff71a2b945149d4db6 100644 --- a/doc/tutorial/index.rst +++ b/doc/tutorial/index.rst @@ -52,6 +52,14 @@ Probes probe_lfpykit +Stochastic Mechanisms +--------------------- + +.. toctree:: + :maxdepth: 1 + + calcium_stdp_curve + Hardware -------- diff --git a/mechanisms/CMakeLists.txt b/mechanisms/CMakeLists.txt index 320fd85236a2d2ca89df94c9a8accda2eb601480..de0718e52caae88aff9ba25418fbe6a0c9d94759 100644 --- a/mechanisms/CMakeLists.txt +++ b/mechanisms/CMakeLists.txt @@ -23,7 +23,7 @@ make_catalogue( make_catalogue( NAME stochastic - MOD ou_input + MOD ou_input calcium_based_synapse VERBOSE ${ARB_CAT_VERBOSE} ADD_DEPS ON) diff --git a/mechanisms/stochastic/calcium_based_synapse.mod b/mechanisms/stochastic/calcium_based_synapse.mod new file mode 100644 index 0000000000000000000000000000000000000000..4d45a19e1c58668c0deece261723c9ce2a1a05e3 --- /dev/null +++ b/mechanisms/stochastic/calcium_based_synapse.mod @@ -0,0 +1,99 @@ +: Calcium-based plasticity model +: Based on the work of Graupner and Brunel, PNAS 109 (10): 3991-3996 (2012) +: https://doi.org/10.1073/pnas.1109359109, https://www.pnas.org/doi/10.1073/pnas.1220044110 +: +: Author: Sebastian Schmitt +: +: The synapse is modeled as synaptic efficacy variable, Ï, which is a function of the calcium +: concentration, c(t). The synapse model features two stable states at Ï=0 (DOWN) and Ï=1 (UP), +: while Ï=Ï_star=0.5 represents a third unstable state between the two stable states. +: The calcium concentration dynamics are represented by a simplified model which ueses a linear sum +: of individual calcium transients elicited by trains of pre- and postsynaptic action potentials. +: +: drho/dt = -(1/Ï„)Ï(1-Ï)(Ï_star-Ï) + (γ_p/Ï„)(1-Ï) H[c(t)-θ_p] - (γ_d/Ï„)Ï H[c(t)-θ_d] + N +: N = (σ/√τ) √(H[c(t)-θ_p] + H[c(t)-θ_d]) W +: +: dc/dt = -(1/Ï„_Ca)c + C_pre Σ_i δ(t-t_i-D) + C_post Σ_j δ(t-t_j) +: +: rho synaptic efficacy variable (unit-less) +: rho_star second root of cubic polynomial (unit-less), rho_star=0.5 +: rho_0 initial value (unit-less) +: tau synaptic time constant (ms), order of seconds to minutes +: gamma_p rate of synaptic increase (unit-less) +: theta_p potentiaton threshold (concentration) +: gamma_d rate of synaptic decrease (unit-less) +: theta_d depression threshold (concentration) +: sigma noise amplitude +: W white noise +: c calcium concentration (concentration) +: C_pre concentration jump after pre-synaptic spike (concentration) +: C_post concentration jump after post-synaptic spike (concentration) +: tau_Ca Calcium decay time constant (ms), order of milliseconds +: H right-continuous heaviside step function ( H[x]=1 for x>=0; H[x]=0 otherwise ) +: t_i presynaptic spike times +: t_j postsynaptic spike times +: D time delay + +NEURON { + POINT_PROCESS calcium_based_synapse + RANGE rho_0, tau, theta_p, gamma_p, theta_d, gamma_d, C_pre, C_post, tau_Ca, sigma +} + +STATE { + c + rho +} + +PARAMETER { + rho_star = 0.5 + rho_0 = 1 + tau = 150000 (ms) + gamma_p = 321.808 + theta_p = 1.3 + gamma_d = 200 + theta_d = 1 + sigma = 2.8248 + C_pre = 1 + C_post = 2 + tau_Ca = 20 (ms) +} + +ASSIGNED { + one_over_tau + one_over_tau_Ca + sigma_over_sqrt_tau +} + +INITIAL { + c = 0 + rho = rho_0 + + one_over_tau = 1/tau + one_over_tau_Ca = 1/tau_Ca + sigma_over_sqrt_tau = sigma/(tau^0.5) +} + +BREAKPOINT { + SOLVE state METHOD stochastic +} + +WHITE_NOISE { + W +} + +DERIVATIVE state { + LOCAL hsp + LOCAL hsd + hsp = step_right(c - theta_p) + hsd = step_right(c - theta_d) + rho' = (-rho*(1-rho)*(rho_star-rho) + gamma_p*(1-rho)*hsp - gamma_d*rho*hsd)*one_over_tau + (hsp + hsd)^0.5*sigma_over_sqrt_tau*W + c' = -c*one_over_tau_Ca +} + +NET_RECEIVE(weight) { + c = c + C_pre +} + +POST_EVENT(time) { + c = c + C_post +} diff --git a/python/example/calcium_stdp.py b/python/example/calcium_stdp.py new file mode 100644 index 0000000000000000000000000000000000000000..ba86050f8b6f5d03e23973045133eaa78300f0ba --- /dev/null +++ b/python/example/calcium_stdp.py @@ -0,0 +1,234 @@ +#!/usr/bin/env python3 +# This script is included in documentation. Adapt line numbers if touched. +# +# Authors: Sebastian Schmitt +# Fabian Bösch +# +# Single-cell simulation: Calcium-based synapse which models synaptic efficacy as proposed by +# Graupner and Brunel, PNAS 109 (10): 3991-3996 (2012); https://doi.org/10.1073/pnas.1109359109, +# https://www.pnas.org/doi/10.1073/pnas.1220044110. +# The synapse dynamics is affected by additive white noise. The results reproduce the spike +# timing-dependent plasticity curve for the DP case described in Table S1 (supplemental material). + +import arbor +import random +import multiprocessing +import numpy # You may have to pip install these. +import pandas # You may have to pip install these. +import seaborn # You may have to pip install these. + +# (1) Set simulation paramters + +# Spike response delay (ms) +D = 13.7 +# Spike frequency in Hertz +f = 1.0 +# Number of spike pairs +num_spikes = 30 +# time lag resolution +stdp_dt_step = 20.0 +# Maximum time lag +stdp_max_dt = 100.0 +# Ensemble size per initial value +ensemble_per_rho_0 = 100 +# Simulation time step +dt = 0.1 +# List of initial values for 2 states +rho_0 = [0] * ensemble_per_rho_0 + [1] * ensemble_per_rho_0 +# We need a synapse for each sample path +num_synapses = len(rho_0) +# Time lags between spike pairs (post-pre: < 0, pre-post: > 0) +stdp_dt = numpy.arange(-stdp_max_dt, stdp_max_dt + stdp_dt_step, stdp_dt_step) + + +# (2) Make the cell + +# Create a morphology with a single (cylindrical) segment of length=diameter=6 μm +tree = arbor.segment_tree() +tree.append(arbor.mnpos, arbor.mpoint(-3, 0, 0, 3), arbor.mpoint(3, 0, 0, 3), tag=1) + +# Define the soma and its midpoint +labels = arbor.label_dict({"soma": "(tag 1)", "midpoint": "(location 0 0.5)"}) + +# Create and set up a decor object +decor = ( + arbor.decor() + .set_property(Vm=-40) + .paint('"soma"', arbor.density("pas")) + .place('"midpoint"', arbor.synapse("expsyn"), "driving_synapse") + .place('"midpoint"', arbor.threshold_detector(-10), "detector") +) +for i in range(num_synapses): + mech = arbor.mechanism("calcium_based_synapse") + mech.set("rho_0", rho_0[i]) + decor.place('"midpoint"', arbor.synapse(mech), f"calcium_synapse_{i}") + +# Create cell +cell = arbor.cable_cell(tree, decor, labels) + + +# (3) Create extended catalogue including stochastic mechanisms + +cable_properties = arbor.neuron_cable_properties() +cable_properties.catalogue = arbor.default_catalogue() +cable_properties.catalogue.extend(arbor.stochastic_catalogue(), "") + + +# (4) Recipe + + +class stdp_recipe(arbor.recipe): + def __init__(self, cell, props, gens): + arbor.recipe.__init__(self) + self.the_cell = cell + self.the_props = props + self.the_gens = gens + + def num_cells(self): + return 1 + + def cell_kind(self, gid): + return arbor.cell_kind.cable + + def cell_description(self, gid): + return self.the_cell + + def global_properties(self, kind): + return self.the_props + + def probes(self, gid): + return [arbor.cable_probe_point_state_cell("calcium_based_synapse", "rho")] + + def event_generators(self, gid): + return self.the_gens + + +# (5) run simulation for a given time lag + + +def run(time_lag): + + # Time between stimuli + T = 1000.0 / f + + # Simulation duration + t1 = num_spikes * T + + # Time difference between post and pre spike including delay + d = -time_lag + D + + # Stimulus and sample times + t0_post = 0.0 if d >= 0 else -d + t0_pre = d if d >= 0 else 0.0 + stimulus_times_post = numpy.arange(t0_post, t1, T) + stimulus_times_pre = numpy.arange(t0_pre, t1, T) + sched_post = arbor.explicit_schedule(stimulus_times_post) + sched_pre = arbor.explicit_schedule(stimulus_times_pre) + + # Create strong enough driving stimulus + generators = [arbor.event_generator("driving_synapse", 1.0, sched_post)] + + # Stimulus for calcium synapses + for i in range(num_synapses): + # Zero weight -> just modify synaptic weight via stdp + generators.append(arbor.event_generator(f"calcium_synapse_{i}", 0.0, sched_pre)) + + # Create recipe + recipe = stdp_recipe(cell, cable_properties, generators) + + # Select one thread and no GPU + alloc = arbor.proc_allocation(threads=1, gpu_id=None) + context = arbor.context(alloc, mpi=None) + domains = arbor.partition_load_balance(recipe, context) + + # Get random seed + random_seed = random.getrandbits(64) + + # Create simulation + sim = arbor.simulation(recipe, context, domains, random_seed) + + # Register prope to read out stdp curve + handle = sim.sample((0, 0), arbor.explicit_schedule([t1 - dt])) + + # Run simulation + sim.run(t1, dt) + + # Process sampled data + data, meta = sim.samples(handle)[0] + data_down = data[-1, 1 : ensemble_per_rho_0 + 1] + data_up = data[-1, ensemble_per_rho_0 + 1 :] + # Initial fraction of synapses in DOWN state + beta = 0.5 + # Synaptic strength ratio UP to DOWN (w1/w0) + b = 5 + # Transition indicator form DOWN to UP + P_UA = (data_down > 0.5).astype(float) + # Transition indicator from UP to DOWN + P_DA = (data_up < 0.5).astype(float) + # Return change in synaptic strength + ds_A = ( + (1 - P_UA) * beta + + P_DA * (1 - beta) + + b * (P_UA * beta + (1 - P_DA) * (1 - beta)) + ) / (beta + (1 - beta) * b) + return pandas.DataFrame({"ds": ds_A, "ms": time_lag, "type": "Arbor"}) + + +with multiprocessing.Pool() as p: + results = p.map(run, stdp_dt) + +ref = numpy.array( + [ + [-100, 0.9793814432989691], + [-95, 0.981715028725338], + [-90, 0.9932274542583821], + [-85, 0.982392230227282], + [-80, 0.9620761851689686], + [-75, 0.9688482001884063], + [-70, 0.9512409611378684], + [-65, 0.940405737106768], + [-60, 0.9329565205853866], + [-55, 0.9146720800329048], + [-50, 0.8896156244609853], + [-45, 0.9024824529979171], + [-40, 0.8252814817763271], + [-35, 0.8171550637530018], + [-30, 0.7656877496052755], + [-25, 0.7176064429672677], + [-20, 0.7582385330838939], + [-15, 0.7981934216985763], + [-10, 0.8835208109434913], + [-5, 0.9390513341028807], + [0, 0.9927519271849183], + [5, 1.2354639175257733], + [10, 1.2255075694250952], + [15, 1.1760718597832], + [20, 1.1862298823123565], + [25, 1.1510154042112806], + [30, 1.125958948639361], + [35, 1.1205413366238108], + [40, 1.0812636495110723], + [45, 1.0717828284838595], + [50, 1.0379227533866708], + [55, 1.0392771563905585], + [60, 1.023024320343908], + [65, 1.046049171409996], + [70, 1.040631559394446], + [75, 1.0257331263516831], + [80, 1.0013538722817072], + [85, 1.0121890963128077], + [90, 1.0013538722817072], + [95, 1.0094802903050326], + [100, 0.9918730512544945], + ] +) +df_ref = pandas.DataFrame({"ds": ref[:, 1], "ms": ref[:, 0], "type": "Reference"}) + +seaborn.set_theme() +df = pandas.concat(results) +df = pandas.concat([df, df_ref]) +plt = seaborn.relplot(kind="line", data=df, x="ms", y="ds", hue="type") +plt.set_xlabels("lag time difference (ms)") +plt.set_ylabels("change in synaptic strenght (after/before)") +plt._legend.set_title("") +plt.savefig("calcium_stdp.svg") diff --git a/scripts/run_python_examples.sh b/scripts/run_python_examples.sh index 3bdc5a7d4c19e4efca9f2ac1a40bfda1b07b21b2..e561ca58b18fb04815cffe9fbb501ed23bb17a51 100755 --- a/scripts/run_python_examples.sh +++ b/scripts/run_python_examples.sh @@ -32,3 +32,4 @@ $PREFIX python python/example/network_two_cells_gap_junctions.py $PREFIX python python/example/diffusion.py $PREFIX python python/example/plasticity.py $PREFIX python python/example/v-clamp.py +$PREFIX python python/example/calcium_stdp.py