moonbit-fish-stock

Fishery stock assessment and management strategy simulation library for MoonBit

fishery
stock-assessment
population-dynamics
ecology
simulation
MSY
CPUE
moon add lfbnntr/moonbit-fish-stock@0.1.1
Download zip
Author
Version
0.1.1
License
Apache-2.0
Last updated
5 hours ago
Downloads
2
README

#moonbit-fish-stock

MoonBit library for fishery stock assessment, population dynamics, and management-strategy evaluation.

Check and Test License: Apache-2.0 MoonBit

#What it provides

moonbit-fish-stock is a dependency-light, reusable implementation of common quantitative fishery workflows. It covers the path from catch/effort time series to standardized abundance indices, surplus-production reference points, age-structured projections, harvest-control rules, closed-loop MSE, and Markdown/terminal reporting.

The library is designed for deterministic analysis building blocks. It does not replace a stock-assessment scientist's choice of data, model assumptions, priors, or management advice.

#Feature map

  • Core types and validation — stock series, catch records, model parameters, typed errors, and simulation configuration.
  • Math — finite-value-safe scalar approximations, statistics, linear algebra, optimization, and deterministic PRNG utilities.
  • CPUE — raw/standardized CPUE, normalization, detrending, seasonal adjustment, abundance indices, and trend diagnostics.
  • Surplus production — Schaefer, Pella–Tomlinson, and Fox dynamics, fitting, reference points, AIC/BIC, and residual diagnostics.
  • Age-structured models — Beverton–Holt and Ricker recruitment, VPA, Baranov catch, Leslie-style transitions, SSB, and yield.
  • Environment — anomaly, moving-average, lag-correlation, and climate-linked carrying-capacity helpers.
  • Uncertainty and management — residual bootstrap, HCR/TAC calculations, closed-loop operating models, and MSE projections.
  • Quality and indices — explicit series-quality reports, weighted survey-index aggregation, confidence intervals, and index comparison.
  • Projection and performance — multi-year age projections, projection summaries, empirical MSE risk metrics, distribution summaries, stable ranking, and Markdown tables.
  • Reporting — ASCII line charts and Markdown assessment reports.

#Package layout

moonbit-fish-stock/ ├── lib/ │ ├── types/ core records, errors, validation, series operations │ ├── math/ statistics, linear algebra, optimization, PRNG │ ├── cpue/ CPUE standardization and abundance-index helpers │ ├── surplus/ surplus-production models and diagnostics │ ├── age_structured/ recruitment, VPA, age transitions, SSB, yield │ ├── environment/ environmental covariates and climate dynamics │ ├── bootstrap/ residual resampling and uncertainty summaries │ ├── indicators/ reference points and Kobe status trajectories │ ├── management/ HCR and TAC recommendations │ ├── mse/ operating model and closed-loop simulations │ ├── quality/ non-mutating input-quality diagnostics │ ├── indices/ weighted annual survey-index summaries │ ├── projection/ multi-year age-structured projections │ ├── performance/ scenario metrics and ranking │ ├── benchmarking/ deterministic cross-package benchmark workload │ └── report/ terminal charts and Markdown reports └── cmd/ ├── main/ end-to-end assessment demonstration └── benchmark/ reproducible benchmark entry point

Each library directory is a MoonBit package. Public API summaries are generated by moon info; generated .mbti files are kept in version control for review.

#Requirements

  • MoonBit stable CLI. The current local verification uses moon 0.1.20260819 and moonc 0.10.9+6e6c44045.
  • Git for cloning and version control.

No external runtime service or data download is required for the examples in this repository.

#Quick start

git clone https://github.com/lfbnntr/moonbit-fish-stock.git cd moonbit-fish-stock # Type-check every supported backend and run all tests. moon check --target all moon test --target all # Run the end-to-end assessment example. moon run cmd/main # Run the deterministic cross-package benchmark. moon run cmd/benchmark

For a stricter local gate, use:

moon check --deny-warn moon test --deny-warn moon fmt --check moon info

#Library example

The following sketch shows the intended composition of the quality, index, and projection APIs. Error handling is explicit so callers can decide whether a data issue should stop an analysis.

import {
"lfbnntr/moonbit-fish-stock/lib/types"
"lfbnntr/moonbit-fish-stock/lib/quality"
"lfbnntr/moonbit-fish-stock/lib/indices"
"lfbnntr/moonbit-fish-stock/lib/projection"
"lfbnntr/moonbit-fish-stock/lib/age_structured"
}

fn assess(series : @types.StockSeries) raise @types.ErrorType {
let quality = @quality.inspect_stock_series(
series,
@quality.QualityConfig::strict(),
)
@quality.require_quality(quality)

let index = @indices.aggregate_cpue_indices(series, 1.96)
println("annual index years=" + index.length().to_string())

let ages = @age_structured.AgeStructureConfig::new(
3, 0.2, [1.0, 2.0, 3.0], [0.0, 0.5, 1.0], [0.0, 0.5, 1.0],
)
let path = @projection.project_age_structure(
[100.0, 80.0, 50.0],
@projection.AgeProjectionConfig::new(2025, 10, 0.1, 0.01, true),
ages,
)
let summary = @projection.summarize_projection(path)
println("projection depletion=" + summary.depletion.to_string())
}

#Reproducible benchmark

benchmarks/README.md records the fixed workload, checksum, observed output, and a local timing sample. Run moon run cmd/benchmark to reproduce the deterministic values. Timing depends on machine, build cache, operating system, and toolchain; the checksum and workload sizes are the stable regression signals.

#Tests and continuous integration

Tests live beside the package they exercise and cover normal paths, typed failures, degenerate inputs, and boundary values. The GitHub Actions workflow checks Linux, macOS, and Windows with the official stable MoonBit installer, moon check --target all, moon test --target all, formatting, and generated-interface cleanliness.

Run a package's tests during development with:

moon test lib/quality --deny-warn moon test lib/indices --deny-warn moon test lib/projection --deny-warn moon test lib/performance --deny-warn

#Modeling scope and limitations

  • Statistical intervals in lib/indices use an explicit normal approximation around weighted annual estimates.
  • MSE probabilities in lib/performance are empirical fractions of simulated trajectories, not guarantees about future stock status.
  • Projection behavior is determined by supplied biological parameters and recruitment/fishing paths; users remain responsible for choosing defensible assumptions.
  • The repository does not silently repair missing years, duplicate records, negative values, or non-finite observations. Inspect with lib/quality before fitting or projecting.

#License

This project is released under the Apache License 2.0.