Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 5 additions & 9 deletions docs/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,24 @@
href: ../README.md

- name: Linear Dynamical Systems
- name: Getting Started
href: ../examples/LinearDynamicalSystems/README.md
- name: Kinematics
- name: Simulated Data
href: ../examples/LinearDynamicalSystems/Kinematics/SimulatedData/README.md
- name: Zebrafish Centroid Tracking
href: ../examples/LinearDynamicalSystems/Kinematics/ZebrafishCentroidTracking/README.md
- name: Foraging Mouse
href: ../examples/LinearDynamicalSystems/Kinematics/ForagingMouse/README.md
- name: Optimizing Model Parameters for Foraging Mouse
href: ../examples/LinearDynamicalSystems/Kinematics/ModelOptimizationForagingMouse/README.md
- name: Online Learning and Kinematics Inference of a Foraging Mouse
href: ../examples/LinearDynamicalSystems/Kinematics/OnlineLearningAndKinematicsInference/README.md
- name: Forecasting Foraging Mouse Kinematics
href: ../examples/LinearDynamicalSystems/Kinematics/ForecastingForagingMouse/README.md
- name: Linear Regression
- name: Simulated Data
href: ../examples/LinearDynamicalSystems/LinearRegression/SimulatedData/README.md
- name: Receptive Field Simple Cell
href: ../examples/LinearDynamicalSystems/LinearRegression/ReceptiveFieldSimpleCell/README.md

- name: Hidden Markov Models
- name: Getting Started
href: ../examples/HiddenMarkovModels/README.md
- name: Simulated Data
href: ../examples/HiddenMarkovModels/SimulatedData/README.md
- name: Inferring Behavioral State from Kinematics
Expand Down Expand Up @@ -52,5 +48,5 @@
href: ../examples/PointProcessDecoder/DecodePositionFromHippocampusClusterless/README.md
- name: Decode Position from Striatum using Sorted Spikes
href: ../examples/PointProcessDecoder/DecodePositionFromStriatumSortedUnits/README.md
- name: Classify Dynamics and Decode Position from Hippocampal Sorted Units
href: ../examples/PointProcessDecoder/ClassifyPositionFromHippocampusSortedUnits/README.md
- name: Classify Dynamics and Decode Position from Hippocampal Sorted Units
href: ../examples/PointProcessDecoder/ClassifyPositionFromHippocampusSortedUnits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the following example, you can see how to construct a Hidden Markov Model (HM
Ensure you have Bonsai 2.9 installed on your system. You will also need to have the [uv Python environment manager](https://docs.astral.sh/uv/) installed.

> [!NOTE]
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.

### Save a Custom HMM Configuration

Expand All @@ -27,10 +27,10 @@ When the workflow is run, the output of the `ConfigureHMM` node is a custom HMM

### Load a Custom HMM Configuration

This example workflow demonstrates how to load the custom HMM model saved in the previous workflow.
This example workflow demonstrates how to load the custom HMM model saved in the previous workflow.

:::workflow
![Hidden Markov Models - Loading Custom Model From Disk](LoadModelConfig.bonsai)
:::

The `LoadStateParameters` is a `SelectMany` operator which will load the JSON file specified in the `Path` property, and outputs a `ModelParameters` object. The `Dimensions`, `NumStates`, and `StateParameters` properties of the `ModelParameters` object are then used as input parameters to the `CreateHMM` operator, which creates an HMM model with the parameters loaded from the JSON file.
The `LoadStateParameters` is a `SelectMany` operator which will load the JSON file specified in the `Path` property, and outputs a `ModelParameters` object. The `Dimensions`, `NumStates`, and `StateParameters` properties of the `ModelParameters` object are then used as input parameters to the `CreateHMM` operator, which creates an HMM model with the parameters loaded from the JSON file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,10 @@ In the following example, you can see how the Hidden Markov Model (HMM) can be u
Ensure you have Bonsai 2.9 installed on your system. You will also need to have the [uv Python environment manager](https://docs.astral.sh/uv/) installed.

> [!NOTE]
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.

### Dependencies

If you used the bootstrapping method, you don't have to worry about the package dependencies, as these should be already installed. However, if creating a new environment or integrating into an existing one, you will need to install the following packages:

* Bonsai - Core v2.8.1
* Bonsai - Design v2.8.0
* Bonsai - Editor v2.8.0
* Bonsai - Expression Scripting v2.8.0
* Bonsai - Gui v0.1.0
* Bonsai - ML Hidden Markov Models v0.2.0
* Bonsai - ML Linear Dynamical Systems v0.2.0
* Bonsai - ML Visualizers Hidden Markov Models v0.2.0
* Bonsai - ML Visualizers Linear Dynamical Systems v0.2.0
* Bonsai - Numerics v0.9.0
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.

> [!WARNING]
> This example builds on the [LDS Kinematics Foraging Mouse example](../../LinearDynamicalSystems/Kinematics/ForagingMouse/README.md) and requires both the *Bonsai.ML.LinearDynamicalSystems* package and the *Bonsai.ML.HiddenMarkovModels* package. See the installation guide to ensure both packages are installed and working correctly.
> This example builds on the [LDS Kinematics Foraging Mouse example](../../LinearDynamicalSystems/Kinematics/ForagingMouse/README.md) and requires both the _Bonsai.ML.LinearDynamicalSystems_ package and the _Bonsai.ML.HiddenMarkovModels_ package. See the installation guide to ensure both packages are installed and working correctly.

### Workflow

Expand All @@ -37,7 +22,7 @@ Below is the workflow.
![Hidden Markov Models - Inferring Behavioral State](InferringBehavioralState.bonsai)
:::

In this example, a Hidden Markov Model (HMM) is used to infer the hidden behavioral state of a foraging mouse. The workflow creates a python runtime (`CreateRuntime`), and then loads both the HMM module (`LoadHMMModule`) and the LDS module (`LoadLDSModule`). The `MouseTracking` group workflow performs image processing to calculate the mouse's `Centroid` position. The `Centroid` is used with `InputMapping` to initialize a Kalman Filter (KF) Kinematics model (`CreateKFModel`) with the initial parameters `Position_x0` and `Position_y0` set to the X and Y values of the `Centroid`. We set the other parameters of the KF model to be the parameters that we think will best track the animal, though these parameters can also be learned online [see the ModelOptimizationForagingMouse example](../../LinearDynamicalSystems/Kinematics/ModelOptimizationForagingMouse/README.md).
In this example, a Hidden Markov Model (HMM) is used to infer the hidden behavioral state of a foraging mouse. The workflow creates a python runtime (`CreateRuntime`), and then loads both the HMM module (`LoadHMMModule`) and the LDS module (`LoadLDSModule`). The `MouseTracking` group workflow performs image processing to calculate the mouse's `Centroid` position. The `Centroid` is used with `InputMapping` to initialize a Kalman Filter (KF) Kinematics model (`CreateKFModel`) with the initial parameters `Position_x0` and `Position_y0` set to the X and Y values of the `Centroid`. We set the other parameters of the KF model to be the parameters that we think will best track the animal, though these parameters can also be learned online [see the OnlineLearningAndKinematicsInference example](../../LinearDynamicalSystems/Kinematics/OnlineLearningAndKinematicsInference/README.md).

We are going to use the absolute velocity and acceleration of the animal as observations to the HMM model. We are going to use 6 hidden states for our model. When we initialize our HMM using the `CreateHMM` node, we set the `Dimensions` to 2, for the number of features of our observations, and the `NumStates` to 6, for the number of hidden behavioral states. The `Observations` and `Transitions` parameters will be left to their default values, `Gaussian` and `Stationary`, respectively.

Expand Down
129 changes: 0 additions & 129 deletions examples/HiddenMarkovModels/README.md

This file was deleted.

18 changes: 2 additions & 16 deletions examples/HiddenMarkovModels/SimulatedData/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,7 @@ In the following example, you can see how the Hidden Markov Model (HMM) can be u
Ensure you have Bonsai 2.9 installed on your system. You will also need to have the [uv Python environment manager](https://docs.astral.sh/uv/) installed.

> [!NOTE]
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.

### Dependencies

If you used the bootstrapping method, you don't have to worry about the package dependencies, as these should be already installed. However, if creating a new environment or integrating into an existing one, you will need to install the following packages:

* Bonsai - Core v2.8.1
* Bonsai - Design v2.8.0
* Bonsai - Editor v2.8.0
* Bonsai - Gui Zedgraph v0.1.1
* Bonsai - ML v0.2.0
* Bonsai - ML Hidden Markov Models v0.2.0
* Bonsai - ML Visualizers Hidden Markov Models v0.2.0
* Bonsai - Numerics v0.9.0
* Bonsai - Scripting Python v0.2.0
> The `ssm` package uses an old version of `setuptools` that is incompatible with modern package management tools. Because of this, you first need to create a new Python virtual environment using `uv venv`, install the required packages using `uv pip install -r requirements.txt`, and then synchronize the Python environment using `uv sync --no-build-isolation`.

### Workflow

Expand All @@ -35,7 +21,7 @@ Below is the workflow.

In this example, a Hidden Markov Model (HMM) is used to infer the hidden state of a simulated system. The workflow creates a python runtime (`CreateRuntime`), loads the HMM module (`LoadHMMModule`), and then initializes an HMM model with two states (`CreateHMM`). The simulation, encapsulated by a group workflow (`SimulatedDataWith2States`), generates data from two distinct multivariate normal distributions. The distribution that the simulation draws samples from switches at a specified rate. These `Data` are then formatted into a string representation of a python list, and subsequently fed as `Observation`s to the HMM model. The HMM model performs inference of the hidden state (`InferState`) given the observation.

When the HMM model is created, the parameters are not yet fit to the data. After 80 data points, the mini batch of data is sent to the model to be fit to the data (`RunFitAsync`). Once the fitting procedure completes asynchronously, the model's parameters will be better tuned to the system, and the model begins performing inferrence of the state of the simulated system.
When the HMM model is created, the parameters are not yet fit to the data. After 80 data points, the mini batch of data is sent to the model to be fit to the data (`RunFitAsync`). Once the fitting procedure completes asynchronously, the model's parameters will be better tuned to the system, and the model begins performing inferrence of the state of the simulated system.

To visualize this, the `SimulationVisualizer` group node displays two graphs. On the left, the X and Y data samples are plotted as individual points in the scatter plot. After a few samples, you should start to see two distinct clusters emerge. On the right, you will see the inferred state of the model, represented as the probability of being in a particular state. After the model has been fit, you should see that the inferred state aligns with the cluster that data samples are being drawn from.

Expand Down
Loading