pip install IMNN jupyter matplotlib
git clone https://github.com/tomcharnock/IMNN-LFI_Taskforce.git
cd IMNN-LFI_Taskforce
jupyter notebook
or go to
tinyurl.com/LFI-IMNN
Tom Charnock
Institut d'Astrophysique de Paris
Notebook: presentations.charnock.fr/IMNN/LFI_Taskforce
|
|
|
|
|
pip install IMNN jupyter matplotlib
git clone https://github.com/tomcharnock/IMNN-LFI_Taskforce.git
cd IMNN-LFI_Taskforce
jupyter notebook
tinyurl.com/LFI-IMNN
Euclid-like survey

Gaussian data with $n_{\bf d}=10$ and variance $\Sigma = 1$
real_data = simulator(np.array([[1.]]),
np.random.randint(int(1e6)),
{"input shape": [10]})
plot_real_data(real_data)
For LFI (and in particular ABC) we work in the space of data ${\bf d}$ and model parameters $\boldsymbol{\theta}$
Posterior is a slice through this space at some given data
Simulate the data and accept simulations close to the true data
The higher the dimension of the data, the less likely any simulation will actually look like the true data
Impossibly large numbers of simulations become necessary to correctly sample the posterior
The information inequality provides a natural description of
We define optimal statistics as the set of summaries which saturate the information inequality
$$Cov\left[{\bf x}_\alpha,{\bf x}_\beta\right] \ge \frac{\partial\langle{\bf x}_\mu\rangle}{\partial\theta_\alpha} {\bf F}^{-1}_{\mu\nu}\frac{\partial\langle{\bf x}_\nu\rangle}{\partial\theta_\beta}$$Amount of information some data, ${\bf d}$, contains about model parameters, $\boldsymbol{\theta}$, with likelihood $\mathcal{L}({\bf d}|\boldsymbol{\theta})$
$$\begin{align*} {\bf F}_{\alpha\beta} & = - \left.\left\langle\frac{\partial^2\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\alpha\partial\theta_\beta}\right\rangle\right|_{\boldsymbol{\theta}^\textrm{fid}}\\ & = \phantom{-}\left.\left\langle\frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\alpha}\frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\beta}\right\rangle\right|_{\boldsymbol{\theta}^\textrm{fid}} \end{align*}$$Start by expanding a generalised log-likelihood about some fiducial parameters, $\boldsymbol{\theta}^\textsf{fid}$ $$\begin{align*} \ln\mathcal{L}({\bf d}|\boldsymbol{\theta})\phantom{+} =&\phantom{+} \ln\mathcal{L}({\bf d}|\boldsymbol{\theta}^\textrm{fid})+\delta\theta_\alpha^T\frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta}^\textrm{fid})}{\partial\theta_\alpha}\\ &\phantom{+}+\frac{1}{2}\delta\theta_\alpha^T\frac{\partial^2\ln\mathcal{L}({\bf d}|\boldsymbol{\theta}^\textrm{fid})}{\partial\theta_\alpha\partial\theta_\beta}\delta\theta_\beta + \cdots \end{align*}$$
To linear order, the data only couples to the log-likelihood through the score fuction at some fiducial parameters
This is a set of sufficient* statistics which saturate the information inequality
$$Cov\left[{\bf x}_\alpha,{\bf x}_\beta\right] = \frac{\partial\langle{\bf x}_\mu\rangle}{\partial\theta_\alpha}{\bf F}^{-1}_{\mu\nu}\frac{\partial\langle{\bf x}_\nu\rangle}{\partial\theta_\beta}$$Since gradient of the expectation value of the summaries (evaluated at the fiducial parameter values) is
$$\begin{align*} \frac{\partial\langle{\bf x}_\beta\rangle}{\partial\theta_\alpha}= & \phantom{=}\left.\left\langle\frac{\partial^2\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\alpha\partial\theta_\beta}\right\rangle\right|_{\boldsymbol{\theta}^\textrm{fid}}\\ = & \phantom{=}-{\bf F}_{\alpha\beta} \end{align*}$$such that
$$\frac{\partial\langle{\bf x}_\mu\rangle}{\partial\theta_\alpha}{\bf F}^{-1}_{\mu\nu}\frac{\partial\langle{\bf x}_\nu\rangle}{\partial\theta_\beta} = {\bf F}_{\alpha\beta}$$and the covariance of the summaries is
$$\begin{align*} Cov\left[{\bf x}_\alpha, {\bf x}_\beta\right] = & \left.\left\langle\frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\alpha}\frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta})}{\partial\theta_\beta}\right\rangle\right|_{\boldsymbol{\theta}^\textrm{fid}}\\ =& {\bf F}_{\alpha\beta} \end{align*}$$then ${\bf x}_\alpha$ saturate the information inequality
$$Cov\left[{\bf x}_\alpha,{\bf x}_\beta\right] = \frac{\partial\langle{\bf x}_\mu\rangle}{\partial\theta_\alpha}{\bf F}^{-1}_{\mu\nu}\frac{\partial\langle{\bf x}_\nu\rangle}{\partial\theta_\beta}$$MASSIVE dimensionality compression
$$\mathbb{R}^{n_{\bf d}}\to\mathbb{R}^{n_\textrm{params}}$$We just need to know how to take the partial derivative of the log-likelihood
$${\bf x}_\alpha = \frac{\partial\ln\mathcal{L}({\bf d}|\boldsymbol{\theta}^\textrm{fid})}{\partial\theta_\alpha}$$If the likelihood of our data is Gaussian:
If our likelihood is known to linear order:
If the likelihood of our data is nearly-Gaussian:
If our data has known useful summaries
(for example the power spectrum):
from IMNN import IMNN
We find a way to map the data to some summaries $\mathscr{f}:{\bf d}\to{\bf x}$, where ${\bf x}$ are described by
$$-2\ln\mathcal{L}({\bf x}|\boldsymbol{\theta}) = ({\bf x}-\mu_\mathscr{f}(\boldsymbol{\theta}))^T{\bf C}^{-1}_\mathscr{f}({\bf x}-\mu_\mathscr{f}(\boldsymbol{\theta}))$$where $\mu_\mathscr{f}(\boldsymbol{\theta})$ and ${\bf C}_\mathscr{f}$ are the mean and covariance an ensemble of summaries mapped from fiducial simulations.
Fully connected networks when you don't know better
(oddly distributed data)
Convolutions for translationally invariant data
(images or local signals)
Other specialised architectures
(spherical convolutional networks for cosmological maps)
We can combine the IMNN with our known and loved summaries to extract just that little bit extra information
def network(input_tensor):
x = tf.nn.leaky_relu(dense(input_tensor, 128, "layer_1"), 0.01)
x = tf.nn.leaky_relu(dense(x, 128, "layer_2"), 0.01)
return dense(x, imnn.n_summaries, "output")
We only need simulations at the fiducial parameter values!
n_s = 1000
n_p = 100
num_summaries = 1
fiducial = [1.]
h = [0.1]
input_shape = [10]
data = generate_data(n_train, n_s, n_p, input_shape, fiducial, h, np.random.randint(int(1e6)))
plot_data(data)
imnn = IMNN.IMNN(
{"number of simulations": n_s,
"number of derivative simulations": n_p,
"fiducial": fiducial,
"number of summaries": num_summaries,
"input shape": input_shape,
"dtype": 32})
imnn.setup(network = network, load_data = data)
WARNING:tensorflow:From /Users/charnock/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. WARNING:tensorflow:From /Users/charnock/.pyenv/versions/3.6.6/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead.
imnn.train(updates = 1000, at_once = n_s, learning_rate = 1e-3,
constraint_strength = 2.)
plot_loss(imnn.history)
from IMNN.ABC import ABC
from IMNN.ABC import priors
prior = priors.TruncatedGaussian(np.array([1.]), np.array([[10.]]),
np.array([0.]), np.array([10.]))
abc = ABC.ABC(real_data=real_data, prior=prior, sess=imnn.sess,
get_compressor=imnn.get_compressor,
simulator=simulator,
simulator_args={"input shape": input_shape},
seed=None)
abc.ABC(draws=100000)
abc.PMC(draws=1000, posterior=1000, criterion=0.1)
iteration = 13, current criterion = 0.09206407659731172, total draws = 43439, ϵ = 0.2352231666445732..
plot_abc(real_data, abc)

|
|
|
|




