MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / set_forecaster

Method set_forecaster

src/pymgrid/microgrid/microgrid.py:527–601  ·  view source on GitHub ↗

Set the forecaster for timeseries modules in the microgrid. You may either pass in a single value for ``forecaster`` to apply the same forecasting logic to all timeseries modules, or pass key-value pairs in a ``dict`` to set the forecaster for specific modules. In the latte

(self,
                       forecaster,
                       forecast_horizon=DEFAULT_HORIZON,
                       forecaster_increase_uncertainty=False,
                       forecaster_relative_noise=False)

Source from the content-addressed store, hash-verified

525 return df.to_dict()
526
527 def set_forecaster(self,
528 forecaster,
529 forecast_horizon=DEFAULT_HORIZON,
530 forecaster_increase_uncertainty=False,
531 forecaster_relative_noise=False):
532 """
533 Set the forecaster for timeseries modules in the microgrid.
534
535 You may either pass in a single value for ``forecaster`` to apply the same forecasting logic to all timeseries
536 modules, or pass key-value pairs in a ``dict`` to set the forecaster for specific modules. In the latter case,
537 you may also set different forecasters for each named module. See :meth:`.get_forecaster` for additional details
538 on setting forecasters.
539
540 forecaster : callable, float, "oracle", None, or dict.
541 Function that gives a forecast n-steps ahead.
542
543 * If ``callable``, must take as arguments ``(val_c: float, val_{c+n}: float, n: int)``, where
544
545 * ``val_c`` is the current value in the time series: ``self.time_series[self.current_step]``
546
547 * ``val_{c+n}`` is the value in the time series n steps in the future
548
549 * n is the number of steps in the future at which we are forecasting.
550
551 The output ``forecast = forecaster(val_c, val_{c+n}, n)`` must have the same sign
552 as the inputs ``val_c`` and ``val_{c+n}``.
553
554 * If ``float``, serves as a standard deviation for a mean-zero gaussian noise function
555 that is added to the true value.
556
557 * If ``"oracle"``, gives a perfect forecast.
558
559 * If ``None``, no forecast.
560
561 * If ``dict``, must contain key-value pairs of the form ``module_name: forecaster``.
562 Will set the forecaster of the module corresponding to ``module_name`` using the logic above.
563
564
565 forecast_horizon : int
566 Number of steps in the future to forecast. If forecaster is None, this parameter is ignored and the resultant
567 horizon will be zero.
568
569 forecaster_increase_uncertainty : bool, default False
570 Whether to increase uncertainty for farther-out dates if using a GaussianNoiseForecaster. Ignored otherwise.
571
572 forecaster_relative_noise : bool, default False
573 Whether to define noise standard deviation relative to mean of time series if using
574 :class:`.GaussianNoiseForecaster`. Ignored otherwise.
575
576 """
577 if isinstance(forecaster, dict):
578 for module_name, _forecaster in forecaster.items():
579 if module_name not in self._modules.names():
580 raise NameError(f'Unrecognized module {module_name}.')
581
582 try:
583 self._modules[module_name].set_forecaster(
584 _forecaster,

Calls 2

namesMethod · 0.80
iterlistMethod · 0.80