This repository contains Python notebooks that demonstrate the Numerics .NET library through pythonnet. The notebooks provide practical, reproducible examples of Numerics applications, including distribution fitting, MCMC, optimization, statistical analysis, time series analysis, machine learning, and linear model fitting.
notebooks/Jupyter notebooks organized by topicexamples/Focused scripts and end-to-end demos
00_getting_started.ipynbSetup and first run01_distributions.ipynbDistribution basics and plotting02_distribution_fitting.ipynbMOM/MLE/L-moments + goodness-of-fit03_mcmc_basics.ipynbIntro Bayesian inference and RWMH04_mcmc_bayesian_inference.ipynbPractical workflows and comparisons05_mcmc_adaptive.ipynbAdaptive MCMC samplers06_mcmc_diagnostics.ipynbDiagnostics (ESS, mixing, multimodal)07_integration_and_root_finding.ipynbNumerical methods08_optimization.ipynbLocal/global optimization09_statistics.ipynbCore statistics and tests10_time_series.ipynbTime series objects and analysis11_machine_learning.ipynbRF, KNN, trees, clustering12_linear_models.ipynbLinear/GLM workflows
- Windows with .NET installed (or .NET 6+ runtime on Linux/macOS)
- Python with pythonnet
- Numerics built and compiled locally. The resulting DLL path must match the path referenced in the notebooks — see Quick Start and/or notebook 00 for setup instructions.
The quick start will step through the creation of an active python environment, installing the notebook requirements & RMC-Numerics, and getting the methods ready to be used. For a more in depth walk through see notebook 00.
NOTE: This set up is geared towards Windows users. For other operating systems see notebook 00.
- Create and activate a virtual Python environment
python -m venv .venv .venv\Scripts\Activate.ps1 pip install ipykernel python -m ipykernel install --user --name=.venv --display-name "Python (.venv)"
- Install notebook requirements
pip install -r notebook-requirements.txt
- Install and build Numerics
git clone https://github.com/USACE-RMC/Numerics.git
cd Numerics
dotnet build Numerics.sln --configuration Release- Load and confirm the DLL path
import pythonnet pythonnet.load("coreclr") import clr from pathlib import Path # Path to your Numerics.dll # MODIFY THIS PATH to make your installation dll_path = Path(r"C:\GIT\Numerics\Numerics\bin\Debug\net8.0\Numerics.dll") clr.AddReference(str(dll_path))
- Create a Normal Distribution
from Numerics.Distributions import Normal dist = Normal(100,15)
- These notebooks compare Numerics to common Python libraries where relevant. When comparing MCMC chains, align warmup/thinning settings.
- Many examples use synthetic data to keep results consistent and easy to interpret.
If your Numerics build output is in a different location, update the DLL path in the setup cell of each notebook. Search for Numerics.dll and replace the path with your local build output.
See the Numerics project license for usage and distribution terms.