dtw_metricTimeSeriesWrapper
Python template · sinapsis_darts_forecasting.templates.time_series_metrics
Overview
Dynamic Template for Darts metrics computation.
This template wraps any metric from the `darts.metrics` module and makes it available as a Sinapsis template. The wrapped metric is applied to the predictions and ground truth of each time series packet in the input container, and the result is stored in the `generic_data` field of the time series packet.
IMPORTANT NOTE: Validation mode should be enabled during model fitting and prediction (e.g., in the `TimeSeriesModel` template), to ensure that the metric is computed on the correct portion of the time series (i.e., the forecast horizon). If validation mode is not enabled, forecasted values and ground truth values may not be properly aligned, which can lead to incorrect metric calculations.
dtw_metric — inherited documentation
Applies Dynamic Time Warping to `actual_series` and `pred_series` before passing it into the metric. Enables comparison between series of different lengths, phases and time indices.
Defaults to using :func:`~darts.metrics.metrics.mae` as a metric.
See :func:`~darts.dataprocessing.dtw.dtw.dtw` for more supported parameters.
Parameters ---------- actual_series The (sequence of) actual series. pred_series The (sequence of) predicted series. metric The selected metric with signature '[[TimeSeries, TimeSeries], float]' to use. Default: `mae`. component_reduction Optionally, a function to aggregate the metrics over the component/column axis. It must reduce a `np.ndarray` of shape `(t, c)` to a `np.ndarray` of shape `(t,)`. The function takes as input a ``np.ndarray`` and a parameter named `axis`, and returns the reduced array. The `axis` receives value `1` corresponding to the component axis. If `None`, will return a metric per component. series_reduction Optionally, a function to aggregate the metrics over multiple series. It must reduce a `np.ndarray` of shape `(s, t, c)` to a `np.ndarray` of shape `(t, c)` The function takes as input a ``np.ndarray`` and a parameter named `axis`, and returns the reduced array. The `axis` receives value `0` corresponding to the series axis. For example with `np.nanmean`, will return the average over all series metrics. If `None`, will return a metric per component. n_jobs The number of jobs to run in parallel. Parallel jobs are created only when a ``Sequence[TimeSeries]`` is passed as input, parallelising operations regarding different ``TimeSeries``. Defaults to `1` (sequential). Setting the parameter to `-1` means using all the available processors. verbose Optionally, whether to print operations progress.
Returns ------- float A single metric score (when `len(q) <= 1`) for:
- a single univariate series. - a single multivariate series with `component_reduction`. - a sequence (list) of uni/multivariate series with `series_reduction` and `component_reduction`. np.ndarray A numpy array of metric scores. The array has shape (n components * n quantiles,) without component reduction, and shape (n quantiles,) with component reduction and `len(q) > 1`. For:
- the same input arguments that result in the `float` return case from above but with `len(q) > 1`. - a single multivariate series and at least `component_reduction=None`. - a sequence of uni/multivariate series including `series_reduction` and `component_reduction=None`. list[float] Same as for type `float` but for a sequence of series. list[np.ndarray] Same as for type `np.ndarray` but for a sequence of series.
Capabilities
Capabilities: not setInstallation
Install the published package using pip or uv.
pip install sinapsis-darts-forecasting==1.0.0uv pip install sinapsis-darts-forecasting==1.0.0uv add sinapsis-darts-forecasting==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Field used to set the template instance name and agent name. Defaults to None. dtw_metric!!! abstract "Usage Documentation" [Models](../concepts/models.md) A base class for creating Pydantic models. Attributes:… Read full field description
Field used to set the template instance name and agent name. Defaults to None. dtw_metric!!! abstract "Usage Documentation" [Models](../concepts/models.md) A base class for creating Pydantic models. Attributes: __class_vars__: The names of the class variables defined on the model. __private_attributes__: Metadata about the private attributes of the model. __signature__: The synthesized `__init__` [`Signature`][inspect.Signature] of the model. __pydantic_complete__: Whether model building is completed, or if there are still undefined fields. __pydantic_core_schema__: The core schema of the model. __pydantic_custom_init__: Whether the model has a custom `__init__` function. __pydantic_decorators__: Metadata containing the decorators defined on the model. This replaces `Model.__validators__` and `Model.__root_validators__` from Pydantic V1. __pydantic_generic_metadata__: A dictionary containing metadata about generic Pydantic models. The `origin` and `args` items map to the [`__origin__`][genericalias.__origin__] and [`__args__`][genericalias.__args__] attributes of [generic aliases][types-genericalias], and the `parameter` item maps to the `__parameter__` attribute of generic classes. __pydantic_parent_namespace__: Parent namespace of the model, used for automatic rebuilding of models. __pydantic_post_init__: The name of the post-init method for the model, if defined. __pydantic_root_model__: Whether the model is a [`RootModel`][pydantic.root_model.RootModel]. __pydantic_serializer__: The `pydantic-core` `SchemaSerializer` used to dump instances of the model. __pydantic_validator__: The `pydantic-core` `SchemaValidator` used to validate instances of the model. __pydantic_fields__: A dictionary of field names and their corresponding [`FieldInfo`][pydantic.fields.FieldInfo] objects. __pydantic_computed_fields__: A dictionary of computed field names and their corresponding [`ComputedFieldInfo`][pydantic.fields.ComputedFieldInfo] objects. __pydantic_extra__: A dictionary containing extra values, if [`extra`][pydantic.config.ConfigDict.extra] is set to `'allow'`. __pydantic_fields_set__: The names of fields explicitly set during instantiation. __pydantic_private__: Values of private attributes set on the model instance.
Optional
Default: null
Required
Default: null
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
templates:
- template_name: "dtw_metricTimeSeriesWrapper"
class_name: "dtw_metricTimeSeriesWrapper"
attributes:
dtw_metric: {}
Inheritance
sinapsis_darts_forecasting.templates.time_series_metrics.TimeSeriesMetricsEnvironment variables
Environment definitions belong to their canonical Python modules.