Getting started (R)

hecfda ports the numerical core of USACE HEC-FDA to C++ with R and Python packages on top. This example installs the package, draws from the seeded generator, and evaluates a distribution. The draws below are identical in R, Python, and the upstream C#, because all three run the same algorithm: .NET’s seeded System.Random.

Install

# install.packages("pak")
pak::pak("cameronbracken/hecfda/hecfdar")

Seeded reproducibility

library(hecfdar)
rng_sequence(seed = 1234L, n = 5L)
[1] 0.3990810 0.8958995 0.3192029 0.9467375 0.3394360

The same call in Python (fda.rng_sequence(seed=1234, n=5)) returns the same five numbers, and so does new Random(1234).NextDouble() in .NET. Every Monte Carlo compute in hecfda draws from this generator with fixed per-curve seeds, so full simulation results carry the same guarantee.

A first distribution

dist_cdf("Normal", c(0, 1, 1), 0) # 0.5
[1] 0.5
dist_quantile("LogPearsonIII", c(3.3, 0.254, 0.0925, 99), 1 - 0.01) # the "100-year" quantile
[1] 8095.733

A first EAD

The smallest useful compute: a uniform flow frequency, a linear flow-stage transform, one stage-damage curve, one deterministic pass. This reproduces the HEC-FDA deterministic oracle of 150000 (the mean of the 600000-damage plateau over the frequency curve).

res = ead_simulation(
  stage_damage = list(list(
    x = c(0, 15, 30), dist = "Uniform",
    params = list(c(0, 0, 10), c(0, 600000, 10), c(0, 600000, 10)),
    damage_category = "residential", asset_category = "Structure"
  )),
  flow_frequency = list(dist = "Uniform", params = c(0, 100000, 1000)),
  flow_stage = list(x = c(0, 100000), dist = "Uniform",
                    params = list(c(0, 0, 10), c(0, 30, 10))),
  min_iterations = 1L, max_iterations = 1L, deterministic = TRUE
)
res$total_ead
[1] 150000