Shortcuts

StateParamScheduler#

class ignite.handlers.state_param_scheduler.StateParamScheduler(param_name, save_history=False, create_new=False)[source]#

An abstract class for updating an engine state parameter values during training.

Parameters
  • param_name (str) – name of parameter to update.

  • save_history (bool) – whether to log the parameter values to engine.state.param_history, (default=False).

  • create_new (bool) – whether to create param_name on engine.state taking into account whether param_name attribute already exists or not. Overrides existing attribute by default, (default=False).

Note

Parameter scheduler works independently of the internal state of the attached engine. More precisely, whatever the state of the engine (newly created or used by another scheduler) the scheduler sets defined absolute values.

New in version 0.4.7.

Methods

attach

Attach the handler to the engine.

simulate_values

Method to simulate scheduled engine state parameter values during num_events events.

attach(engine, event=Events.ITERATION_COMPLETED)[source]#

Attach the handler to the engine. Once the handler is attached, the Engine.state will have a new attribute with the name param_name. Then the current value of the parameter can be retrieved from Engine.state when the engine is running.

Parameters
Return type

None

classmethod simulate_values(num_events, **scheduler_kwargs)[source]#

Method to simulate scheduled engine state parameter values during num_events events.

Parameters
  • num_events (int) – number of events during the simulation.

  • scheduler_kwargs (Any) – parameter scheduler configuration kwargs.

Returns

event_index, value

Return type

List[List[int]]

Examples:

import matplotlib.pyplot as plt
import numpy as np

step_state_param_values = np.array(
    StepStateScheduler.simulate_values(
        num_events=20, param_name="step_scheduled_param", initial_value=10, gamma=0.99, step_size=5
    )
)

plt.plot(step_state_param_values[:, 0], step_state_param_values[:, 1], label="learning rate")
plt.xlabel("events")
plt.ylabel("values")
plt.legend()