Repository navigation
Add a PeriodicFeatureExtractor #120
Description
What's needed?
For forecasting we have been using average load and production profiles.
Given a time series, we want a module that is able to calculate the item wise average of repeating time windows of the same size and the same sample-rate, possibly all having the same distance.
Example:
Consider the time series
Hence we get the sub-series
Note: A position could likewise be a timestamp in a usual time-series representation.
Proposed solution
We want to design such a module in a way such that it
- uses batches of data (most likely cached in memory)
- is designed to work together with the data structure defined here
- it should be able to run calculations on demand and memoize the result
Use cases
It's been used for calculating average load and production profiles certain days.
For example it could just calculate the average load of some consume of the last seven days as well as the average PV production of the last four Tuesdays.
Alternatives and workarounds
It's possible to run the calculation and update the mean on a data stream whenever a new sample arrives. However we plan on storing batches of data in any case, as this can be used as a feature for ml models, and thus calculating the averages from the batches seems obvious.
Additionally this option hasn't been further explored so far.
Additional context
We have had a use-case where we where looking at a full days averaged data plus a 15 minute margin. Thus we will need to add a margin for a window size in order to re-engineer this feature.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
mathias-baumann-frequenz commentedon Dec 20, 2022
We'll probably be able to use https://numpy.org/doc/stable/reference/generated/numpy.lib.stride_tricks.as_strided.html#numpy.lib.stride_tricks.as_strided for accessing arrays in strides in numpy
possilby helpful: https://numpy.org/doc/stable/reference/generated/numpy.mean.html
matthias-wende-frequenz commentedon Dec 20, 2022
We need a margin around the window, such that we can say we want a specific load profile of a certain weekday +-15min. That would translate to the following parameters:
We could also consider introducing independent left and right margins.
Note: maybe we want padding (the one that goes to the outside)
matthias-wende-frequenz commentedon Dec 21, 2022
Indeed useful. We can
reshapethe array into an 2 dimensional first and use thewherearray to select which values to include, i.e. leaf out all values that are not in any window or window margin. Using numpy's internal functions is likely faster then iterating over the values in python for calculating the mean.matthias-wende-frequenz commentedon Dec 22, 2022
Note: Average Time Series can be empty or a series of zeros because there is not enough data existing in the buffer or the buffer is full of NaN or in case the averaging calculation hasn't finished in time.
matthias-wende-frequenz commentedon Dec 22, 2022
Should be able to calculate mean, standard deviation and polynomial coefficients.
12 remaining items
thomas-nicolai-frequenz commentedon Apr 6, 2023
Thats not a question about the MovingWindow but rather application level of what the fallback behaviour would/should look like. Can you put that on the DS agenda?
cwasicki commentedon Apr 6, 2023
Yes, it's about model training. We are using data frames for this, so essentially numpy arrays. If it's possible we could apply only the TimeSeriesAverager from the SDK already now for creating features on our training data. Example could look like:
Sure, the application should always be responsible how this is handled. There should still be a clearly defined behaviour of the TimeSeriesAverager in this case. Added it to the agenda.
matthias-wende-frequenz commentedon Apr 6, 2023
@cwasicki can you please define what you mean by min, max, std in this context?
cwasicki commentedon Apr 6, 2023
For the TimeSeriesAverager you select a subset of the moving window and then take the average of these values. Similarly, you could also get the maximum, minimum or standard deviation on this subset. For instance, what was the maximum value in a specific time period of the day over the last 7 days.
thomas-nicolai-frequenz commentedon Apr 8, 2023
@cwasicki is that the min, max and std of the averaged timeseries or the underlying MovingWindow? @matthias-wende-frequenz that indeed raises a good question if renaming the TimeseriesAverager to MovingWindowAverager is really to way to go. At the very end the derived timeseries isn't really anymore connected the the MovingWindow itself that contains raw data whereas the TimeseriesAvergager contains derived statistical measures from the MovingWindow.
cwasicki commentedon Apr 11, 2023
I meant the underlying moving window. To clarify with an example: Assuming it's 15:00. Based on a time series window with data points every 15 min for the last 28 days, if you want to have the minimum for a time period of today 10:00 - 10:30 (i.e. two data points) and a distance of 7 days (i.e. 4 times a window with 2 data points) you would receive two values. The first value is the minimum value of the four values of 10:00-10:15 data points today, 7, 14 and 21 days ago. Equivalently you determine the second value, but for the 10:15-10:30 data points instead.
cwasicki commentedon Apr 11, 2023
A potential use-case could be for a PV forecast: the production of a recent sunny day gives you at least some indication of the potential of your PV system for the given time period. You can get some estimate by taking the maximum of that time period over the last couple of days. In contrast to that, the production on cloudy days don't tell you much about the future unless you combine it with very good weather forecast data.
[-]Design Timeseries Average (Mean) Calculator[/-][+]Add a `PeriodicFeatureExtractor`[/+]Add PeriodicFeatureExtractor (frequenz-floss#299)