#machine #reinforcement #learning #rl #ai

rsrl

A fast, extensible reinforcement learning framework in Rust

14 releases

✓ Uses Rust 2018 edition

0.7.0 Nov 8, 2019
0.6.0 Nov 22, 2018
0.5.1 Sep 25, 2018
0.5.0 Jun 26, 2018
0.1.0 Dec 24, 2017

#21 in Machine learning

Download history 6/week @ 2019-10-07 14/week @ 2019-10-14 31/week @ 2019-10-21 43/week @ 2019-11-04 23/week @ 2019-11-11 31/week @ 2019-11-18 35/week @ 2019-11-25 15/week @ 2019-12-02 47/week @ 2019-12-09 14/week @ 2019-12-23 3/week @ 2019-12-30 3/week @ 2020-01-06 16/week @ 2020-01-13

93 downloads per month

MIT license

320KB
9K SLoC

RSRL (api)

Crates.io Build Status Coverage Status

Reinforcement learning should be fast, safe and easy to use.

Overview

rsrl provides generic constructs for reinforcement learning (RL) experiments in an extensible framework with efficient implementations of existing methods for rapid prototyping.

Installation

[dependencies]
rsrl = "0.7"

Usage

The code below shows how one could use rsrl to evaluate a QLearning agent using a linear function approximator with Fourier basis projection to solve the canonical mountain car problem.

See examples/ for more...

extern crate rsrl;
#[macro_use]
extern crate slog;

use rsrl::{
    run, make_shared, Evaluation, SerialExperiment,
    control::td::QLearning,
    domains::{Domain, MountainCar},
    fa::linear::{basis::{Fourier, Projector}, optim::SGD, LFA},
    logging,
    policies::{EpsilonGreedy, Greedy, Random},
    spaces::Space,
};

fn main() {
    let domain = MountainCar::default();
    let mut agent = {
        let n_actions = domain.action_space().card().into();

        let basis = Fourier::from_space(5, domain.state_space()).with_constant();
        let q_func = make_shared(LFA::vector(basis, SGD(1.0), n_actions));

        let policy = EpsilonGreedy::new(
            Greedy::new(q_func.clone()),
            Random::new(n_actions),
            0.2
        );

        QLearning::new(q_func, policy, 0.01, 1.0)
    };

    let logger = logging::root(logging::stdout());
    let domain_builder = Box::new(MountainCar::default);

    // Training phase:
    let _training_result = {
        // Start a serial learning experiment up to 1000 steps per episode.
        let e = SerialExperiment::new(&mut agent, domain_builder.clone(), 1000);

        // Realise 1000 episodes of the experiment generator.
        run(e, 1000, Some(logger.clone()))
    };

    // Testing phase:
    let testing_result = Evaluation::new(&mut agent, domain_builder).next().unwrap();

    info!(logger, "solution"; testing_result);
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate and adhere to the angularjs commit message conventions (see here).

License

MIT

Dependencies

~8MB
~223K SLoC