Table of Contents

Class EnvironmentDataLoader<T>

Namespace
AiDotNet.Data.Loaders.RL
Assembly
AiDotNet.dll

Data loader for reinforcement learning that wraps an environment for experience collection.

public class EnvironmentDataLoader<T> : RLDataLoaderBase<T>, IRLDataLoader<T>, IDataLoader<T>, IResettable, ICountable, IBatchIterable<Experience<T, Vector<T>, Vector<T>>>

Type Parameters

T

The numeric type used for calculations, typically float or double.

Inheritance
EnvironmentDataLoader<T>
Implements
IBatchIterable<Experience<T, Vector<T>, Vector<T>>>
Inherited Members
Extension Methods

Remarks

EnvironmentDataLoader provides a clean facade for RL training by wrapping an environment and managing experience collection. Use this with AiModelBuilder for unified training.

For Beginners: This is the main way to set up RL training:

var result = await new AiModelBuilder<double, Vector<double>, Vector<double>>()
    .ConfigureDataLoader(new EnvironmentDataLoader<double>(
        environment: new CartPoleEnvironment<double>(),
        episodes: 1000))
    .ConfigureModel(new DQNAgent<double>(options))
    .BuildAsync();

What it does:

  • Wraps your RL environment
  • Creates a replay buffer for storing experiences
  • Manages episode running during training
  • Provides experience batches for learning

Constructors

EnvironmentDataLoader(IEnvironment<T>, IReplayBuffer<T, Vector<T>, Vector<T>>, int, int, int, bool, int?)

Initializes a new EnvironmentDataLoader with a custom replay buffer.

public EnvironmentDataLoader(IEnvironment<T> environment, IReplayBuffer<T, Vector<T>, Vector<T>> replayBuffer, int episodes = 1000, int maxStepsPerEpisode = 500, int minExperiencesBeforeTraining = 1000, bool verbose = true, int? seed = null)

Parameters

environment IEnvironment<T>

The RL environment to collect experiences from.

replayBuffer IReplayBuffer<T, Vector<T>, Vector<T>>

Custom replay buffer implementation (e.g., prioritized).

episodes int

Number of episodes to run during training.

maxStepsPerEpisode int

Maximum steps per episode.

minExperiencesBeforeTraining int

Minimum experiences before training begins.

verbose bool

Whether to print progress during training.

seed int?

Optional random seed for reproducibility.

Remarks

For Beginners: Use this constructor if you want to provide a custom replay buffer, such as a prioritized experience replay buffer that samples important experiences more often.

EnvironmentDataLoader(IEnvironment<T>, int, int, int, int, bool, int?)

Initializes a new EnvironmentDataLoader with the specified environment.

public EnvironmentDataLoader(IEnvironment<T> environment, int episodes = 1000, int maxStepsPerEpisode = 500, int replayBufferCapacity = 10000, int minExperiencesBeforeTraining = 1000, bool verbose = true, int? seed = null)

Parameters

environment IEnvironment<T>

The RL environment to collect experiences from.

episodes int

Number of episodes to run during training.

maxStepsPerEpisode int

Maximum steps per episode (prevents infinite loops).

replayBufferCapacity int

Size of the replay buffer for storing experiences.

minExperiencesBeforeTraining int

Minimum experiences before training begins.

verbose bool

Whether to print progress during training.

seed int?

Optional random seed for reproducibility.

Remarks

For Beginners: The default values work well for most environments:

  • 1000 episodes is enough for simple environments, increase for complex ones
  • 500 max steps prevents infinite loops in broken environments
  • 10000 buffer size provides good experience diversity
  • 1000 min experiences ensures some exploration before learning

Properties

Name

Gets the human-readable name of this data loader.

public override string Name { get; }

Property Value

string

Remarks

Examples: "MNIST", "Cora Citation Network", "IMDB Reviews"