-
Notifications
You must be signed in to change notification settings - Fork 5
New Bonsai.ML.Lds.Torch package to extract latents from high-dimensional data using TorchSharp
#70
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
Merged
Merged
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
12f5a90
Added kalman filter neural latents package to the Bonsai.ML project
ncguilbeault 79d48e3
Added `Bonsai.ML.Torch` project to references
ncguilbeault dd273a8
Added KalmanFilter class
ncguilbeault 18bf162
Updated KalmanFilter class for better matrix, vector, and scalar vali…
ncguilbeault e17b252
Adding classes from original scripted demo
ncguilbeault 5b88d0b
Added test repo for `Torch.LDS` to compare output with Python impleme…
ncguilbeault 9f740cb
Updated Torch.LDS test for running test against Python script for est…
ncguilbeault 22f7376
Added null checks to properties
ncguilbeault 1740570
Updated target framework to include netstandard2.0
ncguilbeault d7dc4a1
Updated `CreateKalmanFilter` class to use `TensorConverter` for tenso…
ncguilbeault b4939f1
Refactored to use the KalmanFilterModelManager class
ncguilbeault 3adfccf
Removed attempt to move EM algorithm to background process in favor o…
ncguilbeault 408e93d
Removed extra properties of structs to streamline filter and smooth p…
ncguilbeault b4ad0ad
Refactored kalman filter class to support static methods, to streamli…
ncguilbeault 91549b7
Added reserve method to model manager to support model creation from …
ncguilbeault 22efde7
Added project references to tests
ncguilbeault 30799b2
Removed unused variables that were previously there for plotting
ncguilbeault 5c4adc6
Modified requirements.txt to use ssm from github instead of local
ncguilbeault e7a995b
Corrected bug with initialization of state and covariance
ncguilbeault 0a68026
Refactored EM function for improved readability
ncguilbeault 0d161e4
Updated test to correctly compare python and bonsai tensor results
ncguilbeault ef3d11a
Removed unused import
ncguilbeault 5394bd3
Removed unused imports and added XML docs
ncguilbeault 1bb1d45
Removed convoluted lock mechanism in favor of no lock
ncguilbeault b9f6880
Added cleanup to test
ncguilbeault a68f90e
Updated package installs and removed requirements
ncguilbeault 91dea0c
Added the package to the documentation and included a basic article f…
ncguilbeault 3b47e1c
Updated variable naming from state to mean to more accurately represe…
ncguilbeault 3e3ca3b
Removed the line declaring requirements.txt is a deployment item
ncguilbeault 7201ef9
Updated test workflow to use the variable name mean instead of state
ncguilbeault faff97e
Added functionality to allow fine grained control over which paramete…
ncguilbeault e647b4a
Updated package info with better description and shared package tags
ncguilbeault 6a4ea9a
Added `Bonsai.ML.Torch.LDS.Design` package for visualizing latents
ncguilbeault 567dae9
Moved color cycle class to shared `Bonsai.ML.Design` library
ncguilbeault 174752c
Added keyword arguments to function call for precision
ncguilbeault 3cbf26f
Added `StateVisualizer` class to design package to support visualizin…
ncguilbeault 3d9c83b
Added explicit conversion to null for empty tensors
ncguilbeault 4313d3b
Removed initial values from non-static Kalman smoother
ncguilbeault 55dd7a6
Removed explicit null conversion from empty tensor
ncguilbeault 0aab968
Updated `KalmanFilter` with to allow automatically populating null pa…
ncguilbeault 2989912
Updated to allow parameters to contain null tensor values
ncguilbeault fdad188
Added XML docs to class
ncguilbeault 9196517
Refactored to use autosize and expose plot control
ncguilbeault d65888a
Updated `NeuralLatentsTest` with default null values
ncguilbeault 7c1c070
Added categories to class properties and renamed `ModelName` to just …
ncguilbeault f671f33
Added `ResetCombinator` to class attributes
ncguilbeault 39897c1
Added generic class and interface to represent LDS state
ncguilbeault fcd19ad
Removed `ResetCombinator` attribute from classes where it is not needed
ncguilbeault ffac102
Changed naming from `xResult` to `xState` to for improved naming cons…
ncguilbeault 8be2f91
Added property `Bonsai.ML.Torch.LDS.Design` project to ignore repacka…
ncguilbeault ae44889
Refactored `ExpectationMaximization` to emit values on each iteration…
ncguilbeault fd7a98b
Changed `ExpectationMaximization` operator to a type of `Combinator` …
ncguilbeault 69fc383
Updated name of `Bonsai.ML.Torch.LDS` package to `Bonsai.ML.Lds.Torch…
ncguilbeault 513feb7
Added `Bonsai.ML.Torch` using statements to classes that depend on th…
ncguilbeault cda33a3
Added operators to save and load the parameters of a Kalman filter model
ncguilbeault d9a1f46
Added Stochastic Subspace Identification method
ncguilbeault c0db6d4
Added method for `StochasticSubspaceIdentification` which is much fas…
ncguilbeault 152875f
Refactored implementation to use explicit `KalmanFilter` property whi…
ncguilbeault c847d15
Ensure data are centered in SSID method
ncguilbeault 3f55f63
Updated test workflow after changing packge to use explicit model pro…
ncguilbeault 2f4c6fb
Refactored EM to avoid potential mismatch between numStates, numObser…
ncguilbeault 4123370
Updated workflow to correctly update the parameters of the model
ncguilbeault b026f28
Modified python test script to install packages without caching packa…
ncguilbeault 4cf1c76
Modified test case to download data and only run Bonsai script as opp…
ncguilbeault 877d4a8
Removed redundant dependency
ncguilbeault 4ec5828
Updated documentation with correct package naming
ncguilbeault a8f58c7
Changed struct and interface names from LdsState to full LinearDynami…
ncguilbeault 4a9d64b
Removed redundant classes for orthogonalized and smoothed states in f…
ncguilbeault e3d51f6
Changed name from `UpdateParameters` to `UpdateKalmanFilterParameters…
ncguilbeault 12b9422
Updated `StateVisualizer` to match changes in naming
ncguilbeault 7b009de
Fixed test workflow after making changes
ncguilbeault a9d6079
Refactored `KalmanFilter` for improved parameter validation when `num…
ncguilbeault 6b85e19
Added overload to create a `LinearDynamicalSystemState` from a stream…
ncguilbeault 2b5c5ac
Refactored `SaveKalmanFilterParameters` class to save to a folder rat…
ncguilbeault d05077e
Refactored `KalmanFilterParameters` class to handle validation and mo…
ncguilbeault e68add5
Updated `LoadKalmanFilterParameters` operator to load parameters from…
ncguilbeault f89d750
Updated test to use `null` value in `NumStates` property
ncguilbeault 1b51ae4
Removed unnecessary `PredictedState` struct and used `LinearDynamical…
ncguilbeault 7e9bba8
Removed extra check when calling `Validate` on parameters
ncguilbeault 92b36c6
Fixed issue with setting the incorrect number of iterations from the …
ncguilbeault 7140980
Used tensorhelper method to extract float instead of explicitly movin…
ncguilbeault f32b653
Refactored `KalmanFilter` class to rely on device and scalar type pro…
ncguilbeault 92a2175
Refactored `KalmanFilterParameters` to manage operations on tensors, …
ncguilbeault 6898a64
Refactored `CreateKalmanFilter` operator to correctly pass in `Type` …
ncguilbeault 40c1f52
Updated to allow specifying `Device` property when loading parameters
ncguilbeault 7407cdf
Removed device and scalartype overrides in `Initialize` method
ncguilbeault a12b8d5
Refactored `LoadKalmanFilterParameters` operator to allow tensors to …
ncguilbeault 36c6328
Updated filtering step to support missing nan values
ncguilbeault de2278a
Updated neural latents test to use new load/save tensor method
ncguilbeault 50cc8c8
Updated to use `TensorOperatorConverter` class
ncguilbeault e326a85
Added default user-agent in request header when downloading test data…
ncguilbeault d306bc2
Added support in KF for estimating state and observation offset param…
ncguilbeault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Bonsai.ML.Lds.Torch - Overview | ||
|
|
||
| This package provides an implementation of the Kalman filter, Rauch-Tung-Striebel (RTS) smoother, expectation maximization (EM) algorithm, and stochastic subspace identification, developed for online filtering, smoothing, and parameter estimation from data streams in Bonsai using the TorchSharp package. | ||
|
|
||
| ## Installation Guide | ||
|
|
||
| Install the `Bonsai.ML.Lds.Torch` package from the Bonsai package manager. You will also need to follow the [instructions for setting up the Bonsai.ML.Torch package](../Torch/torch-overview.md) for running on the CPU or GPU. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...cessDecoder.Design/OxyColorPresetCycle.cs → src/Bonsai.ML.Design/OxyColorPresetCycle.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Bonsai.ML.Lds.Torch.Design/Bonsai.ML.Lds.Torch.Design.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <Description>Visualizers for the Bonsai.ML.Lds.Torch library.</Description> | ||
| <PackageTags>$(PackageTags) Torch LDS Design</PackageTags> | ||
| <TargetFramework>net472</TargetFramework> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Bonsai.Core" Version="2.9.0" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <ProjectReference Include="..\Bonsai.ML.Lds.Torch\Bonsai.ML.Lds.Torch.csproj" /> | ||
| <ProjectReference Include="..\Bonsai.ML.Design\Bonsai.ML.Design.csproj" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <!-- This property is needed to avoid repacking the native SkiaSharp libraries, which should already be included with the Bonsai.ML.Torch --> | ||
| <ShouldIncludeNativeSkiaSharp>false</ShouldIncludeNativeSkiaSharp> | ||
| </PropertyGroup> | ||
| </Project> |
90 changes: 90 additions & 0 deletions
90
src/Bonsai.ML.Lds.Torch.Design/ExpectationMaximizationVisualizer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| using System; | ||
| using System.Reactive; | ||
| using System.Linq; | ||
| using System.Windows.Forms; | ||
| using System.Collections.Generic; | ||
|
|
||
| using Bonsai; | ||
| using Bonsai.Design; | ||
| using Bonsai.ML.Design; | ||
|
|
||
| using OxyPlot; | ||
| using OxyPlot.Series; | ||
|
|
||
| using static TorchSharp.torch; | ||
|
|
||
| [assembly: TypeVisualizer(typeof(Bonsai.ML.Lds.Torch.Design.ExpectationMaximizationVisualizer), | ||
| Target = typeof(Bonsai.ML.Lds.Torch.ExpectationMaximizationResult))] | ||
|
|
||
| namespace Bonsai.ML.Lds.Torch.Design; | ||
|
|
||
| /// <summary> | ||
| /// Provides a visualizer for the state means and covariances from a Kalman filter or smoother. | ||
| /// </summary> | ||
| public class ExpectationMaximizationVisualizer : BufferedVisualizer | ||
| { | ||
| private TimeSeriesOxyPlotBase _plot; | ||
| private LineSeries _lineSeries; | ||
|
|
||
| /// <summary> | ||
| /// Gets the underlying plot control. | ||
| /// </summary> | ||
| public TimeSeriesOxyPlotBase Plot => _plot; | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void Load(IServiceProvider provider) | ||
| { | ||
| _plot = new TimeSeriesOxyPlotBase() | ||
| { | ||
| Dock = DockStyle.Fill, | ||
| StartTime = DateTime.Now, | ||
| BufferData = true, | ||
| ValueLabel = "Log Likelihood" | ||
| }; | ||
|
|
||
| _lineSeries = _plot.AddNewLineSeries("Log Likelihood", OxyColors.Blue); | ||
|
|
||
| var visualizerService = (IDialogTypeVisualizerService)provider.GetService(typeof(IDialogTypeVisualizerService)); | ||
| visualizerService?.AddControl(_plot); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void Show(object value) | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override void Show(DateTime time, object value) | ||
| { | ||
| if (value is null) return; | ||
|
|
||
| if (value is not ExpectationMaximizationResult result) return; | ||
|
|
||
| var logLikelihood = result.LogLikelihood; | ||
| if (logLikelihood is null) return; | ||
|
|
||
| var ll = logLikelihood[-1].to_type(ScalarType.Float64).item<double>(); | ||
|
|
||
| _plot.AddToLineSeries( | ||
| lineSeries: _lineSeries, | ||
| time: time, | ||
| value: ll | ||
| ); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override void ShowBuffer(IList<Timestamped<object>> values) | ||
| { | ||
| base.ShowBuffer(values); | ||
| if (values.Count > 0) | ||
| { | ||
| _plot.UpdatePlot(); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void Unload() | ||
| { | ||
| if (!_plot.IsDisposed) _plot.Dispose(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| using Bonsai; | ||
|
|
||
| // General Information about an assembly is controlled through the following | ||
| // set of attributes. Change these attribute values to modify the information | ||
| // associated with an assembly. | ||
| [assembly: XmlNamespacePrefix("clr-namespace:Bonsai.ML.Lds.Torch.Design", null)] |
10 changes: 10 additions & 0 deletions
10
src/Bonsai.ML.Lds.Torch.Design/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "profiles": { | ||
| "Bonsai": { | ||
| "commandName": "Executable", | ||
| "executablePath": "$(BonsaiExecutablePath)", | ||
| "commandLineArgs": "--lib:\"$(TargetDir).\"", | ||
| "nativeDebugging": true | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.