diff --git a/docs/source/background.rst b/docs/source/background.rst new file mode 100644 index 00000000..2a2a5803 --- /dev/null +++ b/docs/source/background.rst @@ -0,0 +1,12 @@ +Background on differentiable methods +==================================== + +The tutorials in this section are based on toy models such as +single and double Gaussians, and some supplementary source code +that is not necessarily part of Diffsky. + +.. toctree:: + :maxdepth: 1 + + gaussian_examples/soft_hist_page.rst + gaussian_examples/double_gauss_page.rst diff --git a/docs/source/demos.rst b/docs/source/demos.rst index e657f6c0..176973fe 100644 --- a/docs/source/demos.rst +++ b/docs/source/demos.rst @@ -1,15 +1,17 @@ Diffsky Code Demos ================== +For a pedagogical introduction to the differentiable / probabilistic +methods used in Diffsky (soft histograms, PDF-weighted histograms, etc.), +see the :doc:`background` section. + Reading and analyzing Diffsky mocks ------------------------------------ .. toctree:: - :maxdepth: 1 - :caption: Notebooks: - - demo_diffsky_recompute_from_mock.ipynb + :maxdepth: 1 + demo_diffsky_recompute_from_mock.ipynb Generating Diffsky galaxy samples --------------------------------- -Docs coming soon! \ No newline at end of file +Docs coming soon! diff --git a/docs/source/gaussian_examples/double_gauss_demo.ipynb b/docs/source/gaussian_examples/double_gauss_demo.ipynb new file mode 100644 index 00000000..b3380d16 --- /dev/null +++ b/docs/source/gaussian_examples/double_gauss_demo.ipynb @@ -0,0 +1,331 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "494ee05f-bd9b-45eb-9816-1bacc370ce7c", + "metadata": {}, + "source": [ + "# Fitting a double Gaussian with soft histograms\n", + "\n", + "This notebook shows how to implement a double Gaussian model in JAX, and demonstrates how to optimize the parameters of the model by fitting to soft histograms with gradient descent." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "981d72a6-0042-4f7a-9397-2f7e64429469", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "from matplotlib import pyplot as plt\n", + "from jax import random as jran\n", + "from jax import numpy as jnp\n", + "\n", + "ran_key = jran.key(0)" + ] + }, + { + "cell_type": "markdown", + "id": "bc19e244-4499-4b6c-a4a3-19723b21986c", + "metadata": {}, + "source": [ + "## Stochastic Monte Carlo predictions\n", + "\n", + "The `mc_double_gaussian` function generates a sample of 1d data by standard Monte Carlo methods:\n", + "1. Draw $N$ points from the first Gaussian, $\\{\\mu_0, \\sigma_0\\}$\n", + "2. Draw $N$ points from the second Gaussian, $\\{\\mu_1, \\sigma_1\\}$\n", + "3. Draw $N$ uniform random numbers, $u$\n", + "4. If $f$ is the model parameter controlling the relative height of the two Gaussians, then for points with $u`__ kernels used to predict the SEDs -of a population of galaxies +Diffsky is a python library providing +`JAX `__ kernels used to predict the SEDs +of a population of galaxies with `diffmah `__, -`diffstar `__, -and `dsps `__. +`diffstar `__, +and `dsps `__. Diffsky is open-source code that is publicly available on -`GitHub `__. -These docs show you how to use diffsky to predict the SEDs and photometry -of a population of galaxies and their co-evolving dark matter halos. +`GitHub `__. +These docs show you how to use diffsky to predict the SEDs and photometry +of a population of galaxies and their co-evolving dark matter halos. .. toctree:: :maxdepth: 1 @@ -22,6 +22,7 @@ of a population of galaxies and their co-evolving dark matter halos. installation.rst demos.rst + background.rst .. toctree:: :maxdepth: 1