Machine learning for cosmology and astronomy

Tom Charnock

Institut d'Astrophysique de Paris


Sorbonne Université
ANR
IAP
CNRS
Aquila

What is a neural network?

Neural networks are arbitrary fittable non-linear functions



$$\mathscr{f} : {\bf d}\to\boldsymbol{\tau}$$

There are many different architectures


Convolutional neural networks

Recurrent neural networks


For any given dataset there is generally an obvious choice of architecture

How to fit a neural network



Approximate a function, $\mathscr{g} : {\bf d}\to\boldsymbol{\theta}$,
with a neural network, $\mathscr{f} : {\bf d}\to\boldsymbol{\tau}$

Probabilistic interpretation of a neural network


How likely is any network going to provide the expected function output?

This surface is defined by our choice in distance measure which is called the cost or loss function

Obtaining informative outputs

$$\mathcal{P}(\boldsymbol{\theta}|{\bf d})= \int d\boldsymbol{\omega}d\boldsymbol{\alpha}~\mathcal{L}(\boldsymbol{\theta}|{\bf d},\boldsymbol{\omega},\boldsymbol{\alpha})\mathcal{P}(\boldsymbol{\omega},\boldsymbol{\alpha})$$



Maximum likelihood estimate of weights





$$\boldsymbol{\omega}^\textrm{MLE}=\underset{\boldsymbol{\omega}}{\textrm{argmax}}\left[\mathcal{L}(\boldsymbol{\{}\boldsymbol{\theta}\boldsymbol{\}}^\textrm{train}|\boldsymbol{\{}{\bf d}\boldsymbol{\}}^\textrm{train}, \boldsymbol{\omega}, \boldsymbol{\alpha}^*)\right]$$

Prediction using neural networks



What are neural networks being used for?

EVERYTHING!

Emulation


Emulating high resolution N-body simulations
 
Inpainting high quality observable quantities
Super-resolution and accuracy of dark matter simulations

Generation and anomaly detection


Generation of realistic galaxies and measured differences

Parameter inference

Why should we distrust neural networks?

There is no sense in trust in how correct any output of the network is to be correct

Choosing a neural network with weights at their maximum likelihood estimates degenerates the posterior

Local maximum likelihood estimates


Different results are obtained with each network, none with a sense of trust

Bayesian neural networks and variational inference

Posterior predictive distribution of outputs

Everything is dependent on the training data!


Classical network : $\tiny \mathcal{P}(\boldsymbol{\omega},\boldsymbol{\alpha}|\boldsymbol{\{}{\bf d},\boldsymbol{\theta}\boldsymbol{\}}^\textrm{train}) \to \delta(\boldsymbol{\omega}-\boldsymbol{\omega}^\textrm{MLE},\boldsymbol{\alpha}-\boldsymbol{\alpha}^*)$

Variational inference : $\tiny \mathcal{P}(\boldsymbol{\omega},\boldsymbol{\alpha}|\boldsymbol{\{}{\bf d},\boldsymbol{\theta}\boldsymbol{\}}^\textrm{train}) = \mathcal{Q}(\boldsymbol{\omega}|\boldsymbol{\nu}^\textrm{MLE}, \boldsymbol{\alpha}^*, \boldsymbol{\{}{\bf d},\boldsymbol{\theta}\boldsymbol{\}}^\textrm{train})$

Bayesian networks : $\tiny \mathcal{P}(\boldsymbol{\omega},\boldsymbol{\alpha}|\boldsymbol{\{}{\bf d},\boldsymbol{\theta}\boldsymbol{\}}^\textrm{train}) =\prod_i^{n_\textrm{train}}\mathcal{L}(\boldsymbol{\theta}^\textrm{train}_i|{\bf d}^\textrm{train}_i,\boldsymbol{\omega},\boldsymbol{\alpha})p(\boldsymbol{\omega},\boldsymbol{\alpha})$

If the training data, network optimisation, or (pretty much) anything else is not perfect, the inference will be biased

Likelihood-free inference

We have a model with which we can simulate the data

  • Physical model
  • Generative models based on neural networks

We cannot (easily) describe the data

  • The likelihood of obtaining data is unknown/complex
  • There isn't even a well defined model

Use the same neural network to summarise observations and simulations

Generate simulations drawn from prior and summarise

Make a kernel density estimate (or use ABC) on the simulations


A slice through at the summarised observation is the approximate posterior

Posterior distribution of galaxy counts and fluxes in fields

Extracting information using neural networks

Information maximising neural networks


Which function $\mathscr{f}: \mathbb{R}^{\bf d}\to \mathbb{R}^\boldsymbol{\theta}$ maximises the Fisher information of the summaries ${\bf x}$ from that function?

$$\begin{align} {\bf F}_{\alpha\beta} &\simeq \left.\left\langle\frac{\partial^2\ln\mathcal{L}({\bf x}|\boldsymbol{\theta}, {\bf d})}{\partial\theta_\alpha\partial\theta_\beta}\right\rangle\right|_{\boldsymbol{\theta}=\boldsymbol{\theta}^*}\nonumber \end{align}$$

And also Gaussianises the data $$\mathcal{L}({\bf x}|\boldsymbol{\theta},{\bf d})\approx\mathcal{N}(\boldsymbol{\mu}(\boldsymbol{\theta}), \boldsymbol{\Sigma}(\boldsymbol{\theta}))$$

Calculate the covariance

Calculate the derivative of the mean of the summaries with respect to the parameters

We maximise

$$\ln|{\bf F}_{\alpha\beta}| = \ln\left|\frac{\partial\boldsymbol{\mu}_\mathscr{f}}{\partial\theta_\alpha}^T{\bf C}^{-1}_\mathscr{f}\frac{\partial\boldsymbol{\mu}_\mathscr{f}}{\partial\theta_\beta}\right|.$$

To get our trained, information maximising neural network

And use LFI to do parameter inference


We have lots of examples of how powerful this tool is throughout several scientific domains

Although each one would take a whole seminar to describe in detail...

Maybe next time 😉

Matching data models and physical models

Data models are the description that include all effects that generate the data

Initial conditions

Physical model

Instrumental effects

Other stochasticity

Neural networks are great at fitting the data model

We can build neural networks to deal with parts of the data model we don't understand

We need to sample this neural network, so we need well motivated priors

Neural physical engines

Building symmetries into neural networks






Halo mass distribution function

Summary

Neural networks are extremely powerful for science
They speed up computations
They can also allow us to build model-independent models
When used carefully, and in the right setting they give us exact statistically interpretable results