@@ -145,61 +145,59 @@ def __init__(
145145 # # Initialize RNN
146146 # # input_size = number of features (= 11)
147147 # # num_layers=1: only a single RNN and not stacked
148- # rnn_units = 64 # self.hparams.l1
149- # fc_units = 64 # self.hparams.l1
148+ rnn_units = 64 # self.hparams.l1
149+ fc_units = 64 # self.hparams.l1
150150
151151 # # TODO: make this a hyperparameter
152- # rnn_nonlinearity = "relu"
153-
154- # self.rnn_layer = nn.RNN(
155- # input_size=self._L_in,
156- # hidden_size=rnn_units,
157- # num_layers=1,
158- # nonlinearity=rnn_nonlinearity,
159- # bias=True,
160- # batch_first=True,
161- # bidirectional=False,
162- # )
152+ rnn_nonlinearity = "relu"
153+
154+ self .rnn_layer = nn .RNN (
155+ input_size = self ._L_in ,
156+ hidden_size = rnn_units ,
157+ num_layers = 1 ,
158+ nonlinearity = rnn_nonlinearity ,
159+ bias = True ,
160+ batch_first = True ,
161+ bidirectional = False ,
162+ )
163163
164164 # # Initialize Hidden- and Output-Layer
165- # self.fc = nn.Linear(rnn_units, fc_units)
166- # # self.output_layer = nn.Linear(fc_units, self._L_out)
167- # self.layers =nn.Linear(fc_units, self._L_out)
165+ self .fc = nn .Linear (rnn_units , fc_units )
166+ self .output_layer = nn .Linear (fc_units , self ._L_out )
168167
169168 # # Initialize Activation Function and Dropouts
170- # # self.dropout1 = nn.Dropout(dropout[0])
171- # # self.dropout2 = nn.Dropout(dropout[1])
172- # # self.dropout3 = nn.Dropout(dropout[2])
169+ dropout = [0.2 , 0 , 0 ]
170+ self .dropout1 = nn .Dropout (dropout [0 ])
171+ self .dropout2 = nn .Dropout (dropout [1 ])
172+ self .dropout3 = nn .Dropout (dropout [2 ])
173173 # # TODO: use different dropout for different layers
174174 # self.dropout1 = nn.Dropout(self.hparams.dropout_prob)
175175 # self.dropout2 = nn.Dropout(self.hparams.dropout_prob // 10.0)
176176 # self.dropout3 = nn.Dropout(self.hparams.dropout_prob // 100.0)
177177
178- # activation_fct = nn.ReLU()
179- # self.activation_fct = activation_fct
178+ activation_fct = nn .ReLU ()
179+ self .activation_fct = activation_fct
180180 # self.activation_fct = self.hparams.act_fn
181181
182182 # ###########################################
183183 # old:
184- if self .hparams .l1 < 4 :
185- raise ValueError ("l1 must be at least 4" )
186-
187- hidden_sizes = [self .hparams .l1 , self .hparams .l1 // 2 , self .hparams .l1 // 2 , self .hparams .l1 // 4 ]
188-
184+ # if self.hparams.l1 < 4:
185+ # raise ValueError("l1 must be at least 4")
186+ # hidden_sizes = [self.hparams.l1, self.hparams.l1 // 2, self.hparams.l1 // 2, self.hparams.l1 // 4]
189187 # Create the network based on the specified hidden sizes
190- layers = []
191- layer_sizes = [self ._L_in ] + hidden_sizes
192- layer_size_last = layer_sizes [0 ]
193- for layer_size in layer_sizes [1 :]:
194- layers += [
195- nn .Linear (layer_size_last , layer_size ),
196- self .hparams .act_fn ,
197- nn .Dropout (self .hparams .dropout_prob ),
198- ]
199- layer_size_last = layer_size
200- layers += [nn .Linear (layer_sizes [- 1 ], self ._L_out )]
201- # nn.Sequential summarizes a list of modules into a single module, applying them in sequence
202- self .layers = nn .Sequential (* layers )
188+ # layers = []
189+ # layer_sizes = [self._L_in] + hidden_sizes
190+ # layer_size_last = layer_sizes[0]
191+ # for layer_size in layer_sizes[1:]:
192+ # layers += [
193+ # nn.Linear(layer_size_last, layer_size),
194+ # self.hparams.act_fn,
195+ # nn.Dropout(self.hparams.dropout_prob),
196+ # ]
197+ # layer_size_last = layer_size
198+ # layers += [nn.Linear(layer_sizes[-1], self._L_out)]
199+ # # nn.Sequential summarizes a list of modules into a single module, applying them in sequence
200+ # self.layers = nn.Sequential(*layers)
203201
204202 def forward (self , x : torch .Tensor ) -> torch .Tensor :
205203 """
@@ -212,32 +210,32 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
212210 torch.Tensor: A tensor containing the output of the model.
213211
214212 """
215- # # print(f"input: {x.shape}")
216- # x = self.dropout1(x)
217- # # print(f"dropout1: {x.shape}")
218- # x, _ = self.rnn_layer(x)
219- # # print(f"rnn_layer: {x.shape}")
220- # # x = x[:, -1, :]
221- # # print(f"slicing: {x.shape}")
222- # x = self.dropout2(x)
223- # # print(f"dropout2: {x.shape}")
224- # x = self.activation_fct(self.fc(x))
225- # # print(f"activation_fct: {x.shape}")
226- # x = self.dropout3(x)
227- # # print(f"dropout3: {x.shape}")
228- # x = self.output_layer(x)
229- # # print(f"output_layer: {x.shape}")
230- # return x
213+ # print(f"input: {x.shape}")
214+ x = self .dropout1 (x )
215+ # print(f"dropout1: {x.shape}")
216+ x , _ = self .rnn_layer (x )
217+ # print(f"rnn_layer: {x.shape}")
218+ # x = x[:, -1, :]
219+ # print(f"slicing: {x.shape}")
220+ x = self .dropout2 (x )
221+ # print(f"dropout2: {x.shape}")
222+ x = self .activation_fct (self .fc (x ))
223+ # print(f"activation_fct: {x.shape}")
224+ x = self .dropout3 (x )
225+ # print(f"dropout3: {x.shape}")
226+ x = self .output_layer (x )
227+ # print(f"output_layer: {x.shape}")
228+ return x
231229
232230 # old:
233- x = self .layers (x )
234- # check if the number of columns in x is 1, otherwise throw an error
235- try :
236- assert x .shape [1 ] == 1
237- except AssertionError :
238- print (f"forward x.shape: { x .shape } " )
239- raise AssertionError ("Number of columns in x is not 1." )
240- return x
231+ # x = self.layers(x)
232+ # # check if the number of columns in x is 1, otherwise throw an error
233+ # try:
234+ # assert x.shape[1] == 1
235+ # except AssertionError:
236+ # print(f"forward x.shape: {x.shape}")
237+ # raise AssertionError("Number of columns in x is not 1.")
238+ # return x
241239
242240 def training_step (self , batch : tuple ) -> torch .Tensor :
243241 """
0 commit comments