Skip to content

Add Stream Weighted Average #212

@matthias-wende-frequenz

Description

What's needed?

A weighted moving average implementation that updates the avg whenever a new data sample arrives from the stream.

Proposed solution

We can use the MovingWindow class. Whenever the MovingWindow gets updated it triggers the update of the mean.

Right now, the MovingWindow doesn't support sending events on update.

We propose two different implementation approaches.

  • Add a output trigger channel that informs downstream actors about an update of the window.
  • The moving average is implemented as part of the MovingWindow and downstream users can request an output channel.

The weights can be user defined by an iterator of weights. When no weight is provided the average is supposed to return the arithmetic average. We might also want to provide a couple of defaults, e.g. exponential.

Example

window = MovingWindow(100, resampled_data_recv)
# use the latest three values for the weighted average
ma_recv = window.moving_avg(weights=[0.2, 0.3, 0.5])
...

Example (exponential)

window = MovingWindow(100, resampled_data_recv)
# use the latest three values for the weighted average
ma_recv = window.moving_avg(exponential_weights(num=10))
...

Use cases

The main use case is feature extraction for ML applications.

Alternatives and workarounds

No response

Additional context

No response

Metadata

Metadata

Labels

part:data-pipelineAffects the data pipelinepriority:URGENTAddress this immediately or the sky will fallresolution:wontfixThis will not be worked ontype:enhancementNew feature or enhancement visitble to users

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions