Class OnlineLDA
Online Linear Discriminant Analysis using incremental learning.
Maximizes between-class scatter while minimizing within-class scatter.
Key difference from PCA:
- PCA finds directions of maximum variance (unsupervised)
- LDA finds directions of maximum class separation (supervised)
Inputs (like IncrementalPredictor):
- Input[0]: Data source block (provides feature vectors)
- Input[1]: Trigger block (provides class labels)
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.
Block entry for a larger pipeline. Params: components (2 or 3), learning rate, re-orthonormalisation interval, stability sample count, regularization. Labels must come from a Trigger; provide labelled observations from multiple classes.
{
"OnlineLDA": {
"Type": "onlinelda",
"Inputs": ["Features", "Labels"],
"Params": [2, 0.1, 100, 500, 0.0001]
}
}
How Type, Inputs and Params work · Block catalogue and parameter reference
Assembly: MOSAIC.dll
Syntax
public class OnlineLDA : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Constructors
OnlineLDA(string, double, int, double, int, int, double)
Declaration
public OnlineLDA(string name, double desiredRate = 0, int k = 2, double eta0 = 0.1, int reorthEvery = 100, int minStableCount = 500, double regularization = 0.0001)
Parameters
Fields
_Sb
Declaration
private Matrix<double> _Sb
Field Value
| Type |
Description |
| Matrix<double> |
|
_Sw
Declaration
private Matrix<double> _Sw
Field Value
| Type |
Description |
| Matrix<double> |
|
_W
Declaration
private Matrix<double> _W
Field Value
| Type |
Description |
| Matrix<double> |
|
_availableColors
Declaration
private readonly List<string> _availableColors
Field Value
_classStats
Declaration
private readonly Dictionary<string, OnlineLDA.ClassStats> _classStats
Field Value
_colorIndex
Declaration
Field Value
_currentClassName
Declaration
[ObservableProperty]
private string _currentClassName
Field Value
_currentLabel
Declaration
private string _currentLabel
Field Value
_d
Declaration
Field Value
_diff
Declaration
private Vector<double>? _diff
Field Value
| Type |
Description |
| Vector<double> |
|
_eta0
Declaration
private readonly double _eta0
Field Value
_globalCount
Declaration
private long _globalCount
Field Value
_globalMean
Declaration
private Vector<double> _globalMean
Field Value
| Type |
Description |
| Vector<double> |
|
_isCapturing
Declaration
[ObservableProperty]
private bool _isCapturing
Field Value
_isStable
Declaration
Field Value
_k
Declaration
Field Value
_minStableCount
Declaration
private readonly int _minStableCount
Field Value
_n
Declaration
Field Value
_prevLD1
Declaration
private Vector<double>? _prevLD1
Field Value
| Type |
Description |
| Vector<double> |
|
_prevLD2
Declaration
private Vector<double>? _prevLD2
Field Value
| Type |
Description |
| Vector<double> |
|
_prevLD3
Declaration
private Vector<double>? _prevLD3
Field Value
| Type |
Description |
| Vector<double> |
|
_regularization
Declaration
private readonly double _regularization
Field Value
_reorthEvery
Declaration
private readonly int _reorthEvery
Field Value
_separabilityScores
Declaration
private Vector<double> _separabilityScores
Field Value
| Type |
Description |
| Vector<double> |
|
_xc
Declaration
private Vector<double>? _xc
Field Value
| Type |
Description |
| Vector<double> |
|
_y
Declaration
private Vector<double>? _y
Field Value
| Type |
Description |
| Vector<double> |
|
Properties
CapturedClusters
Declaration
public Dictionary<string, List<Vector<double>>> CapturedClusters { get; }
Property Value
ClassCount
Declaration
public int ClassCount { get; }
Property Value
ClusterColors
Declaration
public Dictionary<string, string> ClusterColors { get; }
Property Value
ComponentCount
Declaration
public int ComponentCount { get; }
Property Value
CurrentClassName
Declaration
[ExcludeFromCodeCoverage]
public string CurrentClassName { get; set; }
Property Value
DumpFilePrefix
Recordings from this block are named <block>_projections.csv.
Declaration
protected override string DumpFilePrefix { get; }
Property Value
Overrides
GlobalMean
Declaration
public Vector<double> GlobalMean { get; }
Property Value
| Type |
Description |
| Vector<double> |
|
IsCapturing
Declaration
[ExcludeFromCodeCoverage]
public bool IsCapturing { get; set; }
Property Value
IsStable
Declaration
public bool IsStable { get; }
Property Value
Loadings
Declaration
public Matrix<double> Loadings { get; }
Property Value
| Type |
Description |
| Matrix<double> |
|
Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).
Declaration
public override int MaxInputs { get; }
Property Value
Overrides
Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).
Declaration
public override int MinInputs { get; }
Property Value
Overrides
SampleCount
Declaration
public long SampleCount { get; }
Property Value
SeparabilityScores
Declaration
public Vector<double> SeparabilityScores { get; }
Property Value
| Type |
Description |
| Vector<double> |
|
Methods
ClearAllClusters()
Declaration
public void ClearAllClusters()
ClearCluster(string)
Declaration
public void ClearCluster(string label)
Parameters
| Type |
Name |
Description |
| string |
label |
|
Declaration
public static OnlineLDA ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Returns
CorrectLDSigns()
Declaration
private void CorrectLDSigns()
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public override void Dispose()
Overrides
EnsureInit(int)
Declaration
private void EnsureInit(int d)
Parameters
| Type |
Name |
Description |
| int |
d |
|
GetJsonParams()
Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Overrides
OnCurrentClassNameChanged(string)
Declaration
private void OnCurrentClassNameChanged(string value)
Parameters
| Type |
Name |
Description |
| string |
value |
The new property value that was set.
|
OnCurrentClassNameChanged(string?, string)
Declaration
private void OnCurrentClassNameChanged(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.
|
OnCurrentClassNameChanging(string)
Declaration
private void OnCurrentClassNameChanging(string value)
Parameters
| Type |
Name |
Description |
| string |
value |
The new property value being set.
|
OnCurrentClassNameChanging(string?, string)
Declaration
private void OnCurrentClassNameChanging(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.
|
OnIsCapturingChanged(bool)
Declaration
private void OnIsCapturingChanged(bool value)
Parameters
| Type |
Name |
Description |
| bool |
value |
The new property value that was set.
|
OnIsCapturingChanged(bool, bool)
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.
|
OnIsCapturingChanging(bool)
Declaration
private void OnIsCapturingChanging(bool value)
Parameters
| Type |
Name |
Description |
| bool |
value |
The new property value being set.
|
OnIsCapturingChanging(bool, bool)
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.
|
OnReceive(object, object)
Processes incoming data from an upstream block.
Must be implemented by derived classes.
Declaration
protected override void OnReceive(object sender, object data)
Parameters
| Type |
Name |
Description |
| object |
sender |
The publishing block, or whatever else delivered the value.
|
| object |
data |
|
Overrides
Orthonormalize(ref Matrix<double>)
Declaration
private static void Orthonormalize(ref Matrix<double> W)
Parameters
| Type |
Name |
Description |
| Matrix<double> |
W |
|
ProcessLabeled(string, Vector<double>)
Declaration
private void ProcessLabeled(string label, Vector<double> x)
Parameters
Project(Vector<double>)
Declaration
public Vector<double> Project(Vector<double> x)
Parameters
| Type |
Name |
Description |
| Vector<double> |
x |
|
Returns
| Type |
Description |
| Vector<double> |
|
RecomputeBetweenClassScatter()
Declaration
private void RecomputeBetweenClassScatter()
Reset()
Declaration
SetCurrentLabel(string)
Declaration
public void SetCurrentLabel(string label)
Parameters
| Type |
Name |
Description |
| string |
label |
|
TryDouble(IReadOnlyList<object>?, int, double)
Declaration
private static double TryDouble(IReadOnlyList<object>? p, int idx, double def)
Parameters
Returns
TryInt(IReadOnlyList<object>?, int, int)
Declaration
private static int TryInt(IReadOnlyList<object>? p, int idx, int def)
Parameters
Returns
UpdateProjection()
Declaration
private void UpdateProjection()
Implements