smartgrid.rewards.reward.Reward

class smartgrid.rewards.reward.Reward(name: str | None = None)[source]

Bases: ABC

The Reward function is responsible for computing a reward for each agent.

The reward is a signal telling the agent to which degree it performed correctly, with respect to the objective(s) specified by the reward function.

Reward functions should judge the agent’s behaviour, based on its actions and/or the action’s consequences on the world (state).

The actuel reward function is defined in calculate(); a simple function could be used instead, but using classes allows for easier extensions, and using attributes for complex computations.

A reward function is identified by its name (by default, the class name); this name is particularly used when multiple reward functions are used (multi-objective reinforcement learning).

__init__(name: str | None = None)[source]

Methods

__init__([name])

calculate(world, agent)

Compute the reward for a specific Agent at the current time step.

reset()

Reset the reward function.

Attributes

name

Uniquely identifying, human-readable name for this reward function.

abstract calculate(world: World, agent: Agent) float[source]

Compute the reward for a specific Agent at the current time step.

Parameters:
  • world – The World, used to get the current state and determine consequences of the agent’s action.

  • agent – The Agent that is rewarded, used to access particular information about the agent (personal state) and its action.

Returns:

A reward, i.e., a single value describing how well the agent performed. The higher the reward, the better its action was. Typically, a value in [0,1] but any range can be used.

name: str

Uniquely identifying, human-readable name for this reward function.

reset()[source]

Reset the reward function.

This function must be overridden by reward functions that use a state, so that the state is reset with the environment. By default, does nothing, as most reward functions do not use a state.