* Porting note: Renamed from __call__. * @param x Variable of which to calculate the regularization score.
(x: Tensor)
| 71 | * @param x Variable of which to calculate the regularization score. |
| 72 | */ |
| 73 | apply(x: Tensor): Scalar { |
| 74 | return tidy(() => { |
| 75 | let regularization: Tensor = zeros([1]); |
| 76 | if (this.hasL1) { |
| 77 | regularization = add(regularization, sum(tfc.mul(this.l1, abs(x)))); |
| 78 | } |
| 79 | if (this.hasL2) { |
| 80 | regularization = |
| 81 | add(regularization, sum(tfc.mul(this.l2, K.square(x)))); |
| 82 | } |
| 83 | return tfc.reshape(regularization, []); |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | getConfig(): serialization.ConfigDict { |
| 88 | return {'l1': this.l1, 'l2': this.l2}; |