Skip to content

Commit

Permalink
Merge pull request #7 from bonsai-rx/package-metadata
Browse files Browse the repository at this point in the history
Add README file to package metadata
  • Loading branch information
glopesdev authored Mar 8, 2024
2 parents fe810f3 + eb540b4 commit 7e0959d
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 45 deletions.
20 changes: 13 additions & 7 deletions src/Bonsai.ML.LinearDynamicalSystems/CreateModelReference.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
using System.ComponentModel;
using System.ComponentModel;
using System;
using System.Reactive.Linq;

namespace Bonsai.ML.LinearDynamicalSystems
{
/// <summary>
/// Provides a Bonsai.ML model with a name that can be referenced
/// Represents an operator that creates a reference for a named model.
/// </summary>
[Description("Name of a Bonsai.ML model")]
[Combinator()]
[Combinator]
[Description("Creates a reference for a named model.")]
[WorkflowElementCategory(ElementCategory.Source)]
public class CreateModelReference : INamedElement
{

/// <summary>
/// The name of the model
/// Gets or sets the name of the model to reference.
/// </summary>
[Description("Name of the model")]
[Description("The name of the model to reference.")]
public string Name { get ; set; }

/// <summary>
/// Generates an observable sequence that contains the model reference object.
/// </summary>
/// <returns>
/// A sequence containing a single instance of the <see cref="ModelReference"/>
/// class.
/// </returns>
public IObservable<ModelReference> Process()
{
return Observable.Defer(() => Observable.Return(new ModelReference(Name)));
Expand Down
21 changes: 15 additions & 6 deletions src/Bonsai.ML.LinearDynamicalSystems/DeserializeFromJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Reactive.Linq;
using Bonsai.Expressions;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Linq.Expressions;
Expand All @@ -13,24 +14,32 @@ namespace Bonsai.ML.LinearDynamicalSystems
/// <summary>
/// Deserializes a sequence of JSON strings into data model objects.
/// </summary>
[DefaultProperty("Type")]
[DefaultProperty(nameof(Type))]
[WorkflowElementCategory(ElementCategory.Transform)]
[XmlInclude(typeof(TypeMapping<Kinematics.KFModelParameters>))]
[XmlInclude(typeof(TypeMapping<Kinematics.Observation2D>))]
[XmlInclude(typeof(TypeMapping<KFModelParameters>))]
[XmlInclude(typeof(TypeMapping<Observation2D>))]
[XmlInclude(typeof(TypeMapping<State>))]
[XmlInclude(typeof(TypeMapping<StateComponent>))]
[XmlInclude(typeof(TypeMapping<Kinematics.KinematicState>))]
[XmlInclude(typeof(TypeMapping<Kinematics.KinematicComponent>))]
[XmlInclude(typeof(TypeMapping<KinematicState>))]
[XmlInclude(typeof(TypeMapping<KinematicComponent>))]
[Description("Deserializes a sequence of JSON strings into data model objects.")]
public partial class DeserializeFromJson : SingleArgumentExpressionBuilder
{
/// <summary>
/// Initializes a new instance of the <see cref="DeserializeFromJson"/> class.
/// </summary>
public DeserializeFromJson()
{
Type = new TypeMapping<Kinematics.KFModelParameters>();
Type = new TypeMapping<KFModelParameters>();
}

/// <summary>
/// Gets or sets the type of the object to deserialize.
/// </summary>
[Description("The type of the object to deserialize.")]
public TypeMapping Type { get; set; }

/// <inheritdoc/>
public override Expression Build(IEnumerable<Expression> arguments)
{
TypeMapping typeMapping = Type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ namespace Bonsai.ML.LinearDynamicalSystems.Kinematics
/// <summary>
/// Model parameters for a Kalman Filter Kinematics python class
/// </summary>
[Description("Model parameters for a Kalman Filter Kinematics (KFK) model")]
[Combinator()]
[Combinator]
[WorkflowElementCategory(ElementCategory.Source)]
[Description("Model parameters for a Kalman Filter Kinematics (KFK) model")]
public class KFModelParameters
{

Expand Down Expand Up @@ -247,6 +247,9 @@ public int Fps
}
}

/// <summary>
/// Initializes a new instance of the <see cref="KFModelParameters"/> class.
/// </summary>
public KFModelParameters ()
{
Sigma_a = 10000;
Expand Down Expand Up @@ -332,10 +335,10 @@ public IObservable<KFModelParameters> Process<TSource>(IObservable<TSource> sour
Fps = _fps
});
}


/// <inheritdoc/>
public override string ToString()
{

return $"pos_x0={pos_x0String},pos_y0={pos_y0String},vel_x0={vel_x0String},vel_y0={vel_y0String},acc_x0={acc_x0String},acc_y0={acc_y0String},sigma_a={sigma_aString},sigma_x={sigma_xString},sigma_y={sigma_yString},sqrt_diag_V0_value={sqrt_diag_V0_valueString},fps={fpsString}";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public IObservable<Observation2D> Process<TSource>(IObservable<TSource> source)
});
}

/// <inheritdoc/>
public override string ToString()
{

return $"x={xString},y={yString}";
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/Bonsai.ML.LinearDynamicalSystems/ModelReference.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel;
using System.ComponentModel;

namespace Bonsai.ML.LinearDynamicalSystems
{
Expand All @@ -9,11 +9,15 @@ namespace Bonsai.ML.LinearDynamicalSystems
public class ModelReference
{
/// <summary>
/// The name of the model
/// Gets or sets the name of the referenced model.
/// </summary>
[Description("Name of the model")]
public string Name { get ; set; }

/// <summary>
/// Initializes a new instance of the <see cref="ModelReference"/> class
/// with the specified name.
/// </summary>
/// <param name="name">The name of the referenced model.</param>
public ModelReference(string name)
{
Name = name;
Expand Down
85 changes: 76 additions & 9 deletions src/Bonsai.ML.LinearDynamicalSystems/SerializeToJson.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.ComponentModel;
using System.Reactive.Linq;
using Bonsai.ML.LinearDynamicalSystems.Kinematics;
using Newtonsoft.Json;

namespace Bonsai.ML.LinearDynamicalSystems
{
/// <summary>
/// Serializes a sequence of data model objects into JSON strings.
/// </summary>
[Combinator()]
[Combinator]
[WorkflowElementCategory(ElementCategory.Transform)]
[Description("Serializes a sequence of data model objects into JSON strings.")]
public class SerializeToJson
Expand All @@ -18,34 +19,100 @@ private IObservable<string> Process<T>(IObservable<T> source)
return source.Select(value => JsonConvert.SerializeObject(value));
}

public IObservable<string> Process(IObservable<Kinematics.KFModelParameters> source)
/// <summary>
/// Serializes each <see cref="KFModelParameters"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="KFModelParameters"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="KFModelParameters"/> object.
/// </returns>
public IObservable<string> Process(IObservable<KFModelParameters> source)
{
return Process<Kinematics.KFModelParameters>(source);
return Process<KFModelParameters>(source);
}

public IObservable<string> Process(IObservable<Kinematics.Observation2D> source)
/// <summary>
/// Serializes each <see cref="Observation2D"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="Observation2D"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="Observation2D"/> object.
/// </returns>
public IObservable<string> Process(IObservable<Observation2D> source)
{
return Process<Kinematics.Observation2D>(source);
return Process<Observation2D>(source);
}

/// <summary>
/// Serializes each <see cref="State"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="State"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="State"/> object.
/// </returns>
public IObservable<string> Process(IObservable<State> source)
{
return Process<State>(source);
}

/// <summary>
/// Serializes each <see cref="StateComponent"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="StateComponent"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="StateComponent"/> object.
/// </returns>
public IObservable<string> Process(IObservable<StateComponent> source)
{
return Process<StateComponent>(source);
}

public IObservable<string> Process(IObservable<Kinematics.KinematicState> source)
/// <summary>
/// Serializes each <see cref="KinematicState"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="KinematicState"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="KinematicState"/> object.
/// </returns>
public IObservable<string> Process(IObservable<KinematicState> source)
{
return Process<Kinematics.KinematicState>(source);
return Process<KinematicState>(source);
}

public IObservable<string> Process(IObservable<Kinematics.KinematicComponent> source)
/// <summary>
/// Serializes each <see cref="KinematicComponent"/> object in the sequence to
/// a JSON string.
/// </summary>
/// <param name="source">
/// A sequence of <see cref="KinematicComponent"/> objects.
/// </param>
/// <returns>
/// A sequence of JSON strings representing the corresponding
/// <see cref="KinematicComponent"/> object.
/// </returns>
public IObservable<string> Process(IObservable<KinematicComponent> source)
{
return Process<Kinematics.KinematicComponent>(source);
return Process<KinematicComponent>(source);
}
}
}
25 changes: 12 additions & 13 deletions src/Bonsai.ML.Visualizers/KinematicComponentVisualizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Reflection;
Expand All @@ -14,6 +14,9 @@

namespace Bonsai.ML.Visualizers
{
/// <summary>
/// Provides a type visualizer to display the state components of a Kalman Filter kinematics model.
/// </summary>
public class KinematicComponentVisualizer : BufferedVisualizer
{

Expand All @@ -25,15 +28,6 @@ public class KinematicComponentVisualizer : BufferedVisualizer

private TimeSeriesOxyPlotBase Plot;

/// <summary>
/// Constructs a KinematicComponentVisualizer object.
/// </summary>
public KinematicComponentVisualizer ()
{
Capacity = 10;
Size = new Size(320, 240);
}

/// <summary>
/// The selected index of the state component to be visualized
/// </summary>
Expand All @@ -42,13 +36,14 @@ public KinematicComponentVisualizer ()
/// <summary>
/// Size of the window when loaded
/// </summary>
public Size Size { get; set; }
public Size Size { get; set; } = new Size(320, 240);

/// <summary>
/// Capacity or length of time shown along the x axis of the plot during automatic updating
/// </summary>
public int Capacity { get; set; }
public int Capacity { get; set; } = 10;

/// <inheritdoc/>
public override void Load(IServiceProvider provider)
{
var stateComponents = GetStateComponents();
Expand Down Expand Up @@ -78,10 +73,12 @@ public override void Load(IServiceProvider provider)
}
}

/// <inheritdoc/>
public override void Show(object value)
{
}

/// <inheritdoc/>
protected override void Show(DateTime time, object value)
{
if (!_startTime.HasValue)
Expand Down Expand Up @@ -111,6 +108,7 @@ protected override void Show(DateTime time, object value)

}

/// <inheritdoc/>
protected override void ShowBuffer(IList<Timestamped<object>> values)
{
base.ShowBuffer(values);
Expand Down Expand Up @@ -138,6 +136,7 @@ private List<string> GetStateComponents()
return stateComponents;
}

/// <inheritdoc/>
public override void Unload()
{
_startTime = null;
Expand All @@ -161,4 +160,4 @@ private void ComponentChanged(object sender, EventArgs e)
Plot.ResetSeries();
}
}
}
}
4 changes: 2 additions & 2 deletions src/Bonsai.ML.Visualizers/TimeSeriesOxyPlotBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Windows.Forms;
using System.Windows.Forms;
using OxyPlot;
using OxyPlot.Series;
using OxyPlot.WindowsForms;
Expand All @@ -9,7 +9,7 @@

namespace Bonsai.ML.Visualizers
{
public class TimeSeriesOxyPlotBase : UserControl
internal class TimeSeriesOxyPlotBase : UserControl
{
private PlotView view;
private PlotModel model;
Expand Down
2 changes: 2 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageOutputPath>..\bin\$(Configuration)</PackageOutputPath>
<PackageProjectUrl>https://bonsai-rx.org/machinelearning</PackageProjectUrl>
<RepositoryUrl>https://github.com/bonsai-rx/machinelearning.git</RepositoryUrl>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -20,5 +21,6 @@
<ItemGroup>
<Content Include="..\..\LICENSE" PackagePath="/" />
<Content Include="..\..\icon.png" PackagePath="/" />
<None Include="..\..\README.md" Pack="True" PackagePath="/" />
</ItemGroup>
</Project>

0 comments on commit 7e0959d

Please sign in to comment.