-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
3,779 additions
and
431 deletions.
There are no files selected for viewing
This file contains 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,29 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
workflow_call: | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4.1.1 | ||
with: | ||
submodules: true | ||
|
||
- name: Setup .NET Core SDK | ||
uses: actions/setup-dotnet@v4.0.0 | ||
with: | ||
dotnet-version: 8.x | ||
|
||
- name: Restore NuGet Packages | ||
run: dotnet restore Bonsai.ML.sln | ||
|
||
- name: Build Solution | ||
run: dotnet build Bonsai.ML.sln -c Release |
This file contains 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 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,20 @@ | ||
# Builds and runs unit tests for the examples | ||
name: Test Examples | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
runs-on: windows-latest | ||
steps: | ||
- name: Setup Python 3.10 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.10 | ||
|
||
- name: Build Solution | ||
uses: ./.github/workflows/build.yml | ||
|
||
- name: Run Tests | ||
run: dotnet test Bonsai.ML.sln |
This file contains 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,58 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{12312384-8828-4786-AE19-EFCEDF968290}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML", "src\Bonsai.ML\Bonsai.ML.csproj", "{AA6BE73F-1E15-49A5-AC3C-CD069035C940}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML.LinearDynamicalSystems", "src\Bonsai.ML.LinearDynamicalSystems\Bonsai.ML.LinearDynamicalSystems.csproj", "{17AABD18-E275-4409-9E33-3D755B809FF6}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML.Visualizers", "src\Bonsai.ML.Visualizers\Bonsai.ML.Visualizers.csproj", "{196AA5C7-AE8A-477B-B01A-B94676EC60EE}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{461FE3E2-21C4-47F9-8405-DF72326AAB2B}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML.LinearDynamicalSystems.Tests", "tests\Bonsai.ML.LinearDynamicalSystems.Tests\Bonsai.ML.LinearDynamicalSystems.Tests.csproj", "{81DB65B3-EA65-4947-8CF1-0E777324C082}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FEFDDEAC-91FD-45DA-A67A-C76D538FD484}" | ||
ProjectSection(SolutionItems) = preProject | ||
Directory.Build.props = Directory.Build.props | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AA6BE73F-1E15-49A5-AC3C-CD069035C940}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{AA6BE73F-1E15-49A5-AC3C-CD069035C940}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{AA6BE73F-1E15-49A5-AC3C-CD069035C940}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AA6BE73F-1E15-49A5-AC3C-CD069035C940}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{17AABD18-E275-4409-9E33-3D755B809FF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{17AABD18-E275-4409-9E33-3D755B809FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{17AABD18-E275-4409-9E33-3D755B809FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{17AABD18-E275-4409-9E33-3D755B809FF6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{196AA5C7-AE8A-477B-B01A-B94676EC60EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{196AA5C7-AE8A-477B-B01A-B94676EC60EE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{196AA5C7-AE8A-477B-B01A-B94676EC60EE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{196AA5C7-AE8A-477B-B01A-B94676EC60EE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{81DB65B3-EA65-4947-8CF1-0E777324C082}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{81DB65B3-EA65-4947-8CF1-0E777324C082}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{81DB65B3-EA65-4947-8CF1-0E777324C082}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{81DB65B3-EA65-4947-8CF1-0E777324C082}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{AA6BE73F-1E15-49A5-AC3C-CD069035C940} = {12312384-8828-4786-AE19-EFCEDF968290} | ||
{17AABD18-E275-4409-9E33-3D755B809FF6} = {12312384-8828-4786-AE19-EFCEDF968290} | ||
{196AA5C7-AE8A-477B-B01A-B94676EC60EE} = {12312384-8828-4786-AE19-EFCEDF968290} | ||
{81DB65B3-EA65-4947-8CF1-0E777324C082} = {461FE3E2-21C4-47F9-8405-DF72326AAB2B} | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {B6468F13-97CD-45E0-9E1E-C122D7F1E09F} | ||
EndGlobalSection | ||
EndGlobal |
This file contains 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 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 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 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<add key="Build Packages" value="../src/bin/Release" /> | ||
</packageSources> | ||
</configuration> |
This file contains 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 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 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
64 changes: 64 additions & 0 deletions
64
src/Bonsai.ML.LinearDynamicalSystems/Kinematics/Forecast.cs
This file contains 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,64 @@ | ||
using System; | ||
using System.Reactive; | ||
using System.Reactive.Linq; | ||
using System.Collections.ObjectModel; | ||
using System.Xml.Serialization; | ||
using System.ComponentModel; | ||
using Newtonsoft.Json; | ||
using Python.Runtime; | ||
using System.Collections.Generic; | ||
|
||
namespace Bonsai.ML.LinearDynamicalSystems.Kinematics | ||
{ | ||
/// <summary> | ||
/// Represents an operator for converting forecasts from a Kalman Filter Kinematics python class into a list of forecasted results. | ||
/// </summary> | ||
[Combinator] | ||
[Description("Forecasts for a Kalman Filter Kinematics (KFK) model.")] | ||
[WorkflowElementCategory(ElementCategory.Transform)] | ||
public class Forecast | ||
{ | ||
/// <summary> | ||
/// Gets or sets the list of forecast results. | ||
/// </summary> | ||
[XmlIgnore()] | ||
[JsonProperty("forecasts")] | ||
[Description("The list of forecast results.")] | ||
public List<ForecastResult> ForecastResults { get; private set; } | ||
|
||
/// <summary> | ||
/// Converts a PyObject representing a Kalman Filter forecast into a Forecast class representing a list of forecasted results. | ||
/// </summary> | ||
public IObservable<Forecast> Process(IObservable<PyObject> source) | ||
{ | ||
return Observable.Select(source, pyObject => { | ||
|
||
dynamic pyObj = pyObject; | ||
|
||
var xs = (PyObject[])pyObj[0]; | ||
var Ps = (PyObject[])pyObj[1]; | ||
var dts = (double[])pyObj[2]; | ||
|
||
var results = new List<ForecastResult>(); | ||
|
||
for (int i = 0; i < xs.Length; i++) | ||
{ | ||
double[,] x = (double[,])PythonHelper.ConvertPythonObjectToCSharp(xs[i]); | ||
double[,] P = (double[,])PythonHelper.ConvertPythonObjectToCSharp(Ps[i]); | ||
var state = new State {X=x, P=P}; | ||
var kinematicState = new KinematicState(state); | ||
|
||
var dt = dts[i]; | ||
var timestep = TimeSpan.FromSeconds(dt); | ||
|
||
results.Add(new ForecastResult(kinematicState, timestep)); | ||
} | ||
|
||
return new Forecast { | ||
ForecastResults = results | ||
}; | ||
}); | ||
} | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
src/Bonsai.ML.LinearDynamicalSystems/Kinematics/ForecastResult.cs
This file contains 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,36 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
using Python.Runtime; | ||
using System.Collections.Generic; | ||
using System.Xml.Serialization; | ||
using System.ComponentModel; | ||
|
||
namespace Bonsai.ML.LinearDynamicalSystems.Kinematics | ||
{ | ||
/// <summary> | ||
/// Forecast result representing a collection of forecasted states at future timesteps | ||
/// </summary> | ||
public class ForecastResult | ||
{ | ||
/// <summary> | ||
/// Gets or privately sets the kinematic state of the forecasted result. | ||
/// </summary> | ||
public KinematicState KinematicState { get; private set; } | ||
|
||
/// <summary> | ||
/// Gets or privately sets the future time step of the forecasted result. | ||
/// </summary> | ||
public TimeSpan Timestep { get; private set; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ForecastResult"/> class. | ||
/// </summary> | ||
/// <param name="kinematicState">The kinematic state of the forecasted result.</param> | ||
/// <param name="timestep">The future timestep of the forecasted result.</param> | ||
public ForecastResult(KinematicState kinematicState, TimeSpan timestep) | ||
{ | ||
KinematicState = kinematicState; | ||
Timestep = timestep; | ||
} | ||
} | ||
} |
Oops, something went wrong.