MyML is a lightweight, original C++ library designed for Reinforcement Learning (RL) research and educational purposes. Built from scratch with zero external dependencies, it provides a clean, abstract interface for environments and efficient algorithm implementations like Q-Learning.
- Standardized RL API: Clean
EnvironmentandAgentabstractions. - Q-Learning Implementation: High-performance implementation of the Bellman Equation.
- Modular Environments: Includes a
GridWorldtask for testing agent convergence. - Convergence Tracking: Automatic export of training rewards and metrics to CSV.
- Built-in CLI CLI Visualization: Real-time terminal rendering of agent behavior.
MyML follows the classical RL ecosystem structure:
- Types: Shared data structures for transitions (
Step). - Environment Interface: Abstract base class requiring
reset()andstep(). - Agent Implementation: Concrete agents (like
QLearner) that interoperate with anyEnvironment.
- C++17 Compatible Compiler (GCC 7+, Clang 5+, or MSVC 2019+)
- CMake 3.10+
mkdir build && cd build
# For Release (Industry Standard Optimization)
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config ReleaseMyML comes with a comprehensive testing suite to ensure "Physics" integrity and mathematical convergence.
# Run Unit Tests (Physics & Bounds checking)
./Release/myml_tests.exe
# Run Integration Demo (Training & Visualization)
./Release/myml_rl_demo.exe#include "myml/rl/QLearner.hpp"
#include "myml/rl/GridWorld.hpp"
myml::rl::GridWorld env(5);
myml::rl::QLearner agent(env.get_num_states(), env.get_num_actions());
// Training loop
for (int i = 0; i < 500; ++i) {
int state = env.reset();
bool done = false;
while (!done) {
int action = agent.predict_action(state);
auto step_res = env.step(action);
agent.train(state, action, step_res.reward, step_res.next_state, step_res.done);
state = step_res.next_state;
done = step_res.done;
}
}