flexmeasures.data.models.forecasting.pipelines.train_predict

Classes

class flexmeasures.data.models.forecasting.pipelines.train_predict.TrainPredictPipeline(config: dict | None = None, delete_model: bool = False, save_config: bool = True, save_parameters: bool = False)
__init__(config: dict | None = None, delete_model: bool = False, save_config: bool = True, save_parameters: bool = False)

Base class for the Schedulers, Reporters and Forecasters.

The configuration config stores static parameters, parameters that, if changed, trigger the creation of a new DataSource. Dynamic parameters, such as the start date, can go into the parameters. See docstring of the method DataGenerator.compute for more details. Nevertheless, the parameter save_parameters can be set to True if some parameters need to be saved to the DB. In that case, the method _clean_parameters is called to remove any field that is not to be persisted, e.g. time parameters which are already contained in the TimedBelief.

Create a new DataGenerator with a certain configuration. There are two alternatives to define the parameters:

  1. Serialized through the keyword argument config.

  2. Deserialized, passing each parameter as keyword arguments.

The configuration is validated using the schema _config_schema, to be defined by the subclass.

config cannot contain the key config at its top level, otherwise it could conflict with the constructor keyword argument config when passing the config as deserialized attributes.

Example:

The configuration requires two parameters for the PV and consumption sensors.

Option 1:
dg = DataGenerator(config = {

“sensor_pv” : 1, “sensor_consumption” : 2

})

Option 2:

sensor_pv = Sensor.query.get(1) sensor_consumption = Sensor.query.get(2)

dg = DataGenerator(sensor_pv = sensor_pv,

sensor_consumption = sensor_consumption)

Parameters:
  • config – serialized config parameters, defaults to None

  • save_config – whether to save the config into the data source attributes

  • save_parameters – whether to save the parameters into the data source attributes

_compute_forecast(as_job: bool = False, **kwargs) list[dict[str, Any]]

Overwrite with the actual computation of your forecast.

Parameters:

as_job – If True, runs as a job.

Returns:

List of dictionaries, for example: [

{

“sensor”: 501, “data”: <a BeliefsDataFrame>,

},

]

_config_schema: Schema | None = <TrainPredictPipelineConfigSchema(many=False)>
_derive_training_period() tuple[datetime, datetime]

Derive the effective training period for model fitting.

The training period ends at predict_start and starts at the most restrictive (latest) of the following:

  • The configured start_date (if any)

  • predict_start - train_period_in_hours (if configured)

  • predict_start - max_training_period (always enforced)

Additionally, the resulting training window is guaranteed to span at least two days.

Returns:

A tuple (train_start, train_end) defining the training window.

run_cycle(train_start: datetime, train_end: datetime, predict_start: datetime, predict_end: datetime, counter: int, multiplier: int, **kwargs)

Runs a single training and prediction cycle.

run_wrap_up(cycle_job_ids: list[str])

Log the status of all cycle jobs after completion.