nn.many_to_many_rnn.ManyToManyRNNRegressor(
input_dim= 1 ,
output_dim= 1 ,
rnn_units= 256 ,
fc_units= 256 ,
act_fn= 'ReLU' ,
dropout_prob= 0.0 ,
bidirectional= True ,
** kwargs,
)
ManyToManyRNN with the spotPython hyperparameter interface.
Accepts the hyperparameter names of the spotPython light_hyper_dict entry ManyToManyRNNRegressor (rnn_units, fc_units, act_fn, dropout_prob, bidirectional) plus the input_dim/output_dim convention used by spotoptim objectives. Training hyperparameters such as epochs, batch_size, patience, optimizer, and lr_mult are accepted via **kwargs and ignored here — they are consumed by the training objective.
Parameters
input_dim
int
Number of input features per time step. Defaults to 1.
1
output_dim
int
Number of outputs per time step. Defaults to 1.
1
rnn_units
int
Hidden size of the RNN layer. Defaults to 256.
256
fc_units
int
Width of the fully connected layer. Defaults to 256.
256
act_fn
Union [str , nn.Module]
Activation between the fully connected layer and the output head, either a name accepted by get_activation or a module instance. Defaults to “ReLU”.
'ReLU'
dropout_prob
float
Dropout probability applied to the RNN output. Defaults to 0.0.
0.0
bidirectional
bool
Whether the RNN is bidirectional. Defaults to True.
True
**kwargs
Ignored. Accepts surplus tuning hyperparameters.
{}
Examples
import torch
from spotoptim.nn.many_to_many_rnn import ManyToManyRNNRegressor
torch.manual_seed(0 )
model = ManyToManyRNNRegressor(
input_dim= 1 , output_dim= 1 , rnn_units= 16 , fc_units= 16 ,
act_fn= "Tanh" , dropout_prob= 0.1 , epochs= 128 , batch_size= 2 ,
)
x = torch.zeros(3 , 4 , 1 )
lengths = torch.tensor([4 , 2 , 3 ])
print (model(x, lengths).shape)
Methods
forward
Compute per-step outputs for a padded batch.
forward
nn.many_to_many_rnn.ManyToManyRNNRegressor.forward(x, lengths)
Compute per-step outputs for a padded batch.
Parameters
x
torch.Tensor
Padded input batch, shape (B, T_max, input_dim).
required
lengths
torch.Tensor
True sequence lengths, shape (B,).
required
Returns
torch.Tensor
torch.Tensor: Padded outputs, shape (B, T_max, output_dim).