MCPcopy Create free account
hub / github.com/dangf15/THLNet / forward

Method forward

complexnn.py:282–393  ·  view source on GitHub ↗
(self, inputs)

Source from the content-addressed store, hash-verified

280 assert(xr.size(1) == self.num_features)
281
282 def forward(self, inputs):
283 #self._check_input_dim(xr, xi)
284
285 #xr, xi = torch.chunk(inputs,2, axis=self.complex_axis)
286 xr, xi = torch.chunk(inputs,2, dim=self.complex_axis) #for torch_version 1.1.0
287 exponential_average_factor = 0.0
288
289 if self.training and self.track_running_stats:
290 self.num_batches_tracked += 1
291 if self.momentum is None: # use cumulative moving average
292 exponential_average_factor = 1.0 / self.num_batches_tracked.item()
293 else: # use exponential moving average
294 exponential_average_factor = self.momentum
295
296 #
297 # NOTE: The precise meaning of the "training flag" is:
298 # True: Normalize using batch statistics, update running statistics
299 # if they are being collected.
300 # False: Normalize using running statistics, ignore batch statistics.
301 #
302 training = self.training or not self.track_running_stats
303 redux = [i for i in reversed(range(xr.dim())) if i!=1]
304 vdim = [1] * xr.dim()
305 vdim[1] = xr.size(1)
306
307 #
308 # Mean M Computation and Centering
309 #
310 # Includes running mean update if training and running.
311 #
312 if training:
313 Mr, Mi = xr, xi
314 for d in redux:
315 Mr = Mr.mean(d, keepdim=True)
316 Mi = Mi.mean(d, keepdim=True)
317 if self.track_running_stats:
318 self.RMr.lerp_(Mr.squeeze(), exponential_average_factor)
319 self.RMi.lerp_(Mi.squeeze(), exponential_average_factor)
320 else:
321 Mr = self.RMr.view(vdim)
322 Mi = self.RMi.view(vdim)
323 xr, xi = xr-Mr, xi-Mi
324
325 #
326 # Variance Matrix V Computation
327 #
328 # Includes epsilon numerical stabilizer/Tikhonov regularizer.
329 # Includes running variance update if training and running.
330 #
331 if training:
332 Vrr = xr * xr
333 Vri = xr * xi
334 Vii = xi * xi
335 for d in redux:
336 Vrr = Vrr.mean(d, keepdim=True)
337 Vri = Vri.mean(d, keepdim=True)
338 Vii = Vii.mean(d, keepdim=True)
339 if self.track_running_stats:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected