Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from .decay_component import DecayComponent
from .exponential_decay import ExponentialDecay
from .polynomial_decay import PolynomialDecay, LinearDecay
DecayComponent.__lookup_classes__ = dict(
linear=LinearDecay,
exponential=ExponentialDecay,
polynomial=PolynomialDecay
)
__all__ = ["DecayComponent", "ExponentialDecay", "PolynomialDecay", "LinearDecay"]
def __init__(self, power=1.0, scope="polynomial-decay", **kwargs):
"""
Args:
power (float): The polynomial power to use (e.g. 1.0 for linear).
Keyword Args:
see DecayComponent
"""
super(PolynomialDecay, self).__init__(scope=scope, **kwargs)
self.power = power
Keyword Args:
see DecayComponent
"""
super(PolynomialDecay, self).__init__(scope=scope, **kwargs)
self.power = power
def decay(self, time_steps_in_decay_window):
if backend == "tf":
import tensorflow as tf
return tf.train.polynomial_decay(self.from_, time_steps_in_decay_window, self.num_timesteps,
self.to_, power=self.power)
# Create an alias for LinearDecay
LinearDecay = partial(PolynomialDecay, power=1.0)