Bivariate Archimedean dependence modeling and joint risk workflows in pure MoonBit
moon new copula-consumer --user guest --name copula-consumer
cd copula-consumer
moon add CYang-dep/mooncopula@0.1.0import { "CYang-dep/mooncopula" }
options("is-main": true)///|
fn main raise {
let model = @mooncopula.Copula::new(@mooncopula.Clayton, 2.0)
println(model.cdf(0.5, 0.5))
let inverse = model.inverse_conditional(0.3, 0.9)
assert_true(inverse.residual <= 1.0e-8)
println(inverse.value)
}git clone https://github.com/CYang-dep/mooncopula.git
cd mooncopula
git checkout v0.1.0
moon run examples/environment
moon run examples/reliability
moon run examples/risk| 用户与输入 | 示例的处理 | 可观察结果 |
|---|---|---|
| 环境分析:12 组模拟降雨/流量 | 平均秩、Gumbel 拟合、联合超越、经验对照、网格诊断 | theta 约 9.80595,阈值 0.8 的联合超越约 0.187031,经验频率 1/12 |
| 可靠性开发:6 组模拟寿命、4 对固定均匀数 | Clayton 逆变换、经验寿命边缘恢复、残差检查 | 场景 (100,130)、(240,410)、(400,360)、(500,410) |
| 风险工具:8 组配对观测 | 11 候选 AIC 比较、校准、Rosenblatt 诊断、4 个固定重采样计划 | 最优 Frank 正分支 AIC 约 -6.31681,联合预测约 0.181204,输出 4 个重复结果 |
let uniforms = @mooncopula.pseudo_observations(raw)
let fitted = @mooncopula.fit(@mooncopula.Clayton, uniforms)
assert_true(fitted.converged)
let joint = fitted.model.risk(0.8, 0.9)
let scenarios = fitted.model.scenarios(raw, supplied_uniforms)moon info
moon fmt --check
moon check --deny-warn
moon build --deny-warn
moon test --deny-warn
moon test --deny-warn --target wasm
moon test --deny-warn --target js
moon test --deny-warn --target nativepython -m pip install -r scripts/oracle-requirements.txt
python scripts/generate_oracle.py --check
python scripts/audit_source.pypub(all) suberror CopulaError {
InvalidInput(String)
BudgetExceeded(String)
NumericalFailure(String)
} derive(Debug)pub struct BootstrapReplicate {
model : Copula
log_likelihood : Double
at_boundary : Bool
upper_joint_probability : Double
}pub struct BootstrapResult {
replicates : Array[BootstrapReplicate]
theta : SampleSummary
upper_joint_probability : SampleSummary
boundary_fits : Int
}pub struct CalibrationPoint {
threshold : Pair
forecast : Double
observed : RateInterval
residual : Double
}pub(all) struct Candidate {
label : String
family : Family
rotation : Rotation
options : FitOptions
}pub struct Concordance {
concordant : Int
discordant : Int
x_only_ties : Int
y_only_ties : Int
both_ties : Int
tau_b : Double
} derive(Debug)fn Copula::calibration_curve(self : Copula, data : Array[Pair], thresholds : Array[Pair], event : ThresholdEvent, z? : Double) -> Array[CalibrationPoint] raise CopulaErrorfn Copula::conditional_exceedance(self : Copula, u : Double, v : Double) -> Double raise CopulaErrorfn Copula::grid_diagnostic(self : Copula, data : Array[Pair], grid : Array[Pair]) -> GridDiagnostic raise CopulaErrorfn Copula::inverse_conditional(self : Copula, u : Double, q : Double, tolerance? : Double, max_iterations? : Int) -> Inversion raise CopulaErrorfn Copula::rectangle(self : Copula, lo_u : Double, hi_u : Double, lo_v : Double, hi_v : Double) -> Double raise CopulaErrorfn Copula::residual_diagnostic(self : Copula, data : Array[Pair]) -> RosenblattDiagnostic raise CopulaErrorpub struct EmpiricalCopula {
// private fields
}fn EmpiricalCopula::from_raw(data : Array[Pair], policy? : TiePolicy) -> EmpiricalCopula raise CopulaErrorfn EmpiricalCopula::rectangle(self : EmpiricalCopula, lo_u : Double, hi_u : Double, lo_v : Double, hi_v : Double) -> Double raise CopulaErrorpub struct EmpiricalMargin {
// private fields
}pub(all) struct FitOptions {
lower : Double
upper : Double
tolerance : Double
iterations : Int
}pub struct FitResult {
model : Copula
log_likelihood : Double
aic : Double
bic : Double
observations : Int
evaluations : Int
converged : Bool
at_boundary : Bool
}pub struct GridDiagnostic {
points : Int
maximum_absolute : Double
root_mean_square : Double
sample_scaled_mean_square : Double
}pub struct JointRisk {
lower_both : Double
upper_both : Double
upper_either : Double
x_above_y_below : Double
x_below_y_above : Double
} derive(Debug)pub struct RateInterval {
successes : Int
trials : Int
observed : Double
lower : Double
upper : Double
}pub struct RosenblattDiagnostic {
first : UniformDiagnostic
second : UniformDiagnostic
residual_spearman : Double
}pub struct SampleSummary {
count : Int
mean : Double
standard_deviation : Double
lower : Double
median : Double
upper : Double
}pub struct TailDiagnostic {
threshold : Double
lower_joint : Double
upper_joint : Double
lower_coefficient : Double
upper_coefficient : Double
observations : Int
} derive(Debug)pub(all) enum ThresholdEvent {
LowerBoth
UpperBoth
UpperEither
FirstUpperSecondLower
FirstLowerSecondUpper
}pub struct UniformDiagnostic {
count : Int
mean : Double
variance : Double
ks_distance : Double
cramer_von_mises : Double
}fn bootstrap_raw(family : Family, raw : Array[Pair], plans : Array[Array[Int]], threshold : Pair, rotation? : Rotation, options? : FitOptions, coverage? : Double) -> BootstrapResult raise CopulaErrorfn compare_models(candidates : Array[Candidate], data : Array[Pair]) -> Array[RankedModel] raise CopulaErrorfn fit(family : Family, data : Array[Pair], rotation? : Rotation, options? : FitOptions) -> FitResult raise CopulaErrorfn restore_margins(data : Array[Pair], x_margin : EmpiricalMargin, y_margin : EmpiricalMargin) -> Array[Pair] raise CopulaErrorInstall
Download zipBivariate Archimedean dependence modeling and joint risk workflows in pure MoonBit