Class SupervisedICA
Supervised version of OnlineICA with manual cluster labelling and capture.
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:
{
"MySupervisedICA": {
"Type": "SupervisedICA",
"Inputs": [ "FeatureExtractor" ],
"Params": [ 3, 0.1, 50, 1000, 0, 500, 1, 0, 0.005 ],
"DesiredRate": 1000,
"Path": "output/sica_log"
}
}
Params: Identical to OnlineICA:
| Index | Description |
|---|---|
| 0 | k (int) — Number of independent components. Default: 2. |
| 1 | eta0 (double) — Initial learning rate. Default: 0.1. |
| 2 | reorthEvery (int) — Orthonormalisation frequency. Default: 50. |
| 3 | minStableCount (int) — Minimum samples before stable. Default: 1000. |
| 4 | contrastFunction (double) — 0=LogCosh, 1=Exp, 2=Cube. Default: 0. |
| 5 | warmupSamples (int) — Warm-up samples. Default: 500. |
| 6 | freezeWhiteningAfterWarmup (int) — 1=freeze, 0=keep updating. Default: 1. |
| 7 | adaptiveWhitening (int) — 1=adaptive, 0=off. Default: 0. |
| 8 | covarianceDecay (double) — EWMA decay factor. Default: 0.005. |
Path: Optional. If provided, CSV logs of projected outputs are written to this directory.
JSON configuration:
{
"EMG_ICA": {
"Type": "OnlineICA",
"Inputs": [ "SlidingWindow1" ],
"Params": [ 3, 0.1, 50, 1000, 0, 500, 1, 0, 0.005 ],
"DesiredRate": 1000,
"Path": "output/emg_ica"
}
}
Params:
| Index | Description |
|---|---|
| 0 | k (int) — Number of independent components to extract. Default: 2. |
| 1 | eta0 (double) — Initial learning rate η₀. Range: 0.01–0.2. Default: 0.1. |
| 2 | reorthEvery (int) — Orthonormalization frequency in samples. Default: 50. |
| 3 | minStableCount (int) — Minimum samples before model is stable. Default: 1000. |
| 4 | contrastFunction (double) — Contrast function: 0 = LogCosh, 1 = Exp, 2 = Cube. Default: 0. |
| 5 | warmupSamples (int) — Warm-up samples (whitening only). Set 0 to disable. Default: 500. |
| 6 | freezeWhiteningAfterWarmup (int) — 1 = freeze whitening after warm-up, 0 = keep updating. Default: 1. |
| 7 | adaptiveWhitening (int) — 1 = enable adaptive whitening for non-stationary signals, 0 = off. Default: 0. |
| 8 | covarianceDecay (double) — EWMA decay for adaptive covariance. Range: 0.0001–0.5. Default: 0.005. |
Path: Optional. If provided, CSV logs of projected outputs are written to this directory.
How Type, Inputs and Params work · Block catalogue and parameter reference
Implements
Inherited Members
Namespace: MOSAIC.Models.Analytics
Assembly: MOSAIC.dll
Syntax
public class SupervisedICA : OnlineICA, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks
Extends OnlineICA by intercepting projections via PublishProjection(Vector<double>) and storing them in labelled clusters for supervised learning or visualisation purposes.
Usage:
- Call StartCapture(string) with a label to begin capturing.
- Process data normally — projections are automatically stored.
- Call StopCapture() to end the capture session.
- Access captured data via CapturedClusters.
All ICA parameters (contrast function, whitening mode, etc.) are inherited from OnlineICA. See the base class for algorithmic details.
Constructors
SupervisedICA(string, double, int, double, int, int, double, int, bool, bool, double)
Initializes a new instance of the SupervisedICA class.
Declaration
public SupervisedICA(string name, double desiredRate = 0, int k = 2, double eta0 = 0.1, int reorthEvery = 50, int minStableCount = 1000, double contrastFunction = 0, int warmupSamples = 500, bool freezeWhiteningAfterWarmup = true, bool adaptiveWhitening = false, double covarianceDecay = 0.005)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Unique identifier for this processing block. |
| double | desiredRate | Target processing rate in Hz (0 = inherited from upstream). |
| int | k | Number of independent components to extract. |
| double | eta0 | Initial learning rate η₀ ∈ (0, 1]. |
| int | reorthEvery | Orthonormalisation frequency (samples). |
| int | minStableCount | Minimum samples before model is considered stable. |
| double | contrastFunction | Contrast function: 0=LogCosh, 1=Exp, 2=Cube. |
| int | warmupSamples | Number of samples for warm-up phase (whitening estimation). |
| bool | freezeWhiteningAfterWarmup | If true, whitening is frozen after warm-up. |
| bool | adaptiveWhitening | If true, enables adaptive whitening for EMG/ultrasound. |
| double | covarianceDecay | Decay factor for EWMA covariance in adaptive mode. |
Fields
_availableColors
Palette of distinct colours cycled through as new clusters appear.
Declaration
private readonly List<string> _availableColors
Field Value
| Type | Description |
|---|---|
| List<string> |
_colorIndex
Next colour index in _availableColors.
Declaration
private int _colorIndex
Field Value
| Type | Description |
|---|---|
| int |
_currentCaptureCount
Gets or sets the number of points captured in the current session.
Declaration
[ObservableProperty]
private int _currentCaptureCount
Field Value
| Type | Description |
|---|---|
| int |
_currentLabel
Gets or sets the class label currently being captured.
Declaration
[ObservableProperty]
private string _currentLabel
Field Value
| Type | Description |
|---|---|
| string |
_isCapturing
Gets or sets whether the block is currently capturing data into a labelled cluster.
Declaration
[ObservableProperty]
private bool _isCapturing
Field Value
| Type | Description |
|---|---|
| bool |
_preserveClustersOnReset
Gets or sets whether to preserve captured clusters when Reset() is called.
Declaration
[ObservableProperty]
private bool _preserveClustersOnReset
Field Value
| Type | Description |
|---|---|
| bool |
Remarks
When true (default), calling Reset() preserves all captured cluster data while resetting only the ICA model parameters.
Properties
CapturedClusters
Stores captured cluster points keyed by class label, used for UI scatter-plot visualisation.
Declaration
public Dictionary<string, List<Vector<double>>> CapturedClusters { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, List<Vector<double>>> | Dictionary mapping cluster labels to lists of k-dimensional projection vectors. |
ClusterColors
Hex colour strings assigned to each cluster label for consistent UI rendering.
Declaration
public Dictionary<string, string> ClusterColors { get; }
Property Value
| Type | Description |
|---|---|
| Dictionary<string, string> | Dictionary mapping cluster labels to hex color strings (e.g., |
CurrentCaptureCount
Gets or sets the number of points captured in the current session.
Declaration
[ExcludeFromCodeCoverage]
public int CurrentCaptureCount { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
CurrentLabel
Gets or sets the class label currently being captured.
Declaration
[ExcludeFromCodeCoverage]
public string CurrentLabel { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
DumpFilePrefix
Recordings from this block are named <block>_projections.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
| Type | Description |
|---|---|
| string |
Overrides
IsCapturing
Gets or sets whether the block is currently capturing data into a labelled cluster.
Declaration
[ExcludeFromCodeCoverage]
public bool IsCapturing { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
MaxInputs
Gets the maximum number of input connections allowed for this block.
Declaration
public override int MaxInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Remarks
Override in derived classes to specify input requirements. Default is 1 (most blocks accept exactly one input). Use MaxValue for blocks that accept unlimited inputs (e.g., Joiner).
MinInputs
Gets the minimum number of input connections required for this block.
Declaration
public override int MinInputs { get; }
Property Value
| Type | Description |
|---|---|
| int |
Overrides
Remarks
Override in derived classes to specify input requirements. Default is 1 (most blocks require exactly one input). Source blocks (devices, generators) should return 0.
PreserveClustersOnReset
Gets or sets whether to preserve captured clusters when Reset() is called.
Declaration
[ExcludeFromCodeCoverage]
public bool PreserveClustersOnReset { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
When true (default), calling Reset() preserves all captured cluster data while resetting only the ICA model parameters.
Methods
ClearAllClusters()
Removes all captured clusters and resets the colour index.
Declaration
public void ClearAllClusters()
ClearCluster(string)
Removes a single cluster and its colour assignment.
Declaration
public void ClearCluster(string label)
Parameters
| Type | Name | Description |
|---|---|---|
| string | label | The label of the cluster to remove. |
ConfigureInput(IServiceProvider, JsonModel)
Creates a SupervisedICA instance from a JSON model definition.
Declaration
public static SupervisedICA ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
| Type | Name | Description |
|---|---|---|
| IServiceProvider | sp | Service provider for dependency injection. |
| JsonModel | m | The JSON model. See class-level |
Returns
| Type | Description |
|---|---|
| SupervisedICA | A fully configured SupervisedICA instance. |
OnCurrentCaptureCountChanged(int)
Executes the logic for when CurrentCaptureCount just changed.
Declaration
private void OnCurrentCaptureCountChanged(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 CurrentCaptureCount is changed.
OnCurrentCaptureCountChanged(int, int)
Executes the logic for when CurrentCaptureCount just changed.
Declaration
private void OnCurrentCaptureCountChanged(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 CurrentCaptureCount is changed.
OnCurrentCaptureCountChanging(int)
Executes the logic for when CurrentCaptureCount is changing.
Declaration
private void OnCurrentCaptureCountChanging(int value)
Parameters
| Type | Name | Description |
|---|---|---|
| int | value | The new property value being set. |
Remarks
This method is invoked right before the value of CurrentCaptureCount is changed.
OnCurrentCaptureCountChanging(int, int)
Executes the logic for when CurrentCaptureCount is changing.
Declaration
private void OnCurrentCaptureCountChanging(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 CurrentCaptureCount is changed.
OnCurrentLabelChanged(string)
Executes the logic for when CurrentLabel just changed.
Declaration
private void OnCurrentLabelChanged(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 CurrentLabel is changed.
OnCurrentLabelChanged(string?, string)
Executes the logic for when CurrentLabel just changed.
Declaration
private void OnCurrentLabelChanged(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 CurrentLabel is changed.
OnCurrentLabelChanging(string)
Executes the logic for when CurrentLabel is changing.
Declaration
private void OnCurrentLabelChanging(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | The new property value being set. |
Remarks
This method is invoked right before the value of CurrentLabel is changed.
OnCurrentLabelChanging(string?, string)
Executes the logic for when CurrentLabel is changing.
Declaration
private void OnCurrentLabelChanging(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 CurrentLabel is changed.
OnIsCapturingChanged(bool)
Executes the logic for when IsCapturing just changed.
Declaration
private void OnIsCapturingChanged(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 IsCapturing is changed.
OnIsCapturingChanged(bool, bool)
Executes the logic for when IsCapturing just changed.
Declaration
private void OnIsCapturingChanged(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 IsCapturing is changed.
OnIsCapturingChanging(bool)
Executes the logic for when IsCapturing is changing.
Declaration
private void OnIsCapturingChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of IsCapturing is changed.
OnIsCapturingChanging(bool, bool)
Executes the logic for when IsCapturing is changing.
Declaration
private void OnIsCapturingChanging(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 IsCapturing is changed.
OnPreserveClustersOnResetChanged(bool)
Executes the logic for when PreserveClustersOnReset just changed.
Declaration
private void OnPreserveClustersOnResetChanged(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 PreserveClustersOnReset is changed.
OnPreserveClustersOnResetChanged(bool, bool)
Executes the logic for when PreserveClustersOnReset just changed.
Declaration
private void OnPreserveClustersOnResetChanged(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 PreserveClustersOnReset is changed.
OnPreserveClustersOnResetChanging(bool)
Executes the logic for when PreserveClustersOnReset is changing.
Declaration
private void OnPreserveClustersOnResetChanging(bool value)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | value | The new property value being set. |
Remarks
This method is invoked right before the value of PreserveClustersOnReset is changed.
OnPreserveClustersOnResetChanging(bool, bool)
Executes the logic for when PreserveClustersOnReset is changing.
Declaration
private void OnPreserveClustersOnResetChanging(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 PreserveClustersOnReset is changed.
PublishProjection(Vector<double>)
Intercepts projections from the base OnlineICA to capture them into the current cluster when capture is active, then publishes downstream.
Declaration
protected override void PublishProjection(Vector<double> projection)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector<double> | projection | The k-dimensional independent component vector. |
Overrides
Remarks
A clone of the projection is stored in CapturedClusters under CurrentLabel. The original vector is always forwarded to downstream subscribers via Publish(object).
Reset()
Resets the ICA model, optionally preserving captured clusters.
Declaration
public void Reset()
Remarks
Behaviour depends on PreserveClustersOnReset:
StartCapture(string)
Starts capturing projected data with the given label.
Declaration
public void StartCapture(string label)
Parameters
| Type | Name | Description |
|---|---|---|
| string | label | The cluster label for captured points. |
Remarks
If already capturing, the current capture session is stopped first. If the label already exists, new points are appended to the existing cluster.
A unique colour is automatically assigned to new clusters from the internal palette.
StopCapture()
Stops the current capture session.
Declaration
public void StopCapture()
Remarks
If not currently capturing, this method is a no-op (logged as a warning).
TryDouble(IReadOnlyList<object>?, int, double)
Attempts to parse a double from a parameter list.
Declaration
private static double TryDouble(IReadOnlyList<object>? p, int idx, double def)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<object> | p | Parameter list. |
| int | idx | Index to read. |
| double | def | Default value if parsing fails. |
Returns
| Type | Description |
|---|---|
| double | Parsed double or default. |
TryInt(IReadOnlyList<object>?, int, int)
Attempts to parse an integer from a parameter list.
Declaration
private static int TryInt(IReadOnlyList<object>? p, int idx, int def)
Parameters
| Type | Name | Description |
|---|---|---|
| IReadOnlyList<object> | p | Parameter list. |
| int | idx | Index to read. |
| int | def | Default value if parsing fails. |
Returns
| Type | Description |
|---|---|
| int | Parsed integer or default. |