Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forecast Service with weighted exponential averaging #526

Closed
pierrekil opened this issue Nov 10, 2021 · 1 comment
Closed

Forecast Service with weighted exponential averaging #526

pierrekil opened this issue Nov 10, 2021 · 1 comment
Assignees
Labels
Feature Development of new feature

Comments

@pierrekil
Copy link
Member

pierrekil commented Nov 10, 2021

Generic approach to add forecasting:

As a user I want to create a new attribute to an asset which stores forecasted data:

  • I add an attribute
  • I can add the configuration item 'forecast'
  • I see a parameter 'forecast methods' and select the method 'time-series weighted exponential'
    • (see below for additional parameters)
  • The forecast get's filled with the forecasted data.

Additional parameters, when selecting 'forecast methods': 'time-series weighted exponential'

  • I optionally select which 'Attribute' is used as input (dropdown with attributes of same asset). As a fefault it's using the same attribute.
  • 'Repeat period', enum with options: day, week (called P in the formula)
  • 'Period range', positive integer (called R in the formula, >=1)
  • 'Interval size (hour)', the interval at which the forecast is being calculated

The 'Repeat period' P indicates the increment at which the forecast needs to look back for historical values.
The 'Period range' R indicates the number of periods to look back

Include hourly forecasts for the future day or week (depending on 'Repeat period')

a = 2/(R+1)
for R = 1: Attribute_t = Attribute_t-P * a
for R = 2: Attribute_t = Attribute_t-P * a + (1-a) * (Attribute_t-2P)
for R = 3: Attribute_t = Attribute_t-P * a + (1-a) * (Attribute_t-2P * a + (1-a) * (Attribute_t-3P)) 
for R = 4: Attribute_t = Attribute_t-P * a + (1-a) * (Attribute_t-2P * a + (1-a) * (Attribute_t-3P * a + (1-a) * (Attribute_t-4P)))
etc...
@pierrekil pierrekil changed the title Time series forecast Forecast weighted exponential averaging Dec 23, 2021
@pierrekil pierrekil added the Feature Development of new feature label Dec 23, 2021
@pierrekil pierrekil changed the title Forecast weighted exponential averaging Forecast - weighted exponential averaging Dec 7, 2022
@richturner richturner changed the title Forecast - weighted exponential averaging Forecast Service with weighted exponential averaging Jan 5, 2023
@richturner
Copy link
Member

As a user I want to create a forecast for an attribute based on the attribute's past data using the weighted exponential average algorithm; the forecast data should then be retrievable from the existing forecast HTTP API.

  1. Add the configuration item forecast to the attribute to generate a forecast; the value type should be a JSON schema that allows all relevant parameters to be configured for weighted exponential average calculation (see below)
  2. Backend reacts to configuration item CRUD and starts/stops a scheduled task to periodically calculate forecast data and to store it using the AssetPredictedDatapointService

Forecast configuration item

  • type - The algorithm to use for now only wea supported (this can be used as @JsonTypeName for deserialisation)
  • pastPeriod - The period of time between each historical value to look back; should be a valid ISO8601 duration (called P in the formula)
  • pastCount The number of periods to look back; positive integer (called R in the formula, >=1)
  • forecastPeriod - The period of time between each forecast value to calculate; should be a valid ISO8601 duration
  • forecastCount - The number of forecast periods to calculate; positive integer

For example, the following defines an hourly forecast for 24h based on the data from the same day a week earlier using the past 4 weeks:

{
  "type": "wea",
  "pastPeriod": "P7D",
  "pastCount": 4,
  "forecastPeriod": "PT1H",
  "forecastCount": 24
}

Weighted Exponential Average Calculations

a = 2/(R+1)
Attributet = Attributet-p * a + (1-a) * (Attributet-pN (1-a) * (Attribute_t-3P))
for R = 1: Attributet = Attributet-P * a
for R = 2: Attributet = Attributet-P * a + (1-a) * Attributet-2P
for R = 3: Attributet = Attributet-P * a + (1-a) * (Attributet-2P * a + (1-a) * Attributet-3P)
for R = 4: Attributet = Attributet-P * a + (1-a) * (Attributet-2P * a + (1-a) * (Attributet-3P * a + (1-a) * Attributet-4P))
etc...

Notes

  • Forecast data points should have consistent timestamps so each iteration replaces the previous value(s)
  • Forecast service needs to find all 'Forecast' configuration items at startup and also monitor AssetEvents (see AgentService monitoring of AgentLink configuration items as an example)
  • Use a single scheduled task for generating all forecast data in series (to minimise load on the system)

Tasks

  • Create abstract ForecastConfiguration class with type field and create concrete sub type ForecastConfigurationWeightedExponentialAverage
  • Add FORECAST meta item descriptor to MetaItemType with type of ForecastConfiguration
  • Create ForecastService (see AgentService for guidance on initialising, getting FORECAST attributes and reacting to asset changes and see ForecastWindService for guidance on storing predicted data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Development of new feature
Projects
None yet
Development

No branches or pull requests

3 participants