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

Added source node capabilities to StateComponent #9

Closed
wants to merge 2 commits into from
Closed
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
41 changes: 40 additions & 1 deletion src/Bonsai.ML.LinearDynamicalSystems/StateComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System;
using System.Reactive.Linq;
using System.Xml.Serialization;
using Newtonsoft.Json;

Expand All @@ -8,7 +9,9 @@ namespace Bonsai.ML.LinearDynamicalSystems
/// <summary>
/// State component of a Kalman Filter
/// </summary>
[Description("State component of a Kalman Filter")]
[Description("State component of a Kalman Filter")]
[Combinator()]
[WorkflowElementCategory(ElementCategory.Source)]
Comment on lines +12 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[Description("State component of a Kalman Filter")]
[Combinator()]
[WorkflowElementCategory(ElementCategory.Source)]
[Combinator]
[Description("State component of a Kalman Filter")]
[WorkflowElementCategory(ElementCategory.Source)]

public class StateComponent
{

Expand Down Expand Up @@ -61,9 +64,45 @@ public StateComponent(double[,] X, double[,] P, int i)
Variance = Sigma(P[i,i]);
}

/// <summary>
/// Creates a new state compenent
/// </summary>
public StateComponent(double mean, double variance)
{
Mean = mean;
Variance = variance;
}

private double Sigma(double variance)
{
return 2 * Math.Sqrt(variance);
}

/// <summary>
/// Given an observable sequence, this function returns an observable sequence of state components for each element in the input sequence
/// /// </summary>
Comment on lines +81 to +83
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <summary>
/// Given an observable sequence, this function returns an observable sequence of state components for each element in the input sequence
/// /// </summary>
/// <summary>
/// Given an observable sequence, this function returns an observable sequence of state
/// components for each element in the input sequence.
/// </summary>

Duplicate /// and minor formatting

public IObservable<StateComponent> Process<TSource>(IObservable<TSource> source)
{
return Observable.Select(source, value =>
{
return new StateComponent (
Mean = Mean,
Variance = Variance
);
});
}

/// <summary>
/// This function returns an observable sequence of state components
/// /// </summary>
Comment on lines +95 to +97
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <summary>
/// This function returns an observable sequence of state components
/// /// </summary>
/// <summary>
/// Returns an observable sequence of state components.
/// </summary>

public IObservable<StateComponent> Process()
{
return Observable.Return(
new StateComponent (
Mean = Mean,
Variance = Variance
)
);
}
}
}