Skip to content

Commit

Permalink
Split visualizers package into separate projects for individual proje…
Browse files Browse the repository at this point in the history
…cts within the Bonsai.ML collection
  • Loading branch information
ncguilbeault committed Jul 16, 2024
1 parent 05007b9 commit f10087a
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 84 deletions.
16 changes: 15 additions & 1 deletion 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 @@ -22,6 +22,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.HiddenMarkovModels", "src\Bonsai.ML.HiddenMarkovModels\Bonsai.ML.HiddenMarkovModels.csproj", "{BAD0A733-8EFB-4EAF-9648-9851656AF7FF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.Visualizers.LinearDynamicalSystems", "src\Bonsai.ML.Visualizers.LinearDynamicalSystems\Bonsai.ML.Visualizers.LinearDynamicalSystems.csproj", "{17DF50BE-F481-4904-A4C8-5DF9725B2CA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bonsai.ML.Visualizers.HiddenMarkovModels", "src\Bonsai.ML.Visualizers.HiddenMarkovModels\Bonsai.ML.Visualizers.HiddenMarkovModels.csproj", "{FC395DDC-62A4-4E14-A198-272AB05B33C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -48,16 +52,26 @@ Global
{BAD0A733-8EFB-4EAF-9648-9851656AF7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAD0A733-8EFB-4EAF-9648-9851656AF7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAD0A733-8EFB-4EAF-9648-9851656AF7FF}.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}
{17DF50BE-F481-4904-A4C8-5DF9725B2CA1} = {12312384-8828-4786-AE19-EFCEDF968290}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B6468F13-97CD-45E0-9E1E-C122D7F1E09F}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Title>Bonsai.ML.Visualizers.HiddenMarkovModels</Title>
<Description>A package for visualizing data from the Bonsai.ML.HiddenMarkovModels package.</Description>
<PackageTags>Bonsai Rx ML Machine Learning Visualizers Hidden Markov Models</PackageTags>
<TargetFramework>net472</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bonsai.Core" Version="2.8.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bonsai.ML.Visualizers\Bonsai.ML.Visualizers.csproj" />
<ProjectReference Include="..\Bonsai.ML.HiddenMarkovModels\Bonsai.ML.HiddenMarkovModels.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using OxyPlot.Series;
using OxyPlot.Axes;
using OxyPlot.WindowsForms;
using MathNet.Numerics.LinearAlgebra;

[assembly: TypeVisualizer(typeof(GaussianObservationsClustersVisualizer), Target = typeof(GaussianObservationsStatistics))]

Expand Down Expand Up @@ -245,40 +244,20 @@ public override void Show(object value)
var yVar = gaussianObservationsStatistics.CovarianceMatrices[i, dimension2SelectedIndex, dimension2SelectedIndex];
var xyCov = gaussianObservationsStatistics.CovarianceMatrices[i, dimension2SelectedIndex, dimension1SelectedIndex];

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]);
var ellipseParameters = EllipseHelper.GetEllipseParameters(xVar, yVar, xyCov);

for (int j = 1; j < 4; j++)
{

var majorAxis = j * Math.Sqrt(evals[0]);
var minorAxis = j * Math.Sqrt(evals[1]);

var points = new List<DataPoint>();
int numPoints = 100;
for (int k = 0; k < numPoints + 1; k++)
{
double theta = 2 * Math.PI * k / numPoints;
double x = majorAxis * Math.Cos(theta);
double y = minorAxis * Math.Sin(theta);
double x = j * ellipseParameters.MajorAxis * Math.Cos(theta);
double y = j * ellipseParameters.MinorAxis * Math.Sin(theta);

double xRot = x * Math.Cos(angle) - y * Math.Sin(angle);
double yRot = x * Math.Sin(angle) + y * Math.Cos(angle);
double xRot = x * Math.Cos(ellipseParameters.Angle) - y * Math.Sin(ellipseParameters.Angle);
double yRot = x * Math.Sin(ellipseParameters.Angle) + y * Math.Cos(ellipseParameters.Angle);

points.Add(new DataPoint(xMean + xRot, yMean + yRot));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Bonsai": {
"commandName": "Executable",
"executablePath": "$(registry:HKEY_CURRENT_USER\\Software\\Bonsai Foundation\\Bonsai@InstallDir)Bonsai.exe",
"commandLineArgs": "--lib:\"$(TargetDir).\"",
"nativeDebugging": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public override void Show(object value)
var paddingPercentage = 0.05;

var nStates = stateProbability.Probabilities.Length;
CategoryAxis categoryAxis = (CategoryAxis)Plot.xAxis;
CategoryAxis categoryAxis = (CategoryAxis)Plot.XAxis;
categoryAxis.ItemsSource = Enumerable.Range(0, nStates);

for (int i = 0; i < nStates; i++)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Title>Bonsai.ML.Visualizers.LinearDynamicalSystems</Title>
<Description>A package for the Bonsai visual programming language.</Description>
<PackageTags>Bonsai Rx ML Machine Learning Visualizers LinearDynamicalSystems</PackageTags>
<TargetFramework>net472</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Bonsai.ML.Visualizers\Bonsai.ML.Visualizers.csproj" />
<ProjectReference Include="..\Bonsai.ML.LinearDynamicalSystems\Bonsai.ML.LinearDynamicalSystems.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Bonsai.Vision.Design" Version="2.8.1" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bonsai.Design;
using Bonsai.Vision.Design;
using Bonsai;
using Bonsai.ML.Visualizers;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using System;
using System.Collections.Generic;
Expand All @@ -11,7 +11,7 @@

[assembly: TypeVisualizer(typeof(ForecastImageOverlay), Target = typeof(MashupSource<ImageMashupVisualizer, ForecastVisualizer>))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{
/// <summary>
/// Provides a mashup visualizer to display the forecast of a Kalman Filter kinematics model overtime of an ImageMashupVisualizer.
Expand Down Expand Up @@ -50,26 +50,17 @@ public override void Show(object value)
double yVar = kinematicState.Position.Y.Variance;
double xyCov = kinematicState.Position.Covariance;

var covariance = Matrix<double>.Build.DenseOfArray(new double[,] {
{ xVar, xyCov },
{ xyCov, yVar }
});

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

double angle = Math.Atan2(evecs[1, 0], evecs[0, 0]) * 180 / Math.PI;
EllipseParameters ellipseParameters = EllipseHelper.GetEllipseParameters(xVar, yVar, xyCov);

Size axes = new Size
{
Width = (int)(2 * Math.Sqrt(evals[0])),
Height = (int)(2 * Math.Sqrt(evals[1]))
Width = (int)(2 * ellipseParameters.MajorAxis),
Height = (int)(2 * ellipseParameters.MinorAxis)
};

OxyColor color = OxyColors.Yellow;

CV.Ellipse(overlay, center, axes, angle, 0, 360, new Scalar(color.B, color.G, color.R, color.A), -1);
CV.Ellipse(overlay, center, axes, ellipseParameters.Angle, 0, 360, new Scalar(color.B, color.G, color.R, color.A), -1);
}

CV.AddWeighted(image, 1 - alpha, overlay, alpha, 1, image);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Bonsai.Design;
using Bonsai;
using Bonsai.ML.Visualizers;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using System;
Expand All @@ -10,10 +10,10 @@

[assembly: TypeVisualizer(typeof(ForecastPlotOverlay), Target = typeof(MashupSource<KinematicStateVisualizer, ForecastVisualizer>))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{
/// <summary>
/// Provides a mashup visualizer to display the forecast of a Kalman Filter kinematics model overtime of a KinematicStateVisualizer.
/// Provides a mashup visualizer to display the forecast of a Kalman Filter kinematics model alongside the kinematic state.
/// </summary>
public class ForecastPlotOverlay : DialogTypeVisualizer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Bonsai;
using Bonsai.Design;
using Bonsai.ML.Visualizers;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using OxyPlot;
using System.Reactive;
Expand All @@ -12,7 +12,7 @@

[assembly: TypeVisualizer(typeof(ForecastVisualizer), Target = typeof(Forecast))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{
/// <summary>
/// Provides a type visualizer to display the forecast of a Kalman Filter kinematics model.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Bonsai.Design;
using Bonsai;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using Bonsai.ML.Visualizers;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using System.Collections.Generic;
using System;
using System.Windows.Forms;
Expand All @@ -11,7 +11,7 @@

[assembly: TypeVisualizer(typeof(KinematicStateVisualizer), Target = typeof(KinematicState))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{

/// <summary>
Expand All @@ -20,7 +20,7 @@ namespace Bonsai.ML.Visualizers
public class KinematicStateVisualizer : MashupVisualizer
{
private TableLayoutPanel container;
private int updateFrequency = 1000 / 50;
private int updateFrequency = 20;
private bool resetAxes = true;
private int rowCount = 3;
private int columnCount = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Reflection;
using Bonsai;
using Bonsai.Design;
using Bonsai.ML.Visualizers;
using Bonsai.ML.LinearDynamicalSystems;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems.LinearRegression;
using System.Drawing;
using System.Reactive;
using Bonsai.Reactive;

[assembly: TypeVisualizer(typeof(MultivariatePDFVisualizer), Target = typeof(MultivariatePDF))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{

/// <summary>
/// Provides a type visualizer to display the state components of a Kalman Filter kinematics model.
/// Provides a type visualizer to display a multivariate probability distribution as a heatmap.
/// </summary>
public class MultivariatePDFVisualizer : DialogTypeVisualizer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Bonsai": {
"commandName": "Executable",
"executablePath": "$(registry:HKEY_CURRENT_USER\\Software\\Bonsai Foundation\\Bonsai@InstallDir)Bonsai.exe",
"commandLineArgs": "--lib:\"$(TargetDir).\"",
"nativeDebugging": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Bonsai;
using Bonsai.Design;
using Bonsai.ML.Visualizers;
using Bonsai.ML.Visualizers.LinearDynamicalSystems;
using Bonsai.ML.LinearDynamicalSystems;
using OxyPlot;
using System.Reactive;
Expand All @@ -12,7 +12,7 @@

[assembly: TypeVisualizer(typeof(StateComponentVisualizer), Target = typeof(StateComponent))]

namespace Bonsai.ML.Visualizers
namespace Bonsai.ML.Visualizers.LinearDynamicalSystems
{
/// <summary>
/// Provides a type visualizer to display the state components of a Kalman Filter kinematics model.
Expand Down
19 changes: 15 additions & 4 deletions src/Bonsai.ML.Visualizers/BarSeriesOxyPlotBase.cs
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
{
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
6 changes: 0 additions & 6 deletions src/Bonsai.ML.Visualizers/Bonsai.ML.Visualizers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@
<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>
Loading

0 comments on commit f10087a

Please sign in to comment.