Base Methods

class pycast.methods.basemethod.BaseMethod(requiredParameters=None, hasToBeSorted=True, hasToBeNormalized=True)[source]

Bases: pycast.common.pycastobject.PyCastObject

Baseclass for all smoothing and forecasting methods.

__init__(requiredParameters=None, hasToBeSorted=True, hasToBeNormalized=True)[source]

Initializes the BaseMethod.

Parameters:
  • requiredParameters (list) – List of parameternames that have to be defined.
  • hasToBeSorted (boolean) – Defines if the TimeSeries has to be sorted or not.
  • hasToBeNormalized (boolean) – Defines if the TimeSeries has to be normalized or not.
_get_parameter_intervals()[source]

Returns the intervals for the methods parameter.

Only parameters with defined intervals can be used for optimization!

Returns:Returns a dictionary containing the parameter intervals, using the parameter name as key, while the value hast the following format: [minValue, maxValue, minIntervalClosed, maxIntervalClosed]
  • minValue
    Minimal value for the parameter
  • maxValue
    Maximal value for the parameter
  • minIntervalClosed
    True, if minValue represents a valid value for the parameter. False otherwise.
  • maxIntervalClosed:
    True, if maxValue represents a valid value for the parameter. False otherwise.
Return type:dictionary
_get_value_error_message_for_invalid_prarameter(parameter, value)[source]

Returns the ValueError message for the given parameter.

Parameters:
  • parameter (string) – Name of the parameter the message has to be created for.
  • value (numeric) – Value outside the parameters interval.
Returns:

Returns a string containing hte message.

Return type:

string

_in_valid_interval(parameter, value)[source]

Returns if the parameter is within its valid interval.

Parameters:
  • parameter (string) – Name of the parameter that has to be checked.
  • value (numeric) – Value of the parameter.
Returns:

Returns True it the value for the given parameter is valid, False otherwise.

Return type:

boolean

can_be_executed()[source]

Returns if the method can already be executed.

Returns:Returns True if all required parameters where already set, False otherwise.
Return type:boolean
execute(timeSeries)[source]

Executes the BaseMethod on a given TimeSeries object.

Parameters:timeSeries (TimeSeries) – TimeSeries object that fullfills all requirements (normalization, sortOrder).
Returns:Returns a TimeSeries object containing the smoothed/forecasted values.
Return type:TimeSeries
Raise:Raises a NotImplementedError if the child class does not overwrite this function.
get_interval(parameter)[source]

Returns the interval for a given parameter.

Parameters:parameter (string) – Name of the parameter.
Returns:Returns a list containing with [minValue, maxValue, minIntervalClosed, maxIntervalClosed]. If no interval definitions for the given parameter exist, None is returned.
  • minValue
    Minimal value for the parameter
  • maxValue
    Maximal value for the parameter
  • minIntervalClosed
    True, if minValue represents a valid value for the parameter. False otherwise.
  • maxIntervalClosed:
    True, if maxValue represents a valid value for the parameter. False otherwise.
Return type:list
get_parameter(name)[source]

Returns a forecasting parameter.

Parameters:name (string) – Name of the parameter.
Returns:Returns the value stored in parameter.
Return type:numeric
Raise:Raises a KeyError if the parameter is not defined.
get_required_parameters()[source]

Returns a list with the names of all required parameters.

Returns:Returns a list with the names of all required parameters.
Return type:list
has_to_be_normalized()[source]

Returns if the TimeSeries has to be normalized or not.

Returns:Returns True if the TimeSeries has to be normalized, False otherwise.
Return type:boolean
has_to_be_sorted()[source]

Returns if the TimeSeries has to be sorted or not.

Returns:Returns True if the TimeSeries has to be sorted, False otherwise.
Return type:boolean
set_parameter(name, value)[source]

Sets a parameter for the BaseMethod.

Parameters:
  • name (string) – Name of the parameter that has to be checked.
  • value (numeric) – Value of the parameter.
_interval_definitions = {False: ['(', ')'], True: ['[', ']']}
class pycast.methods.basemethod.BaseForecastingMethod(requiredParameters=None, valuesToForecast=1, hasToBeSorted=True, hasToBeNormalized=True)[source]

Bases: pycast.methods.basemethod.BaseMethod

Basemethod for all forecasting methods.

__init__(requiredParameters=None, valuesToForecast=1, hasToBeSorted=True, hasToBeNormalized=True)[source]

Initializes the BaseForecastingMethod.

Parameters:
  • requiredParameters (list) – List of parameternames that have to be defined.
  • valuesToForecast (integer) – Number of entries that will be forecasted. This can be changed by using forecast_until().
  • hasToBeSorted (boolean) – Defines if the TimeSeries has to be sorted or not.
  • hasToBeNormalized (boolean) – Defines if the TimeSeries has to be normalized or not.
Raise:

Raises a ValueError when valuesToForecast is smaller than zero.

_calculate_values_to_forecast(timeSeries)[source]

Calculates the number of values, that need to be forecasted to match the goal set in forecast_until.

This sets the parameter “valuesToForecast” and should be called at the beginning of the BaseMethod.execute() implementation.

Parameters:timeSeries (TimeSeries) – Should be a sorted and normalized TimeSeries instance.
Raise:Raises a ValueError if the TimeSeries is either not normalized or sorted.
forecast_until(timestamp, format=None)[source]

Sets the forecasting goal (timestamp wise).

This function enables the automatic determination of valuesToForecast.

Parameters:
  • timestamp – timestamp containing the end date of the forecast.
  • format (string) – Format of the timestamp. This is used to convert the timestamp from UNIX epochs, if necessary. For valid examples take a look into the time.strptime() documentation.
get_optimizable_parameters()[source]

Returns a list with optimizable parameters.

All required parameters of a forecasting method with defined intervals can be used for optimization.

Returns:Returns a list with optimizable parameter names.
Return type:list
Todo:Should we return all parameter names from the self._parameterIntervals instead?
set_parameter(name, value)[source]

Sets a parameter for the BaseForecastingMethod.

Parameters:
  • name (string) – Name of the parameter.
  • value (numeric) – Value of the parameter.

Previous topic

pycast Smoothing and Forecasting Methods

Next topic

Smoothing Methods

This Page