Class EnvironmentDataLoader<T>
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
TThe numeric type used for calculations, typically float or double.
- Inheritance
-
EnvironmentDataLoader<T>
- Implements
-
IDataLoader<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
environmentIEnvironment<T>The RL environment to collect experiences from.
replayBufferIReplayBuffer<T, Vector<T>, Vector<T>>Custom replay buffer implementation (e.g., prioritized).
episodesintNumber of episodes to run during training.
maxStepsPerEpisodeintMaximum steps per episode.
minExperiencesBeforeTrainingintMinimum experiences before training begins.
verboseboolWhether to print progress during training.
seedint?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
environmentIEnvironment<T>The RL environment to collect experiences from.
episodesintNumber of episodes to run during training.
maxStepsPerEpisodeintMaximum steps per episode (prevents infinite loops).
replayBufferCapacityintSize of the replay buffer for storing experiences.
minExperiencesBeforeTrainingintMinimum experiences before training begins.
verboseboolWhether to print progress during training.
seedint?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
Remarks
Examples: "MNIST", "Cora Citation Network", "IMDB Reviews"