moonrllab

    MoonRLLab is a discrete reinforcement-learning lab for MoonBit.

    moonbit
    reinforcement-learning
    q-learning
    sarsa
    gridworld
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    35

    No dependencies

    #MoonRLLab

    MoonRLLab is a reusable tabular reinforcement-learning toolkit for MoonBit.

    #Library quick start

    import { "liuzhiyug/moonrllab" }

    fn main {
    let report = @moonrllab.train_with_memory_logger(8, 40, 20260815)
    println(report.compact_line())
    }

    The checked executable equivalent is in examples/basic:

    moon run examples/basic

    The generic Trainer::train works through open Environment, Agent, Logger and Policy traits. Built-in examples cover GridWorld, CliffWalking, RandomWalk and a multi-armed bandit. See README.md for the full API and acceptance evidence.

    Agent

    pub(open) trait Agent {
    fn reset_episode(Self) -> Unit
    fn choose_action(Self, Int) -> Int
    fn learn(Self, Transition, Int?) -> Unit
    fn epsilon(Self) -> Double
    fn q_report(Self, Int) -> String
    }

    Environment

    pub(open) trait Environment {
    fn reset(Self) -> Int
    fn actions(Self) -> Array[Int]
    fn state_space(Self) -> Array[Int]
    fn step(Self, Int) -> Transition
    fn render(Self) -> String
    }

    Logger

    pub(open) trait Logger {
    fn start_episode(Self, Int) -> Unit
    fn step(Self, Int, Int, Int, Double, Int, Bool, Int) -> Unit
    fn finish_episode(Self, EpisodeRecord) -> Unit
    fn finish(Self, TrainingReport) -> Unit
    }

    Policy

    pub(open) trait Policy {
    fn choose_action(Self, Int, Array[Int], Array[Double]) -> Int
    }

    BanditEnv

    pub struct BanditEnv {
    arms : Array[Double]
    rng : LcgRng
    pulls : Array[Int]
    total_reward : Double
    } derive(
    Debug
    )

    A reproducible k-armed bandit. Rewards are bounded and generated from a deterministic pseudo-random stream, which makes it suitable for CI.

    BanditEnv::actions

    fn BanditEnv::actions(self : BanditEnv) -> Array[Int]

    BanditEnv::arm_count

    fn BanditEnv::arm_count(self : BanditEnv) -> Int

    BanditEnv::average_reward

    fn BanditEnv::average_reward(self : BanditEnv) -> Double

    BanditEnv::best_arm

    fn BanditEnv::best_arm(self : BanditEnv) -> Int

    BanditEnv::new

    fn BanditEnv::new(means : Array[Double], seed : Int) -> BanditEnv

    BanditEnv::pull_count

    fn BanditEnv::pull_count(self : BanditEnv, arm : Int) -> Int

    BanditEnv::render

    fn BanditEnv::render(self : BanditEnv) -> String

    BanditEnv::reset

    fn BanditEnv::reset(self : BanditEnv) -> Int

    BanditEnv::state_space

    fn BanditEnv::state_space(_self : BanditEnv) -> Array[Int]

    BanditEnv::step

    fn BanditEnv::step(self : BanditEnv, action : Int) -> Transition

    BanditPolicy

    pub struct BanditPolicy {
    values : Array[Double]
    counts : Array[Int]
    schedule : EpsilonSchedule
    rng : LcgRng
    } derive(
    Debug
    )

    BanditPolicy::choose

    fn BanditPolicy::choose(self : BanditPolicy, step : Int) -> Int

    BanditPolicy::counts

    fn BanditPolicy::counts(self : BanditPolicy) -> Array[Int]

    BanditPolicy::estimate

    fn BanditPolicy::estimate(self : BanditPolicy, action : Int) -> Double

    BanditPolicy::new

    fn BanditPolicy::new(arms : Int, schedule : EpsilonSchedule, seed : Int) -> BanditPolicy

    BanditPolicy::observe

    fn BanditPolicy::observe(self : BanditPolicy, action : Int, reward : Double) -> Unit

    BenchmarkCase

    pub struct BenchmarkCase {
    name : String
    description : String
    expected_states : Int
    expected_actions : Int
    max_steps : Int
    } derive(Eq,
    Debug
    )

    BenchmarkCase::bandit

    BenchmarkCase::cliff_walking

    fn BenchmarkCase::cliff_walking() -> BenchmarkCase

    BenchmarkCase::gridworld

    fn BenchmarkCase::gridworld() -> BenchmarkCase

    BenchmarkCase::random_walk

    fn BenchmarkCase::random_walk() -> BenchmarkCase

    BenchmarkResult

    pub struct BenchmarkResult {
    name : String
    seed : Int
    episodes : Int
    rewards : Array[Double]
    steps : Array[Int]
    solved : Array[Bool]
    } derive(
    Debug
    )

    Aggregated results for a fixed-seed benchmark.

    BenchmarkResult::new

    fn BenchmarkResult::new(name : String, seed : Int, episodes : Int) -> BenchmarkResult

    BenchmarkResult::record

    fn BenchmarkResult::record(self : BenchmarkResult, episode : Int, reward : Double, steps : Int, solved : Bool) -> Unit

    BenchmarkResult::reward_stats

    fn BenchmarkResult::reward_stats(self : BenchmarkResult) -> RunningStats

    BenchmarkResult::solve_rate

    fn BenchmarkResult::solve_rate(self : BenchmarkResult) -> Double

    BenchmarkResult::solved_count

    fn BenchmarkResult::solved_count(self : BenchmarkResult) -> Int

    BenchmarkResult::step_stats

    fn BenchmarkResult::step_stats(self : BenchmarkResult) -> RunningStats

    BenchmarkResult::summary

    fn BenchmarkResult::summary(self : BenchmarkResult) -> String

    BenchmarkResult::tail_average

    fn BenchmarkResult::tail_average(self : BenchmarkResult, window : Int) -> Double

    BenchmarkResult::to_csv

    fn BenchmarkResult::to_csv(self : BenchmarkResult) -> String

    CliffWalkingEnv

    pub struct CliffWalkingEnv {
    width : Int
    height : Int
    start_x : Int
    start_y : Int
    goal_x : Int
    goal_y : Int
    x : Int
    y : Int
    _last_stage : EpisodeStage
    } derive(
    Debug
    )

    CliffWalkingEnv::actions

    fn CliffWalkingEnv::actions(_self : CliffWalkingEnv) -> Array[Int]

    CliffWalkingEnv::new

    CliffWalkingEnv::render

    fn CliffWalkingEnv::render(self : CliffWalkingEnv) -> String

    CliffWalkingEnv::reset

    fn CliffWalkingEnv::reset(self : CliffWalkingEnv) -> Int

    CliffWalkingEnv::state_space

    fn CliffWalkingEnv::state_space(self : CliffWalkingEnv) -> Array[Int]

    CliffWalkingEnv::step

    fn CliffWalkingEnv::step(self : CliffWalkingEnv, action : Int) -> Transition

    ConsoleLogger

    pub struct ConsoleLogger {
    prefix : String
    } derive(
    Debug
    )

    ConsoleLogger::new

    fn ConsoleLogger::new(prefix : String) -> ConsoleLogger

    DoubleQLearningAgent

    pub struct DoubleQLearningAgent {
    left : QTable
    right : QTable
    policy : EpsilonGreedyPolicy
    alpha : Double
    gamma : Double
    updates : Int
    } derive(
    Debug
    )

    DoubleQLearningAgent::best_action

    fn DoubleQLearningAgent::best_action(self : DoubleQLearningAgent, state : Int) -> Int

    DoubleQLearningAgent::choose_action

    fn DoubleQLearningAgent::choose_action(self : DoubleQLearningAgent, state : Int) -> Int

    DoubleQLearningAgent::learn

    fn DoubleQLearningAgent::learn(self : DoubleQLearningAgent, transition : Transition, update_left : Bool) -> Unit

    DoubleQLearningAgent::new

    fn DoubleQLearningAgent::new(states : Array[Int], actions : Array[Int], policy : EpsilonGreedyPolicy, alpha : Double, gamma : Double) -> DoubleQLearningAgent

    DoubleQLearningAgent::update_count

    fn DoubleQLearningAgent::update_count(self : DoubleQLearningAgent) -> Int

    DoubleQLearningAgent::value

    fn DoubleQLearningAgent::value(self : DoubleQLearningAgent, state : Int, action : Int) -> Double

    EnvironmentAudit

    pub struct EnvironmentAudit {
    states : Int
    actions : Int
    reset_state : Int
    invalid_action_state : Int
    render_nonempty : Bool
    } derive(Eq,
    Debug
    )

    EnvironmentAudit::bandit

    EnvironmentAudit::cliff

    EnvironmentAudit::gridworld

    EnvironmentAudit::random_walk

    fn EnvironmentAudit::random_walk() -> EnvironmentAudit

    EpisodeAccumulator

    pub struct EpisodeAccumulator {
    reward : Double
    steps : Int
    last_state : Int
    solved : Bool
    } derive(
    Debug
    )

    EpisodeAccumulator::finish

    fn EpisodeAccumulator::finish(self : EpisodeAccumulator, episode : Int) -> EvaluationPoint

    EpisodeAccumulator::new

    EpisodeAccumulator::observe

    fn EpisodeAccumulator::observe(self : EpisodeAccumulator, transition : Transition) -> Unit

    EpisodeRecord

    pub struct EpisodeRecord {
    episode : Int
    steps : Int
    reward : Double
    goal_reached : Bool
    final_state : Int
    } derive(Eq,
    Debug
    )

    EpisodeStage

    type EpisodeStage derive(Eq,
    Debug
    )

    EpisodeTrace

    pub struct EpisodeTrace {
    transitions : Array[Transition]
    } derive(
    Debug
    )

    A transition trace retained until an episode finishes.

    EpisodeTrace::length

    fn EpisodeTrace::length(self : EpisodeTrace) -> Int

    EpisodeTrace::new

    EpisodeTrace::push

    fn EpisodeTrace::push(self : EpisodeTrace, transition : Transition) -> Unit

    EpisodeTrace::returns

    fn EpisodeTrace::returns(self : EpisodeTrace, gamma : Double) -> Array[Double]

    EpisodeTrace::total_reward

    fn EpisodeTrace::total_reward(self : EpisodeTrace) -> Double

    EpsilonGreedyPolicy

    pub struct EpsilonGreedyPolicy {
    epsilon : Double
    rng : LcgRng
    } derive(
    Debug
    )

    EpsilonGreedyPolicy::choose_action

    fn EpsilonGreedyPolicy::choose_action(self : EpsilonGreedyPolicy, _state : Int, actions : Array[Int], q_values : Array[Double]) -> Int

    EpsilonGreedyPolicy::new

    fn EpsilonGreedyPolicy::new(epsilon : Double, seed : Int) -> EpsilonGreedyPolicy

    EpsilonSchedule

    pub struct EpsilonSchedule {
    start : Double
    end : Double
    decay_steps : Int
    } derive(Eq,
    Debug
    )

    EpsilonSchedule::new

    fn EpsilonSchedule::new(start : Double, end : Double, decay_steps : Int) -> EpsilonSchedule

    EpsilonSchedule::value

    fn EpsilonSchedule::value(self : EpsilonSchedule, step : Int) -> Double

    EpsilonSchedule::values

    fn EpsilonSchedule::values(self : EpsilonSchedule, count : Int) -> Array[Double]

    EvaluationConfig

    pub struct EvaluationConfig {
    episodes : Int
    max_steps : Int
    seed : Int
    report_window : Int
    } derive(Eq,
    Debug
    )

    EvaluationConfig::new

    fn EvaluationConfig::new(episodes : Int, max_steps : Int, seed : Int) -> EvaluationConfig

    EvaluationConfig::with_window

    fn EvaluationConfig::with_window(self : EvaluationConfig, window : Int) -> EvaluationConfig

    EvaluationPoint

    pub struct EvaluationPoint {
    episode : Int
    reward : Double
    steps : Int
    solved : Bool
    } derive(Eq,
    Debug
    )

    A single observation collected during an evaluation run.

    ExpectedSARSAAgent

    pub struct ExpectedSARSAAgent {
    table : QTable
    policy : EpsilonGreedyPolicy
    alpha : Double
    gamma : Double
    } derive(
    Debug
    )

    ExpectedSARSAAgent::choose_action

    fn ExpectedSARSAAgent::choose_action(self : ExpectedSARSAAgent, state : Int) -> Int

    ExpectedSARSAAgent::epsilon

    fn ExpectedSARSAAgent::epsilon(self : ExpectedSARSAAgent) -> Double

    ExpectedSARSAAgent::learn

    fn ExpectedSARSAAgent::learn(self : ExpectedSARSAAgent, transition : Transition, _next_action : Int?) -> Unit

    ExpectedSARSAAgent::new

    fn ExpectedSARSAAgent::new(states : Array[Int], actions : Array[Int], policy : EpsilonGreedyPolicy, alpha : Double, gamma : Double) -> ExpectedSARSAAgent

    ExpectedSARSAAgent::q_report

    fn ExpectedSARSAAgent::q_report(self : ExpectedSARSAAgent, state : Int) -> String

    ExpectedSARSAAgent::reset_episode

    fn ExpectedSARSAAgent::reset_episode(_self : ExpectedSARSAAgent) -> Unit

    ExperimentSummary

    pub struct ExperimentSummary {
    name : String
    result : BenchmarkResult
    notes : String
    } derive(
    Debug
    )

    ExperimentSummary::report

    fn ExperimentSummary::report(self : ExperimentSummary) -> String

    GridWorldEnv

    pub struct GridWorldEnv {
    width : Int
    height : Int
    start_x : Int
    start_y : Int
    goal_x : Int
    goal_y : Int
    x : Int
    y : Int
    _last_stage : EpisodeStage
    } derive(
    Debug
    )

    GridWorldEnv::actions

    fn GridWorldEnv::actions(_self : GridWorldEnv) -> Array[Int]

    GridWorldEnv::new

    GridWorldEnv::render

    fn GridWorldEnv::render(self : GridWorldEnv) -> String

    GridWorldEnv::state_space

    fn GridWorldEnv::state_space(self : GridWorldEnv) -> Array[Int]

    GridWorldEnv::step

    fn GridWorldEnv::step(self : GridWorldEnv, action : Int) -> Transition

    LcgRng

    LearningRateSchedule

    pub struct LearningRateSchedule {
    initial : Double
    minimum : Double
    decay : Double
    } derive(Eq,
    Debug
    )

    LearningRateSchedule::new

    fn LearningRateSchedule::new(initial : Double, minimum : Double, decay : Double) -> LearningRateSchedule

    LearningRateSchedule::value

    fn LearningRateSchedule::value(self : LearningRateSchedule, step : Int) -> Double

    MemoryLogger

    pub struct MemoryLogger {
    started : Int
    transitions : Int
    finished : Int
    last_report : TrainingReport?
    } derive(
    Debug
    )

    A silent logger for library and CI consumers that need structured results without writing progress lines to stdout.

    MemoryLogger::finished_count

    fn MemoryLogger::finished_count(self : MemoryLogger) -> Int

    MemoryLogger::new

    MemoryLogger::started_count

    fn MemoryLogger::started_count(self : MemoryLogger) -> Int

    MemoryLogger::transition_count

    fn MemoryLogger::transition_count(self : MemoryLogger) -> Int

    MonteCarloAgent

    pub struct MonteCarloAgent {
    table : QTable
    policy : EpsilonGreedyPolicy
    alpha : Double
    gamma : Double
    visits : Array[Int]
    } derive(
    Debug
    )

    MonteCarloAgent::choose_action

    fn MonteCarloAgent::choose_action(self : MonteCarloAgent, state : Int) -> Int

    MonteCarloAgent::learn_episode

    fn MonteCarloAgent::learn_episode(self : MonteCarloAgent, trace : EpisodeTrace) -> Unit

    MonteCarloAgent::new

    fn MonteCarloAgent::new(states : Array[Int], actions : Array[Int], policy : EpsilonGreedyPolicy, alpha : Double, gamma : Double) -> MonteCarloAgent

    MonteCarloAgent::q_value

    fn MonteCarloAgent::q_value(self : MonteCarloAgent, state : Int, action : Int) -> Double

    MonteCarloAgent::visit_count

    fn MonteCarloAgent::visit_count(self : MonteCarloAgent, state : Int, action : Int) -> Int

    PolicyEvaluation

    pub struct PolicyEvaluation {
    values : Array[Double]
    residual : Double
    iterations : Int
    stable : Bool
    } derive(
    Debug
    )

    PolicyEvaluation::value

    fn PolicyEvaluation::value(self : PolicyEvaluation, state : Int) -> Double

    QLearningAgent

    pub struct QLearningAgent {
    table : QTable
    policy : EpsilonGreedyPolicy
    alpha : Double
    gamma : Double
    } derive(
    Debug
    )

    QLearningAgent::choose_action

    fn QLearningAgent::choose_action(self : QLearningAgent, state : Int) -> Int

    QLearningAgent::epsilon

    fn QLearningAgent::epsilon(self : QLearningAgent) -> Double

    QLearningAgent::learn

    fn QLearningAgent::learn(self : QLearningAgent, transition : Transition, _next_action : Int?) -> Unit

    QLearningAgent::new

    fn QLearningAgent::new(states : Array[Int], actions : Array[Int], policy : EpsilonGreedyPolicy, alpha : Double, gamma : Double) -> QLearningAgent

    QLearningAgent::q_report

    fn QLearningAgent::q_report(self : QLearningAgent, state : Int) -> String

    QLearningAgent::q_value

    fn QLearningAgent::q_value(self : QLearningAgent, state : Int, action : Int) -> Double

    QLearningAgent::reset_episode

    fn QLearningAgent::reset_episode(_self : QLearningAgent) -> Unit

    QLearningAgent::set_q_value

    fn QLearningAgent::set_q_value(self : QLearningAgent, state : Int, action : Int, value : Double) -> Unit

    QTable

    RandomWalkEnv

    pub struct RandomWalkEnv {
    width : Int
    start : Int
    left_terminal : Int
    right_terminal : Int
    position : Int
    rng : LcgRng
    } derive(
    Debug
    )

    A small non-terminal random-walk benchmark used for value-estimation tests.

    RandomWalkEnv::actions

    fn RandomWalkEnv::actions(_self : RandomWalkEnv) -> Array[Int]

    RandomWalkEnv::new

    fn RandomWalkEnv::new(width : Int, seed : Int) -> RandomWalkEnv

    RandomWalkEnv::render

    fn RandomWalkEnv::render(self : RandomWalkEnv) -> String

    RandomWalkEnv::reset

    fn RandomWalkEnv::reset(self : RandomWalkEnv) -> Int

    RandomWalkEnv::state_space

    fn RandomWalkEnv::state_space(self : RandomWalkEnv) -> Array[Int]

    RandomWalkEnv::step

    fn RandomWalkEnv::step(self : RandomWalkEnv, action : Int) -> Transition

    ReplayBuffer

    pub struct ReplayBuffer {
    capacity : Int
    items : Array[ReplayItem]
    cursor : Int
    } derive(
    Debug
    )

    ReplayBuffer::at

    fn ReplayBuffer::at(self : ReplayBuffer, index : Int) -> ReplayItem?

    ReplayBuffer::is_full

    fn ReplayBuffer::is_full(self : ReplayBuffer) -> Bool

    ReplayBuffer::length

    fn ReplayBuffer::length(self : ReplayBuffer) -> Int

    ReplayBuffer::mean_reward

    fn ReplayBuffer::mean_reward(self : ReplayBuffer) -> Double

    ReplayBuffer::new

    fn ReplayBuffer::new(capacity : Int) -> ReplayBuffer

    ReplayBuffer::priorities

    fn ReplayBuffer::priorities(self : ReplayBuffer) -> Array[Double]

    ReplayBuffer::push

    fn ReplayBuffer::push(self : ReplayBuffer, transition : Transition, priority : Double) -> Unit

    ReplayItem

    pub struct ReplayItem {
    transition : Transition
    priority : Double
    } derive(
    Debug
    )

    ReportTable

    pub struct ReportTable {
    headers : Array[String]
    rows : Array[Array[String]]
    } derive(
    Debug
    )

    ReportTable::add_row

    fn ReportTable::add_row(self : ReportTable, row : Array[String]) -> Unit

    ReportTable::column_count

    fn ReportTable::column_count(self : ReportTable) -> Int

    ReportTable::new

    fn ReportTable::new(headers : Array[String]) -> ReportTable

    ReportTable::row_count

    fn ReportTable::row_count(self : ReportTable) -> Int

    ReportTable::to_csv

    fn ReportTable::to_csv(self : ReportTable) -> String

    ReportTable::to_markdown

    fn ReportTable::to_markdown(self : ReportTable) -> String

    ReportTable::valid_shape

    fn ReportTable::valid_shape(self : ReportTable) -> Bool

    RunningStats

    pub struct RunningStats {
    count : Int
    mean : Double
    m2 : Double
    minimum : Double
    maximum : Double
    } derive(
    Debug
    )

    Online statistics with numerically stable mean and variance updates.

    RunningStats::average

    fn RunningStats::average(self : RunningStats) -> Double

    RunningStats::new

    RunningStats::push

    fn RunningStats::push(self : RunningStats, value : Double) -> Unit

    RunningStats::standard_error

    fn RunningStats::standard_error(self : RunningStats) -> Double

    RunningStats::summary

    fn RunningStats::summary(self : RunningStats) -> String

    RunningStats::variance

    fn RunningStats::variance(self : RunningStats) -> Double

    SARSAAgent

    pub struct SARSAAgent {
    table : QTable
    policy : EpsilonGreedyPolicy
    alpha : Double
    gamma : Double
    } derive(
    Debug
    )

    impl Agent for SARSAAgent

    SARSAAgent::choose_action

    fn SARSAAgent::choose_action(self : SARSAAgent, state : Int) -> Int

    SARSAAgent::epsilon

    fn SARSAAgent::epsilon(self : SARSAAgent) -> Double

    SARSAAgent::learn

    fn SARSAAgent::learn(self : SARSAAgent, transition : Transition, next_action : Int?) -> Unit

    SARSAAgent::new

    fn SARSAAgent::new(states : Array[Int], actions : Array[Int], policy : EpsilonGreedyPolicy, alpha : Double, gamma : Double) -> SARSAAgent

    SARSAAgent::q_report

    fn SARSAAgent::q_report(self : SARSAAgent, state : Int) -> String

    SARSAAgent::reset_episode

    fn SARSAAgent::reset_episode(_self : SARSAAgent) -> Unit

    Scorecard

    pub struct Scorecard {
    name : String
    expected : Double
    observed : Double
    tolerance : Double
    } derive(Eq,
    Debug
    )

    Scorecard::error

    fn Scorecard::error(self : Scorecard) -> Double

    Scorecard::new

    fn Scorecard::new(name : String, expected : Double, observed : Double, tolerance : Double) -> Scorecard

    Scorecard::passed

    fn Scorecard::passed(self : Scorecard) -> Bool

    Scorecard::text

    fn Scorecard::text(self : Scorecard) -> String

    ScorecardSet

    pub struct ScorecardSet {
    items : Array[Scorecard]
    } derive(
    Debug
    )

    ScorecardSet::add

    fn ScorecardSet::add(self : ScorecardSet, score : Scorecard) -> Unit

    ScorecardSet::failed_count

    fn ScorecardSet::failed_count(self : ScorecardSet) -> Int

    ScorecardSet::new

    ScorecardSet::passed

    fn ScorecardSet::passed(self : ScorecardSet) -> Bool

    ScorecardSet::to_text

    fn ScorecardSet::to_text(self : ScorecardSet) -> String

    SeedBank

    pub struct SeedBank {
    seeds : Array[Int]
    } derive(Eq,
    Debug
    )

    SeedBank::at

    fn SeedBank::at(self : SeedBank, index : Int) -> Int?

    SeedBank::csv

    fn SeedBank::csv(self : SeedBank) -> String

    SeedBank::distinct

    fn SeedBank::distinct(self : SeedBank) -> Bool

    SeedBank::length

    fn SeedBank::length(self : SeedBank) -> Int

    SeedBank::new

    fn SeedBank::new(first : Int, count : Int) -> SeedBank

    Trainer

    pub struct Trainer {
    episodes : Int
    max_steps : Int
    } derive(
    Debug
    )

    Trainer::new

    fn Trainer::new(episodes : Int, max_steps : Int) -> Trainer

    Trainer::train

    fn[Env : Environment, Ag : Agent, Log : Logger] Trainer::train(self : Trainer, env : Env, agent : Ag, logger : Log) -> TrainingReport

    A trait-driven training entry point. The agent receives the next action as an optional hint: SARSA uses it, while Q-learning ignores it. This keeps the episode loop independent of a concrete environment or agent type.

    Trainer::train_q_learning

    fn Trainer::train_q_learning(self : Trainer, env : GridWorldEnv, agent : QLearningAgent, logger : ConsoleLogger) -> TrainingReport

    Trainer::train_sarsa

    fn Trainer::train_sarsa(self : Trainer, env : GridWorldEnv, agent : SARSAAgent, logger : ConsoleLogger) -> TrainingReport

    TrainingReport

    pub struct TrainingReport {
    label : String
    episodes : Int
    rewards : Array[Double]
    steps : Array[Int]
    goal_hits : Int
    final_epsilon : Double
    } derive(
    Debug
    )

    TrainingReport::compact_line

    fn TrainingReport::compact_line(self : TrainingReport) -> String

    TrainingReport::episode_count

    fn TrainingReport::episode_count(self : TrainingReport) -> Int

    TrainingReport::final_epsilon_value

    fn TrainingReport::final_epsilon_value(self : TrainingReport) -> Double

    TrainingReport::goal_count

    fn TrainingReport::goal_count(self : TrainingReport) -> Int

    TrainingReport::reward_at

    fn TrainingReport::reward_at(self : TrainingReport, episode : Int) -> Double

    TrainingReport::steps_at

    fn TrainingReport::steps_at(self : TrainingReport, episode : Int) -> Int

    Transition

    pub struct Transition {
    state : Int
    action : Int
    reward : Double
    next_state : Int
    done : Bool
    step : Int
    } derive(Eq,
    Debug
    )

    Transition::action

    fn Transition::action(self : Transition) -> Int

    Transition::done

    fn Transition::done(self : Transition) -> Bool

    Transition::new

    fn Transition::new(state : Int, action : Int, reward : Double, next_state : Int, done : Bool, step : Int) -> Transition

    Transition::next_state

    fn Transition::next_state(self : Transition) -> Int

    Transition::reward

    fn Transition::reward(self : Transition) -> Double

    Transition::state

    fn Transition::state(self : Transition) -> Int

    Transition::step_index

    fn Transition::step_index(self : Transition) -> Int

    ValidationFinding

    pub struct ValidationFinding {
    rule : String
    severity : ValidationSeverity
    message : String
    } derive(Eq,
    Debug
    )

    ValidationReport

    pub struct ValidationReport {
    findings : Array[ValidationFinding]
    passed : Int
    notices : Int
    failures : Int
    } derive(
    Debug
    )

    ValidationReport::add

    fn ValidationReport::add(self : ValidationReport, finding : ValidationFinding) -> Unit

    ValidationReport::finding_count

    fn ValidationReport::finding_count(self : ValidationReport) -> Int

    ValidationReport::new

    ValidationReport::ok

    fn ValidationReport::ok(self : ValidationReport) -> Bool

    ValidationReport::summary

    fn ValidationReport::summary(self : ValidationReport) -> String

    ValidationReport::to_text

    fn ValidationReport::to_text(self : ValidationReport) -> String

    ValidationSeverity

    pub enum ValidationSeverity {
    Pass
    Notice
    Failure
    } derive(Eq,
    Debug
    )

    ValueIterationResult

    pub struct ValueIterationResult {
    values : Array[Double]
    policy : Array[Int]
    iterations : Int
    converged : Bool
    residual : Double
    } derive(
    Debug
    )

    A value-iteration result that can be inspected independently of a learner.

    ValueIterationResult::action

    fn ValueIterationResult::action(self : ValueIterationResult, state : Int) -> Int

    ValueIterationResult::greedy_path

    fn ValueIterationResult::greedy_path(self : ValueIterationResult, start : Int, goal : Int, limit : Int) -> Array[Int]

    ValueIterationResult::value

    fn ValueIterationResult::value(self : ValueIterationResult, state : Int) -> Double

    acceptance_evidence

    fn acceptance_evidence() -> Array[String]

    action_map_text

    fn action_map_text(actions : Array[Int]) -> String

    all_environment_audits

    fn all_environment_audits() -> String

    audit_score

    fn audit_score(audit : EnvironmentAudit, expected_states : Int, expected_actions : Int) -> ScorecardSet

    benchmark_catalog

    fn benchmark_catalog() -> String

    benchmark_manifest

    fn benchmark_manifest() -> String

    boundary_probe

    fn boundary_probe() -> String

    clipped

    fn clipped(value : Double, lower : Double, upper : Double) -> Double

    compact_result_line

    fn compact_result_line(result : BenchmarkResult) -> String

    compact_results

    fn compact_results(results : Array[BenchmarkResult]) -> String

    compare_results_table

    fn compare_results_table(results : Array[BenchmarkResult]) -> ReportTable

    compare_training_reports

    fn compare_training_reports(left : TrainingReport, right : TrainingReport) -> String

    confidence_interval

    fn confidence_interval(values : Array[Double]) -> String

    csv_escape

    fn csv_escape(value : String) -> String

    discounted_return

    fn discounted_return(rewards : Array[Double], gamma : Double) -> Double

    discounted_returns

    fn discounted_returns(rewards : Array[Double], gamma : Double) -> Array[Double]

    evaluate_grid_policy

    fn evaluate_grid_policy(policy : Array[Int], goal : Int, gamma : Double, limit : Int) -> PolicyEvaluation

    full_benchmark_report

    fn full_benchmark_report(config : EvaluationConfig) -> String

    greedy_action_map

    fn greedy_action_map(agent : QLearningAgent, state_count : Int) -> Array[Int]

    gridworld_value_iteration

    fn gridworld_value_iteration(width : Int, height : Int, goal : Int, gamma : Double, tolerance : Double, limit : Int) -> ValueIterationResult

    Compute an optimal bounded policy for a rectangular navigation task.

    join_lines

    fn join_lines(lines : Array[String]) -> String

    linear_interpolate

    fn linear_interpolate(left : Double, right : Double, ratio : Double) -> Double

    markdown_escape

    fn markdown_escape(value : String) -> String

    merge_reward_series

    fn merge_reward_series(left : Array[Double], right : Array[Double]) -> Array[Double]

    moving_average

    fn moving_average(values : Array[Double], window : Int) -> Array[Double]

    normalize_returns

    fn normalize_returns(values : Array[Double]) -> Array[Double]

    percentile

    fn percentile(values : Array[Double], ratio : Double) -> Double

    performance_budget

    fn performance_budget(episodes : Int, max_steps : Int) -> Int

    policy_agreement

    fn policy_agreement(left : ValueIterationResult, right : ValueIterationResult) -> Double

    policy_histogram

    fn policy_histogram(policy : Array[Int], action_count : Int) -> Array[Int]

    project_name

    fn project_name() -> String

    MoonRLLab is a compact reinforcement-learning lab for discrete problems.

    The project focuses on a small but extensible tabular stack:
    • environments expose a finite state space and legal actions
    • policies choose actions with epsilon-greedy exploration
    • agents implement Q-learning and SARSA updates
    • the trainer produces a readable episode report

    project_self_check

    fn project_self_check(config : EvaluationConfig) -> String

    q_table_snapshot

    fn q_table_snapshot(agent : QLearningAgent, states : Int, actions : Int) -> String

    quality_text

    fn quality_text(result : BenchmarkResult) -> String

    regret

    fn regret(optimal : Double, actual : Array[Double]) -> Array[Double]

    release_checklist_text

    fn release_checklist_text() -> String

    report_contract

    fn report_contract() -> String

    fn report_footer() -> String

    report_header

    fn report_header(title : String, seed : Int) -> String

    report_quality

    fn report_quality(result : BenchmarkResult) -> ScorecardSet

    report_sections

    fn report_sections(config : EvaluationConfig) -> Array[String]

    report_sections_text

    fn report_sections_text(config : EvaluationConfig) -> String

    report_table_from_result

    fn report_table_from_result(result : BenchmarkResult) -> ReportTable

    report_table_from_stats

    fn report_table_from_stats(result : BenchmarkResult) -> ReportTable

    report_version

    fn report_version() -> String

    reproducibility_signature

    fn reproducibility_signature(config : EvaluationConfig) -> String

    result_digest

    fn result_digest(result : BenchmarkResult) -> String

    result_episode_ids

    fn result_episode_ids(result : BenchmarkResult) -> Array[Int]

    result_has_consistent_ids

    fn result_has_consistent_ids(result : BenchmarkResult) -> Bool

    result_has_learning_signal

    fn result_has_learning_signal(result : BenchmarkResult) -> Bool

    result_health

    fn result_health(result : BenchmarkResult) -> String

    result_is_nontrivial

    fn result_is_nontrivial(result : BenchmarkResult) -> Bool

    result_range

    fn result_range(result : BenchmarkResult) -> String

    reward_ceiling

    fn reward_ceiling(values : Array[Double]) -> Double

    reward_floor

    fn reward_floor(values : Array[Double]) -> Double

    risk_flags

    fn risk_flags() -> Array[String]

    run_bandit_benchmark

    fn run_bandit_benchmark(config : EvaluationConfig) -> ExperimentSummary

    run_cliff_benchmark

    fn run_cliff_benchmark(episodes : Int, seed : Int) -> ExperimentSummary

    run_demo

    fn run_demo() -> TrainingReport

    run_gridworld_benchmark

    fn run_gridworld_benchmark(episodes : Int, seed : Int) -> ExperimentSummary

    run_random_walk_benchmark

    fn run_random_walk_benchmark(config : EvaluationConfig) -> ExperimentSummary

    run_sarsa_demo

    fn run_sarsa_demo() -> TrainingReport

    run_standard_reports

    fn run_standard_reports(config : EvaluationConfig) -> String

    seed_sensitivity

    fn seed_sensitivity(episodes : Int) -> String

    solved_prefix

    fn solved_prefix(values : Array[Bool]) -> Int

    source_scale_estimate

    fn source_scale_estimate() -> String

    stable_mean

    fn stable_mean(values : Array[Double]) -> Double

    stable_sum

    fn stable_sum(values : Array[Double]) -> Double

    standard_benchmarks

    fn standard_benchmarks() -> Array[BenchmarkCase]

    suite_summary

    fn suite_summary(config : EvaluationConfig) -> String

    table_is_empty

    fn table_is_empty(table : ReportTable) -> Bool

    table_last_row

    fn table_last_row(table : ReportTable) -> Array[String]?

    table_preview

    fn table_preview(table : ReportTable, limit : Int) -> String

    train_cliff_qlearning_generic

    fn train_cliff_qlearning_generic(episodes : Int, max_steps : Int, seed : Int) -> TrainingReport

    train_gridworld_expected_sarsa_generic

    fn train_gridworld_expected_sarsa_generic(episodes : Int, max_steps : Int, seed : Int) -> TrainingReport

    train_gridworld_qlearning_generic

    fn train_gridworld_qlearning_generic(episodes : Int, max_steps : Int, seed : Int) -> TrainingReport

    train_gridworld_sarsa_generic

    fn train_gridworld_sarsa_generic(episodes : Int, max_steps : Int, seed : Int) -> TrainingReport

    train_with_memory_logger

    fn train_with_memory_logger(episodes : Int, max_steps : Int, seed : Int) -> TrainingReport

    trend

    fn trend(values : Array[Double]) -> Double

    tutorial_blurb

    fn tutorial_blurb() -> String

    validate_cliff

    fn validate_cliff(env : CliffWalkingEnv) -> ValidationReport

    validate_config

    fn validate_config(config : EvaluationConfig) -> ValidationReport

    validate_gridworld

    fn validate_gridworld(env : GridWorldEnv) -> ValidationReport

    validate_planner

    fn validate_planner(result : ValueIterationResult) -> ValidationReport

    validate_policy

    fn validate_policy(policy : Array[Int], action_count : Int) -> ValidationReport

    validate_replay

    fn validate_replay(buffer : ReplayBuffer) -> ValidationReport

    validate_result

    fn validate_result(result : BenchmarkResult) -> ValidationReport

    validate_schedule

    fn validate_schedule(schedule : EpsilonSchedule, samples : Int) -> ValidationReport

    value_error

    fn value_error(left : Array[Double], right : Array[Double]) -> Double

    Powered by MoonBit

    Site sourceReport issueModulesSkillsBuild queueStatistics

    © 2026 mooncakes.io