Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,319 changes: 1,155 additions & 1,164 deletions advanced/GP.ipynb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions advanced/RW_NS.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "7c7c10oq0bx",
"metadata": {},
"source": [
"## Prerequisites\n",
"\n",
"Install the required dependencies:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ibs4jedhvj",
"metadata": {},
"outputs": [],
"source": [
"!pip install git+https://github.com/handley-lab/blackjax\n",
"!pip install tqdm anesthetic numpy"
]
},
{
"cell_type": "markdown",
"id": "40a4be43",
Expand Down
24 changes: 14 additions & 10 deletions basic/basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
"cells": [
{
"cell_type": "markdown",
"source": "# Walkthrough of Nested Sampling\n\nWe walk through the same components in the [Quickstart](quickstart.ipynb), to give more detail as to what the choices mean.\n\n## Problem definition\n\nWe show how to use the basic user interface for Nested Slice Sampling. We will set up a 20D problem involving a multivariate unit Gaussian $\\mathcal{N}(0,\\mathbf{I})$ prior, and a multivariate Gaussian likelihood with a randomized mean and covariance. The resulting posterior and normalizing constant is analytically known.",
"metadata": {},
"source": [
"# Walkthrough of Nested Sampling\n",
"\n",
"We walk through the same components in the [Quickstart](quickstart.ipynb), to give more detail as to what the choices mean.\n",
"\n",
"## Problem definition\n",
"\n",
"We show how to use the basic user interface for Nested Slice Sampling. We will set up a 20D problem involving a multivariate unit Gaussian $\\mathcal{N}(0,\\mathbf{I})$ prior, and a multivariate Gaussian likelihood with a randomized mean and covariance. The resulting posterior and normalizing constant is analytically known."
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
"metadata": {},
"source": "!pip install git+https://github.com/handley-lab/blackjax\n!pip install anesthetic numpy tqdm matplotlib"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -463,4 +467,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
34 changes: 13 additions & 21 deletions basic/line_fitting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
},
{
"cell_type": "markdown",
"id": "e0j955op4hr",
"metadata": {},
"source": [
"### Installation"
]
"id": "sk93iv14d1a",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "wl6jvwv27m",
"metadata": {
"execution": {
Expand All @@ -34,20 +32,14 @@
"shell.execute_reply": "2025-09-22T17:42:50.231409Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.3.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m25.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython3.11 -m pip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!pip install -q git+https://github.com/handley-lab/blackjax anesthetic tqdm"
]
"outputs": [],
"source": "!pip install -q git+https://github.com/handley-lab/blackjax anesthetic tqdm matplotlib distrax optax flax"
},
{
"cell_type": "markdown",
"id": "z8k3wvxkqf",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -958,4 +950,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
20 changes: 14 additions & 6 deletions basic/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
"cells": [
{
"cell_type": "markdown",
"source": "# Quickstart\n\nAssuming some level of knowledge with the blackjax style, the following is a minimum working example of a basic sampling problem",
"metadata": {},
"source": [
"# Quickstart\n",
"\n",
"Assuming some level of knowledge with the blackjax style, the following is a minimum working example of a basic sampling problem "
]
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
"metadata": {},
"source": "!pip install git+https://github.com/handley-lab/blackjax\n!pip install anesthetic numpy tqdm"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -128,4 +136,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
12 changes: 11 additions & 1 deletion integrations/c.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# C\n\nThis example demonstrates how to use BlackJAX nested sampling with C implementations of likelihood and prior functions. The C code is compiled to a shared library and accessed via Python's `ctypes` library, with JAX's `pure_callback` providing the bridge.\n\n## Prerequisites\n\nInstall the required Python packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install numpy tqdm\n```\n\nYou'll also need a C compiler (gcc) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the C implementation\n\nFirst, create a file `model.c` with your likelihood and prior functions:"
"source": "# C\n\nThis example demonstrates how to use BlackJAX nested sampling with C implementations of likelihood and prior functions. The C code is compiled to a shared library and accessed via Python's `ctypes` library, with JAX's `pure_callback` providing the bridge.\n\nYou'll also need a C compiler (gcc) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the C implementation\n\nFirst, create a file `model.c` with your likelihood and prior functions:"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
Expand Down
12 changes: 11 additions & 1 deletion integrations/cpp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# C++\n\nThis example demonstrates how to use BlackJAX nested sampling with C++ implementations of likelihood and prior functions. The C++ code is compiled using pybind11 to create a Python module, with JAX's `pure_callback` providing the bridge.\n\n## Prerequisites\n\nInstall the required Python packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install pybind11 numpy tqdm\n```\n\nYou'll also need a C++ compiler (g++) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the C++ implementation\n\nFirst, create a file `model.cpp` with your likelihood and prior functions using pybind11:"
"source": "# C++\n\nThis example demonstrates how to use BlackJAX nested sampling with C++ implementations of likelihood and prior functions. The C++ code is compiled using pybind11 to create a Python module, with JAX's `pure_callback` providing the bridge.\n\nYou'll also need a C++ compiler (g++) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the C++ implementation\n\nFirst, create a file `model.cpp` with your likelihood and prior functions using pybind11:"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
Expand Down
12 changes: 11 additions & 1 deletion integrations/cupy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# CuPy\n\nThis example demonstrates how to use BlackJAX nested sampling with CuPy, the GPU-accelerated drop-in replacement for NumPy. CuPy enables GPU computation for likelihood and prior functions while maintaining NumPy-like syntax.\n\n## Prerequisites\n\nInstall the required packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install cupy-cuda12x numpy tqdm # Or cupy-cuda11x for CUDA 11.x\n```\n\nNote: CuPy requires CUDA. Choose the appropriate CuPy package for your CUDA version.\n\n## Run nested sampling with CuPy functions"
"source": "# CuPy\n\nThis example demonstrates how to use BlackJAX nested sampling with CuPy, the GPU-accelerated drop-in replacement for NumPy. CuPy enables GPU computation for likelihood and prior functions while maintaining NumPy-like syntax.\n\nNote: CuPy requires CUDA. Choose the appropriate CuPy package for your CUDA version.\n\n## Run nested sampling with CuPy functions"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
12 changes: 11 additions & 1 deletion integrations/fortran.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# Fortran\n\nThis example demonstrates how to use BlackJAX nested sampling with Fortran implementations of likelihood and prior functions. The Fortran code is compiled to a shared library and accessed via Python's `ctypes` library, with JAX's `pure_callback` providing the bridge.\n\n## Prerequisites\n\nInstall the required Python packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install numpy tqdm\n```\n\nYou'll also need a Fortran compiler (gfortran) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the Fortran implementation\n\nFirst, create a file `model.f90` with your likelihood and prior functions:"
"source": "# Fortran\n\nThis example demonstrates how to use BlackJAX nested sampling with Fortran implementations of likelihood and prior functions. The Fortran code is compiled to a shared library and accessed via Python's `ctypes` library, with JAX's `pure_callback` providing the bridge.\n\nYou'll also need a Fortran compiler (gfortran) installed on your system.\n\n## Setup Instructions\n\n### 1. Create the Fortran implementation\n\nFirst, create a file `model.f90` with your likelihood and prior functions:"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
Expand Down
12 changes: 11 additions & 1 deletion integrations/julia.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# Julia\n\nThis example demonstrates how to use BlackJAX nested sampling with Julia implementations of likelihood and prior functions. Julia code is called via JSON-RPC in a separate process to avoid threading conflicts.\n\n## Prerequisites\n\nInstall the required Python packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install numpy tqdm\n```\n\nInstall Julia and the required Julia packages:\n```julia\nusing Pkg\nPkg.add(\"LinearAlgebra\")\nPkg.add(\"Distributions\")\nPkg.add(\"JSON\")\n```\n\n## Setup Instructions\n\n### 1. Create the model file\n\nCreate a file `model.jl` with your likelihood and prior functions:\n\n```julia\nusing LinearAlgebra\nusing Distributions\n\nfunction loglikelihood(theta)\n theta = convert(Matrix{Float64}, theta)\n dist = MvNormal(ones(5), 0.01 * I(5))\n return [logpdf(dist, theta[i, :]) for i in 1:size(theta, 1)]\nend\n\nfunction logprior(theta)\n theta = convert(Matrix{Float64}, theta)\n dist = MvNormal(zeros(5), I(5))\n return [logpdf(dist, theta[i, :]) for i in 1:size(theta, 1)]\nend\n```\n\n### 2. Create the RPC server\n\nCreate a file `julia_server.jl` to handle RPC communication:\n\n```julia\nusing JSON\nusing Base64\n\n# Include the model functions\ninclude(\"model.jl\")\n\n# Simple request/response loop\nwhile true\n try\n line = readline()\n if isempty(line)\n break\n end\n \n request = JSON.parse(line)\n func_name = request[\"function\"]\n \n # Decode base64 numpy array\n theta_bytes = base64decode(request[\"data\"])\n theta = reinterpret(Float64, theta_bytes)\n rows = request[\"rows\"]\n cols = request[\"cols\"]\n theta = reshape(theta, cols, rows)' # Transpose for column-major\n \n # Call function\n if func_name == \"loglikelihood\"\n result = loglikelihood(theta)\n elseif func_name == \"logprior\"\n result = logprior(theta)\n else\n error(\"Unknown function: $func_name\")\n end\n \n # Send response\n response = Dict(\"result\" => result)\n println(JSON.json(response))\n flush(stdout)\n catch e\n println(JSON.json(Dict(\"error\" => string(e))))\n flush(stdout)\n end\nend\n```\n\n### 3. Run nested sampling with Julia functions"
"source": "# Julia\n\nThis example demonstrates how to use BlackJAX nested sampling with Julia implementations of likelihood and prior functions. Julia code is called via JSON-RPC in a separate process to avoid threading conflicts.\n\n## Setup Instructions\n\n### 1. Create the model file\n\nCreate a file `model.jl` with your likelihood and prior functions:\n\n```julia\nusing LinearAlgebra\nusing Distributions\n\nfunction loglikelihood(theta)\n theta = convert(Matrix{Float64}, theta)\n dist = MvNormal(ones(5), 0.01 * I(5))\n return [logpdf(dist, theta[i, :]) for i in 1:size(theta, 1)]\nend\n\nfunction logprior(theta)\n theta = convert(Matrix{Float64}, theta)\n dist = MvNormal(zeros(5), I(5))\n return [logpdf(dist, theta[i, :]) for i in 1:size(theta, 1)]\nend\n```\n\n### 2. Create the RPC server\n\nCreate a file `julia_server.jl` to handle RPC communication:\n\n```julia\nusing JSON\nusing Base64\n\n# Include the model functions\ninclude(\"model.jl\")\n\n# Simple request/response loop\nwhile true\n try\n line = readline()\n if isempty(line)\n break\n end\n \n request = JSON.parse(line)\n func_name = request[\"function\"]\n \n # Decode base64 numpy array\n theta_bytes = base64decode(request[\"data\"])\n theta = reinterpret(Float64, theta_bytes)\n rows = request[\"rows\"]\n cols = request[\"cols\"]\n theta = reshape(theta, cols, rows)' # Transpose for column-major\n \n # Call function\n if func_name == \"loglikelihood\"\n result = loglikelihood(theta)\n elseif func_name == \"logprior\"\n result = logprior(theta)\n else\n error(\"Unknown function: $func_name\")\n end\n \n # Send response\n response = Dict(\"result\" => result)\n println(JSON.json(response))\n flush(stdout)\n catch e\n println(JSON.json(Dict(\"error\" => string(e))))\n flush(stdout)\n end\nend\n```\n\n### 3. Run nested sampling with Julia functions"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
12 changes: 11 additions & 1 deletion integrations/numba.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# Numba\n\nThis example demonstrates how to use BlackJAX nested sampling with Numba JIT-compiled functions. Numba compiles Python functions to machine code at runtime, providing significant speedups for numerical computations while keeping the code in pure Python.\n\n## Prerequisites\n\nInstall the required packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install numba numpy tqdm\n```\n\n## Run nested sampling with Numba functions"
"source": "# Numba\n\nThis example demonstrates how to use BlackJAX nested sampling with Numba JIT-compiled functions. Numba compiles Python functions to machine code at runtime, providing significant speedups for numerical computations while keeping the code in pure Python.\n\n## Run nested sampling with Numba functions"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
12 changes: 11 additions & 1 deletion integrations/numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# NumPy/SciPy\n\nThis example demonstrates how to use BlackJAX nested sampling with NumPy/SciPy distributions. SciPy provides a wide range of statistical distributions that can be used directly with BlackJAX through the wrapping pattern.\n\n## Prerequisites\n\nInstall the required packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install scipy numpy tqdm\n```"
"source": "# NumPy/SciPy\n\nThis example demonstrates how to use BlackJAX nested sampling with NumPy/SciPy distributions. SciPy provides a wide range of statistical distributions that can be used directly with BlackJAX through the wrapping pattern."
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
12 changes: 11 additions & 1 deletion integrations/numpy_scipy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# NumPy/SciPy\n\nThis example demonstrates how to use BlackJAX nested sampling with NumPy and SciPy functions. This approach is useful when you have existing likelihood functions written in NumPy/SciPy that you want to use with BlackJAX.\n\n## Prerequisites\n\nInstall the required packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install scipy numpy tqdm\n```\n\n## Run nested sampling with NumPy/SciPy functions"
"source": "# NumPy/SciPy\n\nThis example demonstrates how to use BlackJAX nested sampling with NumPy and SciPy functions. This approach is useful when you have existing likelihood functions written in NumPy/SciPy that you want to use with BlackJAX.\n\n## Run nested sampling with NumPy/SciPy functions"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
12 changes: 11 additions & 1 deletion integrations/pytorch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
{
"cell_type": "markdown",
"metadata": {},
"source": "# PyTorch\n\nThis example demonstrates how to use BlackJAX nested sampling with PyTorch distributions and likelihood functions. The key is wrapping PyTorch functions to be compatible with JAX using `jax.pure_callback`.\n\n## Prerequisites\n\nInstall the required packages:\n```bash\npip install git+https://github.com/handley-lab/blackjax\npip install torch numpy tqdm\n```\n\n## Run nested sampling with PyTorch functions"
"source": "# PyTorch\n\nThis example demonstrates how to use BlackJAX nested sampling with PyTorch distributions and likelihood functions. The key is wrapping PyTorch functions to be compatible with JAX using `jax.pure_callback`.\n\n## Run nested sampling with PyTorch functions"
},
{
"cell_type": "markdown",
"source": "## Prerequisites\n\nInstall the required dependencies:",
"metadata": {}
},
{
"cell_type": "code",
"source": "!pip install git+https://github.com/handley-lab/blackjax\n!pip install torch numpy tqdm",
"metadata": {}
},
{
"cell_type": "code",
Expand Down
Loading