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

Refactor visualizers package to improve separation between package specific visualizers and reusable visualizers #23

Merged
merged 8 commits into from
Sep 20, 2024
Merged
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
28 changes: 21 additions & 7 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 All @@ -9,7 +9,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML", "src\Bonsai.ML\
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}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bonsai.ML.Design", "src\Bonsai.ML.Design\Bonsai.ML.Design.csproj", "{196AA5C7-AE8A-477B-B01A-B94676EC60EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{461FE3E2-21C4-47F9-8405-DF72326AAB2B}"
EndProject
Expand All @@ -26,6 +26,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.Python", "src\Bon
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.Data", "src\Bonsai.ML.Data\Bonsai.ML.Data.csproj", "{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.LinearDynamicalSystems.Design", "src\Bonsai.ML.LinearDynamicalSystems.Design\Bonsai.ML.LinearDynamicalSystems.Design.csproj", "{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}"
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -56,22 +60,32 @@ 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
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FC395DDC-62A4-4E14-A198-272AB05B33C7} = {12312384-8828-4786-AE19-EFCEDF968290}
{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}
{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}
{A135C7DB-EA50-4FC6-A6CB-6A5A5CC5FA13} = {12312384-8828-4786-AE19-EFCEDF968290}
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1} = {12312384-8828-4786-AE19-EFCEDF968290}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6468F13-97CD-45E0-9E1E-C122D7F1E09F}
Expand Down
12 changes: 9 additions & 3 deletions README.md
glopesdev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ The **Bonsai.ML** project is a collection of packages designed to integrate mach
- **Bonsai.ML**
Provides common tools and functionality.

- **Bonsai.ML.Design**
Provides common tools and functionality for visualizers and editor features.

- **Bonsai.ML.Data**
Provides common tools and functionality for working with data.

Expand All @@ -24,6 +27,9 @@ Facilitates inference using linear dynamical systems (LDS). It interfaces with t
- **Bonsai.ML.LinearDynamicalSystems.LinearRegression**
Utilizes the Kalman Filter to perform online Bayesian linear regression.

### Bonsai.ML.LinearDynamicalSystems.Design
Visualizers and editor features for the LinearDynamicalSystems package.

### Bonsai.ML.HiddenMarkovModels
Facilitates inference using Hidden Markov Models (HMMs). It interfaces with the [ssm](https://github.com/lindermanlab/ssm) package using the [Bonsai - Python Scripting](https://github.com/bonsai-rx/python-scripting) library.

Expand All @@ -32,9 +38,9 @@ Facilitates inference using Hidden Markov Models (HMMs). It interfaces with the

- **Bonsai.ML.HiddenMarkovModels.Transitions**
Provides functionality for specifying different types of transition models.
### Bonsai.ML.Visualizers
Graphing and plotting library for visualizing data.

### Bonsai.ML.HiddenMarkovModels.Design
Visualizers and editor features for the HiddenMarkovModels package.

> [!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
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
using OxyPlot.Series;
using OxyPlot.WindowsForms;
using System.Drawing;
using System;
using OxyPlot.Axes;
using System.Collections;

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Design
{
internal class BarSeriesOxyPlotBase : UserControl
/// <summary>
/// Provides a user control to display data as a bar plot using OxyPlot.
/// </summary>
public class BarSeriesOxyPlotBase : UserControl
{
private PlotView view;
private PlotModel model;
private OxyColor defaultBarSeriesColor = OxyColors.Automatic;

internal Axis xAxis;
private Axis xAxis;
private Axis yAxis;

private StatusStrip statusStrip;
Expand All @@ -30,6 +31,16 @@ internal class BarSeriesOxyPlotBase : UserControl
/// </summary>
public StatusStrip StatusStrip => statusStrip;

/// <summary>
/// Gets the X Axis.
/// </summary>
public Axis XAxis => xAxis;

/// <summary>
/// Gets the Y Axis.
/// </summary>
public Axis YAxis => yAxis;

/// <summary>
/// Initializes a new instance of the <see cref="BarSeriesOxyPlotBase"/> class
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>Bonsai.ML.Visualizers</Title>
<Title>Bonsai.ML.Design</Title>
<Description>A package for the Bonsai visual programming language.</Description>
<PackageTags>Bonsai Rx ML Machine Learning Visualizers</PackageTags>
<PackageTags>Bonsai Rx ML Machine Learning Design</PackageTags>
<TargetFrameworks>net472</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bonsai.Core" Version="2.8.1" />
<PackageReference Include="Bonsai.Design" Version="2.8.0" />
<PackageReference Include="Bonsai.Vision.Design" Version="2.8.1" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="OxyPlot.Core" Version="2.1.2" />
<PackageReference Include="OxyPlot.WindowsForms" Version="2.1.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bonsai.ML.LinearDynamicalSystems\Bonsai.ML.LinearDynamicalSystems.csproj" />
<ProjectReference Include="..\Bonsai.ML.HiddenMarkovModels\Bonsai.ML.HiddenMarkovModels.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Design
{
internal enum ColorPalette
{
Expand Down
66 changes: 66 additions & 0 deletions src/Bonsai.ML.Design/EllipseHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using MathNet.Numerics.LinearAlgebra;
using System;

namespace Bonsai.ML.Design
{
/// <summary>
/// Provides helper methods to compute ellipse parameters from a covariance matrix.
/// </summary>
public static class EllipseHelper
{
/// <summary>
/// Computes the ellipse parameters from the specified covariance matrix.
/// </summary>
/// <param name="xVar">The variance of the x axis.</param>
/// <param name="yVar">The variance of the y axis.</param>
/// <param name="xyCov">The covariance between the x and y axes.</param>
public static EllipseParameters GetEllipseParameters(double xVar, double yVar, double xyCov)
{
var covariance = Matrix<double>.Build.DenseOfArray(new double[,] {
{
xVar,
xyCov
},
{
xyCov,
yVar
},
});

var evd = covariance.Evd();
var evals = evd.EigenValues.Real();
evals = evals.PointwiseAbsoluteMaximum(0);
var evecs = evd.EigenVectors;

double angle = Math.Atan2(evecs[1, 0], evecs[0, 0]);

return new EllipseParameters
{
Angle = angle,
MajorAxis = Math.Sqrt(evals[0]),
MinorAxis = Math.Sqrt(evals[1]),
};
}
}

/// <summary>
/// Represents the parameters of an ellipse.
/// </summary>
public class EllipseParameters
{
/// <summary>
/// Gets or sets the angle of the ellipse.
/// </summary>
public double Angle { get; set; }

/// <summary>
/// Gets or sets the major axis of the ellipse.
/// </summary>
public double MajorAxis { get; set; }

/// <summary>
/// Gets or sets the minor axis of the ellipse.
/// </summary>
public double MinorAxis { get; set; }
}
}
Loading
Loading