Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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 yarl import backend
from .decay_component import DecayComponent
class ExponentialDecay(DecayComponent):
"""
Component that takes a time input and outputs an exponentially decaying value (using a half-life parameter and
init-, and final values).
The formula is:
out = 2exp(-t/h) * (from - to) + to
where
- t=time step (counting from the decay start-time, which is not necessarily 0)
- h=the number of timesteps over which the decay is 50%.
- from=start value
- to=end value
"""
def __init__(self, half_life=None, num_half_lives=10, scope="exponential-decay", **kwargs):
"""
Args:
half_life (Optional[int]): The half life period in number of timesteps. Use `num_half_lives` for a relative
measure against `num_timesteps`.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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 functools import partial
from yarl import backend
from .decay_component import DecayComponent
class PolynomialDecay(DecayComponent):
"""
Component that takes a time input and outputs a linearly decaying value (using init-, and final values).
The formula is:
out = (t/T) * (from - to) + to
where
- t=time step (counting from the decay start-time, which is not necessarily 0)
- T=the number of timesteps over which to decay.
- from=start value
- to=end value
"""
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:
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# 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"]