Class TrendClassificationActor
Actor that detects a decreasing trend (downward drift)
in numeric channel values using a sliding window and a slope-based metric.
Trend definition (slope-based)
For each channel, this classifier maintains the last windowSize numeric samples:
y0, y1, ..., y(n-1) with n = windowSize
It computes the slope b of the best-fit line y = a + b*x
using ordinary least squares, where x is the sample index 0..n-1:
b = Σ((xi - x̄)(yi - ȳ)) / Σ((xi - x̄)^2)
The slope is measured in "value units per sample". For SpO₂, that is "% per sample".
Directional warning condition
This classifier is configured to warn on decreasing trends only. A warning is raised when:
slope <= -delta
where delta is a non-negative threshold.
Persistence / Debouncing
To reduce false positives due to transient artifacts, the classifier optionally requires the
decreasing condition to hold for persistWindows consecutive evaluated windows before it emits a warning.
By default, persistWindows = 2.
Once in the "warning" state for a channel, this implementation emits a warning only on state entry, and resets once the condition is no longer met.
Inputs and outputs
- Input:
fireFunction(Map)is invoked with a snapshotchannel -> value. - Output: A warning message is published to each configured output channel and also logged.
Assumptions: snapshot values are numeric (Number). Non-numeric values throw
ClassCastException.
-
Field Summary
Fields inherited from class com.framed.cdss.Actor
id, inputChannels, outputChannels -
Constructor Summary
ConstructorsConstructorDescriptionTrendClassificationActor(EventBus eventBus, String id, org.json.JSONArray firingRules, org.json.JSONArray inputChannels, org.json.JSONArray outputChannels, org.json.JSONObject windowSizes, org.json.JSONObject persistWindows, org.json.JSONObject deltas, String direction) Constructs aTrendClassifierthat warns on decreasing trends using regression slope, with configurable persistence. -
Method Summary
Modifier and TypeMethodDescriptionvoidfireFunction(Map<String, Object> latestSnapshot) Updates per-channel windows with the newest snapshot values, computes the regression slope when enough samples exist, and emits warnings for channels exhibiting a persistent decreasing trend.Methods inherited from class com.framed.cdss.Actor
getInputChannels, getOutputChannels, valueMatchesExpected
-
Constructor Details
-
TrendClassificationActor
public TrendClassificationActor(EventBus eventBus, String id, org.json.JSONArray firingRules, org.json.JSONArray inputChannels, org.json.JSONArray outputChannels, org.json.JSONObject windowSizes, org.json.JSONObject persistWindows, org.json.JSONObject deltas, String direction) Constructs aTrendClassifierthat warns on decreasing trends using regression slope, with configurable persistence.- Parameters:
eventBus- the event bus used by this actor; must not benullid- identifier of this classifier (often set in configuration); must not benullfiringRules- firing rules as accepted byActor; must not benullinputChannels- channels observed by this classifier; must not benulloutputChannels- channels to publish warning messages to; must not benullwindowSizes- number of recent samples per channel used for trend detection; must be>= 2persistWindows- required number of consecutive satisfied windows; must be>= 1deltas- non-negative threshold per Channel; warning if slope<= -delta- Throws:
NullPointerException- if any required argument isnullIllegalArgumentException- ifwindowSize < 2,delta < 0, orpersistWindows < 1
-
-
Method Details
-
fireFunction
Updates per-channel windows with the newest snapshot values, computes the regression slope when enough samples exist, and emits warnings for channels exhibiting a persistent decreasing trend.Behavior per channel:
- If the channel is missing in the snapshot, it is skipped.
- The numeric value is appended to the channel window (oldest removed if full).
- Once the window is full, compute regression slope over the window.
- If slope
<= -delta, increment the persistence counter; otherwise reset it. - If the counter reaches
persistWindows, enter warning state and emit a warning once. - If slope no longer meets the condition, exit warning state.
- Specified by:
fireFunctionin classActor- Parameters:
latestSnapshot- snapshot mapchannel -> value; values must beNumber- Throws:
ClassCastException- if any encountered snapshot value is not numeric
-