Switched Reference Generator

class gym_electric_motor.reference_generators.SwitchedReferenceGenerator(sub_generators, p=None, super_episode_length=(100, 10000))[source]

Reference Generator that switches randomly between multiple sub generators with a certain probability p for each.

Parameters:
  • sub_generators (list(ReferenceGenerator)) – ReferenceGenerator instances to be used as the sub_generators.

  • p (list(float)/None) – (Optional) Probabilities for each sub_generator. If None a uniform probability for each sub_generator is used.

  • super_episode_length (Tuple(int, int)) – Minimum and maximum number of time steps a sub_generator is used.

close()

Called by the environment, when the environment is deleted to close files, store logs, etc.

get_reference(state, **kwargs)[source]

Returns the reference array of the current time step.

The reference array needs to be in the same shape as the state variables. For referenced states the reference value is passed. For unreferenced states a default value (e.g. Zero) can be set in the reference array.

Parameters:

state (ndarray(float)) – Current state array of the environment.

Returns:

Current reference array.

Return type:

ndarray(float))

get_reference_observation(state, *_, **kwargs)[source]

Returns the reference observation for the next time step. This observation needs to fit in the reference space.

Parameters:

state (ndarray(float)) – Current state array of the environment.

Returns:

Observation for the next reference time step.

Return type:

value in reference_space

next_generator()

Sets a new reference generator for a new episode.

property random_generator

The random generator that has to be used to draw the random numbers.

property reference_names

Returns: reference_names(list(str)): A list containing all names of the referenced states in the reference observation.

property referenced_states

Returns: ndarray(bool): Boolean-Array with the length of the state_variables indicating which states are referenced.

reset(initial_state=None, initial_reference=None)[source]

Reset of references for a new episode.

Parameters:
  • initial_state (ndarray(float)) – The initial state array of the environment.

  • initial_reference (ndarray(float)) – If not None: A desired initial reference array.

Returns:

The reference array at time step 0.

reference_observation(value in reference_space): The reference observation for the next time step.

trajectories(dict(list(float)): If available, generated trajectories for the Visualization can be passed here. Otherwise return None.

Return type:

reference_array(ndarray(float))

seed(seed=None)[source]

The function to set the seed.

This function is called by within the global seed call of the environment. The environment passes the sub-seed to this component that is generated based on the source-seed of the env.

Parameters:

seed ((np.random.SeedSequence, None)) – Seed sequence to derive new seeds and reference generators at every episode start. Default: None (a new SeedSequence is generated).

Returns:

A list containing all seeds within this RandomComponent. In general, this list has length 1. If the RandomComponent holds further RandomComponent instances, the list has to contain also these entropies. The entropy of this instance has to be placed always at first place.

Return type:

List(int)

property seed_sequence

The base seed sequence that generates the sub generators and sub seeds at every environment reset.

set_modules(physical_system)[source]
Parameters:

physical_system (PhysicalSystem) – The physical system of the environment.