├── .github └── workflows │ └── python-package-conda.yml ├── .gitignore ├── .readthedocs.yaml ├── AUTHORS ├── CITATION.cff ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs ├── .gitignore ├── Makefile ├── _static │ └── tmp.txt ├── conf.py ├── images │ ├── museum │ │ ├── bfa_snn │ │ │ ├── bfa_snn.png │ │ │ ├── bfasnn_codes.jpg │ │ │ └── bfasnn_mnist_likelihood.jpg │ │ ├── data_img1.png │ │ ├── data_img2.png │ │ ├── dc_snn │ │ │ ├── dcscnn_syn.jpg │ │ │ ├── dcsnn_raster.png │ │ │ ├── diehl_cook_snn.png │ │ │ ├── digit0.png │ │ │ ├── failures │ │ │ │ ├── digit444.png │ │ │ │ ├── digit6710.png │ │ │ │ ├── digit7822.png │ │ │ │ ├── syn35_digit6710.png │ │ │ │ ├── syn48_digit7822.png │ │ │ │ └── syn63_digit444.png │ │ │ ├── successes │ │ │ │ ├── digit222.png │ │ │ │ ├── digit2331.png │ │ │ │ ├── digit3.png │ │ │ │ ├── syn73_digit222.png │ │ │ │ ├── syn78_digit3.png │ │ │ │ └── syn93_digit2331.png │ │ │ └── syn58_digit0.png │ │ ├── deep_blue.jpg │ │ ├── gncn_pdh.png │ │ ├── gncn_t1.png │ │ ├── gncn_t1_ffm.png │ │ ├── gncn_t1_sc.png │ │ ├── gncn_t1_sigma.png │ │ ├── hgpc │ │ │ ├── HGPC_inputL.jpg │ │ │ ├── Input_layer.png │ │ │ └── hgpc_model.png │ │ ├── pcn_discrim │ │ │ ├── efe_curve.jpg │ │ │ ├── mnist_learning_curves.jpg │ │ │ ├── ngclearn_demo3_arch.png │ │ │ └── pcn_latents.jpg │ │ ├── rat_accuracy.jpg │ │ ├── rat_rewards.jpg │ │ ├── ratmaze.png │ │ ├── rbm_neg.png │ │ ├── rbm_pos.png │ │ ├── real_ratmaze.jpg │ │ ├── sc_cauchy_filters.jpg │ │ ├── sc_ista_filters.jpg │ │ ├── sindy │ │ │ ├── C2D.png │ │ │ ├── L2D.png │ │ │ ├── L3D.png │ │ │ ├── LSQ.png │ │ │ ├── Lorenz3D.png │ │ │ ├── Masking.png │ │ │ ├── O3D.png │ │ │ ├── P1.png │ │ │ ├── P2.png │ │ │ ├── SR.png │ │ │ ├── SRin.png │ │ │ ├── STLSQ.png │ │ │ ├── Theta.png │ │ │ ├── Thresholding.png │ │ │ ├── X_.png │ │ │ ├── X_dX_.png │ │ │ ├── Xtheta.png │ │ │ ├── cubic_2D.png │ │ │ ├── dX_.png │ │ │ ├── d_xyz.png │ │ │ ├── dx.png │ │ │ ├── dy.png │ │ │ ├── dz.png │ │ │ ├── flow.png │ │ │ ├── flow_SR.png │ │ │ ├── flow_full.jpg │ │ │ ├── iterin.png │ │ │ ├── linear_2D.png │ │ │ ├── linear_3D.png │ │ │ ├── lorenz.png │ │ │ ├── oscillator.png │ │ │ ├── sindy.png │ │ │ └── xdx.png │ │ └── snn_ba.png │ ├── ngc-learn-logo.png │ ├── test_ngclearn_install.png │ ├── test_run_output.png │ └── tutorials │ │ ├── lava │ │ ├── lava_fields.jpg │ │ ├── raster_O.png │ │ ├── raster_T.png │ │ └── raster_X.png │ │ ├── lesson1 │ │ ├── 2n_circuit.png │ │ ├── 2n_circuit_viz.png │ │ ├── 2n_circuit_viz2.png │ │ ├── 2n_circuit_viz_save.png │ │ ├── 3n_circuit.png │ │ ├── 5n_circuit.png │ │ ├── gncn_viz.png │ │ ├── ngclearn_enode.png │ │ ├── ngclearn_snode.png │ │ └── nodes_and_cables.png │ │ ├── lesson2 │ │ └── 2n_circuit.png │ │ └── neurocog │ │ ├── 20Hz_stp_std_dom.jpg │ │ ├── 20Hz_stp_stf_dom.jpg │ │ ├── 2Hz_stp_std_dom.jpg │ │ ├── 2Hz_stp_stf_dom.jpg │ │ ├── GEC.png │ │ ├── SingleGEC.png │ │ ├── adex_v_plot.jpg │ │ ├── adex_w_plot.jpg │ │ ├── alphasyn.jpg │ │ ├── bernoulli_raster.jpg │ │ ├── ch_izh.png │ │ ├── ei_circuit_dense_exc.jpg │ │ ├── ei_circuit_dynamics.jpg │ │ ├── ei_circuit_sparse_inh.jpg │ │ ├── euler_integration.jpg │ │ ├── exp2syn.jpg │ │ ├── expsyn.jpg │ │ ├── fncell_plot.jpg │ │ ├── fs_izhcell.png │ │ ├── hh_plot.jpg │ │ ├── ib_izh.png │ │ ├── lif_plot.jpg │ │ ├── lts_izh.png │ │ ├── mod_stdp_component_dynamics.jpg │ │ ├── modstdp_syn_dynamics.jpg │ │ ├── ode_method_comparison.jpg │ │ ├── poisson_raster.jpg │ │ ├── poisson_trace.jpg │ │ ├── poisson_trace_gate.jpg │ │ ├── rate_cell_integration.jpg │ │ ├── rs_izhcell.png │ │ ├── simple_codes.jpg │ │ ├── slif_no_refract_plot.jpg │ │ ├── slif_refract_plot.jpg │ │ ├── stdp_bi_and_poo.png │ │ └── stdp_curve.jpg ├── index.rst ├── installation.md ├── make.bat ├── modeling │ ├── components.md │ ├── input_encoders.md │ ├── neurons.md │ ├── other_ops.md │ └── synapses.md ├── museum │ ├── index.rst │ ├── model_museum.md │ ├── pcn_discrim.md │ ├── rl_snn.md │ ├── sindy.md │ ├── snn_bfa.md │ ├── snn_dc.md │ └── sparse_coding.md ├── ngclearn_papers.md ├── overview.md ├── requirements.txt ├── source │ ├── modules.rst │ ├── ngclearn.commands.rst │ ├── ngclearn.components.input_encoders.rst │ ├── ngclearn.components.lava.neurons.rst │ ├── ngclearn.components.lava.rst │ ├── ngclearn.components.lava.synapses.rst │ ├── ngclearn.components.lava.traces.rst │ ├── ngclearn.components.neurons.graded.rst │ ├── ngclearn.components.neurons.rst │ ├── ngclearn.components.neurons.spiking.rst │ ├── ngclearn.components.other.rst │ ├── ngclearn.components.rst │ ├── ngclearn.components.synapses.convolution.rst │ ├── ngclearn.components.synapses.hebbian.rst │ ├── ngclearn.components.synapses.modulated.rst │ ├── ngclearn.components.synapses.patched.rst │ ├── ngclearn.components.synapses.rst │ ├── ngclearn.modules.regression.rst │ ├── ngclearn.modules.rst │ ├── ngclearn.operations.rst │ ├── ngclearn.rst │ ├── ngclearn.utils.analysis.rst │ ├── ngclearn.utils.density.rst │ ├── ngclearn.utils.diffeq.rst │ ├── ngclearn.utils.optim.rst │ ├── ngclearn.utils.rst │ └── ngclearn.utils.viz.rst └── tutorials │ ├── foundations.md │ ├── foundations │ ├── commands.md │ ├── contexts.md │ ├── monitors.md │ └── operations.md │ ├── index.rst │ ├── intro.md │ ├── lava │ ├── hebbian_learning.md │ ├── introduction.md │ ├── lava_components.md │ ├── lava_context.md │ ├── monitors.md │ └── setup.md │ ├── model_basics │ ├── configuration.md │ ├── evolving_synapses.md │ ├── json_modules.md │ └── model_building.md │ ├── neurocog │ ├── adex_cell.md │ ├── dynamic_synapses.md │ ├── error_cell.md │ ├── fitzhugh_nagumo_cell.md │ ├── hebbian.md │ ├── hodgkin_huxley_cell.md │ ├── index.rst │ ├── input_cells.md │ ├── integration.md │ ├── izhikevich_cell.md │ ├── lif.md │ ├── metrics.md │ ├── mod_stdp.md │ ├── plotting.md │ ├── rate_cell.md │ ├── short_term_plasticity.md │ ├── simple_leaky_integrator.md │ ├── stdp.md │ └── traces.md │ └── theory.md ├── history.txt ├── ngclearn ├── .gitignore ├── __init__.py ├── commands │ └── __init__.py ├── components │ ├── __init__.py │ ├── base_monitor.py │ ├── input_encoders │ │ ├── __init__.py │ │ ├── bernoulliCell.py │ │ ├── latencyCell.py │ │ ├── phasorCell.py │ │ └── poissonCell.py │ ├── jaxComponent.py │ ├── lava │ │ ├── __init__.py │ │ ├── monitor.py │ │ ├── neurons │ │ │ ├── LIFCell.py │ │ │ └── __init__.py │ │ ├── synapses │ │ │ ├── __init__.py │ │ │ ├── hebbianSynapse.py │ │ │ ├── staticSynapse.py │ │ │ └── traceSTDPSynapse.py │ │ └── traces │ │ │ ├── __init__.py │ │ │ └── gatedTrace.py │ ├── monitor.py │ ├── neurons │ │ ├── __init__.py │ │ ├── graded │ │ │ ├── __init__.py │ │ │ ├── bernoulliErrorCell.py │ │ │ ├── gaussianErrorCell.py │ │ │ ├── laplacianErrorCell.py │ │ │ ├── rateCell.py │ │ │ └── rewardErrorCell.py │ │ └── spiking │ │ │ ├── IFCell.py │ │ │ ├── LIFCell.py │ │ │ ├── RAFCell.py │ │ │ ├── WTASCell.py │ │ │ ├── __init__.py │ │ │ ├── adExCell.py │ │ │ ├── fitzhughNagumoCell.py │ │ │ ├── hodgkinHuxleyCell.py │ │ │ ├── izhikevichCell.py │ │ │ ├── quadLIFCell.py │ │ │ └── sLIFCell.py │ ├── other │ │ ├── __init__.py │ │ ├── expKernel.py │ │ └── varTrace.py │ └── synapses │ │ ├── STPDenseSynapse.py │ │ ├── __init__.py │ │ ├── alphaSynapse.py │ │ ├── convolution │ │ ├── __init__.py │ │ ├── convSynapse.py │ │ ├── deconvSynapse.py │ │ ├── hebbianConvSynapse.py │ │ ├── hebbianDeconvSynapse.py │ │ ├── ngcconv.py │ │ ├── staticConvSynapse.py │ │ ├── staticDeconvSynapse.py │ │ ├── traceSTDPConvSynapse.py │ │ └── traceSTDPDeconvSynapse.py │ │ ├── denseSynapse.py │ │ ├── doubleExpSynapse.py │ │ ├── exponentialSynapse.py │ │ ├── hebbian │ │ ├── BCMSynapse.py │ │ ├── __init__.py │ │ ├── eventSTDPSynapse.py │ │ ├── expSTDPSynapse.py │ │ ├── hebbianSynapse.py │ │ └── traceSTDPSynapse.py │ │ ├── modulated │ │ ├── MSTDPETSynapse.py │ │ ├── REINFORCESynapse.py │ │ └── __init__.py │ │ ├── patched │ │ ├── __init__.py │ │ ├── hebbianPatchedSynapse.py │ │ ├── patchedSynapse.py │ │ └── staticPatchedSynapse.py │ │ └── staticSynapse.py ├── modules │ ├── __init__.py │ └── regression │ │ ├── __init__.py │ │ ├── elastic_net.py │ │ ├── lasso.py │ │ └── ridge.py ├── operations │ └── __init__.py └── utils │ ├── __init__.py │ ├── analysis │ ├── __init__.py │ ├── attentive_probe.py │ ├── linear_probe.py │ └── probe.py │ ├── data_loader.py │ ├── density │ ├── __init__.py │ └── gmm.py │ ├── diffeq │ ├── __init__.py │ ├── ode_utils.py │ └── odes.py │ ├── feature_dictionaries │ └── polynomialLibrary.py │ ├── io_utils.py │ ├── jaxProcess.py │ ├── masks │ └── multiblock2d.py │ ├── metric_utils.py │ ├── model_utils.py │ ├── optim │ ├── __init__.py │ ├── adam.py │ ├── optim_utils.py │ └── sgd.py │ ├── patch_utils.py │ ├── surrogate_fx.py │ ├── viz │ ├── __init__.py │ ├── dim_reduce.py │ ├── raster.py │ ├── spike_plot.py │ └── synapse_plot.py │ └── weight_distribution.py ├── pyproject.toml ├── requirements.txt └── tests ├── components ├── input_encoders │ ├── test_bernoulliCell.py │ ├── test_latencyCell.py │ ├── test_phasorCell.py │ └── test_poissonCell.py ├── neurons │ ├── graded │ │ ├── test_RateCell.py │ │ ├── test_bernoulliErrorCell.py │ │ ├── test_gaussianErrorCell.py │ │ ├── test_laplacianErrorCell.py │ │ └── test_rewardErrorCell.py │ └── spiking │ │ ├── test_IFCell.py │ │ ├── test_LIFCell.py │ │ ├── test_RAFCell.py │ │ ├── test_WTASCell.py │ │ ├── test_adExCell.py │ │ ├── test_fitzhughNagumoCell.py │ │ ├── test_hodgkinHuxleyCell.py │ │ ├── test_izhikevichCell.py │ │ ├── test_quadLIFCell.py │ │ └── test_sLIFCell.py ├── other │ ├── test_expKernel.py │ └── test_varTrace.py └── synapses │ ├── convolution │ ├── test_hebbianConvSynapse.py │ ├── test_hebbianDeconvSynapse.py │ ├── test_traceSTDPConvSynapse.py │ └── test_traceSTDPDeconvSynapse.py │ ├── hebbian │ ├── test_BCMSynapse.py │ ├── test_eventSTDPSynapse.py │ ├── test_expSTDPSynapse.py │ ├── test_hebbianSynapse.py │ └── test_traceSTDPSynapse.py │ ├── modulated │ ├── test_MSTDPETSynapse.py │ └── test_REINFORCESynapse.py │ ├── patched │ ├── test_hebbianPatchedSynapse.py │ └── test_patchedSynapse.py │ ├── test_STPDenseSynapse.py │ └── test_exponentialSynapse.py └── test___init__.py /.github/workflows/python-package-conda.yml: -------------------------------------------------------------------------------- 1 | name: Python Package using Conda 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build-linux: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | max-parallel: 5 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | 14 | - name: Install Miniconda 15 | uses: conda-incubator/setup-miniconda@v2 16 | with: 17 | auto-update-conda: true 18 | python-version: 3.11 19 | environment-name: test 20 | 21 | - name: Install dependencies 22 | run: | 23 | conda install -n test numpy=1.26 pytest pip 24 | conda run -n test pip install -e . 25 | 26 | - name: Run tests 27 | run: | 28 | conda run -n test pytest 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.mp4 4 | *.npy 5 | *.npz 6 | *.agent 7 | *.ngc 8 | *.gmm 9 | *.results 10 | build 11 | ngclearn.egg-info 12 | dist 13 | *.png 14 | *.jpg 15 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Set the version of Python and other tools you might need 9 | build: 10 | os: ubuntu-22.04 11 | tools: 12 | python: "3.11" 13 | 14 | # Build documentation in the docs/ directory with Sphinx 15 | sphinx: 16 | configuration: docs/conf.py 17 | 18 | # We recommend specifying your dependencies to enable reproducible builds: 19 | # https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html 20 | python: 21 | install: 22 | - requirements: docs/requirements.txt 23 | - method: pip 24 | path: . #docs/ 25 | # extra_requirements: 26 | # - docs 27 | #python: 28 | # install: 29 | # - requirements: docs/requirements.txt 30 | # - method: setuptools 31 | # path: . 32 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This file contains an official list of authors of this framework. 2 | 3 | # Names should be added to this file as: 4 | # Name or Organization 5 | # The email address is not required for organizations. 6 | 7 | Core Team 8 | Alexander Ororbia 9 | William Gebhardt 10 | Viet Dung Nguyen 11 | Ankur Mali 12 | Faeze Habibi 13 | 14 | Contributors 15 | Maxbeth2 (Ohas) 16 | pagrawal-psu 17 | pulinagrawal 18 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | message: "If you use NGC-Learn, please cite both the software and the source paper/publication referenced in the README." 3 | authors: 4 | - family-names: Ororbia 5 | given-names: Alexander 6 | orcid: https://orcid.org/0000-0002-2590-1310 7 | - family-names: Gebhardt 8 | given-names: William 9 | - family-names: Mali 10 | given-names: Ankur 11 | title: "ngc-learn" 12 | version: 1.0.0 13 | identifiers: 14 | - type: doi 15 | value: 10.5281/zenodo.6605728 16 | date-released: 2022-05-10 17 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | We are a community based on openness, as well as friendly and didactic discussions. 4 | 5 | We aspire to treat everybody equally, and value their contributions. 6 | 7 | Decisions are made based on technical merit and consensus. 8 | 9 | Code is not the only way to help the project. Reviewing pull requests, 10 | answering questions to help others on mailing lists or issues, organizing and 11 | teaching tutorials, as well as working on and improving the documentation, are 12 | all priceless contributions. 13 | 14 | We abide by the principles of openness, respect, and consideration of others of 15 | the Python Software Foundation: https://www.python.org/psf/codeofconduct/ 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2021, The Neural Adaptive Computing Laboratory 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | #@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -b coverage 22 | -------------------------------------------------------------------------------- /docs/_static/tmp.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/_static/tmp.txt -------------------------------------------------------------------------------- /docs/images/museum/bfa_snn/bfa_snn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/bfa_snn/bfa_snn.png -------------------------------------------------------------------------------- /docs/images/museum/bfa_snn/bfasnn_codes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/bfa_snn/bfasnn_codes.jpg -------------------------------------------------------------------------------- /docs/images/museum/bfa_snn/bfasnn_mnist_likelihood.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/bfa_snn/bfasnn_mnist_likelihood.jpg -------------------------------------------------------------------------------- /docs/images/museum/data_img1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/data_img1.png -------------------------------------------------------------------------------- /docs/images/museum/data_img2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/data_img2.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/dcscnn_syn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/dcscnn_syn.jpg -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/dcsnn_raster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/dcsnn_raster.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/diehl_cook_snn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/diehl_cook_snn.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/digit0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/digit0.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/digit444.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/digit444.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/digit6710.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/digit6710.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/digit7822.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/digit7822.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/syn35_digit6710.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/syn35_digit6710.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/syn48_digit7822.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/syn48_digit7822.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/failures/syn63_digit444.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/failures/syn63_digit444.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/digit222.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/digit222.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/digit2331.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/digit2331.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/digit3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/digit3.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/syn73_digit222.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/syn73_digit222.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/syn78_digit3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/syn78_digit3.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/successes/syn93_digit2331.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/successes/syn93_digit2331.png -------------------------------------------------------------------------------- /docs/images/museum/dc_snn/syn58_digit0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/dc_snn/syn58_digit0.png -------------------------------------------------------------------------------- /docs/images/museum/deep_blue.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/deep_blue.jpg -------------------------------------------------------------------------------- /docs/images/museum/gncn_pdh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/gncn_pdh.png -------------------------------------------------------------------------------- /docs/images/museum/gncn_t1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/gncn_t1.png -------------------------------------------------------------------------------- /docs/images/museum/gncn_t1_ffm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/gncn_t1_ffm.png -------------------------------------------------------------------------------- /docs/images/museum/gncn_t1_sc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/gncn_t1_sc.png -------------------------------------------------------------------------------- /docs/images/museum/gncn_t1_sigma.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/gncn_t1_sigma.png -------------------------------------------------------------------------------- /docs/images/museum/hgpc/HGPC_inputL.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/hgpc/HGPC_inputL.jpg -------------------------------------------------------------------------------- /docs/images/museum/hgpc/Input_layer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/hgpc/Input_layer.png -------------------------------------------------------------------------------- /docs/images/museum/hgpc/hgpc_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/hgpc/hgpc_model.png -------------------------------------------------------------------------------- /docs/images/museum/pcn_discrim/efe_curve.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/pcn_discrim/efe_curve.jpg -------------------------------------------------------------------------------- /docs/images/museum/pcn_discrim/mnist_learning_curves.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/pcn_discrim/mnist_learning_curves.jpg -------------------------------------------------------------------------------- /docs/images/museum/pcn_discrim/ngclearn_demo3_arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/pcn_discrim/ngclearn_demo3_arch.png -------------------------------------------------------------------------------- /docs/images/museum/pcn_discrim/pcn_latents.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/pcn_discrim/pcn_latents.jpg -------------------------------------------------------------------------------- /docs/images/museum/rat_accuracy.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/rat_accuracy.jpg -------------------------------------------------------------------------------- /docs/images/museum/rat_rewards.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/rat_rewards.jpg -------------------------------------------------------------------------------- /docs/images/museum/ratmaze.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/ratmaze.png -------------------------------------------------------------------------------- /docs/images/museum/rbm_neg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/rbm_neg.png -------------------------------------------------------------------------------- /docs/images/museum/rbm_pos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/rbm_pos.png -------------------------------------------------------------------------------- /docs/images/museum/real_ratmaze.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/real_ratmaze.jpg -------------------------------------------------------------------------------- /docs/images/museum/sc_cauchy_filters.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sc_cauchy_filters.jpg -------------------------------------------------------------------------------- /docs/images/museum/sc_ista_filters.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sc_ista_filters.jpg -------------------------------------------------------------------------------- /docs/images/museum/sindy/C2D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/C2D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/L2D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/L2D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/L3D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/L3D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/LSQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/LSQ.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/Lorenz3D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/Lorenz3D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/Masking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/Masking.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/O3D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/O3D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/P1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/P1.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/P2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/P2.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/SR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/SR.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/SRin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/SRin.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/STLSQ.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/STLSQ.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/Theta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/Theta.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/Thresholding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/Thresholding.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/X_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/X_.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/X_dX_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/X_dX_.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/Xtheta.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/Xtheta.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/cubic_2D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/cubic_2D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/dX_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/dX_.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/d_xyz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/d_xyz.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/dx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/dx.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/dy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/dy.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/dz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/dz.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/flow.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/flow_SR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/flow_SR.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/flow_full.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/flow_full.jpg -------------------------------------------------------------------------------- /docs/images/museum/sindy/iterin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/iterin.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/linear_2D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/linear_2D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/linear_3D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/linear_3D.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/lorenz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/lorenz.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/oscillator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/oscillator.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/sindy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/sindy.png -------------------------------------------------------------------------------- /docs/images/museum/sindy/xdx.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/sindy/xdx.png -------------------------------------------------------------------------------- /docs/images/museum/snn_ba.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/museum/snn_ba.png -------------------------------------------------------------------------------- /docs/images/ngc-learn-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/ngc-learn-logo.png -------------------------------------------------------------------------------- /docs/images/test_ngclearn_install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/test_ngclearn_install.png -------------------------------------------------------------------------------- /docs/images/test_run_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/test_run_output.png -------------------------------------------------------------------------------- /docs/images/tutorials/lava/lava_fields.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lava/lava_fields.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/lava/raster_O.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lava/raster_O.png -------------------------------------------------------------------------------- /docs/images/tutorials/lava/raster_T.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lava/raster_T.png -------------------------------------------------------------------------------- /docs/images/tutorials/lava/raster_X.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lava/raster_X.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/2n_circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/2n_circuit.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/2n_circuit_viz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/2n_circuit_viz.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/2n_circuit_viz2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/2n_circuit_viz2.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/2n_circuit_viz_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/2n_circuit_viz_save.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/3n_circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/3n_circuit.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/5n_circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/5n_circuit.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/gncn_viz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/gncn_viz.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/ngclearn_enode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/ngclearn_enode.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/ngclearn_snode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/ngclearn_snode.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson1/nodes_and_cables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson1/nodes_and_cables.png -------------------------------------------------------------------------------- /docs/images/tutorials/lesson2/2n_circuit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/lesson2/2n_circuit.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/20Hz_stp_std_dom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/20Hz_stp_std_dom.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/20Hz_stp_stf_dom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/20Hz_stp_stf_dom.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/2Hz_stp_std_dom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/2Hz_stp_std_dom.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/2Hz_stp_stf_dom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/2Hz_stp_stf_dom.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/GEC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/GEC.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/SingleGEC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/SingleGEC.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/adex_v_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/adex_v_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/adex_w_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/adex_w_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/alphasyn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/alphasyn.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/bernoulli_raster.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/bernoulli_raster.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ch_izh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ch_izh.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ei_circuit_dense_exc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ei_circuit_dense_exc.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ei_circuit_dynamics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ei_circuit_dynamics.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ei_circuit_sparse_inh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ei_circuit_sparse_inh.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/euler_integration.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/euler_integration.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/exp2syn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/exp2syn.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/expsyn.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/expsyn.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/fncell_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/fncell_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/fs_izhcell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/fs_izhcell.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/hh_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/hh_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ib_izh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ib_izh.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/lif_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/lif_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/lts_izh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/lts_izh.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/mod_stdp_component_dynamics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/mod_stdp_component_dynamics.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/modstdp_syn_dynamics.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/modstdp_syn_dynamics.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/ode_method_comparison.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/ode_method_comparison.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/poisson_raster.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/poisson_raster.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/poisson_trace.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/poisson_trace.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/poisson_trace_gate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/poisson_trace_gate.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/rate_cell_integration.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/rate_cell_integration.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/rs_izhcell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/rs_izhcell.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/simple_codes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/simple_codes.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/slif_no_refract_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/slif_no_refract_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/slif_refract_plot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/slif_refract_plot.jpg -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/stdp_bi_and_poo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/stdp_bi_and_poo.png -------------------------------------------------------------------------------- /docs/images/tutorials/neurocog/stdp_curve.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/docs/images/tutorials/neurocog/stdp_curve.jpg -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. ngc-learn documentation master file, created by 2 | sphinx-quickstart on Wed Apr 20 02:52:17 2022. 3 | Note - This file needs to at least contain a root `toctree` directive. 4 | 5 | Welcome to ngc-learn's documentation! 6 | ===================================== 7 | 8 | **ngc-learn** is a Python library for building, simulating, and analyzing 9 | biomimetic computational models, arbitrary predictive processing/coding models, 10 | and spiking neural networks. This toolkit is built on top of 11 | `JAX `_ and is distributed under the 3-Clause BSD license. 12 | 13 | .. toctree:: 14 | :maxdepth: 1 15 | :caption: Introduction: 16 | 17 | overview 18 | installation 19 | 20 | .. toctree:: 21 | :maxdepth: 1 22 | :caption: Tutorials 23 | 24 | tutorials/intro 25 | tutorials/theory 26 | tutorials/index 27 | tutorials/neurocog/index 28 | 29 | .. toctree:: 30 | :maxdepth: 1 31 | :caption: Model Museum 32 | 33 | museum/model_museum 34 | museum/index 35 | 36 | 37 | .. toctree:: 38 | :maxdepth: 1 39 | :caption: Modeling API 40 | 41 | modeling/components 42 | modeling/neurons 43 | modeling/synapses 44 | modeling/input_encoders 45 | modeling/other_ops 46 | 47 | .. toctree:: 48 | :maxdepth: 6 49 | :caption: Source API 50 | 51 | source/modules 52 | 53 | .. toctree:: 54 | :maxdepth: 1 55 | :caption: Papers that use NGC-Learn 56 | 57 | ngclearn_papers 58 | 59 | Indices and tables 60 | ================== 61 | 62 | * :ref:`genindex` 63 | * :ref:`modindex` 64 | * :ref:`search` 65 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=. 11 | set BUILDDIR=_build 12 | 13 | %SPHINXBUILD% >NUL 2>NUL 14 | if errorlevel 9009 ( 15 | echo. 16 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 17 | echo.installed, then set the SPHINXBUILD environment variable to point 18 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 19 | echo.may add the Sphinx directory to PATH. 20 | echo. 21 | echo.If you don't have Sphinx installed, grab it from 22 | echo.https://www.sphinx-doc.org/ 23 | exit /b 1 24 | ) 25 | 26 | if "%1" == "" goto help 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/modeling/other_ops.md: -------------------------------------------------------------------------------- 1 | # Other Operators 2 | 3 | Other operators range from variable traces to kernels and hand-crafted transformations. 4 | An important and oft-used one, in the case of spiking neural systems, is the 5 | variable trace (or filter) -- for instance, one might need to track a cumulative 6 | value based on spikes over time to trigger local updates to synaptic cable values 7 | with a compartment such as [VarTrace](ngclearn.components.other.varTrace). 8 | 9 | ## Trace Operators 10 | 11 | ### Variable Trace 12 | 13 | This operator processes and tracks a particular value (dependent upon which 14 | external component's compartment is wired into this one's input compartment). 15 | In general, a trace integrates a differential equation based on an external 16 | component's compartment value, e.g., the spike `s` of a spiking neuronal cell, 17 | producing a real-valued cumulative representation of it across time. For 18 | instance, instead of directly tracking spike times of a particular spiking cell, 19 | a trace can be used to represent a soft, single approximation. Another way to 20 | view a variable trace is that it acts as a low-pass filter of another signal 21 | sequence. 22 | 23 | ```{eval-rst} 24 | .. autoclass:: ngclearn.components.VarTrace 25 | :noindex: 26 | 27 | .. automethod:: advance_state 28 | :noindex: 29 | .. automethod:: reset 30 | :noindex: 31 | ``` 32 | 33 | ## Kernels 34 | 35 | Kernels are an important and useful building block for constructing what is 36 | known in computational neuroscience as spike-response models (SRMs). In 37 | ngc-learn, these generally involve the construction of nodes that apply a 38 | particular mathematical function (or set of them) to integrate over a window 39 | of collected values, generally discrete spikes or action potentials produced 40 | within a particular window of time. 41 | 42 | ### Exponential Kernel 43 | 44 | This kernel operator processes and tracks a window of values (generally spikes) to 45 | produce an excitatory postsynaptic potential (EPSP) pulse value via application 46 | of an exponential kernel. 47 | 48 | ```{eval-rst} 49 | .. autoclass:: ngclearn.components.ExpKernel 50 | :noindex: 51 | 52 | .. automethod:: advance_state 53 | :noindex: 54 | .. automethod:: reset 55 | :noindex: 56 | ``` 57 | -------------------------------------------------------------------------------- /docs/museum/index.rst: -------------------------------------------------------------------------------- 1 | .. ngc-learn documentation master file, created by 2 | sphinx-quickstart on Wed Apr 20 02:52:17 2022. 3 | Note - This file needs to at least contain a root `toctree` directive. 4 | 5 | Model Exhibits 6 | ============== 7 | 8 | Models are presented in ngc-learn's model museum in the form of "exhibits", 9 | which are effectively model-specific walkthroughs and analyses, based on the 10 | relevant, referenced publicly available ngc-learn simulation code. 11 | 12 | .. toctree:: 13 | :maxdepth: 1 14 | :caption: Neuromimetic Models 15 | 16 | pcn_discrim 17 | sparse_coding 18 | snn_dc 19 | snn_bfa 20 | sindy 21 | rl_snn 22 | -------------------------------------------------------------------------------- /docs/museum/model_museum.md: -------------------------------------------------------------------------------- 1 | # The Model Museum 2 | 3 | There is an ever-growing galaxy of neurobiological models and credit assignment 4 | processes [1, 2]. One of ngc-learn's aims, in the spirit of scientific 5 | reproducibility, is to capture a snapshot of as many of these 6 | biomimetic/neuro-mimetic models as possible, in the form of a digital "museum". 7 | This museum is further designed with the notion of exhibits and exhibitors, 8 | aiding to facilitate credit assignment and respectful citation to the ideas and 9 | the work of those that have helped to lay the foundations for the progress 10 | observed today. Recently, we have separated out the model museum into its own 11 | particular maintained repository called 12 | [ngc-museum](https://github.com/NACLab/ngc-museum), where you can find and 13 | access/run historical models and agents built with ngc-learn to perform 14 | different experimental tasks. 15 | 16 | Please refer to the [table of contents](../museum/index.rst) for walkthroughs on 17 | using and running various historical models in the museum. 18 | 19 | ## References 20 | [1] Ororbia, Alexander G. "Brain-inspired machine intelligence: A survey 21 | of neurobiologically-plausible credit assignment." 22 | arXiv preprint arXiv:2312.09257 (2023).
23 | [2] Ororbia, Alexander, Ankur Mali, Adam Kohan, Beren Millidge, and 24 | Tommaso Salvatori. "A Review of Neuroscience-Inspired Machine Learning." 25 | arXiv preprint arXiv:2403.18929 (2024). 26 | -------------------------------------------------------------------------------- /docs/ngclearn_papers.md: -------------------------------------------------------------------------------- 1 | # List of Papers/Publications 2 | 3 | The following is a list of current papers that use ngc-learn (this list will be 4 | actively updated as we discover others that use ngc-learn): 5 | 6 | 1. Ororbia, A., and Kifer, D. The neural coding framework for learning 7 | generative models. Nature Communications 13, 2064 (2022). 8 | 9 | 2. Ororbia, A., and Mali, A. Backprop-free reinforcement learning with active 10 | neural generative coding. Proceedings of the AAAI Conference on Artificial 11 | intelligence (2022). 12 | 13 | 3. Ororbia, A. "Spiking neural predictive coding for continual learning 14 | from data streams." arXiv preprint arXiv:1908.08655 (2019). 15 | 16 | 4. Ororbia, A, and Kelly, M. Alex. "CogNGen: constructing the kernel of 17 | a hyperdimensional predictive processing cognitive architecture." 18 | Proceedings of the Annual Meeting of the Cognitive Science Society (CogSci), Volume 44 (2022). 19 | 20 | 5. Ororbia, A., and Kelly, M. Alex. "“Learning using a Hyperdimensional Predictive Processing Cognitive 21 | Architecture." 15th International Conference on Artificial General Intelligence (AGI) (2022). 22 | 23 | 6. Ororbia, A., Mali, A., Kifer, D., & Giles, C. L. "Lifelong neural predictive coding: Learning cumulatively online without 24 | forgetting." Thirty-sixth Conference on Neural Information Processing Systems (NeurIPS) (2022). 25 | 26 | Note: Please let us know if your work uses ngc-learn so we can update this page to accurately track 27 | ngc-learn's use and include your work in the accumulating body of work in predictive processing 28 | and/or brain-inspired computational modeling. 29 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx>=4.5.0 2 | sphinx_rtd_theme>=0.5.2 3 | myst-parser>=0.17.2 4 | numpy>=1.26.0 5 | scikit-learn>=0.24.2 6 | scipy>=1.7.0 7 | matplotlib>=3.8.0 8 | jax>=0.4.28 9 | jaxlib>=0.4.28 10 | imageio>=2.31.5 11 | ngcsimlib>=1.0.0 12 | -------------------------------------------------------------------------------- /docs/source/modules.rst: -------------------------------------------------------------------------------- 1 | ngclearn 2 | ======== 3 | 4 | .. toctree:: 5 | :maxdepth: 4 6 | 7 | ngclearn 8 | -------------------------------------------------------------------------------- /docs/source/ngclearn.commands.rst: -------------------------------------------------------------------------------- 1 | ngclearn.commands package 2 | ========================= 3 | 4 | Module contents 5 | --------------- 6 | 7 | .. automodule:: ngclearn.commands 8 | :members: 9 | :undoc-members: 10 | :show-inheritance: 11 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.input_encoders.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.input\_encoders package 2 | =========================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.input\_encoders.bernoulliCell module 8 | -------------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.input_encoders.bernoulliCell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.input\_encoders.latencyCell module 16 | ------------------------------------------------------ 17 | 18 | .. automodule:: ngclearn.components.input_encoders.latencyCell 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.input\_encoders.phasorCell module 24 | ----------------------------------------------------- 25 | 26 | .. automodule:: ngclearn.components.input_encoders.phasorCell 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.components.input\_encoders.poissonCell module 32 | ------------------------------------------------------ 33 | 34 | .. automodule:: ngclearn.components.input_encoders.poissonCell 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: ngclearn.components.input_encoders 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.lava.neurons.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.lava.neurons package 2 | ======================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.lava.neurons.LIFCell module 8 | ----------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.lava.neurons.LIFCell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: ngclearn.components.lava.neurons 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.lava.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.lava package 2 | ================================ 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.components.lava.neurons 11 | ngclearn.components.lava.synapses 12 | ngclearn.components.lava.traces 13 | 14 | Submodules 15 | ---------- 16 | 17 | ngclearn.components.lava.monitor module 18 | --------------------------------------- 19 | 20 | .. automodule:: ngclearn.components.lava.monitor 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | Module contents 26 | --------------- 27 | 28 | .. automodule:: ngclearn.components.lava 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.lava.synapses.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.lava.synapses package 2 | ========================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.lava.synapses.hebbianSynapse module 8 | ------------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.lava.synapses.hebbianSynapse 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.lava.synapses.staticSynapse module 16 | ------------------------------------------------------ 17 | 18 | .. automodule:: ngclearn.components.lava.synapses.staticSynapse 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.lava.synapses.traceSTDPSynapse module 24 | --------------------------------------------------------- 25 | 26 | .. automodule:: ngclearn.components.lava.synapses.traceSTDPSynapse 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: ngclearn.components.lava.synapses 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.lava.traces.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.lava.traces package 2 | ======================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.lava.traces.gatedTrace module 8 | ------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.lava.traces.gatedTrace 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: ngclearn.components.lava.traces 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.neurons.graded.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.neurons.graded package 2 | ========================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.neurons.graded.bernoulliErrorCell module 8 | ------------------------------------------------------------ 9 | 10 | .. automodule:: ngclearn.components.neurons.graded.bernoulliErrorCell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.neurons.graded.gaussianErrorCell module 16 | ----------------------------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.neurons.graded.gaussianErrorCell 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.neurons.graded.laplacianErrorCell module 24 | ------------------------------------------------------------ 25 | 26 | .. automodule:: ngclearn.components.neurons.graded.laplacianErrorCell 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.components.neurons.graded.rateCell module 32 | -------------------------------------------------- 33 | 34 | .. automodule:: ngclearn.components.neurons.graded.rateCell 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | ngclearn.components.neurons.graded.rewardErrorCell module 40 | --------------------------------------------------------- 41 | 42 | .. automodule:: ngclearn.components.neurons.graded.rewardErrorCell 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Module contents 48 | --------------- 49 | 50 | .. automodule:: ngclearn.components.neurons.graded 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.neurons.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.neurons package 2 | =================================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.components.neurons.graded 11 | ngclearn.components.neurons.spiking 12 | 13 | Module contents 14 | --------------- 15 | 16 | .. automodule:: ngclearn.components.neurons 17 | :members: 18 | :undoc-members: 19 | :show-inheritance: 20 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.neurons.spiking.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.neurons.spiking package 2 | =========================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.neurons.spiking.IFCell module 8 | ------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.neurons.spiking.IFCell 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.neurons.spiking.LIFCell module 16 | -------------------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.neurons.spiking.LIFCell 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.neurons.spiking.RAFCell module 24 | -------------------------------------------------- 25 | 26 | .. automodule:: ngclearn.components.neurons.spiking.RAFCell 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.components.neurons.spiking.WTASCell module 32 | --------------------------------------------------- 33 | 34 | .. automodule:: ngclearn.components.neurons.spiking.WTASCell 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | ngclearn.components.neurons.spiking.adExCell module 40 | --------------------------------------------------- 41 | 42 | .. automodule:: ngclearn.components.neurons.spiking.adExCell 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | ngclearn.components.neurons.spiking.fitzhughNagumoCell module 48 | ------------------------------------------------------------- 49 | 50 | .. automodule:: ngclearn.components.neurons.spiking.fitzhughNagumoCell 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | ngclearn.components.neurons.spiking.hodgkinHuxleyCell module 56 | ------------------------------------------------------------ 57 | 58 | .. automodule:: ngclearn.components.neurons.spiking.hodgkinHuxleyCell 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | ngclearn.components.neurons.spiking.izhikevichCell module 64 | --------------------------------------------------------- 65 | 66 | .. automodule:: ngclearn.components.neurons.spiking.izhikevichCell 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | ngclearn.components.neurons.spiking.quadLIFCell module 72 | ------------------------------------------------------ 73 | 74 | .. automodule:: ngclearn.components.neurons.spiking.quadLIFCell 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | ngclearn.components.neurons.spiking.sLIFCell module 80 | --------------------------------------------------- 81 | 82 | .. automodule:: ngclearn.components.neurons.spiking.sLIFCell 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | 87 | Module contents 88 | --------------- 89 | 90 | .. automodule:: ngclearn.components.neurons.spiking 91 | :members: 92 | :undoc-members: 93 | :show-inheritance: 94 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.other.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.other package 2 | ================================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.other.expKernel module 8 | ------------------------------------------ 9 | 10 | .. automodule:: ngclearn.components.other.expKernel 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.other.varTrace module 16 | ----------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.other.varTrace 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: ngclearn.components.other 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components package 2 | =========================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.components.input_encoders 11 | ngclearn.components.lava 12 | ngclearn.components.neurons 13 | ngclearn.components.other 14 | ngclearn.components.synapses 15 | 16 | Submodules 17 | ---------- 18 | 19 | ngclearn.components.base\_monitor module 20 | ---------------------------------------- 21 | 22 | .. automodule:: ngclearn.components.base_monitor 23 | :members: 24 | :undoc-members: 25 | :show-inheritance: 26 | 27 | ngclearn.components.jaxComponent module 28 | --------------------------------------- 29 | 30 | .. automodule:: ngclearn.components.jaxComponent 31 | :members: 32 | :undoc-members: 33 | :show-inheritance: 34 | 35 | ngclearn.components.monitor module 36 | ---------------------------------- 37 | 38 | .. automodule:: ngclearn.components.monitor 39 | :members: 40 | :undoc-members: 41 | :show-inheritance: 42 | 43 | Module contents 44 | --------------- 45 | 46 | .. automodule:: ngclearn.components 47 | :members: 48 | :undoc-members: 49 | :show-inheritance: 50 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.synapses.convolution.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.synapses.convolution package 2 | ================================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.synapses.convolution.convSynapse module 8 | ----------------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.synapses.convolution.convSynapse 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.synapses.convolution.deconvSynapse module 16 | ------------------------------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.synapses.convolution.deconvSynapse 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.synapses.convolution.hebbianConvSynapse module 24 | ------------------------------------------------------------------ 25 | 26 | .. automodule:: ngclearn.components.synapses.convolution.hebbianConvSynapse 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.components.synapses.convolution.hebbianDeconvSynapse module 32 | -------------------------------------------------------------------- 33 | 34 | .. automodule:: ngclearn.components.synapses.convolution.hebbianDeconvSynapse 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | ngclearn.components.synapses.convolution.ngcconv module 40 | ------------------------------------------------------- 41 | 42 | .. automodule:: ngclearn.components.synapses.convolution.ngcconv 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | ngclearn.components.synapses.convolution.staticConvSynapse module 48 | ----------------------------------------------------------------- 49 | 50 | .. automodule:: ngclearn.components.synapses.convolution.staticConvSynapse 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | 55 | ngclearn.components.synapses.convolution.staticDeconvSynapse module 56 | ------------------------------------------------------------------- 57 | 58 | .. automodule:: ngclearn.components.synapses.convolution.staticDeconvSynapse 59 | :members: 60 | :undoc-members: 61 | :show-inheritance: 62 | 63 | ngclearn.components.synapses.convolution.traceSTDPConvSynapse module 64 | -------------------------------------------------------------------- 65 | 66 | .. automodule:: ngclearn.components.synapses.convolution.traceSTDPConvSynapse 67 | :members: 68 | :undoc-members: 69 | :show-inheritance: 70 | 71 | ngclearn.components.synapses.convolution.traceSTDPDeconvSynapse module 72 | ---------------------------------------------------------------------- 73 | 74 | .. automodule:: ngclearn.components.synapses.convolution.traceSTDPDeconvSynapse 75 | :members: 76 | :undoc-members: 77 | :show-inheritance: 78 | 79 | Module contents 80 | --------------- 81 | 82 | .. automodule:: ngclearn.components.synapses.convolution 83 | :members: 84 | :undoc-members: 85 | :show-inheritance: 86 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.synapses.hebbian.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.synapses.hebbian package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.synapses.hebbian.BCMSynapse module 8 | ------------------------------------------------------ 9 | 10 | .. automodule:: ngclearn.components.synapses.hebbian.BCMSynapse 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.synapses.hebbian.eventSTDPSynapse module 16 | ------------------------------------------------------------ 17 | 18 | .. automodule:: ngclearn.components.synapses.hebbian.eventSTDPSynapse 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.synapses.hebbian.expSTDPSynapse module 24 | ---------------------------------------------------------- 25 | 26 | .. automodule:: ngclearn.components.synapses.hebbian.expSTDPSynapse 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.components.synapses.hebbian.hebbianSynapse module 32 | ---------------------------------------------------------- 33 | 34 | .. automodule:: ngclearn.components.synapses.hebbian.hebbianSynapse 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | ngclearn.components.synapses.hebbian.traceSTDPSynapse module 40 | ------------------------------------------------------------ 41 | 42 | .. automodule:: ngclearn.components.synapses.hebbian.traceSTDPSynapse 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | 47 | Module contents 48 | --------------- 49 | 50 | .. automodule:: ngclearn.components.synapses.hebbian 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.synapses.modulated.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.synapses.modulated package 2 | ============================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.synapses.modulated.MSTDPETSynapse module 8 | ------------------------------------------------------------ 9 | 10 | .. automodule:: ngclearn.components.synapses.modulated.MSTDPETSynapse 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.synapses.modulated.REINFORCESynapse module 16 | -------------------------------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.synapses.modulated.REINFORCESynapse 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: ngclearn.components.synapses.modulated 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.synapses.patched.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.synapses.patched package 2 | ============================================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.components.synapses.patched.hebbianPatchedSynapse module 8 | ----------------------------------------------------------------- 9 | 10 | .. automodule:: ngclearn.components.synapses.patched.hebbianPatchedSynapse 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.components.synapses.patched.patchedSynapse module 16 | ---------------------------------------------------------- 17 | 18 | .. automodule:: ngclearn.components.synapses.patched.patchedSynapse 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.components.synapses.patched.staticPatchedSynapse module 24 | ---------------------------------------------------------------- 25 | 26 | .. automodule:: ngclearn.components.synapses.patched.staticPatchedSynapse 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: ngclearn.components.synapses.patched 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/ngclearn.components.synapses.rst: -------------------------------------------------------------------------------- 1 | ngclearn.components.synapses package 2 | ==================================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.components.synapses.convolution 11 | ngclearn.components.synapses.hebbian 12 | ngclearn.components.synapses.modulated 13 | ngclearn.components.synapses.patched 14 | 15 | Submodules 16 | ---------- 17 | 18 | ngclearn.components.synapses.STPDenseSynapse module 19 | --------------------------------------------------- 20 | 21 | .. automodule:: ngclearn.components.synapses.STPDenseSynapse 22 | :members: 23 | :undoc-members: 24 | :show-inheritance: 25 | 26 | ngclearn.components.synapses.alphaSynapse module 27 | ------------------------------------------------ 28 | 29 | .. automodule:: ngclearn.components.synapses.alphaSynapse 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | 34 | ngclearn.components.synapses.denseSynapse module 35 | ------------------------------------------------ 36 | 37 | .. automodule:: ngclearn.components.synapses.denseSynapse 38 | :members: 39 | :undoc-members: 40 | :show-inheritance: 41 | 42 | ngclearn.components.synapses.doubleExpSynapse module 43 | ---------------------------------------------------- 44 | 45 | .. automodule:: ngclearn.components.synapses.doubleExpSynapse 46 | :members: 47 | :undoc-members: 48 | :show-inheritance: 49 | 50 | ngclearn.components.synapses.exponentialSynapse module 51 | ------------------------------------------------------ 52 | 53 | .. automodule:: ngclearn.components.synapses.exponentialSynapse 54 | :members: 55 | :undoc-members: 56 | :show-inheritance: 57 | 58 | ngclearn.components.synapses.staticSynapse module 59 | ------------------------------------------------- 60 | 61 | .. automodule:: ngclearn.components.synapses.staticSynapse 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | 66 | Module contents 67 | --------------- 68 | 69 | .. automodule:: ngclearn.components.synapses 70 | :members: 71 | :undoc-members: 72 | :show-inheritance: 73 | -------------------------------------------------------------------------------- /docs/source/ngclearn.modules.regression.rst: -------------------------------------------------------------------------------- 1 | ngclearn.modules.regression package 2 | =================================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.modules.regression.elastic\_net module 8 | ----------------------------------------------- 9 | 10 | .. automodule:: ngclearn.modules.regression.elastic_net 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.modules.regression.lasso module 16 | ---------------------------------------- 17 | 18 | .. automodule:: ngclearn.modules.regression.lasso 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.modules.regression.ridge module 24 | ---------------------------------------- 25 | 26 | .. automodule:: ngclearn.modules.regression.ridge 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: ngclearn.modules.regression 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/ngclearn.modules.rst: -------------------------------------------------------------------------------- 1 | ngclearn.modules package 2 | ======================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.modules.regression 11 | 12 | Module contents 13 | --------------- 14 | 15 | .. automodule:: ngclearn.modules 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | -------------------------------------------------------------------------------- /docs/source/ngclearn.operations.rst: -------------------------------------------------------------------------------- 1 | ngclearn.operations package 2 | =========================== 3 | 4 | Module contents 5 | --------------- 6 | 7 | .. automodule:: ngclearn.operations 8 | :members: 9 | :undoc-members: 10 | :show-inheritance: 11 | -------------------------------------------------------------------------------- /docs/source/ngclearn.rst: -------------------------------------------------------------------------------- 1 | ngclearn package 2 | ================ 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.commands 11 | ngclearn.components 12 | ngclearn.modules 13 | ngclearn.operations 14 | ngclearn.utils 15 | 16 | Module contents 17 | --------------- 18 | 19 | .. automodule:: ngclearn 20 | :members: 21 | :undoc-members: 22 | :show-inheritance: 23 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.analysis.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils.analysis package 2 | =============================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.utils.analysis.attentive\_probe module 8 | ----------------------------------------------- 9 | 10 | .. automodule:: ngclearn.utils.analysis.attentive_probe 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.utils.analysis.linear\_probe module 16 | -------------------------------------------- 17 | 18 | .. automodule:: ngclearn.utils.analysis.linear_probe 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.utils.analysis.probe module 24 | ------------------------------------ 25 | 26 | .. automodule:: ngclearn.utils.analysis.probe 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: ngclearn.utils.analysis 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.density.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils.density package 2 | ============================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.utils.density.gmm module 8 | --------------------------------- 9 | 10 | .. automodule:: ngclearn.utils.density.gmm 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | Module contents 16 | --------------- 17 | 18 | .. automodule:: ngclearn.utils.density 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.diffeq.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils.diffeq package 2 | ============================= 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.utils.diffeq.ode\_utils module 8 | --------------------------------------- 9 | 10 | .. automodule:: ngclearn.utils.diffeq.ode_utils 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.utils.diffeq.odes module 16 | --------------------------------- 17 | 18 | .. automodule:: ngclearn.utils.diffeq.odes 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | Module contents 24 | --------------- 25 | 26 | .. automodule:: ngclearn.utils.diffeq 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.optim.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils.optim package 2 | ============================ 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.utils.optim.adam module 8 | -------------------------------- 9 | 10 | .. automodule:: ngclearn.utils.optim.adam 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.utils.optim.optim\_utils module 16 | ---------------------------------------- 17 | 18 | .. automodule:: ngclearn.utils.optim.optim_utils 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.utils.optim.sgd module 24 | ------------------------------- 25 | 26 | .. automodule:: ngclearn.utils.optim.sgd 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | Module contents 32 | --------------- 33 | 34 | .. automodule:: ngclearn.utils.optim 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils package 2 | ====================== 3 | 4 | Subpackages 5 | ----------- 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | 10 | ngclearn.utils.analysis 11 | ngclearn.utils.density 12 | ngclearn.utils.diffeq 13 | ngclearn.utils.optim 14 | ngclearn.utils.viz 15 | 16 | Submodules 17 | ---------- 18 | 19 | ngclearn.utils.data\_loader module 20 | ---------------------------------- 21 | 22 | .. automodule:: ngclearn.utils.data_loader 23 | :members: 24 | :undoc-members: 25 | :show-inheritance: 26 | 27 | ngclearn.utils.io\_utils module 28 | ------------------------------- 29 | 30 | .. automodule:: ngclearn.utils.io_utils 31 | :members: 32 | :undoc-members: 33 | :show-inheritance: 34 | 35 | ngclearn.utils.jaxProcess module 36 | -------------------------------- 37 | 38 | .. automodule:: ngclearn.utils.jaxProcess 39 | :members: 40 | :undoc-members: 41 | :show-inheritance: 42 | 43 | ngclearn.utils.metric\_utils module 44 | ----------------------------------- 45 | 46 | .. automodule:: ngclearn.utils.metric_utils 47 | :members: 48 | :undoc-members: 49 | :show-inheritance: 50 | 51 | ngclearn.utils.model\_utils module 52 | ---------------------------------- 53 | 54 | .. automodule:: ngclearn.utils.model_utils 55 | :members: 56 | :undoc-members: 57 | :show-inheritance: 58 | 59 | ngclearn.utils.patch\_utils module 60 | ---------------------------------- 61 | 62 | .. automodule:: ngclearn.utils.patch_utils 63 | :members: 64 | :undoc-members: 65 | :show-inheritance: 66 | 67 | ngclearn.utils.surrogate\_fx module 68 | ----------------------------------- 69 | 70 | .. automodule:: ngclearn.utils.surrogate_fx 71 | :members: 72 | :undoc-members: 73 | :show-inheritance: 74 | 75 | ngclearn.utils.weight\_distribution module 76 | ------------------------------------------ 77 | 78 | .. automodule:: ngclearn.utils.weight_distribution 79 | :members: 80 | :undoc-members: 81 | :show-inheritance: 82 | 83 | Module contents 84 | --------------- 85 | 86 | .. automodule:: ngclearn.utils 87 | :members: 88 | :undoc-members: 89 | :show-inheritance: 90 | -------------------------------------------------------------------------------- /docs/source/ngclearn.utils.viz.rst: -------------------------------------------------------------------------------- 1 | ngclearn.utils.viz package 2 | ========================== 3 | 4 | Submodules 5 | ---------- 6 | 7 | ngclearn.utils.viz.dim\_reduce module 8 | ------------------------------------- 9 | 10 | .. automodule:: ngclearn.utils.viz.dim_reduce 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | ngclearn.utils.viz.raster module 16 | -------------------------------- 17 | 18 | .. automodule:: ngclearn.utils.viz.raster 19 | :members: 20 | :undoc-members: 21 | :show-inheritance: 22 | 23 | ngclearn.utils.viz.spike\_plot module 24 | ------------------------------------- 25 | 26 | .. automodule:: ngclearn.utils.viz.spike_plot 27 | :members: 28 | :undoc-members: 29 | :show-inheritance: 30 | 31 | ngclearn.utils.viz.synapse\_plot module 32 | --------------------------------------- 33 | 34 | .. automodule:: ngclearn.utils.viz.synapse_plot 35 | :members: 36 | :undoc-members: 37 | :show-inheritance: 38 | 39 | Module contents 40 | --------------- 41 | 42 | .. automodule:: ngclearn.utils.viz 43 | :members: 44 | :undoc-members: 45 | :show-inheritance: 46 | -------------------------------------------------------------------------------- /docs/tutorials/foundations.md: -------------------------------------------------------------------------------- 1 | # Foundational Elements 2 | 3 | In this set of tutorials/walkthroughs, we go through the some of the core elements 4 | and mechanisms underlying ngc-learn in order understand how its simulation 5 | scheme (and the nodes-and-cables system) works and to help in writing your 6 | own custom elements. 7 | 8 | The foundational walkthroughs are organized as follows: 9 | 1. [Using Model Contexts](../tutorials/foundations/contexts.md): This lesson goes 10 | the fundamentals of the primary simulation construct you need to set up models, the 11 | (simulation) context. 12 | 2. [Understanding Commands](../tutorials/foundations/commands.md): This lesson will 13 | walk you through the basics of a command -- an essential part of building a 14 | simulation controller in ngc-learn and ngcsimlib -- and offer some useful 15 | points for designing new ones. 16 | 3. [Operations](../tutorials/foundations/operations.md): Here, the basics 17 | of bundle rules, a commonly use mechanism for crafting complex biophysical 18 | systems, will be presented. 19 | -------------------------------------------------------------------------------- /docs/tutorials/foundations/contexts.md: -------------------------------------------------------------------------------- 1 | # What are Contexts 2 | 3 | A context in ngclearn is a container that holds all the information for your model and can be used as an access point to 4 | reference different models in a multi-model system. Some of the information that contexts hold is all the components 5 | defined in the context, all the wiring information for each of the components, as well as all the commands defined on 6 | the context through various means. 7 | 8 | ## How to make a Context 9 | 10 | To make a context first import it from ngclearn with `from ngclearn import Context`. This will give you access to not 11 | only the constructor for new contexts but also the ability to get previously defined contexts. The general use case for 12 | this is 13 | 14 | ```python 15 | from ngclearn import Context 16 | 17 | with Context("Model1") as model1: 18 | pass 19 | ``` 20 | 21 | This will make a context named "Model1" and also drops you into a with block where you can define the various parts of 22 | the model. The call `Context("Model1")` will always return the same context. So if there is already a model with that 23 | name defined earlier in the code this instance of `model1` will have all the same object defined previously. 24 | 25 | ## Adding Components 26 | 27 | The best way to add components to a context is by using components that have implemented the `MetaComponent` metaclass. 28 | In ngclearn the base `Component` class does this. If using these components all that is needed to have them added to 29 | the context is calling their constructors inside a with block of the context. For example 30 | 31 | ```python 32 | from ngclearn import Context 33 | from ngclearn.components import LIFCell 34 | 35 | with Context("Model1") as model1: 36 | z1 = LIFCell("z1", n_units=10, tau_m=100) 37 | ``` 38 | 39 | ## Creating Cables 40 | 41 | To add connections between components and their compartments in a model we do that also in a context. Just like with 42 | components there are no special actions that need to be taken to add them beyond doing so in a with block. To connect 43 | to compartments the `<<` operator is used following the outline of `destination << source`. For example 44 | 45 | ```python 46 | with model1: 47 | w1.inputs << z1.s 48 | ``` 49 | 50 | ## Dynamic Commands 51 | 52 | When building models it can be desirable to use the same training and testing scrips while having commands do different 53 | actions. For example if two different models had different clamp procedures to set inputs and labels it is possible to 54 | dynamically add a generic clamp command to each model and call them the same way despite them doing different things. 55 | As an example 56 | ```python 57 | with model1: 58 | @model1.dynamicCommand 59 | def clamp(inputs, labels): 60 | z0.inputs.clamp(inputs) 61 | z2.labels.clamp(labels) 62 | 63 | with model2: 64 | @model2.dynamicCommand 65 | def clamp(inputs, labels): 66 | z0.inputs.clamp(inputs) 67 | z0_p.inputs.clamp(inputs) 68 | z2.labels.clamp(labels) 69 | ``` 70 | In both these cases later we can just call clamp and each one will call their own version of the clamp command. 71 | -------------------------------------------------------------------------------- /docs/tutorials/foundations/monitors.md: -------------------------------------------------------------------------------- 1 | # NGC Monitors 2 | 3 | NGC-monitors are a way of storing a rolling window of compartment values 4 | automatically. Their intended purpose is not to be used "inside" of a model but 5 | just as an auxiliary way to view the internal state of the model even when it is 6 | compiled. A monitor will track the last `n` values it has observed within the 7 | compartment with the oldest value being at `index=0` and the newest being at 8 | `index=n-1`. 9 | 10 | ## Building a Monitor 11 | 12 | Monitors are constructed exactly like regular components are for general models. 13 | To use one, simply import the monitor `from ngclearn.components import Monitor`. Now, 14 | inside of your model, build it like a regular component: 15 | 16 | ```python 17 | with Context("model") as model: 18 | M = Monitor("M", default_window_length=100) 19 | ``` 20 | 21 | ## Watching compartments 22 | 23 | There are then two key ways of watching compartments, the first way looks similar 24 | to the wiring paradigm found in connecting standard ngclearn components 25 | together. The primary difference is that connecting compartments to the monitor 26 | does not require a compartment, they are wired directly into the `Monitor` 27 | following the pattern below: 28 | 29 | ```python 30 | M << z0.s 31 | ``` 32 | 33 | This will wire the spike output of `z0` into the monitor with a view window 34 | length of the `default_window_length`. In the event that you want a view window 35 | that is not the default viewing length, you can use the `watch()` method 36 | instead as in below: 37 | 38 | ```python 39 | M.watch(z0.s, customWindowLength) 40 | ``` 41 | 42 | There is no limit to the number of compartments that a monitor can watch or the 43 | length of the window that it can store. However, as it is constantly shifting 44 | values, tracking large matrices, such as those containing synapse values 45 | over many timesteps, may get expensive. 46 | 47 | For the monitor to run during your `advance_state` and `reset` calls, make sure 48 | to add to the monitor to the list of components to compile. Currently, 49 | monitors do not work with non-compiled methods 50 | (This is a planned feature for future developments of ngc-learn). 51 | 52 | ## Extracting Values 53 | 54 | To look at the currently stored window of any compartment being tracked, there 55 | are two methods available to you. The first method requires that you have 56 | access to the compartment that the monitor is watching. To read out the 57 | monitors values, you can call: 58 | 59 | ```python 60 | M.view(z0.s) 61 | ``` 62 | 63 | In the event that you do not have access to the compartment, all of the stored 64 | values can be found via the path using the following: 65 | 66 | ```python 67 | M.get_store("path/to/compartment") 68 | ``` 69 | 70 | The stored windows are kept in a tree of dictionaries, where each node is a part 71 | of the path and the leaves are compartment objects holding the 72 | tracked value windows. -------------------------------------------------------------------------------- /docs/tutorials/foundations/operations.md: -------------------------------------------------------------------------------- 1 | # The Basics of Operations 2 | 3 | ## What are Operations? 4 | 5 | The underlying method for passing data/signals from component to component inside of 6 | contexts is through the use of cables. A large amount of the time compartments will have a single cable being passed 7 | connected to it that overwrites the previous value in that compartment. However, there are times when this is not the 8 | case and then cable operations must be used. 9 | 10 | ## Built-in operations 11 | 12 | By default, ngclearn comes with four operations defined, `overwrite`, `negate`, `summation` and `add`. Of these four 13 | operations the default one used by all cables is the overwrite operation. This operations will take the value of its 14 | source compartment and place it into the destination compartment overwriting the value currently there. The negate 15 | operation has a similar effect as the overwrite operation with the added functionality of applying the `-` operation to 16 | the value being transmitted. The summation operation takes in any number of source compartments and sums together all 17 | their values and overwrites the previous value with the sum. Finally, the add operation does the same thing as the 18 | summation operation but instead adds the sum to the previous value instead of overwriting it. 19 | 20 | ## Building Custom Operation 21 | 22 | At its core, an operation is a static method that does all the runtime logic of the operation with the source 23 | compartments, and a resolver that does clean up and assignment of the output of the operation to the destination 24 | compartment. 25 | 26 | > General Form of an Operation: 27 | > ```python 28 | > class operationName(BaseOp): 29 | > @staticmethod 30 | > def operation(*sources): 31 | > #Runtime Logic 32 | > return computed_value 33 | > ``` 34 | 35 | > Example Operation (Summation) 36 | > ```python 37 | > class summation(BaseOp): 38 | > @staticmethod 39 | > def operation(*sources): 40 | > s = None 41 | > for source in sources: 42 | > if s is None: 43 | > s = source 44 | > else: 45 | > s += source 46 | > return s 47 | > ``` 48 | 49 | ## Notes 50 | 51 | - Every cable coming into or out of a compartment can have a different operation. 52 | 53 | - The order of these operations should be the order they are wired in, but this is not guaranteed. 54 | 55 | - Only the logic that exists in the static method `operation` is used for a compiled operation, all logic existing in an overwritten resolve method is not captured. 56 | 57 | - Some operations have a flag of `is_compilable` set to false. This is checked during compile to flag if the model can be compiled. 58 | 59 | - Operations can be nested so `summaion(negate(c1), c2)` would be a valid operation and will work while compiled 60 | 61 | -------------------------------------------------------------------------------- /docs/tutorials/index.rst: -------------------------------------------------------------------------------- 1 | .. ngc-learn documentation master file, created by 2 | sphinx-quickstart on Wed Apr 20 02:52:17 2022. 3 | Note - This file needs to at least contain a root `toctree` directive. 4 | 5 | Tutorial Contents 6 | ================= 7 | 8 | Lessons/tutorials go through the very basics of constructing a dynamical system in 9 | ngc-learn, core elements and tools of neurocognitive modeling using ngc-learn's 10 | in-built components and simulation tools, and finally providing foundational insights 11 | into how ngc-learn and its backend, ngc-sim-lib, work (particularly with respect 12 | to configuration). 13 | 14 | .. toctree:: 15 | :maxdepth: 1 16 | :caption: I. Modeling Basics 17 | 18 | model_basics/configuration 19 | model_basics/json_modules 20 | model_basics/model_building 21 | model_basics/evolving_synapses 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | :caption: II. NGC-Learn/Sim-Lib Foundations 26 | 27 | foundations 28 | foundations/contexts 29 | foundations/commands 30 | foundations/operations 31 | foundations/monitors 32 | 33 | .. toctree:: 34 | :maxdepth: 1 35 | :caption: III. NGC-Lava: Support for Loihi 2 Transfer 36 | 37 | lava/introduction 38 | lava/setup 39 | lava/lava_components 40 | lava/lava_context 41 | lava/hebbian_learning 42 | lava/monitors 43 | -------------------------------------------------------------------------------- /docs/tutorials/lava/introduction.md: -------------------------------------------------------------------------------- 1 | # Blending ngc-learn and lava-nc 2 | 3 | The subpackage of ngclearn known as ngc-lava is an interfacing layer between 4 | ngclearn's components and contexts and lava-nc's models and processes. In this 5 | package, there is the introduction of the `LavaContext`, a subclass of the default 6 | ngclearn `Context`. This context has all the same functionality as the base 7 | ngclearn context but adds the ability to convert lava compatible components into 8 | their Lava process and model automatically and on-the-fly. This allows for the 9 | development and testing of models inside ngclearn prior to their deployment onto 10 | a Loihi neuromorphic chip without needing to translate between the two models 11 | written across the two different Python libraries. 12 | 13 | ## Some Cautionary Notes 14 | 15 | - For the best experience in training models in ngclearn, Python version `>=3.10` 16 | should be used. However, much of lava is written to be used in Python `3.8` and, 17 | because of this, there are some flags and functionality that cannot be used in Lava 18 | components directly. It is for this reason that ngc-learn has several 19 | in-built "lava components", i.e., those in `ngclearn.components.lava` that 20 | are meant to directly interact with ngc-lava; other components (such as those 21 | (`ngclearn.components.neurons` or `ngclearn.components.synapses`) are not likely 22 | to work and, when writing your own custom ngc-lava components, we recommend 23 | that you use those in the `ngclearn.components.lava` subpackage as starting 24 | points to see what design patterns will work with Lava. 25 | - As of right now, all of ngc-lava is built using the Loihi2 configuration and 26 | Loihi1 is not actively supported. Loihi1 might still work but nothing is 27 | guaranteed nor has been tested by the ngc-learn dev team. 28 | 29 | ## Table of Contents 30 | 1. [Setting up ngc-lava](setup.md): A brief overview of how to set up 31 | ngc-lava 32 | 2. [Lava components](lava_components.md): An overview of lava components in ngclearn and 33 | how to make custom ones 34 | 3. [Lava Context](lava_context.md): An overview of the Lava context and building 35 | models for Lava 36 | 4. [On-Chip Hebbian Learning](hebbian_learning.md): A walkthrough for getting a simple 37 | hebbian learning model setup 38 | -------------------------------------------------------------------------------- /docs/tutorials/lava/lava_components.md: -------------------------------------------------------------------------------- 1 | # Lava Components 2 | 3 | Inside ngc-learn, there is a wide variety of components with which biophysical 4 | models can be built. Unfortunately, many of those components are not compatible 5 | with Lava and the loihi2. Therefore, ngc-learn supports several in-built 6 | components that are Lava-compliant; many of the components that are compatible 7 | to you can be found in `ngclearn.components.lava`. 8 | 9 | ## What Makes an ngc-learn Component Compatible 10 | 11 | For components to be compatible with Lava, there are a few key rules that must 12 | be followed: 13 | - Lava Components can not make use of JAX's random or JAX's `nn` libraries 14 | - Lava Components must import numpy from ngclearn and not JAX (there is a flag 15 | in the configuration file to control JAX's numpy versus base numpy) 16 | - Lava Components cannot take in any runtime arguments to their `advance_state` method 17 | - Lava Components cannot take in any runtime arguments or compartments to their 18 | `reset` method(s) 19 | 20 | ## Mapping Methods -- Going from ngc-learn to Lava 21 | 22 | There are two methods that are mapped to their lava processes; these include the 23 | `reset` method and the `advance_state` method. The reset method is just mapped 24 | to the lava components and can be called on them without any issue. The 25 | `advance_state` method is mapped to the `run_spk` method and is called during 26 | the runtime loops in Lava. It is important to note that the methods that are 27 | actually mapped are the pure methods passed into the resolvers that 28 | decorate the ngc-learn `reset` and `advance_state` methods, not the 29 | `reset` and `advance_state` methods themselves. -------------------------------------------------------------------------------- /docs/tutorials/lava/monitors.md: -------------------------------------------------------------------------------- 1 | # Monitors 2 | 3 | While lava does have its own version of monitors, ngclearn offers an 4 | in-built version for convenience. It is 5 | recommended that you use the ngclearn monitors as they have expanded 6 | functionality and are designed to interact with the Lava components well. For an 7 | overview of/details on how monitors work please see 8 | [this](../foundations/monitors.md). The 9 | only difference is that Lava has its own monitor found 10 | in `ngclearn.components.lava`. 11 | 12 | ## Sharp Edges and Bits 13 | 14 | - Due to the fact that a Lava component of the monitor must be built, it has to 15 | be defined inside the `LavaContext`. 16 | - To view the values found within the monitor via the `view()` and `get_path()` 17 | methods, `model.write_to_ngc()` must be called to refresh the values. -------------------------------------------------------------------------------- /docs/tutorials/lava/setup.md: -------------------------------------------------------------------------------- 1 | # Setting Up ngc-lava 2 | 3 | Setting up ngc-lava is fairly straightforward. The only part that takes some 4 | time is the setting up of the lava environment itself. 5 | 6 | ## Installation and Setup Steps 7 | 8 | 1. To set up and use ngc-lava, first download lava-nc 9 | found [here](https://lava-nc.org/lava/notebooks/in_depth/tutorial01_installing_lava.html). 10 | 2. Install ngc-learn via pip `pip install ngc-learn` 11 | 3. Clone ngc-lava and add it as a project source 12 | ```bash 13 | git clone https://github.com/NACLab/ngc-lava.git 14 | pip install -e ngc-lava 15 | ``` 16 | 4. To compile for lava, Jax must be turned off; to do this, set the flag 17 | `packages/use_base_numpy` to `true` in the ngc-learn 18 | `config.json` file. If you do not have a `config.json` file written, the 19 | script below will make one for you and add the needed Lava configuration flag: 20 | 21 | ```bash 22 | mkdir json_files 23 | touch json_files/config.json 24 | echo "{\n \"packages\": {\n \"use_base_numpy\": true \n }\n}" > json_files/config.json 25 | ``` 26 | 5. You are now set up and ready to use ngc-lava. -------------------------------------------------------------------------------- /docs/tutorials/neurocog/index.rst: -------------------------------------------------------------------------------- 1 | .. ngc-learn documentation master file, created by 2 | sphinx-quickstart on Wed Apr 20 02:52:17 2022. 3 | Note - This file needs to at least contain a root `toctree` directive. 4 | 5 | Neurocognitive Modeling Lessons 6 | =============================== 7 | 8 | A central motivation for using ngc-learn is to flexibly build computational 9 | models of neuronal information processing, dynamics, and credit 10 | assignment (as well as design one's own custom instantiations of their 11 | mathematical formulations and ideas). In this set of tutorials, we will go 12 | through the central basics of using ngc-learn's in-built biophysical components, 13 | also called "cells" and "synapses", to craft and simulate adaptive neural systems 14 | and biophysical computational models. 15 | 16 | Usefully, ngc-learn starts with a collection of cells -- those that are partitioned 17 | into those that are graded / real-valued (`ngclearn.components.neurons.graded`) 18 | and those that spike (`ngclearn.components.neurons.spiking`). In addition, 19 | ngc-learn supports another collection called synapses -- generally, those that 20 | adapt (or "learn") with biological credit assignment building blocks 21 | (such as those in `ngclearn.components.synapses.hebbian`) such as 22 | spike-timing-dependent plasticity and multi-factor rules. With the in-built, 23 | standard cells and synapses in these two 24 | core collections, you can readily construct a wide variety of models, recovering 25 | many classical ones previously proposed in computational neuroscience 26 | and brain-inspired computing researach (many of these kinds of models are available 27 | for external download in the `Model Museum `_). 28 | 29 | While the reader is free to jump into any one self-contained tutorial in any 30 | order based on their needs, we organize, within each topic, the lessons starting 31 | from more basic, foundational modeling modules and library tools and sequentially 32 | work towards more advanced concepts. 33 | 34 | .. toctree:: 35 | :maxdepth: 1 36 | :caption: Sensory Input Encoding / Transformation 37 | 38 | input_cells 39 | traces 40 | 41 | .. toctree:: 42 | :maxdepth: 1 43 | :caption: Spiking Neuronal Cells 44 | 45 | simple_leaky_integrator 46 | lif 47 | fitzhugh_nagumo_cell 48 | izhikevich_cell 49 | adex_cell 50 | hodgkin_huxley_cell 51 | 52 | .. toctree:: 53 | :maxdepth: 1 54 | :caption: Graded Neuronal Cells 55 | 56 | rate_cell 57 | error_cell 58 | 59 | .. toctree:: 60 | :maxdepth: 1 61 | :caption: Synapses and Forms of Plasticity 62 | 63 | dynamic_synapses 64 | hebbian 65 | stdp 66 | mod_stdp 67 | short_term_plasticity 68 | 69 | .. toctree:: 70 | :maxdepth: 1 71 | :caption: Model and Analysis Tools 72 | 73 | plotting 74 | metrics 75 | integration 76 | -------------------------------------------------------------------------------- /docs/tutorials/neurocog/plotting.md: -------------------------------------------------------------------------------- 1 | # Plotting and Visualization 2 | 3 | While writing one's own custom task-specific matplotlib visualization code 4 | might be needed for specific experimental setups, there are several useful tools 5 | already in-built to ngc-learn, organized under the package sub-directory 6 | `ngclearn.utils.viz`, including utilities for generating raster plots and 7 | synaptic receptive field views (useful for biophysical models such as spiking 8 | neural networks) as well as t-SNE plots of model latent codes. While the other 9 | lesson/tutorials demonstrate some of these useful routines (e.g., raster plots 10 | for spiking neuronal cells), in this small lesson, we will demonstrate how to 11 | produce a t-SNE plot using ngc-learn's in-built tool. 12 | 13 | ## Generating a t-SNE Plot 14 | 15 | Let's say you have a labeled five-dimensional (5D) dataset -- which we will 16 | synthesize artificially in this lesson from an "unobserved" trio of multivariate 17 | Gaussians -- and wanted to visualize these "model outputs" and their 18 | corresponding labels in 2D via ngc-learn's in-built t-SNE. 19 | 20 | The following bit of Python code will do this for you (including the artificial 21 | data generator): 22 | 23 | ```python 24 | from jax import numpy as jnp, random 25 | from ngclearn.utils.viz.dim_reduce import extract_tsne_latents, plot_latents 26 | 27 | dkey = random.PRNGKey(1234) 28 | 29 | def gen_data(dkey, N): ## artificial data generator (or proxy model) 30 | mu1 = jnp.asarray([[2.1, 3.2, 0.6, -4., -2.]]) 31 | cov1 = jnp.eye(5) * 0.78 32 | mu2 = jnp.asarray([[-1.8, 0.2, -0.1, 1.99, 1.56]]) 33 | cov2 = jnp.eye(5) * 0.52 34 | mu3 = jnp.asarray([[0.3, -1.2, -0.56, -4., 3.6]]) 35 | cov3 = jnp.eye(5) * 1.2 36 | 37 | dkey, *subkeys = random.split(dkey, 7) 38 | samp1 = random.multivariate_normal(subkeys[0], mu1, cov1, shape=(N,)) 39 | samp2 = random.multivariate_normal(subkeys[0], mu2, cov2, shape=(N,)) 40 | samp3 = random.multivariate_normal(subkeys[0], mu3, cov3, shape=(N,)) 41 | X = jnp.concatenate((samp1, samp2, samp3), axis=0) 42 | y1 = jnp.ones((N, 3)) * jnp.asarray([[1., 0., 0.]]) 43 | y2 = jnp.ones((N, 3)) * jnp.asarray([[0., 1., 0.]]) 44 | y3 = jnp.ones((N, 3)) * jnp.asarray([[0., 0., 1.]]) 45 | lab = jnp.concatenate((y1, y2, y3), axis=0) ## one-hot codes 46 | return X, lab 47 | 48 | ## generate data or theoretical "model outputs" 49 | data, lab = gen_data(dkey, 400) 50 | 51 | ## visualize the above data via the t-SNE algorithm 52 | print("data.shape = ",data.shape) 53 | codes = extract_tsne_latents(data) 54 | print("code.shape = ",codes.shape) 55 | plot_latents(codes, lab, plot_fname="codes.jpg") 56 | ``` 57 | 58 | which should produce a plot, i.e., `codes.jpg`, similar to the one below: 59 | 60 | 61 | 62 | In this example scenario, we see that we can successfully map the 5D model output 63 | data to a plottable 2D space, facilitating some level of downstream qualitative 64 | interpretation of the model. 65 | -------------------------------------------------------------------------------- /ngclearn/.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.mp4 4 | *.npy 5 | *.agent 6 | -------------------------------------------------------------------------------- /ngclearn/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import subprocess 3 | import pkg_resources 4 | from pkg_resources import get_distribution 5 | #from pathlib import Path 6 | #from sys import argv 7 | 8 | __version__ = get_distribution('ngclearn').version 9 | 10 | if sys.version_info.minor < 10: 11 | import warnings 12 | warnings.warn( 13 | "Running ngclearn and jax in a python version prior to 3.10 may have unintended consequences. Compatability " 14 | "with python 3.8 is maintained to allow for lava-nc components and should only be used with those") 15 | 16 | #required = {'ngcsimlib', 'jax', 'jaxlib'} ## list of core ngclearn dependencies 17 | required = {'ngcsimlib'} #, 'jax', 'jaxlib'} 18 | installed = {pkg.key for pkg in pkg_resources.working_set} 19 | missing = required - installed 20 | 21 | for key in required: 22 | if key in missing: 23 | raise ImportError(str(key) + ", a core dependency of ngclearn, is not " \ 24 | "currently installed!") 25 | 26 | 27 | ## Needed to preload is called before anything in ngclearn 28 | from pathlib import Path 29 | from sys import argv 30 | import numpy 31 | 32 | import ngcsimlib 33 | 34 | from ngcsimlib.context import Context 35 | from ngcsimlib.component import Component 36 | from ngcsimlib.compartment import Compartment 37 | from ngcsimlib.resolver import resolver 38 | from ngcsimlib import utils as sim_utils 39 | 40 | from ngclearn.utils.jaxProcess import JaxProcess 41 | from ngcsimlib.compilers.process import transition, Process 42 | 43 | 44 | from ngcsimlib import configure, preload_modules 45 | from ngcsimlib import logger 46 | 47 | if not Path(argv[0]).name == "sphinx-build" or Path(argv[0]).name == "build.py": 48 | if "readthedocs" not in argv[0]: ## prevent readthedocs execution of preload 49 | configure() 50 | logger.init_logging() 51 | from ngcsimlib.configManager import get_config 52 | pkg_config = get_config("packages") 53 | if pkg_config is not None: 54 | use_base_numpy = pkg_config.get("use_base_numpy", False) 55 | if use_base_numpy: 56 | import numpy as numpy 57 | else: 58 | from jax import numpy 59 | else: 60 | from jax import numpy 61 | 62 | 63 | preload_modules() 64 | -------------------------------------------------------------------------------- /ngclearn/commands/__init__.py: -------------------------------------------------------------------------------- 1 | from ngcsimlib.commands import * 2 | -------------------------------------------------------------------------------- /ngclearn/components/input_encoders/__init__.py: -------------------------------------------------------------------------------- 1 | from .bernoulliCell import BernoulliCell 2 | from .poissonCell import PoissonCell 3 | from .latencyCell import LatencyCell 4 | from .phasorCell import PhasorCell 5 | -------------------------------------------------------------------------------- /ngclearn/components/jaxComponent.py: -------------------------------------------------------------------------------- 1 | import time 2 | from jax import random 3 | #from ngclearn import resolver, Component, Compartment 4 | from ngcsimlib.component import Component 5 | from ngcsimlib.compartment import Compartment 6 | 7 | class JaxComponent(Component): 8 | """ 9 | Base Jax component that all Jax-based cells and synapses inherit from. 10 | 11 | Args: 12 | name: the string name of this cell 13 | 14 | key: PRNG key to control determinism of any underlying random values 15 | associated with this cell 16 | 17 | directory: string indicating directory on disk to save component parameter 18 | values to 19 | """ 20 | 21 | def __init__(self, name, key=None, directory=None, **kwargs): 22 | super().__init__(name, **kwargs) 23 | self.directory = directory 24 | self.key = Compartment( 25 | random.PRNGKey(time.time_ns()) if key is None else key) 26 | -------------------------------------------------------------------------------- /ngclearn/components/lava/__init__.py: -------------------------------------------------------------------------------- 1 | ## lava-compliant neuronal cells 2 | from .neurons.LIFCell import LIFCell 3 | ## lava-compliant synapses 4 | from .synapses.staticSynapse import StaticSynapse 5 | from .synapses.traceSTDPSynapse import TraceSTDPSynapse 6 | from .synapses.hebbianSynapse import HebbianSynapse 7 | ## Lava-compliant encoders/traces 8 | from .traces.gatedTrace import GatedTrace 9 | 10 | #monitor 11 | from .monitor import Monitor -------------------------------------------------------------------------------- /ngclearn/components/lava/monitor.py: -------------------------------------------------------------------------------- 1 | from ngclearn.components.base_monitor import Base_Monitor 2 | 3 | 4 | class Monitor(Base_Monitor): 5 | """ 6 | A numpy implementation of `Base_Monitor`. Designed to be used with all lava compatible ngclearn components 7 | """ 8 | auto_resolve = False 9 | 10 | 11 | @staticmethod 12 | def build_advance(compartments): 13 | @staticmethod 14 | def _advance(**kwargs): 15 | return_vals = [] 16 | for comp in compartments: 17 | new_val = kwargs[comp] 18 | current_store = kwargs[comp + "*store"] 19 | current_store[:-1] = current_store[1:] 20 | current_store[-1] = new_val 21 | return_vals.append(current_store) 22 | return return_vals if len(compartments) > 1 else return_vals[0] 23 | 24 | return _advance 25 | 26 | @staticmethod 27 | def build_advance_state(component): 28 | return super().build_advance_state(component) 29 | 30 | @staticmethod 31 | def build_reset(component): 32 | return super().build_reset(component) 33 | -------------------------------------------------------------------------------- /ngclearn/components/lava/neurons/__init__.py: -------------------------------------------------------------------------------- 1 | from .LIFCell import LIFCell 2 | -------------------------------------------------------------------------------- /ngclearn/components/lava/synapses/__init__.py: -------------------------------------------------------------------------------- 1 | from .staticSynapse import StaticSynapse 2 | from .hebbianSynapse import HebbianSynapse 3 | from .traceSTDPSynapse import TraceSTDPSynapse 4 | -------------------------------------------------------------------------------- /ngclearn/components/lava/traces/__init__.py: -------------------------------------------------------------------------------- 1 | from .gatedTrace import GatedTrace 2 | -------------------------------------------------------------------------------- /ngclearn/components/lava/traces/gatedTrace.py: -------------------------------------------------------------------------------- 1 | from ngclearn import numpy as jnp 2 | from ngcsimlib.logger import info, warn 3 | from ngcsimlib.compilers.process import transition 4 | from ngcsimlib.component import Component 5 | from ngcsimlib.compartment import Compartment 6 | from ngclearn.utils.weight_distribution import initialize_params 7 | from ngcsimlib.logger import info 8 | from ngclearn.utils import tensorstats 9 | 10 | class GatedTrace(Component): ## gated/piecewise low-pass filter 11 | """ 12 | A gated/piecewise variable trace (filter). This is a Lava-compliant trace component. 13 | 14 | | --- Cell Input Compartments: (Takes wired-in signals) --- 15 | | inputs - input (takes wired-in external signals) 16 | | --- Cell Output Compartments: (These signals are generated) --- 17 | | trace - traced value signal 18 | 19 | Args: 20 | name: the string name of this operator 21 | 22 | n_units: number of calculating entities or units 23 | 24 | dt: integration time constant (ms) 25 | 26 | tau_tr: trace time constant (in milliseconds, or ms) 27 | """ 28 | 29 | # Define Functions 30 | def __init__(self, name, n_units, dt, tau_tr, **kwargs): 31 | super().__init__(name, **kwargs) 32 | 33 | ## trace control coefficients 34 | self.dt = dt 35 | self.tau_tr = tau_tr ## trace time constant 36 | 37 | ## Layer size setup 38 | self.batch_size = 1 39 | self.n_units = n_units 40 | 41 | restVals = jnp.zeros((self.batch_size, self.n_units)) 42 | self.inputs = Compartment(restVals) # input compartment 43 | self.trace = Compartment(restVals) 44 | 45 | @transition(output_compartments=["trace"]) 46 | @staticmethod 47 | def advance_state(dt, tau_tr, inputs, trace): 48 | trace = (trace * (1. - dt/tau_tr)) * (1. - inputs) + inputs 49 | return trace 50 | 51 | @transition(output_compartments=["inputs", "trace"]) 52 | @staticmethod 53 | def reset(batch_size, n_units): 54 | restVals = jnp.zeros((batch_size, n_units)) 55 | return restVals, restVals 56 | 57 | def __repr__(self): 58 | comps = [varname for varname in dir(self) if Compartment.is_compartment(getattr(self, varname))] 59 | maxlen = max(len(c) for c in comps) + 5 60 | lines = f"[{self.__class__.__name__}] PATH: {self.name}\n" 61 | for c in comps: 62 | stats = tensorstats(getattr(self, c).value) 63 | if stats is not None: 64 | line = [f"{k}: {v}" for k, v in stats.items()] 65 | line = ", ".join(line) 66 | else: 67 | line = "None" 68 | lines += f" {f'({c})'.ljust(maxlen)}{line}\n" 69 | return lines 70 | -------------------------------------------------------------------------------- /ngclearn/components/monitor.py: -------------------------------------------------------------------------------- 1 | from ngclearn.components.base_monitor import Base_Monitor 2 | from ngclearn import transition 3 | 4 | class Monitor(Base_Monitor): 5 | """ 6 | A jax implementation of `Base_Monitor`. Designed to be used with all 7 | non-lava ngclearn components 8 | """ 9 | auto_resolve = False 10 | 11 | @staticmethod 12 | def _record_internal(compartments): 13 | @staticmethod 14 | def _record(**kwargs): 15 | return_vals = [] 16 | for comp in compartments: 17 | new_val = kwargs[comp] 18 | current_store = kwargs[comp + "*store"] 19 | current_store = current_store.at[:-1].set(current_store[1:]) 20 | current_store = current_store.at[-1].set(new_val) 21 | return_vals.append(current_store) 22 | return return_vals if len(compartments) > 1 else return_vals[0] 23 | return _record 24 | 25 | @staticmethod 26 | def build_advance_state(component): 27 | return super().build_advance_state(component) 28 | 29 | @staticmethod 30 | def build_reset(component): 31 | return super().build_reset(component) 32 | -------------------------------------------------------------------------------- /ngclearn/components/neurons/__init__.py: -------------------------------------------------------------------------------- 1 | ## point to rate-coded cell componet types 2 | from .graded.rateCell import RateCell 3 | from .graded.gaussianErrorCell import GaussianErrorCell 4 | from .graded.laplacianErrorCell import LaplacianErrorCell 5 | from .graded.bernoulliErrorCell import BernoulliErrorCell 6 | from .graded.rewardErrorCell import RewardErrorCell 7 | ## point to standard spiking cell component types 8 | from .spiking.sLIFCell import SLIFCell 9 | from .spiking.IFCell import IFCell 10 | from .spiking.LIFCell import LIFCell 11 | from .spiking.WTASCell import WTASCell 12 | from .spiking.quadLIFCell import QuadLIFCell 13 | from .spiking.adExCell import AdExCell 14 | from .spiking.fitzhughNagumoCell import FitzhughNagumoCell 15 | from .spiking.izhikevichCell import IzhikevichCell 16 | from .spiking.hodgkinHuxleyCell import HodgkinHuxleyCell 17 | from .spiking.RAFCell import RAFCell 18 | -------------------------------------------------------------------------------- /ngclearn/components/neurons/graded/__init__.py: -------------------------------------------------------------------------------- 1 | ## point to rate-coded cell componet types 2 | from .rateCell import RateCell 3 | from .gaussianErrorCell import GaussianErrorCell 4 | from .laplacianErrorCell import LaplacianErrorCell 5 | from .bernoulliErrorCell import BernoulliErrorCell 6 | from .rewardErrorCell import RewardErrorCell 7 | -------------------------------------------------------------------------------- /ngclearn/components/neurons/spiking/__init__.py: -------------------------------------------------------------------------------- 1 | ## point to standard spiking cell component types 2 | from .sLIFCell import SLIFCell 3 | from .LIFCell import LIFCell 4 | from .IFCell import IFCell 5 | from .WTASCell import WTASCell 6 | from .quadLIFCell import QuadLIFCell 7 | from .adExCell import AdExCell 8 | from .fitzhughNagumoCell import FitzhughNagumoCell 9 | from .izhikevichCell import IzhikevichCell 10 | from .RAFCell import RAFCell 11 | from .hodgkinHuxleyCell import HodgkinHuxleyCell 12 | -------------------------------------------------------------------------------- /ngclearn/components/other/__init__.py: -------------------------------------------------------------------------------- 1 | from .varTrace import VarTrace 2 | from .expKernel import ExpKernel 3 | 4 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/__init__.py: -------------------------------------------------------------------------------- 1 | from .denseSynapse import DenseSynapse 2 | from .staticSynapse import StaticSynapse 3 | 4 | 5 | ## short-term plasticity components 6 | from .STPDenseSynapse import STPDenseSynapse 7 | from .exponentialSynapse import ExponentialSynapse 8 | from .doubleExpSynapse import DoupleExpSynapse 9 | from .alphaSynapse import AlphaSynapse 10 | 11 | ## dense synaptic components 12 | from .hebbian.hebbianSynapse import HebbianSynapse 13 | from .hebbian.traceSTDPSynapse import TraceSTDPSynapse 14 | from .hebbian.expSTDPSynapse import ExpSTDPSynapse 15 | from .hebbian.eventSTDPSynapse import EventSTDPSynapse 16 | from .hebbian.BCMSynapse import BCMSynapse 17 | 18 | 19 | ## conv/deconv synaptic components 20 | from .convolution.convSynapse import ConvSynapse 21 | from .convolution.staticConvSynapse import StaticConvSynapse 22 | from .convolution.hebbianConvSynapse import HebbianConvSynapse 23 | from .convolution.traceSTDPConvSynapse import TraceSTDPConvSynapse 24 | from .convolution.deconvSynapse import DeconvSynapse 25 | from .convolution.staticDeconvSynapse import StaticDeconvSynapse 26 | from .convolution.hebbianDeconvSynapse import HebbianDeconvSynapse 27 | from .convolution.traceSTDPDeconvSynapse import TraceSTDPDeconvSynapse 28 | 29 | 30 | ## modulated synaptic components 31 | from .modulated.MSTDPETSynapse import MSTDPETSynapse 32 | from .modulated.REINFORCESynapse import REINFORCESynapse 33 | 34 | ## patched synaptic components 35 | from .patched.patchedSynapse import PatchedSynapse 36 | from .patched.staticPatchedSynapse import StaticPatchedSynapse 37 | from .patched.hebbianPatchedSynapse import HebbianPatchedSynapse 38 | 39 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/convolution/__init__.py: -------------------------------------------------------------------------------- 1 | from .convSynapse import ConvSynapse 2 | from .staticConvSynapse import StaticConvSynapse 3 | from .deconvSynapse import DeconvSynapse 4 | from .staticDeconvSynapse import StaticDeconvSynapse 5 | from .hebbianConvSynapse import HebbianConvSynapse 6 | from .hebbianDeconvSynapse import HebbianDeconvSynapse 7 | from .traceSTDPConvSynapse import TraceSTDPConvSynapse 8 | from .traceSTDPDeconvSynapse import TraceSTDPDeconvSynapse 9 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/convolution/staticConvSynapse.py: -------------------------------------------------------------------------------- 1 | from .convSynapse import ConvSynapse 2 | 3 | class StaticConvSynapse(ConvSynapse): 4 | """ 5 | A static convolutional synaptic cable; no form of synaptic evolution/adaptation 6 | is in-built to this component. 7 | 8 | | --- Synapse Compartments: --- 9 | | inputs - input (takes in external signals) 10 | | outputs - output signals 11 | | weights - current value tensor of kernel efficacies 12 | | biases - current base-rate/bias efficacies 13 | 14 | Args: 15 | name: the string name of this cell 16 | 17 | x_shape: 2d shape of input map signal (component currently assumess a square input maps) 18 | 19 | shape: tuple specifying shape of this synaptic cable (usually a 4-tuple 20 | with number `filter height x filter width x input channels x number output channels`); 21 | note that currently filters/kernels are assumed to be square 22 | (kernel.width = kernel.height) 23 | 24 | filter_init: a kernel to drive initialization of this synaptic cable's 25 | filter values 26 | 27 | bias_init: kernel to drive initialization of bias/base-rate values 28 | (Default: None, which turns off/disables biases) 29 | 30 | stride: length/size of stride 31 | 32 | padding: pre-operator padding to use -- "VALID" (none), "SAME" 33 | 34 | resist_scale: a fixed (resistance) scaling factor to apply to synaptic 35 | transform (Default: 1.), i.e., yields: out = ((K @ in) * resist_scale) + b 36 | where `@` denotes convolution 37 | 38 | batch_size: batch size dimension of this component 39 | """ 40 | 41 | pass 42 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/convolution/staticDeconvSynapse.py: -------------------------------------------------------------------------------- 1 | from .deconvSynapse import DeconvSynapse 2 | 3 | class StaticDeconvSynapse(DeconvSynapse): 4 | """ 5 | A static deconvolutional (transposed convolutional) synaptic cable; no form 6 | of synaptic evolution/adaptation is in-built to this component. 7 | 8 | | --- Synapse Compartments: --- 9 | | inputs - input (takes in external signals) 10 | | outputs - output signals 11 | | weights - current value tensor of kernel efficacies 12 | | biases - current base-rate/bias efficacies 13 | 14 | Args: 15 | name: the string name of this cell 16 | 17 | x_shape: dimension of input signal (assuming a square input) 18 | 19 | shape: tuple specifying shape of this synaptic cable (usually a 4-tuple 20 | with number `filter height x filter width x input channels x number output channels`); 21 | note that currently filters/kernels are assumed to be square 22 | (kernel.width = kernel.height) 23 | 24 | filter_init: a kernel to drive initialization of this synaptic cable's 25 | filter values 26 | 27 | bias_init: kernel to drive initialization of bias/base-rate values 28 | (Default: None, which turns off/disables biases) 29 | 30 | stride: length/size of stride 31 | 32 | padding: pre-operator padding to use -- "VALID" (none), "SAME" 33 | 34 | resist_scale: a fixed (resistance) scaling factor to apply to synaptic 35 | transform (Default: 1.), i.e., yields: out = ((K @ in) * resist_scale) + b 36 | where `@` denotes convolution 37 | 38 | batch_size: batch size dimension of this component 39 | """ 40 | 41 | pass 42 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/hebbian/__init__.py: -------------------------------------------------------------------------------- 1 | from .hebbianSynapse import HebbianSynapse 2 | from .traceSTDPSynapse import TraceSTDPSynapse 3 | from .expSTDPSynapse import ExpSTDPSynapse 4 | from .eventSTDPSynapse import EventSTDPSynapse 5 | from .BCMSynapse import BCMSynapse 6 | 7 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/modulated/__init__.py: -------------------------------------------------------------------------------- 1 | from .MSTDPETSynapse import MSTDPETSynapse 2 | from .REINFORCESynapse import REINFORCESynapse 3 | 4 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/patched/__init__.py: -------------------------------------------------------------------------------- 1 | ## patched synaptic components 2 | from .patchedSynapse import PatchedSynapse 3 | from .staticPatchedSynapse import StaticPatchedSynapse 4 | from .hebbianPatchedSynapse import HebbianPatchedSynapse 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/patched/staticPatchedSynapse.py: -------------------------------------------------------------------------------- 1 | from .patchedSynapse import PatchedSynapse 2 | 3 | 4 | 5 | class StaticPatchedSynapse(PatchedSynapse): 6 | """ 7 | A static dense synaptic cable; no form of synaptic evolution/adaptation 8 | is in-built to this component. 9 | 10 | | --- Synapse Compartments: --- 11 | | inputs - input (takes in external signals) 12 | | outputs - output 13 | | weights - current value matrix of synaptic efficacies 14 | 15 | Args: 16 | name: the string name of this cell 17 | 18 | shape: tuple specifying shape of this synaptic cable (usually a 2-tuple 19 | with number of inputs by number of outputs) 20 | 21 | 22 | n_sub_models: tuple specifying the number of sub models (the number of fully connected/dense synapses) or the number of patches of this synaptic cable (usually a 2-tuple 23 | with number of inputs by number of outputs) 24 | 25 | stride_shape: tuple specifying the stride (overlap) between sub models (patches) (Default: (0, 0)) 26 | 27 | w_mask= Helps in creating patches (Default: None) 28 | 29 | weight_init: a kernel to drive initialization of this synaptic cable's values; 30 | typically a tuple with 1st element as a string calling the name of 31 | initialization to use 32 | 33 | bias_init: a kernel to drive initialization of this synaptic bias's values; 34 | typically a tuple with 1st element as a string calling the name of 35 | initialization to use 36 | 37 | resist_scale: a fixed (resistance) scaling factor to apply to synaptic 38 | transform (Default: 1.), i.e., yields: out = ((W * Rscale) * in) 39 | 40 | p_conn: probability of a connection existing (default: 1.); setting 41 | this to < 1 and > 0. will result in a sparser synaptic structure 42 | (lower values yield sparse structure) 43 | """ 44 | pass 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /ngclearn/components/synapses/staticSynapse.py: -------------------------------------------------------------------------------- 1 | from .denseSynapse import DenseSynapse 2 | 3 | class StaticSynapse(DenseSynapse): 4 | """ 5 | A static dense synaptic cable; no form of synaptic evolution/adaptation 6 | is in-built to this component. 7 | 8 | | --- Synapse Compartments: --- 9 | | inputs - input (takes in external signals) 10 | | outputs - output 11 | | weights - current value matrix of synaptic efficacies 12 | 13 | Args: 14 | name: the string name of this cell 15 | 16 | shape: tuple specifying shape of this synaptic cable (usually a 2-tuple 17 | with number of inputs by number of outputs) 18 | 19 | weight_init: a kernel to drive initialization of this synaptic cable's values; 20 | typically a tuple with 1st element as a string calling the name of 21 | initialization to use 22 | 23 | resist_scale: a fixed (resistance) scaling factor to apply to synaptic 24 | transform (Default: 1.), i.e., yields: out = ((W * Rscale) * in) 25 | 26 | p_conn: probability of a connection existing (default: 1.); setting 27 | this to < 1 and > 0. will result in a sparser synaptic structure 28 | (lower values yield sparse structure) 29 | """ 30 | pass 31 | -------------------------------------------------------------------------------- /ngclearn/modules/__init__.py: -------------------------------------------------------------------------------- 1 | from .regression.elastic_net import Iterative_ElasticNet 2 | from .regression.lasso import Iterative_Lasso 3 | from .regression.ridge import Iterative_Ridge 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ngclearn/modules/regression/__init__.py: -------------------------------------------------------------------------------- 1 | from .elastic_net import Iterative_ElasticNet 2 | from .lasso import Iterative_Lasso 3 | from .ridge import Iterative_Ridge 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /ngclearn/operations/__init__.py: -------------------------------------------------------------------------------- 1 | from ngcsimlib.operations import * -------------------------------------------------------------------------------- /ngclearn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .model_utils import tensorstats 2 | from .jaxProcess import JaxProcess 3 | ## forward imports from core ngc-learn utility sub-packages 4 | from . import viz 5 | from . import io_utils 6 | from . import metric_utils 7 | from . import model_utils 8 | from . import patch_utils 9 | from . import weight_distribution 10 | from . import surrogate_fx 11 | -------------------------------------------------------------------------------- /ngclearn/utils/analysis/__init__.py: -------------------------------------------------------------------------------- 1 | ## point to supported analysis probes 2 | from .linear_probe import LinearProbe 3 | from .attentive_probe import AttentiveProbe 4 | -------------------------------------------------------------------------------- /ngclearn/utils/density/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NACLab/ngc-learn/d85f040a6db570a45e3ccc7faf2070ffe45c0635/ngclearn/utils/density/__init__.py -------------------------------------------------------------------------------- /ngclearn/utils/density/gmm.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from functools import partial 3 | import time, sys 4 | import numpy as np 5 | #from sklearn import mixture 6 | #from sklearn.cluster import KMeans 7 | from scipy.stats import multivariate_normal 8 | #from ngclearn.utils.stat_utils import calc_log_gauss_pdf 9 | from ngclearn.utils.model_utils import softmax 10 | #from kmeans import K_Means 11 | from sklearn import mixture 12 | 13 | #seed = 69 14 | #tf.random.set_seed(seed=seed) 15 | 16 | class GMM: 17 | """ 18 | Implements a Gaussian mixture model (GMM) -- or mixture of Gaussians, MoG. 19 | Adaptation of parameters is conducted via the Expectation-Maximization (EM) 20 | learning algorithm and leverages full covariance matrices in the component 21 | multivariate Gaussians. 22 | 23 | Note this is a (JAX) wrapper model that houses the sklearn implementation for learning. 24 | The sampling process has been rewritten to utilize GPU matrix computation. 25 | 26 | Args: 27 | k: the number of components/latent variables within this GMM 28 | 29 | max_iter: the maximum number of EM iterations to fit parameters to data 30 | (Default = 5) 31 | 32 | assume_diag_cov: if True, assumes a diagonal covariance for each component 33 | (Default = False) 34 | 35 | init_kmeans: if True, first learn use the K-Means algorithm to initialize 36 | the component Gaussians of this GMM (Default = True) 37 | """ 38 | def __init__(self, k, max_iter=5, assume_diag_cov=False, init_kmeans=True): 39 | self.use_sklearn = True 40 | self.k = k 41 | self.max_iter = int(max_iter) 42 | self.assume_diag_cov = assume_diag_cov 43 | self.init_kmeans = init_kmeans 44 | self.mu = [] 45 | self.sigma = [] 46 | self.prec = [] 47 | self.weights = None 48 | self.z_weights = None # variables for parameterizing weights for SGD 49 | 50 | def fit(self, data): 51 | """ 52 | Run full fitting process of this GMM. 53 | 54 | Args: 55 | data: the dataset to fit this GMM to 56 | """ 57 | pass 58 | 59 | def update(self, X): 60 | """ 61 | Performs a single iterative update of parameters (assuming model initialized) 62 | 63 | Args: 64 | X: the dataset / design matrix to fit this GMM to 65 | """ 66 | pass 67 | 68 | def sample(self, n_s, mode_i=-1, samples_modes_evenly=False): 69 | """ 70 | (Efficiently) Draw samples from the current underlying GMM model 71 | 72 | Args: 73 | n_s: the number of samples to draw from this GMM 74 | 75 | mode_i: if >= 0, will only draw samples from a specific component of this GMM 76 | (Default = -1), ignoring the Categorical prior over latent variables/components 77 | 78 | samples_modes_evenly: if True, will ignore the Categorical prior over latent 79 | variables/components and draw an approximately equal number of samples from 80 | each component 81 | """ 82 | pass 83 | -------------------------------------------------------------------------------- /ngclearn/utils/diffeq/__init__.py: -------------------------------------------------------------------------------- 1 | from . import odes 2 | from . import ode_utils 3 | 4 | -------------------------------------------------------------------------------- /ngclearn/utils/feature_dictionaries/polynomialLibrary.py: -------------------------------------------------------------------------------- 1 | import jax.numpy as jnp 2 | from jax import jit, random 3 | import jax.numpy as jnp 4 | from typing import List, Tuple, Union 5 | from dataclasses import dataclass 6 | 7 | 8 | 9 | @dataclass 10 | class PolynomialLibrary: 11 | """ 12 | A class for creating polynomial feature libraries in 1D, 2D, or 3D. 13 | 14 | Attributes: 15 | poly_order (int): Maximum order of polynomial terms 16 | include_bias (bool): Whether to include the bias term in the output 17 | """ 18 | 19 | poly_order: int = None 20 | include_bias: bool = True 21 | 22 | def __post_init__(self): 23 | if self.poly_order is None: 24 | raise ValueError("poly_order must be specified") 25 | if self.poly_order < 0 or not isinstance(self.poly_order, int): 26 | raise ValueError("poly_order must be an integer") 27 | 28 | 29 | def _create_library(self, *arrays: jnp.ndarray) -> Tuple[jnp.ndarray, List[str]]: 30 | """ 31 | Create polynomial library for given input arrays. 32 | 33 | Args: 34 | arrays: Input arrays (x, y, z) 35 | 36 | Returns: 37 | Tuple of (feature matrix, feature names) 38 | """ 39 | dim = len(arrays) 40 | lib = jnp.ones_like(arrays[0]) 41 | names = ['1'] 42 | 43 | if dim == 1: 44 | for i in range(self.poly_order + 1): 45 | lib = jnp.concatenate([lib, arrays[0] ** i], axis=1) 46 | if not (i == 0): 47 | names.append(r'𝑥^{} |'.format(i)) 48 | 49 | if dim == 2: 50 | for i in range(self.poly_order + 1): 51 | for j in range(self.poly_order - i + 1): 52 | lib = jnp.concatenate([lib, arrays[0] ** i * arrays[1] ** j], axis=1) 53 | if not (i == 0 and j == 0): 54 | names.append(r'$𝑥^{} . 𝑦^{}$ |'.format(i, j)) 55 | 56 | if dim == 3: 57 | for i in range(self.poly_order + 1): 58 | for j in range(self.poly_order + 1 - i): 59 | for k in range(self.poly_order + 1 - (i + j)): 60 | lib = jnp.concatenate([lib, arrays[0] ** i * arrays[1] ** j * arrays[2] ** k], axis=1) 61 | if not (i == 0 and j == 0 and k == 0): 62 | names.append(r'$𝑥^{} . 𝑦^{} . 𝓏^{}$ |'.format(i, j, k)) 63 | 64 | return lib, names 65 | 66 | 67 | def fit(self, X: List[jnp.ndarray]) -> Tuple[jnp.ndarray, List[str]]: 68 | 69 | if not 1 <= len(X) <=3: 70 | raise ValueError("Input must be 1D, 2D, or 3D; e.g. len(X) >= 1 ") 71 | 72 | arrays = [jnp.array(x).reshape(-1, 1) for x in X] 73 | lib, names = self._create_library(*arrays) 74 | 75 | 76 | start_idx = 1 if not self.include_bias else 0 77 | return lib[:, start_idx+1:], names[start_idx:] 78 | 79 | -------------------------------------------------------------------------------- /ngclearn/utils/io_utils.py: -------------------------------------------------------------------------------- 1 | """ 2 | File and OS input/output (reading/writing) utilities. 3 | """ 4 | import jax 5 | from jax import numpy as jnp, grad, jit, vmap, random, lax 6 | import os, sys, pickle 7 | 8 | def serialize(fname, object): ## object "saving" routine 9 | """ 10 | Serialization (saving) routine 11 | 12 | Args: 13 | fname: file name to serialize to on disk 14 | 15 | object: generic object to serialize 16 | """ 17 | fd = open(fname, 'wb') 18 | pickle.dump(object, fd) 19 | fd.close() 20 | 21 | def deserialize(fname): ## object "loading" routine 22 | """ 23 | Deserialization (loading) routine 24 | 25 | Args: 26 | fname: file name from disk to deserialize 27 | 28 | Returns: 29 | deserialized object from disk 30 | """ 31 | fd = open(fname, 'rb') 32 | object = pickle.load( fd ) 33 | fd.close() 34 | return object 35 | 36 | def makedir(directory): 37 | """ 38 | Creates a folder/directory on disk 39 | 40 | Args: 41 | directory: string name of directory/folder to create on disk 42 | """ 43 | folders = directory.split('/') 44 | prefix = "" 45 | remove = [] 46 | for idx, f in enumerate(folders): 47 | if f == ".." or f == ".": 48 | prefix = prefix + f + "/" 49 | remove.append(idx) 50 | 51 | for i in reversed(remove): 52 | folders.pop(i) 53 | 54 | for folder in folders: 55 | if not os.path.isdir(prefix + folder): 56 | os.mkdir(prefix + folder) 57 | prefix = prefix + folder + "/" 58 | 59 | def makedirs(directories): 60 | """ 61 | Creates a set of folders/directories on disk 62 | 63 | Args: 64 | directories: array of string names of directories/folders to create on disk 65 | """ 66 | for dir in directories: 67 | makedir(dir) 68 | -------------------------------------------------------------------------------- /ngclearn/utils/optim/__init__.py: -------------------------------------------------------------------------------- 1 | from .optim_utils import get_opt_init_fn, get_opt_step_fn 2 | -------------------------------------------------------------------------------- /ngclearn/utils/optim/optim_utils.py: -------------------------------------------------------------------------------- 1 | import functools 2 | from .sgd import sgd_step, sgd_init 3 | from .adam import adam_step, adam_init 4 | 5 | def get_opt_init_fn(opt='adam'): 6 | return { 7 | 'adam': adam_init, 8 | 'sgd': sgd_init 9 | }[opt] 10 | 11 | 12 | def get_opt_step_fn(opt='adam', **kwargs): 13 | # **kwargs here is the hyper parameters you want to pass in the optimization function 14 | return { 15 | 'adam': functools.partial(adam_step, **kwargs), 16 | 'sgd': functools.partial(sgd_step, **kwargs), 17 | }[opt] 18 | -------------------------------------------------------------------------------- /ngclearn/utils/optim/sgd.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from ngcsimlib.component import Component 4 | from ngcsimlib.compartment import Compartment 5 | from ngcsimlib.resolver import resolver 6 | 7 | import numpy as np 8 | from jax import jit, numpy as jnp, random, nn, lax 9 | from functools import partial 10 | import time 11 | 12 | def step_update(param, update, lr): 13 | """ 14 | Runs one step of SGD over a set of parameters given updates. 15 | 16 | Args: 17 | lr: global step size to apply when adjusting parameters 18 | 19 | Returns: 20 | adjusted parameter tensor (same shape as "param") 21 | """ 22 | _param = param - lr * update 23 | return _param 24 | 25 | @jit 26 | def sgd_step(opt_params, theta, updates, eta=0.001): ## apply adjustment to theta 27 | """Return a params update 28 | 29 | Args: 30 | opt_params: (ArrayLike) parameters of the optimization algorithm 31 | 32 | theta: (ArrayLike) the weights of neural networks 33 | 34 | updates: (ArrayLike) the updates of neural networks 35 | 36 | eta: (float, optional) hyperparams. Defaults to 0.001. 37 | 38 | Returns: 39 | ArrayLike: opt_params. New opt params, ArrayLike: theta. The updated weights 40 | """ 41 | time_step = opt_params 42 | time_step = time_step + 1 43 | new_theta = [] 44 | for i in range(len(theta)): 45 | px_i = step_update(theta[i], updates[i], eta) 46 | new_theta.append(px_i) 47 | new_opt_params = time_step 48 | return new_opt_params, new_theta 49 | 50 | @jit 51 | def sgd_init(theta): 52 | return jnp.asarray(0.0) 53 | 54 | 55 | if __name__ == '__main__': 56 | opt_params, theta = sgd_step((2.0), [1.0, 1.0], [3.0, 4.0], 3e-2) 57 | print(f"opt_params: {opt_params}, theta: {theta}") 58 | -------------------------------------------------------------------------------- /ngclearn/utils/viz/__init__.py: -------------------------------------------------------------------------------- 1 | from . import dim_reduce 2 | from . import raster 3 | from . import spike_plot 4 | from . import synapse_plot 5 | -------------------------------------------------------------------------------- /ngclearn/utils/viz/spike_plot.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | cmap = plt.cm.jet 3 | import numpy as np 4 | 5 | def plot_spiking_neuron(curr, mem, spike, ref, dt, thr_line=False, 6 | title=False, min_mem_val=0.0, max_mem_val=1.25, 7 | spike_loc=1., spike_spr=0.05, fname=None): 8 | import matplotlib #.pyplot as plt 9 | matplotlib.use('Agg') 10 | import matplotlib.pyplot as plt 11 | cmap = plt.cm.jet 12 | """ 13 | Simple plotting function for visualizing the trajectory of a single neuron 14 | (where its input electrical current, membrane potential value, output 15 | spike readings, and refractory variable states have been recorded into arrays). 16 | 17 | This is particularly useful for single neuronal dynamics demonstrations and 18 | analyses. 19 | 20 | Args: 21 | curr: the recorded electrical current (over T steps) 22 | 23 | mem: the recorded membrane potential (over T steps) 24 | 25 | spike: the recorded spike train (over T steps) 26 | 27 | ref: the recorded refractory state value (over T steps) 28 | 29 | dt: the integration time constant 30 | 31 | thr_line: optional vertical threshold line to plot for voltage 32 | 33 | title: the title of the plot 34 | 35 | min_mem_val: minimum value bound on membrane potential subplot (min of y-axis) 36 | 37 | max_mem_val: maximum value bound on membrane potential subplot (max of y-axis) 38 | 39 | fname: the filename to save this plot as, i.e., /path/to/name.png (Default: lif_analysis.png) 40 | """ 41 | spk_ = spike + 0 42 | mask = 0. 43 | if ref != None: 44 | mask = np.greater_equal(ref,dt).astype(np.float32) 45 | spk_ = spk_ * (1.0 - mask) 46 | stat = np.where(spk_ > 0.) 47 | indx = (stat[0] * 1. - 1.).tolist() 48 | 49 | x_lim = curr.shape[0] 50 | y_curr_lim = float(np.amax(curr)) + 0.2 51 | fig, ax = plt.subplots(2, figsize=(8,6), sharex=True, 52 | gridspec_kw = {'height_ratios': [1, 1]}) 53 | # plot input current 54 | ax[0].plot(curr, c="tab:blue") 55 | ax[0].set_ylim([0, y_curr_lim]) 56 | ax[0].set_xlim([0, x_lim]) 57 | ax[0].set_ylabel("Input Current ($J_t$)") 58 | if title: 59 | ax[0].set_title(title) 60 | 61 | # plot membrane potential 62 | ax[1].plot(mem, c="tab:red") 63 | ax[1].vlines(x=indx, ymin=spike_loc-spike_spr, ymax=spike_loc+spike_spr, 64 | colors='black', ls='--', lw=5) 65 | ax[1].set_ylim([min_mem_val, max_mem_val]) 66 | ax[1].set_ylabel("Membrane Potential ($V_t$)") 67 | if thr_line: 68 | ax[1].axhline(y=thr_line, alpha=0.25, linestyle="dashed", c="black", linewidth=2) 69 | plt.xlabel("Time Step $t$") 70 | 71 | if fname is None: 72 | fname = "lif_plot.png" 73 | plt.tight_layout() 74 | plt.savefig(fname) 75 | plt.clf() 76 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=61.0", # default 4 | "wheel", # also often needed 5 | "numpy>=1.19.5" # add numpy here for build-time use 6 | ] 7 | build-backend = "setuptools.build_meta" # using setuptool building engine 8 | 9 | [project] 10 | name = "ngclearn" 11 | version = "2.0.2" 12 | description = "Simulation software for building and analyzing arbitrary predictive coding, spiking network, and biomimetic neural systems." 13 | authors = [ 14 | {name = "Alexander Ororbia", email = "ago@cs.rit.edu"}, 15 | {name = "William Gebhardt", email = "wdg1351@rit.edu"}, 16 | ] 17 | readme = "README.md" 18 | keywords = ['python', 'ngc-learn', 'predictive-processing', 'predictive-coding', 'neuro-ai', 19 | 'jax', 'spiking-neural-networks', 'biomimetics', 'bionics', 'computational-neuroscience'] 20 | requires-python = ">=3.10" #3.8 21 | license = "BSD-3-Clause" # {text = "BSD-3-Clause License"} 22 | classifiers=[ 23 | "Development Status :: 4 - Beta", #3 - Alpha", # 5 - Production/Stable 24 | "Intended Audience :: Education", 25 | "Intended Audience :: Science/Research", 26 | "Intended Audience :: Developers", 27 | #"License :: OSI Approved :: BSD License", 28 | "Topic :: Scientific/Engineering", 29 | "Topic :: Scientific/Engineering :: Mathematics", 30 | "Topic :: Scientific/Engineering :: Artificial Intelligence", 31 | "Programming Language :: Python", 32 | "Programming Language :: Python :: 3", 33 | "Programming Language :: Python :: 3.10", 34 | "Programming Language :: Python :: 3.11", 35 | "Operating System :: Unix" 36 | ] 37 | dynamic = ["dependencies"] 38 | [tool.setuptools.dynamic] 39 | dependencies = {file = ["requirements.txt"]} ## use classic requirements file 40 | 41 | [project.urls] 42 | Homepage = "https://github.com/NACLab/ngc-learn" 43 | Documentation = "https://ngc-learn.readthedocs.io/" 44 | "Lab Page" = "https://www.cs.rit.edu/~ago/nac_lab.html" 45 | Changelog = "https://github.com/NACLab/ngc-learn/blob/main/history.txt" 46 | 47 | [tool.setuptools.packages.find] 48 | exclude = ["docs"] 49 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy>=1.22.0 2 | scikit-learn>=1.6.1 3 | scipy>=1.7.0 4 | matplotlib>=3.8.0 5 | patchify 6 | jax>=0.4.28 7 | jaxlib>=0.4.28 8 | ngcsimlib>=1.0.0 9 | imageio>=2.31.5 10 | pandas>=2.2.3 11 | -------------------------------------------------------------------------------- /tests/components/input_encoders/test_bernoulliCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import BernoulliCell 6 | #from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngclearn.utils import JaxProcess 11 | from ngcsimlib.context import Context 12 | #from ngcsimlib.utils.compartment import Get_Compartment_Batch 13 | 14 | 15 | def test_bernoulliCell1(): 16 | name = "bernoulli_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | #T = 300 # ms 22 | # ---- build a simple Bernoulli cell system ---- 23 | with Context(name) as ctx: 24 | a = BernoulliCell(name="a", n_units=1, key=subkeys[0]) 25 | 26 | advance_process = (JaxProcess("advance_proc") 27 | >> a.advance_state) 28 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 29 | 30 | reset_process = (Process("reset_proc") 31 | >> a.reset) 32 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 33 | 34 | ## set up non-compiled utility commands 35 | @Context.dynamicCommand 36 | def clamp(x): 37 | a.inputs.set(x) 38 | 39 | ## input spike train 40 | x_seq = jnp.asarray([[1., 1., 0., 0., 1.]], dtype=jnp.float32) 41 | 42 | outs = [] 43 | ctx.reset() 44 | for ts in range(x_seq.shape[1]): 45 | x_t = jnp.array([[x_seq[0,ts]]]) ## get data at time t 46 | ctx.clamp(x_t) 47 | ctx.run(t=ts*1., dt=dt) 48 | outs.append(a.outputs.value) 49 | outs = jnp.concatenate(outs, axis=1) 50 | 51 | ## output should equal input 52 | assert_array_equal(outs, x_seq) 53 | #print(outs) 54 | 55 | #test_bernoulliCell1() 56 | -------------------------------------------------------------------------------- /tests/components/input_encoders/test_latencyCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import LatencyCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | 16 | def test_latencyCell1(): 17 | name = "latency_ctx" 18 | ## create seeding keys 19 | dkey = random.PRNGKey(1234) 20 | dkey, *subkeys = random.split(dkey, 6) 21 | T = 50 # 100 #5 ## number of simulation steps to run 22 | dt = 1. # 0.1 # ms ## compute integration time constant 23 | tau = 1. 24 | # ---- build a simple Poisson cell system ---- 25 | with Context(name) as ctx: 26 | a = LatencyCell( 27 | "a", n_units=4, tau=tau, threshold=0.01, linearize=True, 28 | normalize=True, num_steps=T, clip_spikes=False 29 | ) 30 | 31 | ## create and compile core simulation commands 32 | advance_process = (Process("advance_proc") 33 | >> a.advance_state) 34 | ctx.wrap_and_add_command(jit(advance_process.pure), name="advance") 35 | calc_spike_times_process = (Process("calc_sptimes_proc") 36 | >> a.calc_spike_times) 37 | ctx.wrap_and_add_command(jit(calc_spike_times_process.pure), name="calc_spike_times") 38 | reset_process = (Process("reset_proc") 39 | >> a.reset) 40 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 41 | 42 | ## set up non-compiled utility commands 43 | @Context.dynamicCommand 44 | def clamp(x): 45 | a.inputs.set(x) 46 | 47 | ## input spike train 48 | inputs = jnp.asarray([[0.02, 0.5, 1., 0.0]]) 49 | 50 | targets = np.zeros((T, 4)) 51 | targets[0, 2] = 1. 52 | targets[24, 1] = 1. 53 | targets[48, 0] = 1. 54 | targets[49, 3] = 1. 55 | targets = jnp.array(targets) ## gold-standard solution to check against 56 | 57 | outs = [] 58 | ctx.reset() 59 | ctx.clamp(inputs) 60 | ctx.calc_spike_times() 61 | for ts in range(T): 62 | ctx.clamp(inputs) 63 | ctx.advance(t=ts * dt, dt=dt) 64 | ## naively extract simple statistics at time ts and print them to I/O 65 | s = a.outputs.value 66 | outs.append(s) 67 | #print(" {}: s {} ".format(ts, jnp.squeeze(s))) 68 | outs = jnp.concatenate(outs, axis=0) 69 | 70 | ## output should equal input 71 | assert_array_equal(outs, targets) 72 | 73 | #test_latencyCell1() 74 | -------------------------------------------------------------------------------- /tests/components/input_encoders/test_phasorCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import PhasorCell 6 | #from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | #from ngcsimlib.component import Component 11 | #from ngcsimlib.compartment import Compartment 12 | #from ngcsimlib.context import Context 13 | #from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | 16 | def test_phasorCell1(): 17 | name = "phasor_ctx" 18 | ## create seeding keys 19 | dkey = random.PRNGKey(1234) 20 | dkey, *subkeys = random.split(dkey, 6) 21 | dt = 1. # ms 22 | # T = 300 # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = PhasorCell(name="a", n_units=1, target_freq=1000., disable_phasor=True, key=subkeys[0]) 26 | 27 | advance_process = (Process("advance_proc") 28 | >> a.advance_state) 29 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 30 | 31 | reset_process = (Process("reset_proc") 32 | >> a.reset) 33 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 34 | 35 | ## set up non-compiled utility commands 36 | @Context.dynamicCommand 37 | def clamp(x): 38 | a.inputs.set(x) 39 | 40 | ## input spike train 41 | x_seq = jnp.asarray([[1., 1., 0., 0., 1.]], dtype=jnp.float32) 42 | 43 | outs = [] 44 | ctx.reset() 45 | for ts in range(x_seq.shape[1]): 46 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 47 | ctx.clamp(x_t) 48 | ctx.run(t=ts * 1., dt=dt) 49 | outs.append(a.outputs.value) 50 | #print(a.outputs.value) 51 | outs = jnp.concatenate(outs, axis=1) 52 | #print(outs) 53 | 54 | ## output should equal input 55 | assert_array_equal(outs, x_seq) 56 | 57 | #test_phasorCell1() 58 | -------------------------------------------------------------------------------- /tests/components/input_encoders/test_poissonCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import PoissonCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | 16 | def test_poissonCell1(): 17 | name = "poisson_ctx" 18 | ## create seeding keys 19 | dkey = random.PRNGKey(1234) 20 | dkey, *subkeys = random.split(dkey, 6) 21 | dt = 1. # ms 22 | # T = 300 # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = PoissonCell(name="a", n_units=1, target_freq=1000., key=subkeys[0]) 26 | 27 | advance_process = (Process("advance_proc") 28 | >> a.advance_state) 29 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 30 | 31 | reset_process = (Process("reset_proc") 32 | >> a.reset) 33 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 34 | 35 | ## set up non-compiled utility commands 36 | @Context.dynamicCommand 37 | def clamp(x): 38 | a.inputs.set(x) 39 | 40 | ## input spike train 41 | x_seq = jnp.asarray([[1., 1., 0., 0., 1.]], dtype=jnp.float32) 42 | 43 | outs = [] 44 | ctx.reset() 45 | for ts in range(x_seq.shape[1]): 46 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 47 | ctx.clamp(x_t) 48 | ctx.run(t=ts * 1., dt=dt) 49 | outs.append(a.outputs.value) 50 | outs = jnp.concatenate(outs, axis=1) 51 | 52 | ## output should equal input 53 | assert_array_equal(outs, x_seq) 54 | 55 | #test_poissonCell1() 56 | -------------------------------------------------------------------------------- /tests/components/neurons/graded/test_RateCell.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import RateCell 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_RateCell1(): 19 | name = "rate_ctx" 20 | dkey = random.PRNGKey(42) 21 | dkey, *subkeys = random.split(dkey, 100) 22 | dt = 1. # ms 23 | with Context(name) as ctx: 24 | a = RateCell( 25 | name="a", n_units=1, tau_m=50., prior=("gaussian", 0.), act_fx="identity", 26 | threshold=("none", 0.), integration_type="euler", 27 | batch_size=1, resist_scale=1., shape=None, is_stateful=True 28 | ) 29 | advance_process = (Process("advance_proc") >> a.advance_state) 30 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 31 | reset_process = (Process("reset_proc") >> a.reset) 32 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 33 | 34 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 35 | # ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 36 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 37 | # ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 38 | 39 | @Context.dynamicCommand 40 | def clamp(x): 41 | a.j.set(x) 42 | 43 | ## input spike train 44 | x_seq = jnp.ones((1, 10)) 45 | ## desired output/epsp pulses 46 | y_seq = jnp.asarray([[0.02, 0.04, 0.06, 0.08, 0.09999999999999999, 0.11999999999999998, 0.13999999999999999, 0.15999999999999998, 0.17999999999999998, 0.19999999999999998]], dtype=jnp.float32) 47 | 48 | outs = [] 49 | ctx.reset() 50 | for ts in range(x_seq.shape[1]): 51 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 52 | ctx.clamp(x_t) 53 | ctx.run(t=ts * 1., dt=dt) 54 | outs.append(a.z.value) 55 | outs = jnp.concatenate(outs, axis=1) 56 | # print(outs) 57 | ## output should equal input 58 | # assert_array_equal(outs, y_seq, tol=1e-3) 59 | np.testing.assert_allclose(outs, y_seq, atol=1e-3) 60 | 61 | -------------------------------------------------------------------------------- /tests/components/neurons/graded/test_bernoulliErrorCell.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import BernoulliErrorCell 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_bernoulliErrorCell(): 19 | np.random.seed(42) 20 | name = "bernoulli_error_ctx" 21 | dkey = random.PRNGKey(42) 22 | dkey, *subkeys = random.split(dkey, 100) 23 | dt = 1. # ms 24 | with Context(name) as ctx: 25 | a = BernoulliErrorCell( 26 | name="a", n_units=1, batch_size=1, input_logits=False, shape=None 27 | ) 28 | advance_process = (Process("advance_proc") >> a.advance_state) 29 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 30 | reset_process = (Process("reset_proc") >> a.reset) 31 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 32 | 33 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 34 | # ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 35 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 36 | # ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 37 | 38 | @Context.dynamicCommand 39 | def clamp(x): 40 | a.p.set(x) 41 | 42 | @Context.dynamicCommand 43 | def clamp_target(x): 44 | a.target.set(x) 45 | 46 | ## input spike train 47 | x_seq = jnp.asarray(np.random.randn(1, 10)) 48 | target_seq = (jnp.arange(10)[None] - 5.0) / 2.0 49 | ## desired output/epsp pulses 50 | y_seq = jnp.asarray([[-2.8193381, -4976.9263, -2.1224928, -2939.0425, -1233.3916, -0.24662945, -708.30042, 0.28213939, 3550.8477, 1.3651246]], dtype=jnp.float32) 51 | 52 | outs = [] 53 | ctx.reset() 54 | for ts in range(x_seq.shape[1]): 55 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 56 | ctx.clamp(x_t) 57 | target_xt = jnp.array([[target_seq[0, ts]]]) 58 | ctx.clamp_target(target_xt) 59 | ctx.run(t=ts * 1., dt=dt) 60 | outs.append(a.dp.value) 61 | outs = jnp.concatenate(outs, axis=1) 62 | # print(outs) 63 | ## output should equal input 64 | np.testing.assert_allclose(outs, y_seq, atol=1e-3) 65 | 66 | # test_bernoulliErrorCell() 67 | -------------------------------------------------------------------------------- /tests/components/neurons/graded/test_gaussianErrorCell.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import GaussianErrorCell 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_gaussianErrorCell(): 19 | np.random.seed(42) 20 | name = "gaussian_error_ctx" 21 | dkey = random.PRNGKey(42) 22 | dkey, *subkeys = random.split(dkey, 100) 23 | dt = 1. # ms 24 | with Context(name) as ctx: 25 | a = GaussianErrorCell( 26 | name="a", n_units=1, batch_size=1, sigma=1.0, shape=None 27 | ) 28 | advance_process = (Process("advance_proc") >> a.advance_state) 29 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 30 | reset_process = (Process("reset_proc") >> a.reset) 31 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 32 | 33 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 34 | # ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 35 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 36 | # ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 37 | 38 | @Context.dynamicCommand 39 | def clamp_mu(x): 40 | a.mu.set(x) 41 | 42 | @Context.dynamicCommand 43 | def clamp_target(x): 44 | a.target.set(x) 45 | 46 | ## input sequence 47 | mu_seq = jnp.asarray(np.random.randn(1, 10)) 48 | target_seq = (jnp.arange(10)[None] - 5.0) / 2.0 49 | ## expected output based on the Gaussian error cell formula 50 | ## L = -0.5 * (target - mu)^2 / sigma, dmu = (target - mu) / sigma 51 | expected_dmu = (target_seq - mu_seq) / 1.0 # sigma = 1.0 52 | expected_L = -0.5 * jnp.square(target_seq - mu_seq) / 1.0 53 | 54 | dmu_outs = [] 55 | L_outs = [] 56 | ctx.reset() 57 | for ts in range(mu_seq.shape[1]): 58 | mu_t = jnp.array([[mu_seq[0, ts]]]) ## get data at time t 59 | ctx.clamp_mu(mu_t) 60 | target_t = jnp.array([[target_seq[0, ts]]]) 61 | ctx.clamp_target(target_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | dmu_outs.append(a.dmu.value) 64 | L_outs.append(a.L.value) 65 | 66 | dmu_outs = jnp.concatenate(dmu_outs, axis=1) 67 | L_outs = jnp.array(L_outs)[None] # (1, 10) 68 | # print(dmu_outs.shape) 69 | # print(L_outs.shape) 70 | # print(expected_dmu.shape) 71 | # print(expected_L.shape) 72 | 73 | ## verify outputs match expected values 74 | np.testing.assert_allclose(dmu_outs, expected_dmu, atol=1e-5) 75 | np.testing.assert_allclose(L_outs, expected_L, atol=1e-5) 76 | 77 | # test_gaussianErrorCell() -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_IFCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import IFCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_IFCell1(): 16 | name = "if_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = IFCell( 25 | name="a", n_units=1, tau_m=5., resist_m=10., key=subkeys[0] 26 | ) 27 | 28 | #""" 29 | advance_process = (Process("advance_proc") 30 | >> a.advance_state) 31 | #ctx.wrap_and_add_command(advance_process.pure, name="run") 32 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 33 | 34 | reset_process = (Process("reset_proc") 35 | >> a.reset) 36 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 37 | #""" 38 | 39 | """ 40 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 41 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 42 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 43 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 44 | """ 45 | 46 | ## set up non-compiled utility commands 47 | @Context.dynamicCommand 48 | def clamp(x): 49 | a.j.set(x) 50 | 51 | ## input spike train 52 | x_seq = jnp.asarray([[1., 1., 1., 1., 1., 0., 0., 1., 1., 1., 1., 1., 1., 1., 0.]], dtype=jnp.float32) 53 | ## desired output/epsp pulses 54 | y_seq = jnp.asarray([[0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0.]], dtype=jnp.float32) 55 | 56 | outs = [] 57 | ctx.reset() 58 | for ts in range(x_seq.shape[1]): 59 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 60 | ctx.clamp(x_t) 61 | ctx.run(t=ts * 1., dt=dt) 62 | outs.append(a.s.value) 63 | outs = jnp.concatenate(outs, axis=1) 64 | print(outs) 65 | 66 | ## output should equal input 67 | assert_array_equal(outs, y_seq) 68 | 69 | #test_IFCell1() 70 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_LIFCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import LIFCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_LIFCell1(): 16 | name = "lif_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = LIFCell( 25 | name="a", n_units=1, tau_m=5., resist_m=30., key=subkeys[0] 26 | ) 27 | 28 | #""" 29 | advance_process = (Process("advance_proc") 30 | >> a.advance_state) 31 | #ctx.wrap_and_add_command(advance_process.pure, name="run") 32 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 33 | 34 | reset_process = (Process("reset_proc") 35 | >> a.reset) 36 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 37 | #""" 38 | 39 | """ 40 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 41 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 42 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 43 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 44 | """ 45 | 46 | ## set up non-compiled utility commands 47 | @Context.dynamicCommand 48 | def clamp(x): 49 | a.j.set(x) 50 | 51 | ## input spike train 52 | x_seq = jnp.asarray([[1., 1., 1., 1., 1., 0., 0., 1., 1., 1., 1., 1., 1., 0.]], dtype=jnp.float32) 53 | ## desired output/epsp pulses 54 | y_seq = jnp.asarray([[0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.]], dtype=jnp.float32) 55 | 56 | outs = [] 57 | ctx.reset() 58 | for ts in range(x_seq.shape[1]): 59 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 60 | ctx.clamp(x_t) 61 | ctx.run(t=ts * 1., dt=dt) 62 | outs.append(a.s.value) 63 | outs = jnp.concatenate(outs, axis=1) 64 | #print(outs) 65 | 66 | ## output should equal input 67 | assert_array_equal(outs, y_seq) 68 | 69 | #test_LIFCell1() 70 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_RAFCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import RAFCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | 17 | def test_RAFCell1(): 18 | name = "raf_ctx" 19 | ## create seeding keys 20 | dkey = random.PRNGKey(1234) 21 | dkey, *subkeys = random.split(dkey, 6) 22 | dt = 1. # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = RAFCell( 26 | name="a", n_units=1, tau_v=20., resist_v=1., key=subkeys[0] 27 | ) 28 | 29 | #""" 30 | advance_process = (Process("advance_proc") 31 | >> a.advance_state) 32 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 33 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 34 | 35 | reset_process = (Process("reset_proc") 36 | >> a.reset) 37 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 38 | #""" 39 | 40 | """ 41 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 42 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 43 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 44 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 45 | """ 46 | 47 | ## set up non-compiled utility commands 48 | @Context.dynamicCommand 49 | def clamp(x): 50 | a.j.set(x) 51 | 52 | ## input spike train 53 | x_seq = jnp.asarray([[0., 1., 0., 0., 0., 0., 1., 0., 0.]], dtype=jnp.float32) 54 | ## desired output/epsp pulses 55 | y_seq = jnp.asarray([[0., 0., 0., 1., 0., 0., 0., 0., 1.]], dtype=jnp.float32) 56 | 57 | outs = [] 58 | ctx.reset() 59 | for ts in range(x_seq.shape[1]): 60 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 61 | ctx.clamp(x_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | outs.append(a.s.value) 64 | outs = jnp.concatenate(outs, axis=1) 65 | #print(outs) 66 | 67 | ## output should equal input 68 | assert_array_equal(outs, y_seq) 69 | 70 | #test_RAFCell1() 71 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_WTASCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import WTASCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | 17 | def test_WTASCell1(): 18 | name = "wtas_ctx" 19 | ## create seeding keys 20 | dkey = random.PRNGKey(1234) 21 | dkey, *subkeys = random.split(dkey, 6) 22 | dt = 1. # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = WTASCell( 26 | name="a", n_units=2, tau_m=25., resist_m=1., key=subkeys[0] 27 | ) 28 | 29 | #""" 30 | advance_process = (Process("advance_proc") 31 | >> a.advance_state) 32 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 33 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 34 | 35 | reset_process = (Process("reset_proc") 36 | >> a.reset) 37 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 38 | #""" 39 | 40 | """ 41 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 42 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 43 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 44 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 45 | """ 46 | 47 | ## set up non-compiled utility commands 48 | @Context.dynamicCommand 49 | def clamp(x): 50 | a.j.set(x) 51 | 52 | ## input spike train 53 | x_seq = jnp.asarray([[0., 1.], [0., 1.], [1., 0.], [1., 0.]], dtype=jnp.float32) 54 | ## desired output/epsp pulses 55 | y_seq = x_seq 56 | 57 | outs = [] 58 | ctx.reset() 59 | for ts in range(x_seq.shape[0]): 60 | x_t = x_seq[ts:ts+1, :] ## get data at time t 61 | ctx.clamp(x_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | outs.append(a.s.value) 64 | outs = jnp.concatenate(outs, axis=0) 65 | #print(outs) 66 | #exit() 67 | ## output should equal input 68 | assert_array_equal(outs, y_seq) 69 | 70 | #test_WTASCell1() 71 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_adExCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import AdExCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | 17 | def test_adExCell1(): 18 | name = "adex_ctx" 19 | ## create seeding keys 20 | dkey = random.PRNGKey(1234) 21 | dkey, *subkeys = random.split(dkey, 6) 22 | dt = 1. # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = AdExCell( 26 | name="a", n_units=1, tau_m=50., resist_m=30., thr=-66., key=subkeys[0] 27 | ) 28 | 29 | #""" 30 | advance_process = (Process("advance_proc") 31 | >> a.advance_state) 32 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 33 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 34 | 35 | reset_process = (Process("reset_proc") 36 | >> a.reset) 37 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 38 | #""" 39 | 40 | """ 41 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 42 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 43 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 44 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 45 | """ 46 | 47 | ## set up non-compiled utility commands 48 | @Context.dynamicCommand 49 | def clamp(x): 50 | a.j.set(x) 51 | 52 | ## input spike train 53 | x_seq = jnp.ones((1, 10)) 54 | ## desired output/epsp pulses 55 | y_seq = jnp.asarray([[0., 0., 0., 0., 0., 0., 0., 1., 0., 0.]], dtype=jnp.float32) 56 | 57 | outs = [] 58 | ctx.reset() 59 | for ts in range(x_seq.shape[1]): 60 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 61 | ctx.clamp(x_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | outs.append(a.s.value) 64 | outs = jnp.concatenate(outs, axis=1) 65 | #print(outs) 66 | 67 | ## output should equal input 68 | assert_array_equal(outs, y_seq) 69 | 70 | #test_adExCell1() 71 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_fitzhughNagumoCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import FitzhughNagumoCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | 17 | def test_fitzhughNagumoCell1(): 18 | name = "fh_ctx" 19 | ## create seeding keys 20 | dkey = random.PRNGKey(1234) 21 | dkey, *subkeys = random.split(dkey, 6) 22 | dt = 0.1 #1. # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = FitzhughNagumoCell( 26 | name="a", n_units=1, tau_m=1., resist_m=5., v_thr=2.1, key=subkeys[0] 27 | ) 28 | 29 | #""" 30 | advance_process = (Process("advance_proc") 31 | >> a.advance_state) 32 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 33 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 34 | 35 | reset_process = (Process("reset_proc") 36 | >> a.reset) 37 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 38 | #""" 39 | 40 | """ 41 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 42 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 43 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 44 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 45 | """ 46 | 47 | ## set up non-compiled utility commands 48 | @Context.dynamicCommand 49 | def clamp(x): 50 | a.j.set(x) 51 | 52 | ## input spike train 53 | x_seq = jnp.asarray([[0., 0., 1., 1., 1., 1., 0., 0., 0., 0.]], dtype=jnp.float32) 54 | ## desired output/epsp pulses 55 | y_seq = jnp.asarray([[0., 0., 0., 0., 0., 1., 0., 0., 0., 0.]], dtype=jnp.float32) 56 | 57 | outs = [] 58 | ctx.reset() 59 | for ts in range(x_seq.shape[1]): 60 | x_t = x_seq[:, ts:ts+1] ## get data at time t 61 | ctx.clamp(x_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | outs.append(a.s.value) 64 | outs = jnp.concatenate(outs, axis=1) 65 | #print(outs) 66 | 67 | ## output should equal input 68 | assert_array_equal(outs, y_seq) 69 | 70 | #test_fitzhughNagumoCell1() 71 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_hodgkinHuxleyCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import HodgkinHuxleyCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_almost_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | import matplotlib.pyplot as plt 17 | 18 | 19 | def test_hodgkinHuxleyCell1(): 20 | name = "hh_ctx" 21 | ## create seeding keys 22 | dkey = random.PRNGKey(1234) 23 | dkey, *subkeys = random.split(dkey, 6) 24 | dt = 0.01 # 1. # ms 25 | 26 | # ---- build a simple Poisson cell system ---- 27 | with Context(name) as ctx: 28 | a = HodgkinHuxleyCell( 29 | name="a", n_units=1, tau_v=1., resist_m=1., key=subkeys[0] 30 | ) 31 | 32 | # """ 33 | advance_process = (Process("advance_proc") 34 | >> a.advance_state) 35 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 36 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 37 | 38 | reset_process = (Process("reset_proc") 39 | >> a.reset) 40 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 41 | # """ 42 | 43 | """ 44 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 45 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 46 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 47 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 48 | """ 49 | 50 | ## set up non-compiled utility commands 51 | @Context.dynamicCommand 52 | def clamp(x): 53 | a.j.set(x) 54 | 55 | ## input spike train 56 | x_seq = jnp.zeros((1, 20)) 57 | y_seq = jnp.array( 58 | [[ 59 | 0.02414415, 0.04820144, 0.07217567, 0.09607048, 0.11988933, 0.14363553, 0.16731221, 0.19092241, 60 | 0.21446899, 0.23795472, 0.26138224, 0.28475408, 0.30807265, 0.3313403, 0.35455925, 0.37773165, 61 | 0.40085957, 0.42394499, 0.44698984, 0.46999594]], dtype=jnp.float32) 62 | 63 | v = [] 64 | ctx.reset() 65 | for ts in range(x_seq.shape[1]): 66 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 67 | ctx.clamp(x_t) 68 | ctx.run(t=ts * 1., dt=dt) 69 | v.append(a.v.value[0, 0]) 70 | outs = jnp.array(v) 71 | diff = np.abs(outs - y_seq) 72 | ## delta/error should be approximately zero 73 | assert_array_almost_equal(diff, diff * 0., decimal=6) 74 | 75 | #test_hodgkinHuxleyCell1() 76 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_izhikevichCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | 5 | np.random.seed(42) 6 | from ngclearn.components import IzhikevichCell 7 | from ngcsimlib.compilers import compile_command, wrap_command 8 | from numpy.testing import assert_array_equal 9 | 10 | from ngcsimlib.compilers.process import Process, transition 11 | from ngcsimlib.component import Component 12 | from ngcsimlib.compartment import Compartment 13 | from ngcsimlib.context import Context 14 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 15 | 16 | 17 | def test_izhikevichCell1(): 18 | name = "izh_ctx" 19 | ## create seeding keys 20 | dkey = random.PRNGKey(1234) 21 | dkey, *subkeys = random.split(dkey, 6) 22 | dt = 1. # ms 23 | # ---- build a simple Poisson cell system ---- 24 | with Context(name) as ctx: 25 | a = IzhikevichCell( 26 | name="a", n_units=1, tau_m=1., resist_m=4., v_thr=30., key=subkeys[0] 27 | ) 28 | 29 | #""" 30 | advance_process = (Process("advance_proc") 31 | >> a.advance_state) 32 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 33 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 34 | 35 | reset_process = (Process("reset_proc") 36 | >> a.reset) 37 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 38 | #""" 39 | 40 | """ 41 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 42 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 43 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 44 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 45 | """ 46 | 47 | ## set up non-compiled utility commands 48 | @Context.dynamicCommand 49 | def clamp(x): 50 | a.j.set(x) 51 | 52 | ## input spike train 53 | x_seq = jnp.asarray([[0., 0., 1., 1., 1., 1., 1., 1., 1., 1., 0., 0., 0., 0., 0.]], dtype=jnp.float32) 54 | ## desired output/epsp pulses 55 | y_seq = jnp.asarray([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.]], dtype=jnp.float32) 56 | 57 | outs = [] 58 | ctx.reset() 59 | for ts in range(x_seq.shape[1]): 60 | x_t = x_seq[:, ts:ts+1] ## get data at time t 61 | ctx.clamp(x_t) 62 | ctx.run(t=ts * 1., dt=dt) 63 | outs.append(a.s.value) 64 | print(a.v.value) 65 | outs = jnp.concatenate(outs, axis=1) 66 | print(outs) 67 | #exit() 68 | ## output should equal input 69 | assert_array_equal(outs, y_seq) 70 | 71 | #test_izhikevichCell1() 72 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_quadLIFCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import QuadLIFCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_quadLIFCell1(): 16 | name = "quadlif_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = QuadLIFCell( 25 | name="a", n_units=1, tau_m=30., resist_m=1., key=subkeys[0] 26 | ) 27 | 28 | #""" 29 | advance_process = (Process("advance_proc") 30 | >> a.advance_state) 31 | #ctx.wrap_and_add_command(advance_process.pure, name="run") 32 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 33 | 34 | reset_process = (Process("reset_proc") 35 | >> a.reset) 36 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 37 | #""" 38 | 39 | """ 40 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 41 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 42 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 43 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 44 | """ 45 | 46 | ## set up non-compiled utility commands 47 | @Context.dynamicCommand 48 | def clamp(x): 49 | a.j.set(x) 50 | 51 | ## input spike train 52 | x_seq = jnp.asarray([[1., 1., 1., 1., 1., 0., 0., 0., 1., 1., 1., 1., 1., 1., 0., 0.]], dtype=jnp.float32) 53 | ## desired output/epsp pulses 54 | y_seq = jnp.asarray([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 0.]], dtype=jnp.float32) 55 | 56 | outs = [] 57 | ctx.reset() 58 | for ts in range(x_seq.shape[1]): 59 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 60 | ctx.clamp(x_t) 61 | ctx.run(t=ts * 1., dt=dt) 62 | outs.append(a.s.value) 63 | outs = jnp.concatenate(outs, axis=1) 64 | #print(outs) 65 | 66 | ## output should equal input 67 | assert_array_equal(outs, y_seq) 68 | 69 | #test_quadLIFCell1() 70 | -------------------------------------------------------------------------------- /tests/components/neurons/spiking/test_sLIFCell.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import SLIFCell 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_sLIFCell1(): 16 | name = "slif_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = SLIFCell( 25 | name="a", n_units=1, tau_m=50., resist_m=10., thr=0.3, key=subkeys[0] 26 | ) 27 | 28 | #""" 29 | advance_process = (Process("advance_proc") 30 | >> a.advance_state) 31 | #ctx.wrap_and_add_command(advance_process.pure, name="run") 32 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 33 | 34 | reset_process = (Process("reset_proc") 35 | >> a.reset) 36 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 37 | #""" 38 | 39 | """ 40 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 41 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 42 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 43 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 44 | """ 45 | 46 | ## set up non-compiled utility commands 47 | @Context.dynamicCommand 48 | def clamp(x): 49 | a.j.set(x) 50 | 51 | ## input spike train 52 | x_seq = jnp.asarray([[1., 1., 0., 0., 1., 1., 0.]], dtype=jnp.float32) 53 | ## desired output/epsp pulses 54 | y_seq = jnp.asarray([[0., 1., 0., 0., 0., 1., 0.]], dtype=jnp.float32) 55 | 56 | outs = [] 57 | ctx.reset() 58 | for ts in range(x_seq.shape[1]): 59 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 60 | ctx.clamp(x_t) 61 | ctx.run(t=ts * 1., dt=dt) 62 | outs.append(a.s.value) 63 | outs = jnp.concatenate(outs, axis=1) 64 | 65 | ## output should equal input 66 | assert_array_equal(outs, y_seq) 67 | 68 | #test_sLIFCell1() 69 | -------------------------------------------------------------------------------- /tests/components/other/test_expKernel.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import ExpKernel 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_expKernel1(): 16 | name = "expKernel_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = ExpKernel( 25 | name="a", n_units=1, dt=1., tau_w=500., nu=4., key=subkeys[0] 26 | ) 27 | 28 | advance_process = (Process("advance_proc") 29 | >> a.advance_state) 30 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 31 | 32 | reset_process = (Process("reset_proc") 33 | >> a.reset) 34 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 35 | 36 | ## set up non-compiled utility commands 37 | @Context.dynamicCommand 38 | def clamp(x): 39 | a.inputs.set(x) 40 | 41 | ## input spike train 42 | x_seq = jnp.asarray([[1., 1., 0., 0., 1.]], dtype=jnp.float32) 43 | ## desired output/epsp pulses 44 | y_seq = jnp.asarray([[0., 1., 0.998002, 0.996008, 1.9940181]], dtype=jnp.float32) 45 | 46 | outs = [] 47 | ctx.reset() 48 | for ts in range(x_seq.shape[1]): 49 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 50 | ctx.clamp(x_t) 51 | ctx.run(t=ts * 1., dt=dt) 52 | outs.append(a.epsp.value) 53 | outs = jnp.concatenate(outs, axis=1) 54 | #print(outs) 55 | 56 | ## output should equal input 57 | np.testing.assert_allclose(outs, y_seq, atol=1e-8) 58 | 59 | #test_expKernel1() 60 | -------------------------------------------------------------------------------- /tests/components/other/test_varTrace.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import VarTrace 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 14 | 15 | def test_varTrace1(): 16 | name = "trace_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | trace_increment = 0.1 22 | # ---- build a simple Poisson cell system ---- 23 | with Context(name) as ctx: 24 | a = VarTrace( 25 | name="a", n_units=1, a_delta=trace_increment, decay_type="step", tau_tr=1., 26 | key=subkeys[0] 27 | ) 28 | 29 | advance_process = (Process("advance_proc") 30 | >> a.advance_state) 31 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 32 | 33 | reset_process = (Process("reset_proc") 34 | >> a.reset) 35 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 36 | 37 | ## set up non-compiled utility commands 38 | @Context.dynamicCommand 39 | def clamp(x): 40 | a.inputs.set(x) 41 | 42 | ## input spike train 43 | x_seq = jnp.asarray([[1., 1., 0., 0., 1.]], dtype=jnp.float32) 44 | ## desired output pulses 45 | y_seq = x_seq * trace_increment 46 | 47 | outs = [] 48 | ctx.reset() 49 | for ts in range(x_seq.shape[1]): 50 | x_t = jnp.array([[x_seq[0, ts]]]) ## get data at time t 51 | ctx.clamp(x_t) 52 | ctx.run(t=ts * 1., dt=dt) 53 | outs.append(a.outputs.value) 54 | outs = jnp.concatenate(outs, axis=1) 55 | #print(outs) 56 | 57 | ## output should equal input 58 | assert_array_equal(outs, y_seq) 59 | 60 | #test_varTrace1() 61 | -------------------------------------------------------------------------------- /tests/components/synapses/hebbian/test_BCMSynapse.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import BCMSynapse 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | 14 | def test_BCMSynapse1(): 15 | name = "bcm_stdp_ctx" 16 | ## create seeding keys 17 | dkey = random.PRNGKey(1234) 18 | dkey, *subkeys = random.split(dkey, 6) 19 | dt = 1. # ms 20 | # ---- build a simple Poisson cell system ---- 21 | with Context(name) as ctx: 22 | a = BCMSynapse( 23 | name="a", shape=(1,1), tau_w=40., tau_theta=20., key=subkeys[0] 24 | ) 25 | 26 | #""" 27 | evolve_process = (Process("evolve_proc") 28 | >> a.evolve) 29 | #ctx.wrap_and_add_command(evolve_process.pure, name="run") 30 | ctx.wrap_and_add_command(jit(evolve_process.pure), name="adapt") 31 | 32 | advance_process = (Process("advance_proc") 33 | >> a.advance_state) 34 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 35 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 36 | 37 | reset_process = (Process("reset_proc") 38 | >> a.reset) 39 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 40 | #""" 41 | 42 | """ 43 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 44 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 45 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 46 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 47 | evolve_cmd, evolve_args = ctx.compile_by_key(a, compile_key="evolve") 48 | ctx.add_command(wrap_command(jit(ctx.evolve)), name="adapt") 49 | """ 50 | 51 | pre_value = jnp.ones((1, 1)) * 0.425 52 | post_value = jnp.ones((1, 1)) * 1.55 53 | 54 | truth = jnp.array([[-1.6798127]]) 55 | ctx.reset() 56 | a.pre.set(pre_value) 57 | a.post.set(post_value) 58 | ctx.run(t=1., dt=dt) 59 | ctx.adapt(t=1., dt=dt) 60 | #print(a.dWeights.value) 61 | assert_array_equal(a.dWeights.value, truth) 62 | 63 | 64 | #test_BCMSynapse1() 65 | -------------------------------------------------------------------------------- /tests/components/synapses/hebbian/test_hebbianSynapse.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import HebbianSynapse 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_hebbianSynapse(): 19 | np.random.seed(42) 20 | name = "hebbian_synapse_ctx" 21 | dkey = random.PRNGKey(42) 22 | dkey, *subkeys = random.split(dkey, 100) 23 | dt = 1. # ms 24 | 25 | # model hyper 26 | shape = (10, 5) 27 | batch_size = 1 28 | resist_scale = 1.0 29 | 30 | with Context(name) as ctx: 31 | a = HebbianSynapse( 32 | name="a", 33 | shape=shape, 34 | resist_scale=resist_scale, 35 | batch_size=batch_size, 36 | prior = ("gaussian", 0.01) 37 | ) 38 | 39 | advance_process = (Process("advance_proc") >> a.advance_state) 40 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 41 | reset_process = (Process("reset_proc") >> a.reset) 42 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 43 | evolve_process = (Process("evolve_proc") >> a.evolve) 44 | ctx.wrap_and_add_command(jit(evolve_process.pure), name="evolve") 45 | 46 | # Compile and add commands 47 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 48 | # ctx.add_command(wrap_command(jit(reset_cmd)), name="reset") 49 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 50 | # ctx.add_command(wrap_command(jit(advance_cmd)), name="run") 51 | # evolve_cmd, evolve_args = ctx.compile_by_key(a, compile_key="evolve") 52 | # ctx.add_command(wrap_command(jit(evolve_cmd)), name="evolve") 53 | 54 | @Context.dynamicCommand 55 | def clamp_inputs(x): 56 | a.inputs.set(x) 57 | 58 | @Context.dynamicCommand 59 | def clamp_pre(x): 60 | a.pre.set(x) 61 | 62 | @Context.dynamicCommand 63 | def clamp_post(x): 64 | a.post.set(x) 65 | 66 | # Test input sequence 67 | # Initial weights 68 | a.weights.set(jnp.ones((10, 5)) * 0.5) 69 | 70 | in_pre = jnp.ones((1, 10)) * 1.0 71 | in_post = jnp.ones((1, 5)) * 0.75 72 | 73 | ctx.reset() 74 | clamp_pre(in_pre) 75 | clamp_post(in_post) 76 | ctx.run(t=1. * dt, dt=dt) 77 | ctx.evolve(t=1. * dt, dt=dt) 78 | 79 | print(a.weights.value) 80 | 81 | # Basic assertions to check learning dynamics 82 | assert a.weights.value.shape == (10, 5), "" 83 | assert a.weights.value[0, 0] == 0.5, "" 84 | 85 | # test_hebbianSynapse() -------------------------------------------------------------------------------- /tests/components/synapses/hebbian/test_traceSTDPSynapse.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import TraceSTDPSynapse 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | 14 | def test_traceSTDPSynapse1(): 15 | name = "trace_stdp_ctx" 16 | ## create seeding keys 17 | dkey = random.PRNGKey(1234) 18 | dkey, *subkeys = random.split(dkey, 6) 19 | dt = 1. # ms 20 | # ---- build a simple Poisson cell system ---- 21 | with Context(name) as ctx: 22 | a = TraceSTDPSynapse( 23 | name="a", shape=(1,1), A_plus=1., A_minus=1., key=subkeys[0] 24 | ) 25 | 26 | #""" 27 | evolve_process = (Process("evolve_proc") 28 | >> a.evolve) 29 | #ctx.wrap_and_add_command(evolve_process.pure, name="run") 30 | ctx.wrap_and_add_command(jit(evolve_process.pure), name="adapt") 31 | 32 | advance_process = (Process("advance_proc") 33 | >> a.advance_state) 34 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 35 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 36 | 37 | reset_process = (Process("reset_proc") 38 | >> a.reset) 39 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 40 | #""" 41 | 42 | """ 43 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 44 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 45 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 46 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 47 | evolve_cmd, evolve_args = ctx.compile_by_key(a, compile_key="evolve") 48 | ctx.add_command(wrap_command(jit(ctx.evolve)), name="adapt") 49 | """ 50 | a.weights.set(jnp.ones((1, 1)) * 0.1) 51 | 52 | in_spike = jnp.ones((1, 1)) 53 | in_trace = jnp.ones((1, 1,)) * 1.25 54 | out_spike = jnp.ones((1, 1)) 55 | out_trace = jnp.ones((1, 1,)) * 0.65 56 | 57 | ## check pre-synaptic STDP only 58 | truth = jnp.array([[1.25]]) 59 | ctx.reset() 60 | a.preSpike.set(in_spike * 0) 61 | a.preTrace.set(in_trace) 62 | a.postSpike.set(out_spike) 63 | a.postTrace.set(out_trace) 64 | ctx.run(t=1., dt=dt) 65 | ctx.adapt(t=1., dt=dt) 66 | #print(a.dWeights.value) 67 | assert_array_equal(a.dWeights.value, truth) 68 | 69 | truth = jnp.array([[-0.65]]) 70 | ctx.reset() 71 | a.preSpike.set(in_spike) 72 | a.preTrace.set(in_trace) 73 | a.postSpike.set(out_spike * 0) 74 | a.postTrace.set(out_trace) 75 | ctx.run(t=1., dt=dt) 76 | ctx.adapt(t=1., dt=dt) 77 | #print(a.dWeights.value) 78 | assert_array_equal(a.dWeights.value, truth) 79 | 80 | #test_traceSTDPSynapse1() 81 | -------------------------------------------------------------------------------- /tests/components/synapses/patched/test_hebbianPatchedSynapse.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import HebbianPatchedSynapse 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_hebbianPatchedSynapse(): 19 | np.random.seed(42) 20 | name = "hebbian_patched_synapse_ctx" 21 | dkey = random.PRNGKey(42) 22 | dkey, *subkeys = random.split(dkey, 100) 23 | dt = 1. # ms 24 | 25 | # model hyper 26 | shape = (10, 5) 27 | n_sub_models = 2 28 | stride_shape = (1, 1) 29 | batch_size = 1 30 | resist_scale = 1.0 31 | 32 | with Context(name) as ctx: 33 | a = HebbianPatchedSynapse( 34 | name="a", 35 | shape=shape, 36 | n_sub_models=n_sub_models, 37 | stride_shape=stride_shape, 38 | resist_scale=resist_scale, 39 | batch_size=batch_size 40 | ) 41 | 42 | advance_process = (Process("advance_proc") >> a.advance_state) 43 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 44 | reset_process = (Process("reset_proc") >> a.reset) 45 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 46 | evolve_process = (Process("evolve_proc") >> a.evolve) 47 | ctx.wrap_and_add_command(jit(evolve_process.pure), name="evolve") 48 | 49 | # Compile and add commands 50 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 51 | # ctx.add_command(wrap_command(jit(reset_cmd)), name="reset") 52 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 53 | # ctx.add_command(wrap_command(jit(advance_cmd)), name="run") 54 | # evolve_cmd, evolve_args = ctx.compile_by_key(a, compile_key="evolve") 55 | # ctx.add_command(wrap_command(jit(evolve_cmd)), name="evolve") 56 | 57 | @Context.dynamicCommand 58 | def clamp_inputs(x): 59 | a.inputs.set(x) 60 | 61 | @Context.dynamicCommand 62 | def clamp_pre(x): 63 | a.pre.set(x) 64 | 65 | @Context.dynamicCommand 66 | def clamp_post(x): 67 | a.post.set(x) 68 | 69 | a.weights.set(jnp.ones((12, 12)) * 0.5) 70 | 71 | in_pre = jnp.ones((10, 12)) * 1.0 72 | in_post = jnp.ones((10, 12)) * 0.75 73 | 74 | ctx.reset() 75 | clamp_pre(in_pre) 76 | clamp_post(in_post) 77 | ctx.run(t=1. * dt, dt=dt) 78 | ctx.evolve(t=1. * dt, dt=dt) 79 | 80 | print(a.weights.value) 81 | 82 | # Basic assertions to check learning dynamics 83 | assert a.weights.value.shape == (12, 12), "" 84 | assert a.weights.value[0, 0] == 0.5, "" 85 | 86 | 87 | 88 | # test_hebbianPatchedSynapse() -------------------------------------------------------------------------------- /tests/components/synapses/patched/test_patchedSynapse.py: -------------------------------------------------------------------------------- 1 | # %% 2 | 3 | from jax import numpy as jnp, random, jit 4 | from ngcsimlib.context import Context 5 | import numpy as np 6 | np.random.seed(42) 7 | from ngclearn.components import PatchedSynapse 8 | from ngcsimlib.compilers import compile_command, wrap_command 9 | from numpy.testing import assert_array_equal 10 | 11 | from ngcsimlib.compilers.process import Process, transition 12 | from ngcsimlib.component import Component 13 | from ngcsimlib.compartment import Compartment 14 | from ngcsimlib.context import Context 15 | from ngcsimlib.utils.compartment import Get_Compartment_Batch 16 | 17 | 18 | def test_patchedSynapse(): 19 | np.random.seed(42) 20 | name = "patched_synapse_ctx" 21 | dkey = random.PRNGKey(42) 22 | dkey, *subkeys = random.split(dkey, 100) 23 | dt = 1. # ms 24 | # model hyper 25 | shape = (10, 5) 26 | n_sub_models = 2 27 | stride_shape = (1, 1) 28 | batch_size = 1 29 | resist_scale = 1.0 30 | with Context(name) as ctx: 31 | a = PatchedSynapse( 32 | name="a", 33 | shape=shape, 34 | n_sub_models=n_sub_models, 35 | stride_shape=stride_shape, 36 | resist_scale=resist_scale, 37 | batch_size=batch_size, 38 | weight_init={"dist": "gaussian", "std": 0.1}, 39 | bias_init={"dist": "constant", "value": 0.0} 40 | ) 41 | 42 | advance_process = (Process("advance_proc") >> a.advance_state) 43 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 44 | reset_process = (Process("reset_proc") >> a.reset) 45 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 46 | 47 | # Compile and add commands 48 | # reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 49 | # ctx.add_command(wrap_command(jit(reset_cmd)), name="reset") 50 | # advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 51 | # ctx.add_command(wrap_command(jit(advance_cmd)), name="run") 52 | 53 | @Context.dynamicCommand 54 | def clamp_inputs(x): 55 | a.inputs.set(x) 56 | 57 | inputs_seq = jnp.asarray(np.random.randn(1, 12)) 58 | weights = a.weights.value 59 | biases = a.biases.value 60 | expected_outputs = (jnp.matmul(inputs_seq, weights) * resist_scale) + biases 61 | outputs_outs = [] 62 | ctx.reset() 63 | ctx.clamp_inputs(inputs_seq) 64 | ctx.run(t=0., dt=dt) 65 | outputs_outs.append(a.outputs.value) 66 | outputs_outs = jnp.concatenate(outputs_outs, axis=1) 67 | # Verify outputs match expected values 68 | np.testing.assert_allclose(outputs_outs, expected_outputs, atol=1e-5) 69 | 70 | -------------------------------------------------------------------------------- /tests/components/synapses/test_STPDenseSynapse.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | from ngcsimlib.context import Context 3 | import numpy as np 4 | np.random.seed(42) 5 | from ngclearn.components import STPDenseSynapse 6 | from ngcsimlib.compilers import compile_command, wrap_command 7 | from numpy.testing import assert_array_equal 8 | 9 | from ngcsimlib.compilers.process import Process, transition 10 | from ngcsimlib.component import Component 11 | from ngcsimlib.compartment import Compartment 12 | from ngcsimlib.context import Context 13 | import ngclearn.utils.weight_distribution as dist 14 | 15 | def test_STPDenseSynapse1(): 16 | name = "stp_ctx" 17 | ## create seeding keys 18 | dkey = random.PRNGKey(1234) 19 | dkey, *subkeys = random.split(dkey, 6) 20 | dt = 1. # ms 21 | # ---- build a simple Poisson cell system ---- 22 | with Context(name) as ctx: 23 | a = STPDenseSynapse( 24 | name="a", shape=(1,1), resources_init=dist.constant(value=1.),key=subkeys[0] 25 | ) 26 | 27 | #""" 28 | advance_process = (Process("advance_proc") 29 | >> a.advance_state) 30 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 31 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 32 | 33 | reset_process = (Process("reset_proc") 34 | >> a.reset) 35 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 36 | #""" 37 | 38 | """ 39 | reset_cmd, reset_args = ctx.compile_by_key(a, compile_key="reset") 40 | ctx.add_command(wrap_command(jit(ctx.reset)), name="reset") 41 | advance_cmd, advance_args = ctx.compile_by_key(a, compile_key="advance_state") 42 | ctx.add_command(wrap_command(jit(ctx.advance_state)), name="run") 43 | """ 44 | a.weights.set(jnp.ones((1, 1))) 45 | in_pulse = jnp.ones((1, 1)) * 0.425 46 | 47 | outs_truth = jnp.array([[0.07676563, 0.14312361, 0.16848783]]) 48 | Wdyn_truth = jnp.array([[0.180625, 0.33676142, 0.39644194]]) 49 | 50 | outs = [] 51 | Wdyn = [] 52 | ctx.reset() 53 | for t in range(3): 54 | a.inputs.set(in_pulse) 55 | ctx.run(t=t * dt, dt=dt) 56 | outs.append(a.outputs.value) 57 | Wdyn.append(a.Wdyn.value) 58 | outs = jnp.concatenate(outs, axis=1) 59 | Wdyn = jnp.concatenate(Wdyn, axis=1) 60 | # print(outs) 61 | # print(Wdyn) 62 | np.testing.assert_allclose(outs, outs_truth, atol=1e-8) 63 | np.testing.assert_allclose(Wdyn, Wdyn_truth, atol=1e-8) 64 | 65 | #test_STPDenseSynapse1() 66 | -------------------------------------------------------------------------------- /tests/components/synapses/test_exponentialSynapse.py: -------------------------------------------------------------------------------- 1 | from jax import numpy as jnp, random, jit 2 | import numpy as np 3 | np.random.seed(42) 4 | from ngclearn.components import ExponentialSynapse 5 | 6 | from ngcsimlib.compilers.process import Process 7 | from ngcsimlib.context import Context 8 | import ngclearn.utils.weight_distribution as dist 9 | 10 | def test_exponentialSynapse1(): 11 | name = "expsyn_ctx" 12 | ## create seeding keys 13 | dkey = random.PRNGKey(1234) 14 | dkey, *subkeys = random.split(dkey, 6) 15 | dt = 1. # ms 16 | ## excitatory properties 17 | tau_syn = 2. 18 | E_rest = 0. 19 | # ---- build a single exp-synapse system ---- 20 | with Context(name) as ctx: 21 | a = ExponentialSynapse( 22 | name="a", shape=(1,1), tau_decay=tau_syn, g_syn_bar=2.4, syn_rest=E_rest, weight_init=dist.constant(value=1.), 23 | key=subkeys[0] 24 | ) 25 | 26 | advance_process = (Process("advance_proc") 27 | >> a.advance_state) 28 | # ctx.wrap_and_add_command(advance_process.pure, name="run") 29 | ctx.wrap_and_add_command(jit(advance_process.pure), name="run") 30 | 31 | reset_process = (Process("reset_proc") 32 | >> a.reset) 33 | ctx.wrap_and_add_command(jit(reset_process.pure), name="reset") 34 | 35 | sp_train = jnp.array([1., 0., 1.], dtype=jnp.float32) 36 | post_syn_neuron_volt = jnp.ones((1, 1)) * -65. ## post-syn neuron is at rest 37 | 38 | outs_truth = jnp.array([[156., 78., 195.]]) 39 | 40 | outs = [] 41 | ctx.reset() 42 | for t in range(3): 43 | in_pulse = jnp.expand_dims(sp_train[t], axis=0) 44 | a.inputs.set(in_pulse) 45 | a.v.set(post_syn_neuron_volt) 46 | ctx.run(t=t * dt, dt=dt) 47 | #print("g: ",a.g_syn.value) 48 | #print("i: ", a.i_syn.value) 49 | outs.append(a.outputs.value) 50 | outs = jnp.concatenate(outs, axis=1) 51 | #print(outs) 52 | 53 | np.testing.assert_allclose(outs, outs_truth, atol=1e-8) 54 | 55 | #test_exponentialSynapse1() 56 | -------------------------------------------------------------------------------- /tests/test___init__.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | class TestInit(): 4 | 5 | def test_import(self): 6 | successful = False 7 | try: 8 | import ngclearn 9 | successful = True 10 | except: 11 | successful = False 12 | assert successful, "Cannot import ngclearn" 13 | 14 | --------------------------------------------------------------------------------