UNPKG

@tensorflow/tfjs-core

Version:

Hardware-accelerated JavaScript library for machine intelligence

51 lines 2.36 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { doc } from '../doc'; import { variableGrads } from '../globals'; import { Serializable } from '../serialization'; var Optimizer = (function (_super) { __extends(Optimizer, _super); function Optimizer() { return _super !== null && _super.apply(this, arguments) || this; } Optimizer.prototype.minimize = function (f, returnCost, varList) { if (returnCost === void 0) { returnCost = false; } var _a = this.computeGradients(f, varList), value = _a.value, grads = _a.grads; this.applyGradients(grads); var varNames = Object.keys(grads); varNames.forEach(function (varName) { return grads[varName].dispose(); }); if (returnCost) { return value; } else { value.dispose(); return null; } }; Optimizer.prototype.computeGradients = function (f, varList) { return variableGrads(f, varList); }; __decorate([ doc({ heading: 'Training', subheading: 'Optimizers' }) ], Optimizer.prototype, "minimize", null); Optimizer = __decorate([ doc({ heading: 'Training', subheading: 'Classes', namespace: 'train' }) ], Optimizer); return Optimizer; }(Serializable)); export { Optimizer }; //# sourceMappingURL=optimizer.js.map