MCPcopy
hub / github.com/tensorflow/tfjs / apply

Method apply

tfjs-layers/src/regularizers.ts:73–85  ·  view source on GitHub ↗

* Porting note: Renamed from __call__. * @param x Variable of which to calculate the regularization score.

(x: Tensor)

Source from the content-addressed store, hash-verified

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};

Callers

nothing calls this directly

Calls 8

tidyFunction · 0.90
zerosFunction · 0.90
addFunction · 0.90
sumFunction · 0.90
mulMethod · 0.80
squareMethod · 0.80
reshapeMethod · 0.80
absFunction · 0.50

Tested by

no test coverage detected