* 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[])
| 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…