MCPcopy Create free account
hub / github.com/tensorflow/tfjs / minimize

Function minimize

tfjs-core/src/optimizers/optimizer.ts:59–80  ·  view source on GitHub ↗

* Executes `f()` and minimizes the scalar output of `f()` by computing * gradients of y with respect to the list of trainable variables provided by * `varList`. If no list is provided, it defaults to all trainable variables. * * @param f The function to execute and whose output to minimi

(f: () => Scalar, returnCost = false, varList?: Variable[])

Source from the content-addressed store, hash-verified

57 * @doc {heading: 'Training', subheading: 'Optimizers'}
58 */
59 minimize(f: () => Scalar, returnCost = false, varList?: Variable[]): Scalar
60 |null {
61 const {value, grads} = this.computeGradients(f, varList);
62
63 if (varList != null) {
64 const gradArray: NamedTensor[] =
65 varList.map(v => ({name: v.name, tensor: grads[v.name]}));
66 this.applyGradients(gradArray);
67 } else {
68 this.applyGradients(grads);
69 }
70
71 // Dispose gradients.
72 dispose(grads);
73
74 if (returnCost) {
75 return value;
76 } else {
77 value.dispose();
78 return null;
79 }
80 }
81
82 /**
83 * The number of iterations that this optimizer instance has been invoked for.

Callers

nothing calls this directly

Calls 3

disposeFunction · 0.90
applyGradientsMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…