"Setup a mock VLBI imaging task using the `InterferometryResponse` of `resolve`. The `mock_observation` contains all information relevant to set up the likelihood, including visibility data, uv-coordinates, and the noise levels of each measurement. The `measurement_sky` contains all relevant information regarding the prior model of the sky brightness distribution. The additional parameters passed to the `InterferometryResponse` control the accuracy and behaviour of the `wgridder` used within `resolve` which defines the response function."
"Setup a mock VLBI imaging task using the `InterferometryResponse` of `resolve`. The `mock_observation` contains all information relevant to set up the likelihood, including visibility data, uv-coordinates, and the noise levels of each measurement. The `sky` contains all relevant information regarding the prior model of the sky brightness distribution. The additional parameters passed to the `InterferometryResponse` control the accuracy and behaviour of the `wgridder` used within `resolve` which defines the response function."
]
},
{
...
...
@@ -204,7 +196,7 @@
"Solve the inference problem\n",
"---------------------------\n",
"\n",
"The `likelihood` together with the `sky_model` fully specify a Bayesian inverse problem and imply a posterior probability distribution over the degrees of freedom (DOF) of the model. This distribution is, in general, a high-dimensional (number of pixels + DOF of power spectrum) and non-Gaussian distribution, which prohibits analytical integration. To access its information and compute posterior expectation values, numerical approximations have to be made.\n",
"The `likelihood` together with the `sky` fully specify a Bayesian inverse problem and imply a posterior probability distribution over the degrees of freedom (DOF) of the model. This distribution is, in general, a high-dimensional (number of pixels + DOF of power spectrum) and non-Gaussian distribution, which prohibits analytical integration. To access its information and compute posterior expectation values, numerical approximations have to be made.\n",
"\n",
"`nifty` provides multiple ways of posterior approximation, with Variational Inference (VI) being by far the most frequently used method. In VI the posterior distribution is approximated with another distribution by minimizing their respective forward Kullbach-Leibler divergence (KL). In the following, the Geometric VI method is employed which utilizes concepts of differential geometry to provide a local estimate of the distribution function.\n",
"\n",
...
...
@@ -223,12 +215,8 @@
"Posterior visualization\n",
"-----------------------\n",
"\n",
"Before we run the minimization routine, we set up a `plotting_callback` function for visualization. Note that additional information and plots regarding the reconstruction are generated during an `ift.optimize_kl` run and stored in the folder passed to the `output_directory` argument of `ift.optimize_kl`\n",
"The final output of `ift.optimize_kl` is a collection of approximate posterior samples and is provided via an instance of `ift.ResidualSampleList`. A `SampleList` provides a variety of convenience functions such as: \n",
"- `average`: to compute sample averages\n",
"- `sample_stat`: to get the approximate mean and variance of a model\n",
"- `iterator`: a python iterator over all samples\n",
"- ..."
"Before we run the minimization routine, we set up a `plotting_callback` function for visualization. Note that additional information and plots regarding the reconstruction are generated during an `jft.optimize_kl` run and stored in the folder passed to the `output_directory` argument of `jft.optimize_kl`\n",
"The final output of `jft.optimize_kl` is a collection of approximate posterior samples and is provided via an instance of `jft.Samples`. You can iterate over these samples samples. With `jft.mean_and_std` you can get the mean and the standard deviation."
]
},
{
...
...
@@ -344,7 +332,7 @@
"n_samples = (lambda iiter: 2 if iiter < 10 else 5) # Number of samples used for KL approximation\n",
Set up the FOV and number of pixels of the space which defines the image plane.
%% Cell type:code id: tags:
``` python
x_fov,y_fov=300,300# Field of view in x and y directon in myas
x_npix,y_npix=256,256# Number of pixels
dx=rve.str2rad(f'{x_fov}muas')/x_npix
dy=rve.str2rad(f'{y_fov}muas')/y_npix
```
%% Cell type:markdown id: tags:
Model of the sky brightness distribution
----------------------------------------
The sky model is going to be a log-normal random process (the log-brightness is Gaussian distributed). As the prior correlation structure of the log-brightness is unknown, it will be generated using a `CorrelatedField` model and the power-spectrum is inferred along with the realization.
%% Cell type:code id: tags:
``` python
# Hyperparameters (mean and std pairs) for prior models of parameters
args_zm={# Overall offset from zero of Gaussian process
'offset_mean':-np.log(dx*dy)-10.,
# Variability of inferred offset amplitude
'offset_std':(3.,1.)}
args_fl={# Amplitude of field fluctuations
'fluctuations':(1.5,0.5),
# Exponent of power law power spectrum component
'loglogavgslope':(-4.,.5),
# Amplitude of integrated Wiener process power spectrum component
'flexibility':(.3,.1),
# How ragged the integrated Wiener process component is
'asperity':None# Passing 'None' disables this part of the model
}
cfm=jft.CorrelatedFieldMaker("cf")
cfm.set_amplitude_total_offset(**args_zm)
cfm.add_fluctuations(
(x_npix,y_npix),
distances=(dx,dy),
**args_fl,
prefix="ax1",
non_parametric_kind="power"
)
log_sky=cfm.finalize()
classSky_model(jft.Model):
def__init__(self,log_sky):
self.log_sky=log_sky
super().__init__(init=self.log_sky.init)
def__call__(self,x):
returnjnp.exp(self.log_sky(x))
sky=Sky_model(log_sky)
sky=lambdax:jnp.exp(log_sky(x))
```
%% Cell type:markdown id: tags:
Prior samples
-------------
To get a feeling for the prior variability of the sky model we generate several random realizations of the process and visualize them. The power-spectra, generated for each process realization, are depicted in the last panel.
Setup a mock VLBI imaging task using the `InterferometryResponse` of `resolve`. The `mock_observation` contains all information relevant to set up the likelihood, including visibility data, uv-coordinates, and the noise levels of each measurement. The `measurement_sky` contains all relevant information regarding the prior model of the sky brightness distribution. The additional parameters passed to the `InterferometryResponse` control the accuracy and behaviour of the `wgridder` used within `resolve` which defines the response function.
Setup a mock VLBI imaging task using the `InterferometryResponse` of `resolve`. The `mock_observation` contains all information relevant to set up the likelihood, including visibility data, uv-coordinates, and the noise levels of each measurement. The `sky` contains all relevant information regarding the prior model of the sky brightness distribution. The additional parameters passed to the `InterferometryResponse` control the accuracy and behaviour of the `wgridder` used within `resolve` which defines the response function.
The `likelihood` together with the `sky_model` fully specify a Bayesian inverse problem and imply a posterior probability distribution over the degrees of freedom (DOF) of the model. This distribution is, in general, a high-dimensional (number of pixels + DOF of power spectrum) and non-Gaussian distribution, which prohibits analytical integration. To access its information and compute posterior expectation values, numerical approximations have to be made.
The `likelihood` together with the `sky` fully specify a Bayesian inverse problem and imply a posterior probability distribution over the degrees of freedom (DOF) of the model. This distribution is, in general, a high-dimensional (number of pixels + DOF of power spectrum) and non-Gaussian distribution, which prohibits analytical integration. To access its information and compute posterior expectation values, numerical approximations have to be made.
`nifty` provides multiple ways of posterior approximation, with Variational Inference (VI) being by far the most frequently used method. In VI the posterior distribution is approximated with another distribution by minimizing their respective forward Kullbach-Leibler divergence (KL). In the following, the Geometric VI method is employed which utilizes concepts of differential geometry to provide a local estimate of the distribution function.
Its numerical implementation (`jft.optimize_kl`) consists of a repeated and successive re-approximation of the VI objective function (the KL) via a stochastic estimate. This estimate is generated using the at the time best available approximation of the posterior, and then the KL gets minimized to further improve it. The resulting algorithm consists of a repeated re-generation of new samples for the estimate and a successing optimization thereof until convergence is reached.
The internal steps of `jft.optimize_kl` invoke the approximate solution of multiple interdependent optimization problems:
- For sample generation, a linear system of equations is approximated using the `ConjugateGradient` (CG) method
- Furthermore, the sample generation invokes a non-linear optimization problem approximated using the `NewtonCG` method
- Finally, the approximative distribution is optimized by minimizing the KL between the true posterior and the approximation. This again invokes a non-linear optimization problem approximated with `NewtonCG`.
%% Cell type:markdown id: tags:
Posterior visualization
-----------------------
Before we run the minimization routine, we set up a `plotting_callback` function for visualization. Note that additional information and plots regarding the reconstruction are generated during an `ift.optimize_kl` run and stored in the folder passed to the `output_directory` argument of `ift.optimize_kl`
The final output of `ift.optimize_kl` is a collection of approximate posterior samples and is provided via an instance of `ift.ResidualSampleList`. A `SampleList` provides a variety of convenience functions such as:
-`average`: to compute sample averages
-`sample_stat`: to get the approximate mean and variance of a model
-`iterator`: a python iterator over all samples
- ...
Before we run the minimization routine, we set up a `plotting_callback` function for visualization. Note that additional information and plots regarding the reconstruction are generated during an `jft.optimize_kl` run and stored in the folder passed to the `output_directory` argument of `jft.optimize_kl`
The final output of `jft.optimize_kl` is a collection of approximate posterior samples and is provided via an instance of `jft.Samples`. You can iterate over these samples samples. With `jft.mean_and_std` you can get the mean and the standard deviation.
We can generate and study the posterior uncertainty maps for any kind of quantity we are interested in (i.e., not only for the sky brightness). In particular, we can also take a look at the uncertainty of the sky brightness in the UV plane. Comparing this to the measured UV-tracks is insghtfull.