Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/point process decoder design #53

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
bf99a53
Added tensors library
ncguilbeault Aug 23, 2024
19497a5
Added arange function
ncguilbeault Aug 23, 2024
fd57f8c
Added concat class
ncguilbeault Aug 23, 2024
0d31457
Added arange function
ncguilbeault Aug 23, 2024
0858c93
Added linspace
ncguilbeault Aug 23, 2024
812be10
Added meshgrid
ncguilbeault Aug 23, 2024
0d8f732
Added ones
ncguilbeault Aug 23, 2024
c679dd4
Added zeros
ncguilbeault Aug 23, 2024
044f30e
Added device initialization
ncguilbeault Aug 23, 2024
9aeca78
Added ability to move tensor to device
ncguilbeault Aug 23, 2024
daa2519
Added permute
ncguilbeault Aug 23, 2024
05d88d5
Added reshape
ncguilbeault Aug 23, 2024
e07a7f7
Added set
ncguilbeault Aug 23, 2024
59ec8cd
Updated csproj with opencv.net package
ncguilbeault Aug 23, 2024
b051999
Added concatenate class
ncguilbeault Aug 23, 2024
31b3981
Added convert data type
ncguilbeault Aug 23, 2024
78e7026
Added create tensor method
ncguilbeault Aug 23, 2024
ac2f0cb
Added index method and updated set method
ncguilbeault Aug 23, 2024
eb62f4b
Defined tensor data types as subset of ScalarType
ncguilbeault Aug 23, 2024
c36931c
Added to array method
ncguilbeault Aug 23, 2024
4f01250
Added tensor data type helper
ncguilbeault Aug 23, 2024
f879960
Added methods to convert OpenCV types
ncguilbeault Aug 23, 2024
40615ab
Refactored to torch namespace instead of tensors
ncguilbeault Aug 27, 2024
1386ff3
Removed previous Bonsai.ML.Tensors directory and contents
ncguilbeault Aug 27, 2024
0e820d7
Updated solution to reflect change
ncguilbeault Aug 27, 2024
f06a445
Moved Tensors namespace to main Torch namespace
ncguilbeault Aug 27, 2024
980a03d
Updated to reflect new namespace
ncguilbeault Aug 27, 2024
b3f3417
Removed unfinished classes
ncguilbeault Aug 27, 2024
df313d7
Updated to use common Bonsai.ML.Data project
ncguilbeault Sep 4, 2024
e75e2a9
Added additional overloads to process method
ncguilbeault Sep 4, 2024
35f5308
Updated to use common data tools
ncguilbeault Sep 4, 2024
c13c510
Updated tensor data type and helper
ncguilbeault Sep 4, 2024
a7742ef
Updated formatting
ncguilbeault Sep 4, 2024
6bd2e66
Removed bonsai core dependency in favor of bonsai.ml dependency
ncguilbeault Sep 26, 2024
df6bd16
Fixed bugs with create tensor method and updated to use string formatter
ncguilbeault Sep 26, 2024
9b3c4f9
Added empty tensor creator
ncguilbeault Sep 26, 2024
2ced9dd
Moved index helper to main library
ncguilbeault Sep 26, 2024
a2fa420
Moved opencv helper to main library
ncguilbeault Sep 26, 2024
05c12ce
Removed opencv helper from helpers subfolder
ncguilbeault Sep 26, 2024
57901ae
Updated with new index helper
ncguilbeault Sep 26, 2024
51ab15b
Updated with opencv helper
ncguilbeault Sep 26, 2024
ac4b398
Added process overload for generating on input
ncguilbeault Sep 26, 2024
e69923a
Added xml ignore tag on device
ncguilbeault Sep 27, 2024
9099cf9
Updated to use shared module interface
ncguilbeault Oct 16, 2024
f76181e
Modified to use Module interface
ncguilbeault Oct 30, 2024
befe81b
Removed unnecessary null string
ncguilbeault Oct 30, 2024
d4c4cc0
Added a common interface
ncguilbeault Nov 1, 2024
b9bacdd
Added swap axes function
ncguilbeault Nov 6, 2024
624c703
Added tile function
ncguilbeault Nov 6, 2024
2f799b7
Updated model loading and model forward procedure
ncguilbeault Nov 6, 2024
637020e
Added backward function for running online gradient descent with spec…
ncguilbeault Nov 14, 2024
65d8c70
Added function to save model
ncguilbeault Nov 14, 2024
47dde6c
Changed name to indicate loading from an existing architecture
ncguilbeault Jan 20, 2025
6d8442e
Added descriptions and documentation
ncguilbeault Jan 20, 2025
f40aa4f
Added some useful classes for linear algebra
ncguilbeault Jan 20, 2025
abb108b
Adding classes for creating tensor indexes
ncguilbeault Jan 20, 2025
d8f19ff
Updated MNIST model architecture with correct fully connected layer size
ncguilbeault Jan 20, 2025
6331273
Added class to explicitly create a clone of a tensor
ncguilbeault Jan 20, 2025
4708507
Update to use correct width for an IplImage based on widthstep rather…
ncguilbeault Jan 20, 2025
1926bcd
Explicitly use static torch.Tensor type for defining expressions
ncguilbeault Jan 20, 2025
597265f
Update set with process overloads to handle passing in tensor index
ncguilbeault Jan 20, 2025
5d2cb1e
Fixed incorrectly generating ones instead of zeros
ncguilbeault Jan 20, 2025
04a1f56
Updated to correctly parse colons in string
ncguilbeault Jan 20, 2025
2dd1b91
Updated to use collection expressions
ncguilbeault Jan 20, 2025
f725c58
Added documentation
ncguilbeault Jan 20, 2025
4f0776e
Updated to use collection expressions
ncguilbeault Jan 21, 2025
5b04e35
Add process overload to initialize device on input
ncguilbeault Jan 21, 2025
2a6190d
Added documentation
ncguilbeault Jan 21, 2025
9601460
Added file name editor attribute to model path
ncguilbeault Jan 21, 2025
506d8a1
Updated to latest torchsharp version
ncguilbeault Jan 21, 2025
ccfe400
Update class name to reflect file name
ncguilbeault Jan 21, 2025
ff8b463
Added documentation to package
ncguilbeault Jan 23, 2025
2f4d6e3
Fixed issue with MNIST model not accepting num classes
ncguilbeault Jan 23, 2025
d17584f
Made slight correction to GPU documentation
ncguilbeault Jan 24, 2025
49eef38
Modified torch module classes to be internel
ncguilbeault Jan 29, 2025
1f063a9
Reworked OpenCV <-> TorchSharp conversions to respect the garbage col…
PathogenDavid Jan 29, 2025
6cdd764
Removed unnecessary GCHandle usage (the lambda itself makes the ancho…
PathogenDavid Feb 4, 2025
3a68d6b
Added point process model package
ncguilbeault Jan 10, 2025
fd4ea05
Added get model function
ncguilbeault Jan 13, 2025
a911045
Changed "IsDispose" to correct "IsDisposed" use of past tense
ncguilbeault Jan 13, 2025
4533762
Added dispose method to model manager
ncguilbeault Jan 13, 2025
2f2689a
Updated comments/docs
ncguilbeault Jan 15, 2025
1f7fe53
Added Bonsai.ML.Torch dependency
ncguilbeault Jan 21, 2025
3979a66
Moved property group to top for consistency with other packages. Also…
ncguilbeault Jan 21, 2025
86a2174
Updated dependency version
ncguilbeault Jan 24, 2025
ff7140d
Added documentation for point process decoder package
ncguilbeault Jan 24, 2025
63ce3be
Updated point process model to include ignore no spikes parameter
ncguilbeault Jan 27, 2025
094964d
Updated point process decoder core package version
ncguilbeault Jan 28, 2025
094173b
Update decode method to allow modifying the ignore no spikes property…
ncguilbeault Jan 28, 2025
b0fd4db
Updated create model node to dispose model using the observable.final…
ncguilbeault Jan 28, 2025
1254dfe
Changed get model to source and add process function for no input
ncguilbeault Jan 28, 2025
b1e0ca0
Moved ignore no spikes property to likelihood parameters category
ncguilbeault Jan 28, 2025
29058e2
Added property descriptions
ncguilbeault Jan 28, 2025
edeed96
Update package version
ncguilbeault Jan 29, 2025
93c24ad
Update package dependency version
ncguilbeault Feb 4, 2025
1b3d302
Add kernel limit parameter to model
ncguilbeault Feb 4, 2025
2141c27
Added load model class
ncguilbeault Feb 4, 2025
8d680e6
Added save model
ncguilbeault Feb 4, 2025
8307f73
Removed try get call in create model
ncguilbeault Feb 6, 2025
6a64264
Update suffix string format for datetime suffix type
ncguilbeault Feb 7, 2025
0f5a1b4
Added initial visualizers for conditional intensities and kernel esti…
ncguilbeault Feb 6, 2025
aa61162
Make GetModel function public for visualizer
ncguilbeault Feb 11, 2025
48e359f
Removed kernel estimates visualizer
ncguilbeault Feb 11, 2025
454bd51
Updated conditional intensities visualizer
ncguilbeault Feb 11, 2025
65a0bb7
Adding all changes from altering dispose methods
ncguilbeault Feb 11, 2025
3d25d6b
Moved toolstrip numeric up down class to seperate file
ncguilbeault Feb 12, 2025
ed29327
Fixed issue with visualizers not displaying properly
ncguilbeault Feb 12, 2025
5faf9a7
Update heatmap series plot to make visualizer drop down public
ncguilbeault Feb 21, 2025
e15854b
Update heatmap series to expose plot model and plot view publically.
ncguilbeault Feb 21, 2025
1659700
Changed formatting. Used a lambda expression for on mouse view change…
ncguilbeault Feb 21, 2025
4327dbd
Make heatmap plot field public.
ncguilbeault Feb 21, 2025
21ae0ce
Update decoder package to v0.3.0
ncguilbeault Feb 21, 2025
bca52d8
Update documentation for ignore no spikes property
ncguilbeault Feb 21, 2025
db968f3
Ensured ignore no spikes property is applied to both clusterless and …
ncguilbeault Feb 21, 2025
a3661d2
Added documentation to public get model function
ncguilbeault Feb 21, 2025
b014433
Updated documentation for using Datetime suffix and used high resolut…
ncguilbeault Feb 21, 2025
dbf2949
Renamed `ConditionalIntensitiesVisualizer` to just `IntensitiesVisual…
ncguilbeault Feb 21, 2025
5af05b1
Added a density estimations visualizer
ncguilbeault Feb 21, 2025
dfd1c3e
Added a likelihood visualizer
ncguilbeault Feb 21, 2025
0514fcf
Added a posterior visualizer
ncguilbeault Feb 21, 2025
e18af86
Added a point2D overlay visualizer for posterior and likelihood mashu…
ncguilbeault Feb 21, 2025
4f8e962
Added `Bonsai.Vision.Design` package to project reference
ncguilbeault Feb 21, 2025
aea32e2
Updated heatmap series oxyplot base to enable setting x and y axis ra…
ncguilbeault Feb 25, 2025
6825818
Added a decoder visualizer interface
ncguilbeault Feb 25, 2025
cb7fc07
Added a class which will automatically cycle through different oxyplo…
ncguilbeault Feb 25, 2025
2e2f216
Updated to use decoder visualizer interface and to use value min/max …
ncguilbeault Feb 25, 2025
7d091d3
Updated point overlay class to allow mashup visualizer class to handl…
ncguilbeault Feb 25, 2025
d7b16c0
Add `SumAcrossBatch` parameter to model constructor and decode function
ncguilbeault Feb 25, 2025
0173558
Fixed issue with not being able to set the min/max heatmap values pro…
ncguilbeault Feb 28, 2025
0ddb210
Updated `PointProcessDecoder.Core` package version
ncguilbeault Feb 28, 2025
72f43aa
Updated likelihood visualizer to place capacity property into visuali…
ncguilbeault Mar 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions Bonsai.ML.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
Expand Down Expand Up @@ -30,6 +30,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.LinearDynamicalSy
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.HiddenMarkovModels.Design", "src\Bonsai.ML.HiddenMarkovModels.Design\Bonsai.ML.HiddenMarkovModels.Design.csproj", "{FC395DDC-62A4-4E14-A198-272AB05B33C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.Torch", "src\Bonsai.ML.Torch\Bonsai.ML.Torch.csproj", "{06FCC9AF-CE38-44BB-92B3-0D451BE88537}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.PointProcessDecoder", "src\Bonsai.ML.PointProcessDecoder\Bonsai.ML.PointProcessDecoder.csproj", "{AD32C680-1E8C-4340-81B1-DA19C9104516}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.PointProcessDecoder.Design", "src\Bonsai.ML.PointProcessDecoder.Design\Bonsai.ML.PointProcessDecoder.Design.csproj", "{91C3E252-9457-43AB-A21A-6064E2404BAA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,18 +66,30 @@ Global
{39A4414F-52B1-42D7-82FA-E65DAD885264}.Debug|Any CPU.Build.0 = Debug|Any CPU
{39A4414F-52B1-42D7-82FA-E65DAD885264}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39A4414F-52B1-42D7-82FA-E65DAD885264}.Release|Any CPU.Build.0 = Release|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Release|Any CPU.Build.0 = Release|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Release|Any CPU.Build.0 = Release|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Release|Any CPU.Build.0 = Release|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}.Release|Any CPU.Build.0 = Release|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}.Release|Any CPU.Build.0 = Release|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC395DDC-62A4-4E14-A198-272AB05B33C7}.Release|Any CPU.Build.0 = Release|Any CPU
{06FCC9AF-CE38-44BB-92B3-0D451BE88537}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06FCC9AF-CE38-44BB-92B3-0D451BE88537}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06FCC9AF-CE38-44BB-92B3-0D451BE88537}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06FCC9AF-CE38-44BB-92B3-0D451BE88537}.Release|Any CPU.Build.0 = Release|Any CPU
{AD32C680-1E8C-4340-81B1-DA19C9104516}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD32C680-1E8C-4340-81B1-DA19C9104516}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD32C680-1E8C-4340-81B1-DA19C9104516}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD32C680-1E8C-4340-81B1-DA19C9104516}.Release|Any CPU.Build.0 = Release|Any CPU
{91C3E252-9457-43AB-A21A-6064E2404BAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{91C3E252-9457-43AB-A21A-6064E2404BAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{91C3E252-9457-43AB-A21A-6064E2404BAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{91C3E252-9457-43AB-A21A-6064E2404BAA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -84,8 +102,11 @@ Global
{81DB65B3-EA65-4947-8CF1-0E777324C082} = {461FE3E2-21C4-47F9-8405-DF72326AAB2B}
{BAD0A733-8EFB-4EAF-9648-9851656AF7FF} = {12312384-8828-4786-AE19-EFCEDF968290}
{39A4414F-52B1-42D7-82FA-E65DAD885264} = {12312384-8828-4786-AE19-EFCEDF968290}
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13} = {12312384-8828-4786-AE19-EFCEDF968290}
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1} = {12312384-8828-4786-AE19-EFCEDF968290}
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13} = {12312384-8828-4786-AE19-EFCEDF968290}
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1} = {12312384-8828-4786-AE19-EFCEDF968290}
{06FCC9AF-CE38-44BB-92B3-0D451BE88537} = {12312384-8828-4786-AE19-EFCEDF968290}
{AD32C680-1E8C-4340-81B1-DA19C9104516} = {12312384-8828-4786-AE19-EFCEDF968290}
{91C3E252-9457-43AB-A21A-6064E2404BAA} = {12312384-8828-4786-AE19-EFCEDF968290}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6468F13-97CD-45E0-9E1E-C122D7F1E09F}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Facilitates inference using Hidden Markov Models (HMMs). It interfaces with the
### Bonsai.ML.HiddenMarkovModels.Design
Visualizers and editor features for the HiddenMarkovModels package.

### Bonsai.ML.PointProcessDecoder
Interfaces with the [PointProcessDecoder](https://github.com/ncguilbeault/PointProcessDecoder) package which can be used for decoding neural activity and other point processes.

### Bonsai.ML.Torch
Interfaces with the [TorchSharp](https://github.com/dotnet/TorchSharp) package, a C# wrapper around the torch library. Provides tooling for manipulating tensors, performing linear algebra, training and inference with deep neural networks, and more.

> [!NOTE]
> Bonsai.ML packages can be installed through Bonsai's integrated package manager and are generally ready for immediate use. However, some packages may require additional installation steps. Refer to the specific package section for detailed installation guides and documentation.

Expand Down
27 changes: 27 additions & 0 deletions docs/articles/PointProcessDecoder/ppd-getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Getting Started

The `Bonsai.ML.PointProcessDecoder` package provides a Bonsai interface to the [PointProcessDecoder](https://github.com/ncguilbeault/PointProcessDecoder) package used for decoding neural activity (point processes), and relies on the `Bonsai.ML.Torch` package for tensor operations.

## Installation

The package can be installed by going to the bonsai package manager and installing the `Bonsai.ML.PointProcessDecoder`. Additional installation steps are required for installing the CPU or GPU version of the `Bonsai.ML.Torch` package. See the [Torch installation guide](../Torch/torch-overview.md) for more information.

## Package Overview

The `PointProcessDecoder` package is a C# implementation of a Bayesian state space point process decoder inspired by the [replay_trajectory_classification repository](https://github.com/Eden-Kramer-Lab/replay_trajectory_classification) from the Eden-Kramer Lab. It can decode latent state observations from spike-train data or clusterless mark data based on point processes using Bayesian state space models.

For more detailed information and documentation about the model, please see the [PointProcessDecoder repo](https://github.com/ncguilbeault/PointProcessDecoder).

## Bonsai Implementation

The following workflow showcases the core functionality of the `Bonsai.ML.PointProcessDecoder` package.

:::workflow
![Point Process Decoder Implementation](~/workflows/PointProcessDecoder.bonsai)
:::

The `CreatePointProcessModel` node is used to define a model and configure it's parameters. For details on model configuration, please see the [PointProcessDecoder documentation](https://github.com/ncguilbeault/PointProcessDecoder). Crucially, the user must specify the `Name` property in the `Model Parameters` section, as this is what allows you to reference the specific model in the `Encode` and `Decode` nodes, the two main methods that the model will use.

During encoding, the user passes in a tuple of `Observation`s and `SpikeCounts`. Observations are variables that the user measures (for example, the animal's position), represented as a (M, N) tensor, where M is the number of samples in a batch and N is the dimensionality of the observations. Spike counts are the data you will use for decoding. For instance, spike counts might be sorted spike data or clusterless marks. If the data are sorted spiking units, then the `SpikeCounts` tensor will be an (M, U) tensor, where U is the number of sorted units. If the data are clusterles marks, then the `SpikeCounts` tensor will be an (M, F, C) tensor, where F is the number of features computed for each mark (for instance, the maximum spike amplitude across electrodes), and C is the number of independant recording channels (for example, individual tetrodes). Internally, the model fits the data as a point process, which will be used during decoding.

Decoding is the process of taking just the `SpikeCounts` and inferring what is the latent `Observation`. To do this, the model uses a bayesian state space model to predict a posterior distribution over the latent observation space using the information contained in the spike counts data. The output of the `Decode` node will provide you with an (M x D*) tensor, with D* representing a discrete latent state space determined by the parameters defined in the model.
13 changes: 13 additions & 0 deletions docs/articles/Torch/torch-getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Getting Started

The aim of the `Bonsai.ML.Torch` package is to integrate the [TorchSharp](https://github.com/dotnet/TorchSharp) package, a C# wrapper around the powerful libtorch library, into Bonsai. In the current version, the package primarily provides tooling and functionality for users to interact with and manipulate `Tensor`s, the core data type of libtorch which underlies many of the advanced torch operations. Additionally, the package provides some capabilities for defining neural network architectures, running forward inference, and learning via back propogation.

## Tensor Operations
The package provides several ways to work with tensors. Users can initialize tensors, (`Ones`, `Zeros`, etc.), create tensors from .NET data types, (`ToTensor`), and define custom tensors using Python-like syntax (`CreateTensor`). Tensors can be converted back to .NET types using the `ToArray` node (for flattening tensors into a single array) or the `ToNDArray` node (for preserving multidimensional array shapes). Furthermore, the `Tensor` data types contains many extension methods which can be used via scripting, such as using `ExpressionTransform` (for example, it.sum() to sum a tensor, or it.T to transpose), and works with overloaded operators, for example, `Zip` -> `Multiply`. Thus, `ExpressionTransform` can also be used to access individual elements of a tensor, using the syntax `it.data<T>.ReadCpuT(0)` where `T` is a primitive .NET data type.


## Running on the GPU
Users must be explicit about running tensors on the GPU. First, the `InitializeDeviceType` node must run with a CUDA-compatible GPU. Afterwards, tensors are moved to the GPU using the `ToDevice` node. Converting tensors back to .NET data types requires moving the tensor back to the CPU before converting.

## Neural Networks
The package provides initial support for working with torch `Module`s, the conventional object for deep neural networks. The `LoadModuleFromArchitecture` node allows users to select from a list of common architectures, and can optionally load in pretrained weights from disk. Additionally, the package supports loading `TorchScript` modules with the `LoadScriptModule` node, which enables users to use torch modules saved in the `.pt` file format. Users can then use the `Forward` node to run inference and the `Backward` node to run back propogation.
27 changes: 27 additions & 0 deletions docs/articles/Torch/torch-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Bonsai.ML.Torch Overview

The Torch package provides a Bonsai interface to interact with the [TorchSharp](https://github.com/dotnet/TorchSharp) package, a C# implementation of the torch library.

## General Guide

The Bonsai.ML.Torch package can be installed through the Bonsai Package Manager and depends on the TorchSharp library. Additionally, running the package requires installing the specific torch DLLs needed for your desired application. The steps for installing are outlined below.

### Running on the CPU
For running the package using the CPU, the `TorchSharp-cpu` library can be installed though the `nuget` package source.

### Running on the GPU
To run torch on the GPU, you first need to ensure that you have a CUDA compatible device installed on your system.

Next, you must follow the [CUDA installation guide for Windows](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) or the [guide for Linux](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html). Make sure to install the correct `CUDA v12.1` version [found here](https://developer.nvidia.com/cuda-12-1-0-download-archive). Ensure that you have the correct CUDA version (v12.1) installed, as `TorchSharp` currently only supports this version.

Next, you need to install the `cuDNN v9` library following the [guide for Windows](https://docs.nvidia.com/deeplearning/cudnn/latest/installation/windows.html) or the [guide for Linux](https://docs.nvidia.com/deeplearning/cudnn/latest/installation/linux.html). Again, you need to ensure you have the correct version installed (v9). You should consult [nvidia's support matrix](https://docs.nvidia.com/deeplearning/cudnn/latest/reference/support-matrix.html) to ensure the versions of CUDA and cuDNN you installed are compatible with your specific OS, graphics driver, and hardware.

Once complete, you need to install the cuda-compatible torch libraries and place them into the correct location. You can download the libraries from [the pytorch website](https://pytorch.org/get-started/locally/) with the following options selected:

- PyTorch Build: Stable (2.5.1)
- OS: [Your OS]
- Package: LibTorch
- Language: C++/Java
- Compute Platform: CUDA 12.1

Finally, extract the zip folder and copy the contents of the `lib` folder into the `Extensions` folder of your bonsai installation directory.
10 changes: 9 additions & 1 deletion docs/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
- name: Overview
href: HiddenMarkovModels/hmm-overview.md
- name: Getting Started
href: HiddenMarkovModels/hmm-getting-started.md
href: HiddenMarkovModels/hmm-getting-started.md
- name: PointProcessDecoder
- name: Getting Started
href: PointProcessDecoder/ppd-getting-started.md
- name: Torch
- name: Overview
href: Torch/torch-overview.md
- name: Getting Started
href: Torch/torch-getting-started.md
73 changes: 73 additions & 0 deletions docs/workflows/PointProcessDecoder.bonsai
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:Bonsai.ML.PointProcessDecoder;assembly=Bonsai.ML.PointProcessDecoder"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:CreatePointProcessModel">
<p1:Name>PointProcessModel</p1:Name>
<p1:EstimationMethod>KernelDensity</p1:EstimationMethod>
<p1:TransitionsType>RandomWalk</p1:TransitionsType>
<p1:EncoderType>SortedSpikeEncoder</p1:EncoderType>
<p1:DecoderType>StateSpaceDecoder</p1:DecoderType>
<p1:StateSpaceType>DiscreteUniformStateSpace</p1:StateSpaceType>
<p1:LikelihoodType>Poisson</p1:LikelihoodType>
<p1:ScalarType xsi:nil="true" />
<p1:StateSpaceDimensions>2</p1:StateSpaceDimensions>
<p1:MinStateSpace>
<p1:double>0</p1:double>
<p1:double>0</p1:double>
</p1:MinStateSpace>
<p1:MaxStateSpace>
<p1:double>120</p1:double>
<p1:double>120</p1:double>
</p1:MaxStateSpace>
<p1:StepsStateSpace>
<p1:long>50</p1:long>
<p1:long>50</p1:long>
</p1:StepsStateSpace>
<p1:ObservationBandwidth>
<p1:double>5</p1:double>
<p1:double>5</p1:double>
</p1:ObservationBandwidth>
<p1:NUnits>104</p1:NUnits>
<p1:MarkDimensions xsi:nil="true" />
<p1:MarkChannels xsi:nil="true" />
<p1:DistanceThreshold>1.5</p1:DistanceThreshold>
<p1:SigmaRandomWalk xsi:nil="true" />
</Combinator>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>Observation</Name>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>SpikeCounts</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:Encode">
<p1:Model>PointProcessModel</p1:Model>
</Combinator>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>SortedSpikeCounts</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:Decode">
<p1:Model>PointProcessModel</p1:Model>
</Combinator>
</Expression>
</Nodes>
<Edges>
<Edge From="1" To="3" Label="Source1" />
<Edge From="2" To="3" Label="Source2" />
<Edge From="3" To="4" Label="Source1" />
<Edge From="5" To="6" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
Loading
Loading