コード例 #1
0
  def forward(self, x, hidden=None):
    if hidden is None:
      hx = torch.zeors_like(x)
      cx = torch.zeros_like(x)
    else:
      hx, cx = hidden

    gates = self.x2h(x) + self.h2h(hx)
    ingate, forgetgate, cellgate, outgate = torch.split(gates, self.hidden_size, dim=1)

    ingate = torch.sigmoid(ingate)
    forgetgate = torch.sigmoid(forgetgate)
    cellgate = torch.tanh(cellgate)
    outgate = torch.sigmoid(outgate)

    cy = torch.mul(cx, forgetgate) +  torch.mul(ingate, cellgate)
    hy = torch.mul(outgate, torch.tanh(cy))
    return (hy, cy)
コード例 #2
0
 def forward(self, x):
     rmask = torch.ge(x.r, torch.zeors_like(x.r)).float()
     imask = torch.ge(x.i, torch.zeors_like(x.i)).float()
     mask = rmask * imask
     out = CPLX(x.r * mask, x.i * mask)
     return out