UNPKG

federer

Version:

Experiments in asynchronous federated learning and decentralized learning

38 lines 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ExponentialDecay = exports.LearningRateSchedule = void 0; const assert = require("assert"); exports.LearningRateSchedule = { /** Get the schedule that corresponds to the given options. */ get: (options) => { switch (options.type) { case "none": return undefined; case "exponential": return new ExponentialDecay(options.initialLearningRate, options.decayRounds, options.decayRate, options.stairCase); } }, }; /** * Exponential learning rate decay. * * @see {@link ExponentialDecayOptions} */ class ExponentialDecay { constructor(initialLearningRate, decayRounds = 10, decayRate = 0.96, stairCase = true) { this.initialLearningRate = initialLearningRate; this.decayRounds = decayRounds; this.decayRate = decayRate; this.stairCase = stairCase; } decayedLearningRate(round) { assert(Number.isInteger(round)); let power = round / this.decayRounds; if (this.stairCase) { power = Math.floor(power); } return this.initialLearningRate * this.decayRate ** power; } } exports.ExponentialDecay = ExponentialDecay; //# sourceMappingURL=decay.js.map