def W_decay(self, lr): #go through weights if self.L_coeff > 0: #L2 self.W -= self.L_coeff * lr * self.W elif self.L_coeff < 0: #L1 self.W += self.L_coeff * lr * nd.sign(self.W) else: #fix boundary self.W = nd.clip(self.W, -10.0, 10.0) return
def l1_regularization(X): return (-nd.norm(X).asscalar(), nd.multiply(-1.0, nd.sign(X)))
def poly_kernels(self, x: NDArray, y: NDArray): prod = nd.dot(x, y) return nd.sign(prod) * nd.abs(prod)**2