Skip to content

Commit

Permalink
Merge branch 'main' into docs-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ncguilbeault committed Jul 5, 2024
2 parents 11afc29 + 1f027c3 commit c87231a
Show file tree
Hide file tree
Showing 52 changed files with 3,779 additions and 431 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
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
17 changes: 3 additions & 14 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,16 @@ on:
workflow_dispatch:

jobs:
build:
build_docs:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.1
with:
submodules: true
- name: Build Solution
uses: ./.github/workflows/build.yml

- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: 7.x

- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2

- name: Restore NuGet Packages
run: msbuild -t:restore src/Bonsai.ML.sln

- name: Build Solution
run: msbuild src/Bonsai.ML.sln /p:Configuration=Release

- name: Setup DocFX
run: dotnet tool restore
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
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
58 changes: 58 additions & 0 deletions Bonsai.ML.sln
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
1 change: 1 addition & 0 deletions src/Directory.Build.props → Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageIcon>icon.png</PackageIcon>
<IncludeSymbols>true</IncludeSymbols>
<RepositoryType>git</RepositoryType>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The Bonsai.ML project is a collection of packages with reactive infrastructure f
* Bonsai.ML - provides core functionality across all Bonsai.ML packages.
* Bonsai.ML.LinearDynamicalSystems - package for performing inference of linear dynamical systems. Interfaces with the [lds_python](https://github.com/joacorapela/lds_python) package.
- *Bonsai.ML.LinearDynamicalSystems.Kinematics* - subpackage included in the LinearDynamicalSystems package which supports using the Kalman Filter to infer kinematic data.
- *Bonsai.ML.LinearDynamicalSystems.LinearRegression* - subpackage included in the LinearDynamicalSystems package which supports using the Kalman Filter to perform Bayesian linear regression.
* Bonsai.ML.Visualizers - provides a set of visualizers for dynamic graphing/plotting.

> [!NOTE]
Expand Down
6 changes: 6 additions & 0 deletions docs/NuGet.config
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>
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ source .venv/bin/activate
2. Install the lds_python package

```cmd
pip install lds_python@git+https://github.com/joacorapela/lds_python@4233363320e021f77f9b3e124846ec2e49c0e741
pip install lds_python@git+https://github.com/joacorapela/lds_python@f761c201f3df883503ecb67acef35ba846e3524c
```

If you encounter errors during installation of the lds_python package, you will have to diagnose the issue and install the correct packge dependencies manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Alternatively, you can use the `Setup.cmd` file to setup the bonsai environment
2. Install the lds_python package

```cmd
pip install lds_python@git+https://github.com/joacorapela/lds_python@4233363320e021f77f9b3e124846ec2e49c0e741
pip install lds_python@git+https://github.com/joacorapela/lds_python@f761c201f3df883503ecb67acef35ba846e3524c
```

If you encounter errors during installation of the lds_python package, you will have to diagnose the issue and install the correct packge dependencies manually.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<Description>A Bonsai package for implementing the Kalman Filter using python.</Description>
<PackageTags>Bonsai Rx ML KalmanFilter LinearDynamicalSystems</PackageTags>
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
<Version>0.1.0</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bonsai.Core" Version="2.8.1" />
Expand Down
64 changes: 64 additions & 0 deletions src/Bonsai.ML.LinearDynamicalSystems/Kinematics/Forecast.cs
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 src/Bonsai.ML.LinearDynamicalSystems/Kinematics/ForecastResult.cs
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;
}
}
}
Loading

0 comments on commit c87231a

Please sign in to comment.