Validated multi-margin bounded survey raking extension for moon-causal
moon update
moon check --deny-warn --target all
moon build --target all
moon test --deny-warn --target all
moon run examples/demo --target wasm --deny-warn
moon run examples/audit --target wasm --deny-warn
moon fmt --check
moon infolet problem : @rake.Problem = {
rows: [
{ id: "a", cells: ["all"], base_weight: 3.0, lower: 1.0, upper: 4.0 },
{ id: "b", cells: ["all"], base_weight: 1.0, lower: 1.0, upper: 20.0 },
],
margins: [{ name: "population", targets: [{ category: "all", total: 10.0 }] }],
}
let result = @rake.fit(problem).unwrap()
// result.weights: [{id:"a",weight:4}, {id:"b",weight:6}]
let audit = @rake.evaluate(problem, [4.0, 6.0]).unwrap()
assert_true(audit.passes)| API | 责任 |
|---|---|
| fit(problem, options?) | 逐维逐类别执行有界乘法投影,完整扫轮后复核所有边际 |
| evaluate(problem, weights, tolerance?) | 审查任意权重;输入顺序与 problem.rows 一致,不是按 ID 排序后的顺序 |
| oneway_baseline(problem) | 实际调用上游单分组 raking,并重新审查其输出的边际与边界 |
| weighted_mean(values, weights) | 严格校验后归一化权重尺度,调用上游 Hájek 均值 |
| default_options() | 默认 100 轮、容差 1e-8 |
| 结果 to_json() | 导出 Double 权重、状态、逐组残差与诊断,JSON 字符串正常转义 |
pub(all) struct Fit {
status : Status
iterations : Int
weights : Array[WeightedRow]
trace : Array[Double]
diagnostics : Diagnostics
} derive(Eq, ToJson, Debug)fn evaluate(problem : Problem, weights : Array[Double], tolerance? : Double) -> Result[Diagnostics, RakeError]Install
Download zipValidated multi-margin bounded survey raking extension for moon-causal