Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions ignite/handlers/state_param_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,21 +281,36 @@ class ExpStateScheduler(StateParamScheduler):

Examples:

.. code-block:: python
.. testsetup::

...
engine = Engine(train_step)
engine = get_default_trainer()

.. testcode::

param_scheduler = ExpStateScheduler(
param_name="param", initial_value=10, gamma=0.99
param_name="param", initial_value=1, gamma=0.9, create_new=True
)

# parameter is param, initial_value sets param to 1, gamma is set as 0.9
# Epoch 1, param changes from 1 to 1*0.9, param = 0.9
# Epoch 2, param changes from 0.9 to 0.9*0.9, param = 0.81
# Epoch 3, param changes from 0.81 to 0.81*0.9, param = 0.729
# Epoch 4, param changes from 0.81 to 0.729*0.9, param = 0.6561

param_scheduler.attach(engine, Events.EPOCH_COMPLETED)

# basic handler to print scheduled state parameter
engine.add_event_handler(Events.EPOCH_COMPLETED, lambda _ : print(engine.state.param))
@engine.on(Events.EPOCH_COMPLETED)
def print_param():
print(engine.state.param)

engine.run([0] * 8, max_epochs=2)
engine.run([0], max_epochs=4)

.. testoutput::

0.9
0.81
0.7290...
0.6561

.. versionadded:: 0.5.0

Expand Down