pyoe.algorithms package

Submodules

pyoe.algorithms.loss module

class pyoe.algorithms.loss.LossTemplate(net: Module, **kargws)

Bases: object

This is a template for loss function. We implemented some common loss functions and you can also implement your own loss function using this template.

abstract loss(x_window: Tensor, y_window: Tensor, y_outlier: Tensor | None = None, **kargws) float

This is the loss function. You can implement your own loss function here.

Parameters:
  • x_window (torch.Tensor) – The input data window.

  • y_window (torch.Tensor) – The target data window.

  • y_outlier (Optional[torch.Tensor]) – Optional outlier target data.

  • **kwargs – Additional optional parameters.

Returns:

The computed loss value.

Return type:

out (float)

class pyoe.algorithms.loss.classification_loss(net: Module, **kwargs)

Bases: LossTemplate

loss(x_window: Tensor, y_window: Tensor, y_outlier: Tensor | None = None, **kwargs)

This is the loss function. You can implement your own loss function here.

Parameters:
  • x_window (torch.Tensor) – The input data window.

  • y_window (torch.Tensor) – The target data window.

  • y_outlier (Optional[torch.Tensor]) – Optional outlier target data.

  • **kwargs – Additional optional parameters.

Returns:

The computed loss value.

Return type:

out (float)

class pyoe.algorithms.loss.classification_loss_tree(net: Module, **kwargs)

Bases: LossTemplate

loss(x_window: Tensor, y_window: Tensor, y_outlier: Tensor | None = None, **kwargs)

This is the loss function. You can implement your own loss function here.

Parameters:
  • x_window (torch.Tensor) – The input data window.

  • y_window (torch.Tensor) – The target data window.

  • y_outlier (Optional[torch.Tensor]) – Optional outlier target data.

  • **kwargs – Additional optional parameters.

Returns:

The computed loss value.

Return type:

out (float)

class pyoe.algorithms.loss.regression_loss(net: Module, **kwargs)

Bases: LossTemplate

loss(x_window: Tensor, y_window: Tensor, y_outlier: Tensor | None = None, **kwargs)

This is the loss function. You can implement your own loss function here.

Parameters:
  • x_window (torch.Tensor) – The input data window.

  • y_window (torch.Tensor) – The target data window.

  • y_outlier (Optional[torch.Tensor]) – Optional outlier target data.

  • **kwargs – Additional optional parameters.

Returns:

The computed loss value.

Return type:

out (float)

class pyoe.algorithms.loss.regression_loss_tree(net: Module, **kwargs)

Bases: LossTemplate

loss(x_window: Tensor, y_window: Tensor, y_outlier: Tensor | None = None, **kwargs)

This is the loss function. You can implement your own loss function here.

Parameters:
  • x_window (torch.Tensor) – The input data window.

  • y_window (torch.Tensor) – The target data window.

  • y_outlier (Optional[torch.Tensor]) – Optional outlier target data.

  • **kwargs – Additional optional parameters.

Returns:

The computed loss value.

Return type:

out (float)

pyoe.algorithms.trainer module

class pyoe.algorithms.trainer.ClusterTrainer(dataloader: Dataloader, model: ModelTemplate, preprocessor: Preprocessor, **kargws)

Bases: TrainerTemplate

This class is a training wrapper for the model. It will call the model’s training function to train the model. Actually ClusterModel is trained in an online manner, so we don’t need to train it in a batch manner.

train(need_test: bool = False) None

This function is used to train the model with clustering task.

Parameters:

need_test (bool) – If this parameter is True, the accurate loss will be calculated during training.

class pyoe.algorithms.trainer.IcarlTrainer(dataloader: Dataloader, model: ModelTemplate, preprocessor: Preprocessor, lr: float = 0.01, epochs: int = 1, batch_size: int = 128, buffer_size: int = 100, **kargws)

Bases: TrainerTemplate

This class is a training wrapper for the model. It will call the model’s preprocessing and training function to train the model.

train(need_test: bool = False) None

This function is used to train the model with regression or classification task using iCaRL algorithm.

Parameters:

need_test (bool) – If this parameter is True, the accurate loss will be calculated during training.

class pyoe.algorithms.trainer.MultiProcessTrainer(world_size: int, dataloader: Dataloader, trainer: TrainerTemplate, preprocessor: Preprocessor)

Bases: TrainerTemplate

This is a multi-process training function. It will create a distributed dataloader and train the model using the distributed data.

train(need_test=False)

This function is used to train the model using multi-process.

Parameters:

need_test (bool) – If this parameter is True, the accurate loss will be calculated during training.

class pyoe.algorithms.trainer.NaiveTrainer(dataloader: Dataloader, model: ModelTemplate, preprocessor: Preprocessor, lr: float = 0.01, epochs: int = 1, batch_size: int = 64, buffer_size: int = 100, **kargws)

Bases: TrainerTemplate

This class is a training wrapper for the model. It will call the model’s preprocessing and training function to train the model.

train(need_test: bool = False) None

This function is used to train the model with regression or classification task using naive algorithm.

Parameters:

need_test (bool) – If this parameter is True, the accurate loss will be calculated during training.

class pyoe.algorithms.trainer.TrainerTemplate(dataloader: Dataloader, model: ModelTemplate, preprocessor: Preprocessor, lr: float = 0.01, epochs: int = 1, batch_size: int = 64, buffer_size: int = 100, **kargws)

Bases: object

This is a template for training function. We implemented some common training functions and you can also implement your own training function using this template.

get_last_training_time() float | None

This function is used to get the last training time.

Returns:

The last training time.

Return type:

out (Optional[float])

abstract train(need_test: bool = False) None

This is the training function. You can implement your own training function here.

Parameters:

need_test (bool) – If this parameter is True, the accurate loss will be calculated during training.

Module contents