public override NDArray Call(NDArray w) { var norms = NDArray.Sqrt(NDArray.Square(w)); var desired = NDArray.Clip(norms, 0, MaxValue); w *= (desired / (norms + float.Epsilon)); return(w); }
public override NDArray Call(NDArray w) { var norms = NDArray.Sqrt(NDArray.Sum(NDArray.Square(w), new Shape(Axis), true)); var desired = (NDArray.Clip(norms, MinValue, MaxValue) * Rate) + (norms * (1 - Rate)); w *= desired / (norms + float.Epsilon); return(w); }
public override void Update(NDArray labels, NDArray preds) { CheckLabelShapes(labels, preds, true); preds = preds.Clip(0, 1); var label = labels.Ravel(); preds = preds.Ravel() > Threshold; var num_correct = nd.Equal(preds, label).AsType(DType.Float32).Sum(); sum_metric += num_correct; global_sum_metric += num_correct; num_inst += preds.Shape.Size; global_num_inst += preds.Shape.Size; }