Skip to content

Add moving average option for ML classifiers (fixes #640) - #858

Open
samerzumot wants to merge 3 commits into
brainflow-dev:masterfrom
samerzumot:feature/issue-640-moving-average-classifier
Open

Add moving average option for ML classifiers (fixes #640)#858
samerzumot wants to merge 3 commits into
brainflow-dev:masterfrom
samerzumot:feature/issue-640-moving-average-classifier

Conversation

@samerzumot

Copy link
Copy Markdown
  • Implement MovingAverageClassifier in C++ core supporting custom scores and built-in metric models
  • Add MOVING_AVERAGE_CLASSIFIER enum across Python, Java, C#, TypeScript, Rust, Swift, Julia, and MATLAB bindings
  • Add automated test moving_average_classifier.py

- Implement MovingAverageClassifier in C++ core supporting custom scores and built-in metric models
- Add MOVING_AVERAGE_CLASSIFIER enum across Python, Java, C#, TypeScript, Rust, Swift, Julia, and MATLAB bindings
- Add automated test moving_average_classifier.py
@Andrey1994
Andrey1994 self-requested a review September 1, 2026 22:22

@Andrey1994 Andrey1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi, I was thinking about adding moving average option to already existing classifiers instead of adding a new classifier type.
To enable it or not other_info field can be used.
In terms of implementation will need to think how to make it generic and uniform for all classifier types

- Remove MOVING_AVERAGE_CLASSIFIER enum across all language bindings
- Implement generic moving average smoothing in BaseClassifier using NVI pattern
- Support moving average configuration via other_info (JSON, key-value, integer)
- Support multi-channel smoothing with bounded window history
- Update automated tests for existing classifiers with moving average
…est, newline and BOM fixes

- Make BaseClassifier public NVI methods non-virtual
- Document other_info moving average behavior for DynLibClassifier plugin authors
- Add multi-element vector output moving average test with DynLibClassifier
- Fix missing trailing newlines in mindfulness_classifier.cpp and BrainFlowClassifiers.m
- Remove BOM in C# library file to clean up diff
@samerzumot

Copy link
Copy Markdown
Author

Hi @Andrey1994,

Thanks for the feedback! I've updated the implementation according to your suggestion:

  1. Removed the Standalone Classifier
  2. Generic Implementation in BaseClassifier:
    • This makes moving average support completely generic and uniform across all classifier types—supporting both scalar outputs (Mindfulness, Restfulness) and multi-channel vector outputs (ONNX, DynLib).
    • Third-party .dll/.so plugin symbol resolution ("prepare", "predict", "release") in DynLibClassifier remains 100% unchanged.
  3. other_info Parsing:
    • Accepts JSON ({"window_len": 4}, {"moving_average": true}, {"period": 5}), key-value (moving_average=5, window_len=4), or simple integer string ("3").
    • Defaults to DEFAULT_MOVING_AVERAGE_WINDOW = 5 when a flag without a window length is provided.
    • Moving average is only activated if recognized keys are found; arbitrary strings or unrelated JSON configs for custom plugins leave moving average disabled to prevent unintended collisions.
  4. Memory Bounded: The sliding window history is explicitly trimmed upon every prediction cycle.
  5. Tests: Updated moving_average_classifier.py with comprehensive tests covering baseline raw predictions, window smoothing, restfulness score inversion, default fallbacks, key-value syntax, negative tests, and multi-element vector output via DynLibClassifier.

Please take a look when you get a chance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants