Class IncrementalPredictor
Incremental regression block that learns to map input feature vectors to multi-dimensional output predictions in real time.
JSON configuration
Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.
JSON configuration:
{
"Predictor": {
"Type": "IncrementalPredictor",
"DesiredRate": 200,
"Inputs": [ "LowpassFilter", "Trigger" ],
"Params": [ "RidgeRFF", 8, 12, 0.5, 1.0, 300 ],
"Path": "C:/recordings"
}
}
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.MachineLearning
Assembly: MOSAIC.dll
Syntax
public sealed class IncrementalPredictor : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Overview: The IncrementalPredictor sits between a feature-extraction pipeline (e.g. EMG → Filter → Features) and a control algorithm. It learns an online mapping from input features to output activations using incremental ridge regression (optionally with Random Fourier Features for non-linear kernels). Training is driven by a Trigger block that supplies labeled target vectors.
Inputs: Expects exactly two upstream connections:
-
Feature source — any block publishing
Vector<double>of length InputDim, or aMatrix<double>of shape[timesteps × InputDim]where each row is processed as an individual feature vector. -
Trigger — publishes a target
Vector<double>of length OutputDim to start training, or null to stop.
Output: After every feature input, publishes a prediction Vector<double>
of length OutputDim. For matrix input, only the last row's prediction is published
(all rows are trained on if training is active).
Constructors
IncrementalPredictor(string, double, int, int)
Declaration
public IncrementalPredictor(string name, double desiredRate, int inputDim, int outputDim)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| double | desiredRate | |
| int | inputDim | |
| int | outputDim |
IncrementalPredictor(string, double, int, int, RegressorType, RegressorConfig)
Declaration
public IncrementalPredictor(string name, double desiredRate, int inputDim, int outputDim, RegressorType modelType, RegressorConfig config)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| double | desiredRate | |
| int | inputDim | |
| int | outputDim | |
| RegressorType | modelType | |
| RegressorConfig | config |
IncrementalPredictor(string, double, int, int, RegressorType, RegressorConfig, string?)
Declaration
public IncrementalPredictor(string name, double desiredRate, int inputDim, int outputDim, RegressorType modelType, RegressorConfig config, string? savePath)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| double | desiredRate | |
| int | inputDim | |
| int | outputDim | |
| RegressorType | modelType | |
| RegressorConfig | config | |
| string | savePath |
Fields
_confidence
Raw confidence value from the regressor.
Declaration
[ObservableProperty]
private double _confidence
Field Value
| Type | Description |
|---|---|
| double |
_currentTarget
Current training target vector, or null when not training.
Declaration
private Vector<double>? _currentTarget
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_currentTargetName
Name of the current training target.
Declaration
[ObservableProperty]
private string _currentTargetName
Field Value
| Type | Description |
|---|---|
| string |
_isTraining
Whether the block is currently training.
Declaration
[ObservableProperty]
[NotifyPropertyChangedFor("TrainingStatusText")]
private bool _isTraining
Field Value
| Type | Description |
|---|---|
| bool |
_lastPrediction
Most recent prediction vector.
Declaration
private Vector<double>? _lastPrediction
Field Value
| Type | Description |
|---|---|
| Vector<double> |
_lastVizFeedTicks
Timestamp of last viz feed for stall detection.
Declaration
private long _lastVizFeedTicks
Field Value
| Type | Description |
|---|---|
| long |
_model
The active regression model.
Declaration
private IRegressor _model
Field Value
| Type | Description |
|---|---|
| IRegressor |
_sampleCount
Total training samples processed.
Declaration
[ObservableProperty]
private int _sampleCount
Field Value
| Type | Description |
|---|---|
| int |
_savePath
Directory for model auto-save.
Declaration
private readonly string? _savePath
Field Value
| Type | Description |
|---|---|
| string |
_viz
Visualization bundle set by the ViewModel.
Declaration
private BlockVisualization? _viz
Field Value
| Type | Description |
|---|---|
| BlockVisualization |
Properties
Confidence
Raw confidence value from the regressor.
Declaration
[ExcludeFromCodeCoverage]
public double Confidence { get; set; }
Property Value
| Type | Description |
|---|---|
| double |
Config
Hyperparameters for the active regressor.
Declaration
public RegressorConfig Config { get; private set; }
Property Value
| Type | Description |
|---|---|
| RegressorConfig |
CurrentTargetName
Name of the current training target.
Declaration
[ExcludeFromCodeCoverage]
public string CurrentTargetName { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
DumpFilePrefix
Recordings from this block are named <block>_predictions.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
InputDim
Expected length of incoming feature vectors.
Declaration
public int InputDim { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
IsTraining
Whether the block is currently training.
Declaration
[ExcludeFromCodeCoverage]
public bool IsTraining { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
JsonTypeName
Block type identifier for JSON serialization. Override for a custom name.
Declaration
protected override string JsonTypeName { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
LastPrediction
Most recent prediction vector.
Declaration
public Vector<double>? LastPrediction { get; }
Property Value
| Type | Description |
|---|---|
| Vector<double> |
MaxInputs
Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).
Declaration
public override int MaxInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
MinInputs
Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).
Declaration
public override int MinInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
ModelType
Active regression algorithm type.
Declaration
public RegressorType ModelType { get; private set; }
Property Value
| Type | Description |
|---|---|
| RegressorType |
OutputDim
Number of prediction output dimensions.
Declaration
public int OutputDim { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
OutputLabels
Per-output-column labels from the Trigger's action dictionary.
Declaration
public List<string>? OutputLabels { get; private set; }
Property Value
| Type | Description |
|---|---|
| List<string> |
SampleCount
Total training samples processed.
Declaration
[ExcludeFromCodeCoverage]
public int SampleCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
TrainingStatusText
Human-readable training status for UI.
Declaration
public string TrainingStatusText { get; }
Property Value
| Type | Description |
|---|---|
| string |
Visualization
This block's visualization, or null when it has none.
Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
| Type | Description |
|---|---|
| BlockVisualization |
Overrides
Remarks
Blocks own their scope as a public Viz property rather than inheriting one, so the
base class has no way to reach it. Overriding this is what lets the rate below be wired up
automatically. With correct publication metadata, the bundle derives the time axis for
one vector per publication or fixed-size contiguous sample packets from the feed shape.
When a plot needs a rate that publication frequency and feed shape cannot express (for
example, variable-sized packets or overlapping windows), declare it with
Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block
with several bundles must configure each one; this hook exposes only one bundle.
Viz
Live plot for this block. Assigned by the ViewModel, which owns the scope.
Declaration
public BlockVisualization? Viz { get; set; }
Property Value
| Type | Description |
|---|---|
| BlockVisualization |
Remarks
Setting this re-pushes the publish rate: the rate is normally pushed when it changes, which for these blocks happens during construction — before the ViewModel has handed over the scope — so without this the scope would never learn its time base.
Methods
AutoSave()
Declaration
public void AutoSave()
ChangeModel(RegressorType, RegressorConfig?)
Declaration
public void ChangeModel(RegressorType type, RegressorConfig? config = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RegressorType | type | |
| RegressorConfig | config |
ConfigureInput(IServiceProvider, JsonModel)
Declaration
public static IncrementalPredictor ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | |
| JsonModel | m |
Returns
| Type | Description |
|---|---|
| IncrementalPredictor |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public override void Dispose()
Overrides
GetDefaultSavePath()
Declaration
private string? GetDefaultSavePath()
Returns
| Type | Description |
|---|---|
| string |
GetJsonParams()
Block-specific parameters for JSON. Override to provide custom parameters.
Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<object> | The values for Params, in the order this block's |
Overrides
GetJsonPath()
Overrides what this block writes to Path.
Declaration
protected override string? GetJsonPath()
Returns
| Type | Description |
|---|---|
| string | The path to export, or null to fall back to the block's own recording folder. |
Overrides
Remarks
Only for blocks that read Path as something other than a recording folder — a
predictor's model directory, say. Such a block also overrides
PathIsDumpFolder; without this override it would export null
and saving the pipeline would silently drop the directory.
HandleFeatureInput(Vector<double>)
Processes a feature vector: trains (if active), predicts, publishes, and visualizes.
Declaration
private void HandleFeatureInput(Vector<double> x)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | x |
HandleFeatureInputSilent(Vector<double>)
Processes a feature vector for training and prediction only — no Publish, no Viz feed. Used for intermediate rows of a matrix input so only the last row triggers output.
Declaration
private void HandleFeatureInputSilent(Vector<double> x)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | x |
HandleTriggerInput(object?, object?)
Processes Trigger messages: target vectors start training, null stops it.
Declaration
private void HandleTriggerInput(object? sender, object? data)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | |
| object | data |
LoadModel(string)
Declaration
public void LoadModel(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path |
OnConfidenceChanged(double)
Executes the logic for when Confidence just changed.
Declaration
private void OnConfidenceChanged(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value that was set. |
Remarks
This method is invoked right after the value of Confidence is changed.
OnConfidenceChanged(double, double)
Executes the logic for when Confidence just changed.
Declaration
private void OnConfidenceChanged(double oldValue, double newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| double | oldValue | The previous property value that was replaced. |
| double | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of Confidence is changed.
OnConfidenceChanging(double)
Executes the logic for when Confidence is changing.
Declaration
private void OnConfidenceChanging(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The new property value being set. |
Remarks
This method is invoked right before the value of Confidence is changed.
OnConfidenceChanging(double, double)
Executes the logic for when Confidence is changing.
Declaration
private void OnConfidenceChanging(double oldValue, double newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| double | oldValue | The previous property value that is being replaced. |
| double | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of Confidence is changed.
OnCurrentTargetNameChanged(string)
Executes the logic for when CurrentTargetName just changed.
Declaration
private void OnCurrentTargetNameChanged(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The new property value that was set. |
Remarks
This method is invoked right after the value of CurrentTargetName is changed.
OnCurrentTargetNameChanged(string?, string)
Executes the logic for when CurrentTargetName just changed.
Declaration
private void OnCurrentTargetNameChanged(string? oldValue, string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oldValue | The previous property value that was replaced. |
| string | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of CurrentTargetName is changed.
OnCurrentTargetNameChanging(string)
Executes the logic for when CurrentTargetName is changing.
Declaration
private void OnCurrentTargetNameChanging(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The new property value being set. |
Remarks
This method is invoked right before the value of CurrentTargetName is changed.
OnCurrentTargetNameChanging(string?, string)
Executes the logic for when CurrentTargetName is changing.
Declaration
private void OnCurrentTargetNameChanging(string? oldValue, string newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | oldValue | The previous property value that is being replaced. |
| string | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of CurrentTargetName is changed.
OnIsTrainingChanged(bool)
Executes the logic for when IsTraining just changed.
Declaration
private void OnIsTrainingChanged(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value that was set. |
Remarks
This method is invoked right after the value of IsTraining is changed.
OnIsTrainingChanged(bool, bool)
Executes the logic for when IsTraining just changed.
Declaration
private void OnIsTrainingChanged(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that was replaced. |
| bool | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of IsTraining is changed.
OnIsTrainingChanging(bool)
Executes the logic for when IsTraining is changing.
Declaration
private void OnIsTrainingChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of IsTraining is changed.
OnIsTrainingChanging(bool, bool)
Executes the logic for when IsTraining is changing.
Declaration
private void OnIsTrainingChanging(bool oldValue, bool newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | oldValue | The previous property value that is being replaced. |
| bool | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of IsTraining is changed.
OnReceive(object, object)
Dispatches incoming data. Trigger inputs control training state; feature inputs (Vector or Matrix) drive prediction.
Declaration
protected override void OnReceive(object sender, object data)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender | |
| object | data |
Overrides
OnSampleCountChanged(int)
Executes the logic for when SampleCount just changed.
Declaration
private void OnSampleCountChanged(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value that was set. |
Remarks
This method is invoked right after the value of SampleCount is changed.
OnSampleCountChanged(int, int)
Executes the logic for when SampleCount just changed.
Declaration
private void OnSampleCountChanged(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that was replaced. |
| int | newValue | The new property value that was set. |
Remarks
This method is invoked right after the value of SampleCount is changed.
OnSampleCountChanging(int)
Executes the logic for when SampleCount is changing.
Declaration
private void OnSampleCountChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of SampleCount is changed.
OnSampleCountChanging(int, int)
Executes the logic for when SampleCount is changing.
Declaration
private void OnSampleCountChanging(int oldValue, int newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| int | oldValue | The previous property value that is being replaced. |
| int | newValue | The new property value being set. |
Remarks
This method is invoked right before the value of SampleCount is changed.
ResetModel()
Declaration
public void ResetModel()
SaveModel(string?)
Declaration
public void SaveModel(string? path = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path |
SetTarget(Vector<double>?, string?)
Declaration
public void SetTarget(Vector<double>? target, string? targetName = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | target | |
| string | targetName |
TryExtractLabels(object?)
Declaration
private void TryExtractLabels(object? sender)
Parameters
| Type | Name | Description |
|---|---|---|
| object | sender |
Events
OnLabelsUpdated
Fired once when output labels are derived.
Declaration
public event Action<List<string>>? OnLabelsUpdated
Event Type
| Type | Description |
|---|---|
| Action<List<string>> |
OnPrediction
Fired after every prediction.
Declaration
public event Action<Vector<double>, Vector<double>?, double, int>? OnPrediction
Event Type
| Type | Description |
|---|---|
| Action<Vector<double>, Vector<double>, double, int> |
OnTrainingStateChanged
Fired when training starts/stops.
Declaration
public event Action<bool, string?>? OnTrainingStateChanged
Event Type
| Type | Description |
|---|---|
| Action<bool, string> |