timesead.models.layers.kervolution
Attributes
Classes
Base class for all neural network modules. |
|
Base class for all neural network modules. |
|
Base class for all neural network modules. |
|
Base class for all neural network modules. |
|
Applies a 1D kervolution over an input signal composed of several inputplanes. |
Module Contents
- class timesead.models.layers.kervolution.Kernel(learnable_parameters: bool = False)
Bases:
torch.nn.Module,abc.ABCBase class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will also have their parameters converted when you call
to(), etc.Note
As per the example above, an
__init__()call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
learnable_parameters (bool)
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- learnable_parameters = False
- forward(x1: torch.Tensor, x2: torch.Tensor, diag_only: bool = False) torch.Tensor
Compute the kernel function for inputs x1 and x2
- Parameters:
x1 (torch.Tensor) – A tensor of shape ([B1], D)
x2 (torch.Tensor) – A tensor of shape ([B2], D)
diag_only (bool) – Whether the entire kernel matrix should be computed or only the diagonal
- Returns:
A tensor of shape ([B1] + [B2]) if diag_only = False, else a tensor of shape ([B]), where [B] is the result of broadcasting [B1] and [B2].
- Return type:
- class timesead.models.layers.kervolution.LinearKernel(learnable_parameters: bool = False)
Bases:
KernelBase class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will also have their parameters converted when you call
to(), etc.Note
As per the example above, an
__init__()call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
learnable_parameters (bool)
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class timesead.models.layers.kervolution.PolynomialKernel(degree: int = 2, c0: float = 0.0, learnable_parameters: bool = False)
Bases:
KernelBase class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will also have their parameters converted when you call
to(), etc.Note
As per the example above, an
__init__()call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- degree = 2
- c0 = 0.0
- class timesead.models.layers.kervolution.RBFKernel(gamma: float = 1.0, learnable_parameters: bool = False)
Bases:
KernelBase class for all neural network modules.
Your models should also subclass this class.
Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:
import torch.nn as nn import torch.nn.functional as F class Model(nn.Module): def __init__(self) -> None: super().__init__() self.conv1 = nn.Conv2d(1, 20, 5) self.conv2 = nn.Conv2d(20, 20, 5) def forward(self, x): x = F.relu(self.conv1(x)) return F.relu(self.conv2(x))
Submodules assigned in this way will be registered, and will also have their parameters converted when you call
to(), etc.Note
As per the example above, an
__init__()call to the parent class must be made before assignment on the child.- Variables:
training (bool) – Boolean represents whether this module is in training or evaluation mode.
- Parameters:
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- gamma = 1.0
- timesead.models.layers.kervolution.kernels
- class timesead.models.layers.kervolution.Kerv1d(in_channels: int, out_channels: int, kernel_size: int, stride: int = 1, padding: int = 0, dilation: int = 1, groups: int = 1, bias: bool = True, padding_mode: str = 'zeros', kernel: str | Kernel = 'linear', learnable_kernel: bool = False)
Bases:
torch.nn.Conv1dApplies a 1D kervolution over an input signal composed of several inputplanes.
- Parameters:
in_channels (int) – Number of channels in the input image
out_channels (int) – Number of channels produced by the convolution
stride (int or tuple, optional) – Stride of the convolution. Default: 1
padding (int or tuple, optional) – Zero-padding added to both sides of the input. Default: 0
padding_mode (string, optional) – zeros
dilation (int or tuple, optional) – Spacing between kernel elements. Default: 1
groups (int, optional) – Number of blocked connections from input channels to output channels. Default: 1
bias (bool, optional) – If
True, adds a learnable bias to the output. Default:Truelearnable_kernel (bool) – Learnable kernel parameters. Default: False
- Shape:
Input: \((N, C_{in}, L_{in})\)
Output: \((N, C_{out}, L_{out})\) where
\[L_{out} = \left\lfloor\frac{L_{in} + 2 \times \text{padding} - \text{dilation} \times (\text{kernel_size} - 1) - 1}{\text{stride}} + 1\right\rfloor\]
Examples
>>> m = Kerv1d(16, 33, 3, kernel='rbf') >>> input = torch.randn(20, 16, 70) >>> output = m(input)
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- unfold
- kernel = 'linear'
- forward(x: torch.Tensor) torch.Tensor
- Parameters:
x (torch.Tensor)
- Return type: