Docs /Templates/ sinapsis-sktime

MACNNClassifierTorchSKTimeWrapper

sinapsis-sktimeSKTimedynamicinferencemodelsprediction

Python template · sinapsis_sktime.templates.sktime_classifiers

Overview

Template for SkTime classification model training and inference for the deep_learning module.

MACNNClassifierTorch — inherited documentation

Multi-Scale Attention Convolutional Neural Network (MACNN) classifier in PyTorch.

This classifier implements a multi-scale attention mechanism that learns feature representations across different temporal scales.

Parameters ---------- padding : str, default="same" The type of padding to be provided in MACNN Blocks. Used for pooling layers only. Convolution layers always use "same" padding, so that multi-scale outputs can be concatenated. pool_size : int, default=3 A single value representing pooling windows which are applied between two MACNN Blocks. strides : int, default=2 A single value representing strides to be taken during the pooling operation. repeats : int, default=2 The number of MACNN Blocks to be stacked. filter_sizes : tuple of int, default=(64, 128, 256) The filter sizes of Conv1D layers within each MACNN Block. kernel_sizes : tuple of int, default=(3, 6, 12) The kernel sizes of Conv1D layers within each MACNN Block. reduction : int, default=16 The factor by which the first dense layer of a MACNN Block will be divided by. activation : str, Callable, or None, default=None Activation applied to the output layer.

Permitted values:

- ``None``: no activation is applied to the output layer and the network returns raw outputs (logits). This is typically required when using ``CrossEntropyLoss``, which expects logits as input. - ``str``: name of a class in ``torch.nn``. Case-sensitive names are recommended and must match PyTorch (e.g., ``"ReLU"``, ``"LeakyReLU"``). Lowercase aliases for common activations are also accepted (e.g., ``"relu"`` is resolved to ``"ReLU"``). The class is instantiated with default constructor arguments. Must be a valid ``torch.nn`` activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity - ``torch.nn.Module``: an instance of a ``torch.nn.Module`` subclass, for example ``torch.nn.ReLU()``. Arbitrary callables are not supported.

Recommended activations: ``ReLU``, ``Tanh``, ``Sigmoid``, ``LeakyReLU``, ``ELU``, ``SELU``, ``GELU``. activation_hidden : str, Callable, or None, default="ReLU" Activation applied to the hidden layers.

Permitted values:

- ``None``: no activation is applied to the hidden layers. - ``str``: name of a class in ``torch.nn``. Case-sensitive names are recommended and must match PyTorch (e.g., ``"ReLU"``, ``"LeakyReLU"``). Lowercase aliases for common activations are also accepted (e.g., ``"relu"`` is resolved to ``"ReLU"``). The class is instantiated with default constructor arguments. Must be a valid ``torch.nn`` activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity - ``torch.nn.Module``: an instance of a ``torch.nn.Module`` subclass, for example ``torch.nn.ReLU()``. Arbitrary callables are not supported.

Recommended activations: ``ReLU``, ``Tanh``, ``Sigmoid``, ``LeakyReLU``, ``ELU``, ``SELU``, ``GELU``. num_epochs : int, default=1500 The number of epochs to train the model. batch_size : int, default=4 The size of each mini-batch during training. optimizer : case insensitive str or None, or a class or instance of optimizers defined in torch.optim, default = "RMSprop" The optimizer to use for training the model. optimizer_kwargs : dict or None, default = None Additional keyword arguments to pass to the optimizer. criterion : case insensitive str or None or an instance of a loss function defined in PyTorch, default = "CrossEntropyLoss" The loss function to be used in training the neural network. criterion_kwargs : dict or None, default = None Additional keyword arguments to pass to the loss function. callbacks : None or str or a tuple of str, default = "ReduceLROnPlateau" Currently only learning rate schedulers are supported as callbacks. callback_kwargs : dict or None, default = None The keyword arguments to be passed to the callbacks. lr : float, default = 0.001 The learning rate to use for the optimizer. verbose : bool, default = False Whether to print progress information during training. init_weights: str or None, default = None The method to initialize the weights of the conv layers. Supported values are 'kaiming_uniform', 'kaiming_normal', 'xavier_uniform', 'xavier_normal', or None for default PyTorch initialization. random_state : int, default = 0 Seed to ensure reproducibility.

References ---------- .. [1] Wei Chen et. al, Multi-scale Attention Convolutional Neural Network for time series classification, Neural Networks, Volume 136, 2021, Pages 126-140, ISSN 0893-6080, https://doi.org/10.1016/j.neunet.2021.01.001.

Examples -------- >>> from sktime.classification.deep_learning.macnn import MACNNClassifierTorch >>> from sktime.datasets import load_unit_test >>> X_train, y_train = load_unit_test(split="train") >>> X_test, y_test = load_unit_test(split="test") >>> clf = MACNNClassifierTorch(num_epochs=50, batch_size=2) # doctest: +SKIP >>> clf.fit(X_train, y_train) # doctest: +SKIP MACNNClassifierTorch(...)

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-sktime==1.0.0
uv pip install sinapsis-sktime==1.0.0
uv add sinapsis-sktime==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
root_dir
str
Optional
Default: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
model_save_pathRequired
Path where the trained model will be saved. macnnclassifiertorch_init padding <class 'str'>: default: same pool_size <class 'int'>: default: 3 strides <class 'int'>: default: 2 repeats <class 'int'>: default: 2… Read full field description

Path where the trained model will be saved. macnnclassifiertorch_init padding <class 'str'>: default: same pool_size <class 'int'>: default: 3 strides <class 'int'>: default: 2 repeats <class 'int'>: default: 2 filter_sizes <class 'tuple'>: default: (64, 128, 256) kernel_sizes <class 'tuple'>: default: (3, 6, 12) reduction <class 'int'>: default: 16 activation typing.Union[str, collections.abc.Callable, NoneType]: default: None activation_hidden typing.Union[str, collections.abc.Callable, NoneType]: default: ReLU num_epochs <class 'int'>: default: 100 batch_size <class 'int'>: default: 1 optimizer typing.Union[str, collections.abc.Callable, NoneType]: default: RMSprop optimizer_kwargs typing.Optional[dict]: default: None criterion typing.Union[str, collections.abc.Callable, NoneType]: default: CrossEntropyLoss criterion_kwargs typing.Optional[dict]: default: None callbacks typing.Union[NoneType, str, tuple[str, ...]]: default: ReduceLROnPlateau callback_kwargs typing.Optional[dict]: default: None lr <class 'float'>: default: 0.001 verbose <class 'bool'>: default: False init_weights typing.Optional[str]: default: None random_state <class 'int'>: default: 0

str
Required
Default: null
macnnclassifiertorch_initRequired
MACNNClassifierTorchAttributes
Required
Default: null
lr
float
Optional
Default: 0.001
padding
str
Optional
Default: "same"
repeats
int
Optional
Default: 2
strides
int
Optional
Default: 2
verbose
bool
Optional
Default: false
callbacks
typing.Union[NoneType, str, tuple[str, ...]]
Optional
Default: "ReduceLROnPlateau"
criterion
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "CrossEntropyLoss"
optimizer
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "RMSprop"
pool_size
int
Optional
Default: 3
reduction
int
Optional
Default: 16
activation
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: null
batch_size
int
Optional
Default: 1
num_epochs
int
Optional
Default: 100
filter_sizes
tuple
Optional
Default: [64,128,256]
init_weights
typing.Optional[str]
Optional
Default: null
kernel_sizes
tuple
Optional
Default: [3,6,12]
random_state
int
Optional
Default: 0
callback_kwargs
typing.Optional[dict]
Optional
Default: null
criterion_kwargs
typing.Optional[dict]
Optional
Default: null
optimizer_kwargs
typing.Optional[dict]
Optional
Default: null
activation_hidden
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "ReLU"

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "MACNNClassifierTorchSKTimeWrapper"
    class_name: "MACNNClassifierTorchSKTimeWrapper"
    attributes:
      root_dir: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
      model_save_path: "<required>"
      macnnclassifiertorch_init:
        lr: 0.001
        padding: "same"
        repeats: 2
        strides: 2
        verbose: false
        callbacks: "ReduceLROnPlateau"
        criterion: "CrossEntropyLoss"
        optimizer: "RMSprop"
        pool_size: 3
        reduction: 16
        activation: null
        batch_size: 1
        num_epochs: 100
        filter_sizes: {}
        init_weights: null
        kernel_sizes: {}
        random_state: 0
        callback_kwargs: null
        criterion_kwargs: null
        optimizer_kwargs: null
        activation_hidden: "ReLU"

Inheritance

Immediate parent: sinapsis_sktime.templates.sktime_classifiers.SKTimeDeepLearningClassifiers

Environment variables

Environment definitions belong to their canonical Python modules.

SINAPSIS_BUILD_DOCS · defined elsewhere