timeeval.adapters package

timeeval.adapters.base module

class timeeval.adapters.base.Adapter

Bases: ABC

The base class for all adapters. An adapter is a wrapper around an anomaly detection algorithm that allows to execute it in a standardized way with the TimeEval framework. A subclass of Adapter must implement the _call method that executes the algorithm and returns the results. Optionally, it can also implement the get_prepare_fn and get_finalize_fn methods that are called before and after the execution of the algorithm, respectively.

get_finalize_fn() Optional[Callable[[], None]]

This method is executed after all algorithms are run.

get_prepare_fn() Optional[Callable[[], None]]

This method is executed before all algorithms are run.

timeeval.adapters.distributed module

class timeeval.adapters.distributed.DistributedAdapter(algorithm: Callable[[Union[ndarray, Path], dict], Union[ndarray, Path]], remote_command: str, remote_user: str, remote_hosts: List[str])

Bases: Adapter

An adapter that allows to run a function as an anomaly detector on multiple remote machines. So far, this adapter only supports TSFunctions as algorithms. Please, be aware that you need password-less ssh to the remote machines!

Warning

This adapter is deprecated and will be removed in a future version of TimeEval.

Parameters
  • algorithm (TSFunction) – The function to run.

  • remote_command (str) – The command to run on the remote machines.

  • remote_user (str) – The user to use for the ssh connection.

  • remote_hosts (List[str]) – The hosts to connect to.

timeeval.adapters.docker module

class timeeval.adapters.docker.AlgorithmInterface(dataInput: pathlib.PurePath, dataOutput: pathlib.PurePath, modelInput: pathlib.PurePath, modelOutput: pathlib.PurePath, executionType: timeeval.data_types.ExecutionType, customParameters: Dict[str, Any] = <factory>)

Bases: object

customParameters: Dict[str, Any]
dataInput: PurePath
dataOutput: PurePath
executionType: ExecutionType
modelInput: PurePath
modelOutput: PurePath
to_json_string() str
class timeeval.adapters.docker.DockerAdapter(image_name: str, tag: str = 'latest', group_privileges: str = 'akita', skip_pull: bool = False, timeout: Optional[Duration] = None, memory_limit_overwrite: Optional[int] = None, cpu_limit_overwrite: Optional[float] = None)

Bases: Adapter

An adapter that allows to run a Docker image as an anomaly detector. You can find a list of available Docker images on GitHub.

Parameters
  • image_name (str) – The name of the Docker image to run.

  • tag (str) – The tag of the Docker image to run. Defaults to “latest”.

  • group_privileges (str) – The group privileges to use for the Docker container. Defaults to “akita”.

  • skip_pull (bool) – Whether to skip pulling the Docker image. Defaults to False.

  • timeout (Optional[Duration]) – The timeout for the Docker container. If not set, the timeout is taken from the ResourceConstraints.

  • memory_limit_overwrite (Optional[int]) – The memory limit for the Docker container. If not set, the memory limit is taken from the ResourceConstraints.

  • cpu_limit_overwrite (Optional[float]) – The CPU limit for the Docker container. If not set, the CPU limit is taken from the ResourceConstraints.

get_finalize_fn() Optional[Callable[[], None]]

This method is executed after all algorithms are run.

get_prepare_fn() Optional[Callable[[], None]]

This method is executed before all algorithms are run.

exception timeeval.adapters.docker.DockerAdapterInternalError

Bases: Exception

exception timeeval.adapters.docker.DockerAlgorithmFailedError

Bases: Exception

class timeeval.adapters.docker.DockerJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: NumpyEncoder

default(o: Any) Any

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
exception timeeval.adapters.docker.DockerMemoryError

Bases: Exception

exception timeeval.adapters.docker.DockerTimeoutError

Bases: Exception

timeeval.adapters.function module

class timeeval.adapters.function.FunctionAdapter(fn: Callable[[Union[ndarray, Path], dict], Union[ndarray, Path]])

Bases: Adapter

An adapter that allows to run a function as an anomaly detector.

Parameters

fn (TSFunction) – The function to run.

static identity() FunctionAdapter

timeeval.adapters.jar module

class timeeval.adapters.jar.JarAdapter(jar_file: str, output_file: str, args: List[Any], kwargs: Dict[str, Any], verbose: bool = False)

Bases: Adapter

An adapter that allows to run a jar file as an anomaly detector.

Warning

This adapter is deprecated and will be removed in a future version of TimeEval.

Parameters
  • jar_file (str) – The path to the jar file to run.

  • output_file (str) – The path to the file to which the jar file writes its output.

  • args (List[Any]) – The arguments to pass to the jar file.

  • kwargs (Dict[str, Any]) – The keyword arguments to pass to the jar file.

  • verbose (bool) – Whether to print the output of the jar file to the console.

timeeval.adapters.multivar module

class timeeval.adapters.multivar.AggregationMethod(value)

Bases: Enum

An enum that specifies how to aggregate the anomaly scores of the channels.

MAX = 2

aggregates channel scores using the element-wise max.

MEAN = 0

aggregates channel scores using the element-wise mean.

MEDIAN = 1

aggregates channel scores using the element-wise median.

SUM_BEFORE = 3

sums the channels before running the anomaly detector.

class timeeval.adapters.multivar.MultivarAdapter(adapter: Adapter, aggregation: AggregationMethod = AggregationMethod.MEAN)

Bases: Adapter

An adapter that allows to apply univariate anomaly detectors to multiple dimensions of a timeseries. In one case, the adapter runs the anomaly detector on each dimension separately and aggregates the results using the specified aggregation method. In the other case, the adapter combines the dimensions into a single timeseries and runs the anomaly detector on the combined timeseries.

Parameters
  • adapter (Adapter) – The Adapter that runs the anomaly detector on each dimension.

  • aggregation (AggregationMethod) – The AggregationMethod to use to combine the anomaly scores of the dimensions.

get_finalize_fn() Optional[Callable[[], None]]

This method is executed after all algorithms are run.

get_prepare_fn() Optional[Callable[[], None]]

This method is executed before all algorithms are run.