From 720bb1b051c9dcd5054606d076d2dca407ddffa2 Mon Sep 17 00:00:00 2001 From: Brandon Rozek Date: Fri, 20 Mar 2020 17:59:56 -0400 Subject: [PATCH] Documented scheduler module --- docs/source/scheduler.rst | 4 +++- rltorch/scheduler/ExponentialScheduler.py | 25 +++++++++++++++++++++++ rltorch/scheduler/LinearScheduler.py | 22 ++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/docs/source/scheduler.rst b/docs/source/scheduler.rst index 61fd10c..5f698d3 100644 --- a/docs/source/scheduler.rst +++ b/docs/source/scheduler.rst @@ -1,4 +1,6 @@ Hyperparameter Scheduling ========================= -.. automodule:: rltorch.scheduler +.. autoclass:: rltorch.scheduler.LinearScheduler + :members: +.. autoclass:: rltorch.scheduler.ExponentialScheduler :members: diff --git a/rltorch/scheduler/ExponentialScheduler.py b/rltorch/scheduler/ExponentialScheduler.py index ca8d162..f5d3c65 100644 --- a/rltorch/scheduler/ExponentialScheduler.py +++ b/rltorch/scheduler/ExponentialScheduler.py @@ -1,5 +1,30 @@ from .Scheduler import Scheduler class ExponentialScheduler(Scheduler): + r""" + A exponential scheduler that given a certain number + of iterations, spaces the values between + a start and an end point in an exponential order. + + Notes + ----- + The forumula used to produce the value :math:`y` is based on the number of + times you call `next`. (denoted as :math:`i`) + + :math:`y(1) = initial\_value` + :math:`y(i) = y(1) \cdot base^{i - 1}` + :math:`base = \sqrt[iterations]{\frac{end\_value}{initial\_value}}`. + + Another property is that :math:`y(iterations) = end\_value`. + + Parameters + ---------- + initial_value : number + The first value returned in the schedule. + end_value: number + The value returned when the maximum number of iterations are reached + iterations: int + The total number of iterations + """ def __init__(self, initial_value, end_value, iterations): super(ExponentialScheduler, self).__init__(initial_value, end_value, iterations) self.base = (end_value / initial_value) ** (1.0 / iterations) diff --git a/rltorch/scheduler/LinearScheduler.py b/rltorch/scheduler/LinearScheduler.py index 984f3eb..3637538 100644 --- a/rltorch/scheduler/LinearScheduler.py +++ b/rltorch/scheduler/LinearScheduler.py @@ -1,5 +1,27 @@ from .Scheduler import Scheduler class LinearScheduler(Scheduler): + r""" + A linear scheduler that given a certain number + of iterations, equally spaces the values between + a start and an end point. + + Notes + ----- + The forumula used to produce the value :math:`y` is based on the number of + times you call `next`. (denoted as :math:`i`) + + :math:`y(i) = slope \cdot (i - 1) + initial\_value` + where :math:`slope = \frac{end\_value - initial\_value)}{iterations}`. + + Parameters + ---------- + initial_value : number + The first value returned in the schedule. + end_value: number + The value returned when the maximum number of iterations are reached + iterations: int + The total number of iterations + """ def __init__(self, initial_value, end_value, iterations): super(LinearScheduler, self).__init__(initial_value, end_value, iterations) self.slope = (end_value - initial_value) / iterations