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
- Python 3.10–3.13 recommended. pythonnet does not yet support Python 3.14.
- .NET 6+ runtime (or .NET Framework 4.8.1 on Windows). Install the .NET SDK if you don't already have it.
- The RMC.Numerics NuGet package (see Quick Start).
The quick start will walk you through creating a virtual Python environment, installing the notebook requirements, and pulling in the RMC.Numerics NuGet package. For a more in-depth walkthrough see notebook 00_getting_started.ipynb.
NOTE: The commands below assume Windows. See notebook 00 for macOS/Linux equivalents.
-
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 the Python requirements
pip install -r notebook-requirements.txt
-
Install the
RMC.NumericsNuGet package# Option A — global NuGet cache (recommended; requires the .NET SDK): dotnet add package RMC.Numerics # Option B — local packages/ folder (requires nuget.exe on PATH): nuget install RMC.Numerics -OutputDirectory packages
Both commands pull the latest published version by default. This demo was built against version
2.0.1; to pin that version, append--version 2.0.1(Option A) or-Version 2.0.1(Option B).The notebooks auto-discover the DLL in either location via
resolve_numerics_dll()innotebooks/helper_functions.py. -
Load Numerics in a notebook or script
import pythonnet pythonnet.load("coreclr") import clr from helper_functions import resolve_numerics_dll clr.AddReference(str(resolve_numerics_dll()))
-
Create a Normal distribution
from Numerics.Distributions import Normal dist = Normal(100, 15)
If you prefer to build Numerics from source — for example, to develop against the latest main branch — clone the Numerics repo and build it:
git clone https://github.com/USACE-RMC/Numerics.git
cd Numerics
dotnet build Numerics.sln --configuration ReleaseThen point the notebooks at your build by setting the NUMERICS_DLL environment variable before launching Jupyter:
# PowerShell
$env:NUMERICS_DLL = "C:\path\to\Numerics\Numerics\bin\Release\net8.0\Numerics.dll"
# bash / zsh
export NUMERICS_DLL=/path/to/Numerics/Numerics/bin/Release/net8.0/Numerics.dllresolve_numerics_dll() uses this variable first, then falls back to the NuGet cache and finally a local packages/ folder.
- 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.
This project is released under the USACE-RMC license. It is compatible with the parent Numerics project license.