Optimization Methods

class pycast.optimization.baseoptimizationmethod.BaseOptimizationMethod(errorMeasureClass, errorMeasureInitializationParameters=None, precision=-1)[source]

Bases: pycast.common.pycastobject.PyCastObject

Baseclass for all optimization methods.

__init__(errorMeasureClass, errorMeasureInitializationParameters=None, precision=-1)[source]

Initializes the optimization method.

Parameters:
  • errorMeasureClass (BaseErrorMeasure) – Error measure class from pycast.errors.
  • errorMeasureInitializationParameters (dictionary) – Parameters used to initialize the errorMeasureClass. This dictionary will be passed to the errorMeasureClass as **kwargs.
  • precision (integer) – Defines the accuracy for parameter tuning in 10^precision. This parameter has to be an integer in [-7, 0].
Raise:

Raises a TypeError if errorMeasureClass is not a valid class. Valid classes are derived from pycast.errors.BaseErrorMeasure.

Raise:

Raises a ValueError if precision is not in [-7, 0].

optimize(timeSeries, forecastingMethods=None)[source]

Runs the optimization on the given TimeSeries.

Parameters:
  • timeSeries (TimeSeries) – TimeSeries instance that requires an optimized forecast.
  • forecastingMethods (list) – List of forecastingMethods that will be used for optimization.
Returns:

Returns the optimized forecasting method with the smallest error.

Return type:

(BaseForecastingMethod, Dictionary)

Raise:

Raises a ValueError ValueError if no forecastingMethods is empty.

class pycast.optimization.gridsearch.GridSearch(errorMeasureClass, errorMeasureInitializationParameters=None, precision=-1)[source]

Bases: pycast.optimization.baseoptimizationmethod.BaseOptimizationMethod

Implements the grid search method for parameter optimization.

GridSearch is the brute force method.

_generate_next_parameter_value(parameter, forecastingMethod)[source]

Generator for a specific parameter of the given forecasting method.

Parameters:
  • parameter (string) – Name of the parameter the generator is used for.
  • forecastingMethod (BaseForecastingMethod) – Instance of a ForecastingMethod.
Returns:

Creates a generator used to iterate over possible parameters.

Return type:

generator

optimization_loop(timeSeries, forecastingMethod, remainingParameters, currentParameterValues=None)[source]

The optimization loop.

This function is called recursively, until all parameter values were evaluated.

Parameters:
  • timeSeries (TimeSeries) – TimeSeries instance that requires an optimized forecast.
  • forecastingMethod (BaseForecastingMethod) – ForecastingMethod that is used to optimize the parameters.
  • remainingParameters (list) – List containing all parameters with their corresponding values that still need to be evaluated. When this list is empty, the most inner optimization loop is reached.
  • currentParameterValues (dictionary) – The currently evaluated forecast parameter combination.
Returns:

Returns a list containing a BaseErrorMeasure instance as defined in BaseOptimizationMethod.__init__() and the forecastingMethods parameter.

Return type:

list

optimize(timeSeries, forecastingMethods=None, startingPercentage=0.0, endPercentage=100.0)[source]

Runs the optimization of the given TimeSeries.

Parameters:
  • timeSeries (TimeSeries) – TimeSeries instance that requires an optimized forecast.
  • forecastingMethods (list) – List of forecastingMethods that will be used for optimization.
  • startingPercentage (float) – Defines the start of the interval. This has to be a value in [0.0, 100.0]. It represents the value, where the error calculation should be started. 25.0 for example means that the first 25% of all calculated errors will be ignored.
  • endPercentage (float) – Defines the end of the interval. This has to be a value in [0.0, 100.0]. It represents the value, after which all error values will be ignored. 90.0 for example means that the last 10% of all local errors will be ignored.
Returns:

Returns the optimized forecasting method, the corresponding error measure and the forecasting methods parameters.

Return type:

[BaseForecastingMethod, BaseErrorMeasure, Dictionary]

Raise:

Raises a ValueError ValueError if no forecastingMethods is empty.

optimize_forecasting_method(timeSeries, forecastingMethod)[source]

Optimizes the parameters for the given timeSeries and forecastingMethod.

Parameters:
  • timeSeries (TimeSeries) – TimeSeries instance, containing hte original data.
  • forecastingMethod (BaseForecastingMethod) – ForecastingMethod that is used to optimize the parameters.
Returns:

Returns a tuple containing only the smallest BaseErrorMeasure instance as defined in BaseOptimizationMethod.__init__() and the forecastingMethods parameter.

Return type:

tuple

Previous topic

Custom Error Measures

Next topic

Performance Optimization

This Page