def __call__(self, net, input, target): if not self.adapt: while True: g, output = self.calc(net, input, target) # regularization grad if self.rr > 0: g = tool.reg_grad(g, net, self.rr) e = self.error(net, input, target, output) # regularization error if self.rr: e = tool.reg_error(e, net, self.rr) self.epochf(e, net, input, target) self.learn(net, g) else: while True: for i in range(input.shape[0]): g = self.calc(net, [input[i]], [target[i]])[0] # regularization grad if self.rr > 0: g = tool.reg_grad(g, net, self.rr) self.learn(net, g) e = self.error(net, input, target) # regularization error if self.rr: e = tool.reg_error(e, self.rr, net) self.epochf(e, net, input, target) return None
def grad(self, x): self.x[:] = x g, g_flat, output = tool.ff_grad(self.net, self.input, self.target) if self.rr: # g_flat is link to g tool.reg_grad(g, self.net, self.rr) return g_flat