Model helpers
- class softsensor.model.CNN(input_channels, window_size, filters, kernel_size, depth=1, pooling=None, pooling_size=2, activation='relu', bias=True, dropout=None)[source]
Convolutional Model
- Parameters:
input_channels (int) – Number of input channels
window_size (int) – Size of the sliding window applied to the time series
filters (int or list of int) – Number of filters used in the convolution
kernel_size (int or list of int) – Width of the filter, (needs to be uneven)
depth (int,) – Depth of the Network, (how often is Convolution, Activation and Pooling repeated) The default is 1.
pooling (str, optional) – Pooling Variant to pool filtered time series. options are: ‘average’ and ‘max’ The default is None.
pooling_size (int, optional) – Kernel size of the pooling layer. The default is 2.
activation (str, optional) – Activation function to activate the feature space. The default is ‘relu’.
bias (bool, optional) – If True, bias weights are used. The default is True.
dropout (float [0,1], optional) – Adds dropout layers after each activation. The default is None.
- Return type:
None.
Example
>>> import softsensor.model as model >>> import torch >>> model = model.CNN(input_channels=4, window_size=50, filters=8, kernel_size=5, depth=2, pooling='average') >>> print(model) CNN( (ConvNet): Sequential( (0): conv_block( (Conv): Conv1d(4, 8, kernel_size=(5,), stride=(1,)) (pool): AvgPool1d(kernel_size=(2,), stride=(2,), padding=(0,)) (activation): ReLU() ) (1): conv_block( (Conv): Conv1d(8, 8, kernel_size=(5,), stride=(1,)) (pool): AvgPool1d(kernel_size=(2,), stride=(2,), padding=(0,)) (activation): ReLU() ) ) ) >>> input = torch.randn(32, 4, 50) >>> output = model(input) >>> print(output.size()) torch.Size([32, 8, 10])
To get the length of the output time series: >>> print(model.ts_length) 10
- class softsensor.model.Feed_ForwardNN(input_size, output_size, hidden_size=None, activation='relu', bias=True, dropout=None, concrete_dropout=False, bn=False)[source]
Deep Neural Network with Fully Connected Layers
- Parameters:
input_size (int) – Size of input array.
output_size (int) – Size of output array.
hidden_size (list of int or None, optional) – List gives the size of hidden units. The default is None.
activation (str, optional) – Activation function to activate the feature space. The default is ‘relu’.
bias (bool, optional) – If True, bias weights are used. The default is True.
dropout (float [0,1], optional) – Adds dropout layers after each Linear Layer. The default is None.
concrete_dropout (bool, optional) – Whether to use normal or concrete dropout layers if dropout is not None. The default is False
- Return type:
None.
Example
>>> import softsensor.model as model >>> import torch >>> model = model.Feed_ForwardNN(input_size=40, output_size=2, hidden_size=None, bias=True) >>> print(model) Feed_ForwardNN( (DNN): Sequential( (0): Linear(in_features=40, out_features=2, bias=True) ) ) >>> input = torch.randn(32, 40) >>> output = model(input) >>> print(output.size()) torch.Size([32, 2])
- class softsensor.model.Freq_Att_CNN(input_channels, filters, kernel_size, max_dilation=4, oscillations=4, depth=1, bypass=True, activation='relu', bias=True, dropout=None)[source]
Convolutional Model build on the parallel convolutions of the input with delated convolutions and subsequent convolution of the resulting parallel time series
- Parameters:
input_channels (int) – Number of channels of the external excitation signal
filters (int or list of int) – Number of filters used in the convolution.
max_dilation (int) – maximum dilation in the parallel convolution. The derfault is 4
oscillation (int) – Number of full oscillations for each parallel convolution is processed. The default is 4
depth (int, optional) – Depth of the Convolutional Network. The depth is applied to the convolutions (how often is Convolution, Activation and Pooling repeated) The default is 1.
bypass (bool, optional) – if True bypass is applied for faster convergence. The default is True.
activation (str, optional) – Activation function to activate the feature space. The default is ‘relu’.
bias (bool, optional) – If True, bias weights are used. The default is True.
dropout (float [0,1], optional) – Adds dropout layers after each activation. The default is None.
- Return type:
None.
Example
>>> import softsensor.model as model >>> import torch >>> model = model.Freq_Att_CNN(input_channels=2, filters=4, kernel_size=5, max_dilation=2, oscillations=2) >>> print(model) Freq_Att_CNN( (stage1): _Parallel_Conv( (Convs): ModuleList( (0): _delated_conv( (ConvNet): Sequential( (0): Conv1d(2, 4, kernel_size=(5,), stride=(1,)) (1): ReLU() ) ) (1): _delated_conv( (ConvNet): Sequential( (0): Conv1d(2, 4, kernel_size=(5,), stride=(2,), dilation=(2,)) (1): ReLU() ) ) ) ) >>> ws = model.window_size >>> input = torch.randn(32, 2, ws) >>> output = model(input) >>> print(output.size()) torch.Size([32, 6, 2])