Reward modeling, shaping, and debugging toolkit for MoonBit.
moon add weidekais/moonrewardforgeimport weidekais/moonrewardforge
fn main {
let step = @moonrewardforge.RewardStep::{
index: 0,
terms: [
@moonrewardforge.RewardTerm::{ name: "goal", raw: 1.0, weight: 1.0, kind: Base },
@moonrewardforge.RewardTerm::{ name: "time_penalty", raw: -0.1, weight: 1.0, kind: Penalty },
],
terminal: true,
}
let trace = [step]
let config = @moonrewardforge.default_config()
let (_breakdowns, summary) = @moonrewardforge.evaluate_trace(trace, config)
println("Reward span: \{summary.reward_span}")
println("Final clipped total: \{summary.total_clipped}")
}moon check
moon build
moon test
moon run cmd/mainpub(all) struct BenchmarkCase {
name : String
scenario : RewardScenario
expected_min_total : Double
expected_max_total : Double
} derive(Debug)pub(all) struct RewardAlert {
step_index : Int
level : AlertLevel
code : String
message : String
value : Double
} derive(Debug)pub(all) struct RewardBreakdown {
step_index : Int
term_count : Int
raw_total : Double
weighted_total : Double
normalized_total : Double
clipped_total : Double
mean : Double
spread : Double
sparse_terms : Int
zero_ratio : Double
shaping_share : Double
penalty_share : Double
dominant_name : String
terminal : Bool
} derive(Debug)pub(all) struct RewardConfig {
mode : NormalizationMode
clip_min : Double
clip_max : Double
epsilon : Double
} derive(Debug)pub(all) struct RewardTerm {
name : String
raw : Double
weight : Double
kind : RewardKind
} derive(Debug)pub(all) struct TraceSummary {
step_count : Int
sparse_steps : Int
clipped_steps : Int
avg_zero_ratio : Double
total_raw : Double
total_weighted : Double
total_normalized : Double
total_clipped : Double
best_step : Int
worst_step : Int
best_score : Double
worst_score : Double
terminal_score : Double
reward_span : Double
} derive(Debug)pub(all) enum ValidationCode {
EmptyTrace
EmptyStep
InvalidClipRange
InvalidEpsilon
InvalidSparseThreshold
} derive(Debug)pub(all) struct ValidationIssue {
code : ValidationCode
step_index : Int
message : String
} derive(Debug)fn audit_trace(steps : Array[RewardStep], config : RewardConfig, sparse_threshold : Double) -> Array[RewardAlert]fn compare_traces(left : Array[RewardStep], right : Array[RewardStep], config : RewardConfig) -> (TraceSummary, TraceSummary, Double)fn evaluate_trace(steps : Array[RewardStep], config : RewardConfig) -> (Array[RewardBreakdown], TraceSummary)fn inspect_breakdown(breakdown : RewardBreakdown, sparse_threshold : Double, clip_threshold : Double) -> Array[RewardAlert]fn is_valid_trace(steps : Array[RewardStep], config : RewardConfig, sparse_threshold : Double) -> Boolfn make_benchmark_case(name : String, steps : Array[RewardStep], expected_min_total : Double, expected_max_total : Double) -> BenchmarkCasefn validate_trace_issues(steps : Array[RewardStep], config : RewardConfig, sparse_threshold : Double) -> Array[ValidationIssue]Reward modeling, shaping, and debugging toolkit for MoonBit.