Neural networks as universal model approximators
We can think of a neural network, , as an approximation of a model, , where is some input data to the network and the output of the network is which is an estimate of some target, , associated with the data. The neural network itself is a function of some trainable parameters called weights, , and some hyperparameters, , which encompass the architecture of the network, the initial values of the weights, the form of activation functions, the choice of cost function, etc.
Likelihood of obtaining targets given a network
In a traditional sense, the training of a neural network is equivalent to minimising a cost or loss function, , with respect to the weights of the network, (and hyperparameters, ) given a set of pairs of data and targets for training and validation, and . The cost function, , measures how close the outputs of a fixed network, , are to some target, , given a datatarget pair, , at some fixed network parameters and hyperparameters, and . That is, how likely is it that the output of the network provides the true target for the input data given a chosen set of weights and fixed network hyperparameters, i.e. the cost function is equivalent to the (negative logarithm of the) likelihood function
The likelihood surface, although regular for a given set of network parameters and hyperparameters, is extremely complex, degenerate, and even discrete and nonconvex in the directions of the network parameters and hyperparameters.
Although the cost function is normally chosen to be convex, i.e. with a global minimum and defined everywhere, at a given value of and , the shape of the likelihood is extremely complex, degenerate and bumpy when considering all possible and will often be discrete and nonconvex in the direction.
Maximum likelihood network parameter estimates
The normal procedure for using neural networks is to train them. This means finding the maximum likelihood estimates of the weights of a network with a given set of training datatarget pairs and fixed hyperparameters, , by doing
That is, find the set of for which the likelihood function evaluated at every member in the training set is maximum. In the case that each pair of data and targets, are independent and identically distributed we can write the likelihood as
By finding the set of which are closest (in the sense of the minimum cost function) to the target , given some a neural network and some input data , the weights of the network traverse the negative logarithm of the likelhiood surface for the true target, hopefully ending at some minimum (which is a maximum in the likelihood).
To find the maximum likelihood of the weights, one would normally consider some sort of stochastic gradient descent. Since most software is more efficient at finding minima rather than maxima, we actually minimise the negative logarithm of the likelihood, i.e. the cost function
The weights are updated using . In the ideal case there would be one global minimum in the likelihood so that after training the value of the weights of the neural network would be equal to the maximum likelihood estimates, . However, since the likelihood surface is, in reality, extremely degenerate and flat in the space of weight values, it is most likely that the weights only achieve a local maximum, i.e. . In fact, which local maximum is found will normally depend extremely strongly on the initial which is used for the gradient descent.
The initialisation of the weights will be very important in determining which local maximum likelihood estimate is found. This is because the surface of the likelihood is very bumpy. It can also be highly degenerate which leads to whole families of pseudomaximum likelihood estimates.
Once the maximum (or at least local maximum) is found, it is normal to evaluate the accuracy (or some other figure of merit) using some validation set, . This validation set is used to modify the hyperparameters, , of the network to achieve the best fit to both the training and validation sets as possible. These modifications could include changing the initial seeds of the weights, changing the activation functions, or changing the entire architecture, for example. However, networks trained in such a way do not provide a way to obtain scientifically robust estimates of the true targets , given observed data . To see why, we need to consider the probabilistic interpretation of neural networks.
Probabilistic interpretation of neural networks
The posterior predictive density of obtaining a target, , given some input data, , is
The likelihood of obtaining the true value of the target , which is the (unnormalised) negative exponential of the cost function, when given some input data and network parameters and hyperparameters and . is the probability of obtaining the weights and hyperparameters of the neural network. Since the likelihood of obtaining any value of the target, , given some input data, , for any given neural network, i.e. any combination of and , is essentially equal then the likelihood, , is almost flat. Therefore, the majority of the information about the posterior predictive density, , comes from the any a priori or a posteriori knowledge of the weights , and therefore, it has to be chosen or found very carefully.
The form of the posterior predictive density of the targets depends mostly on the probability of the weights and hyperparameters of the network. This means that the prior for the weights and hyperparameters must be chosen carefully or the posterior extremely well characterised via training data.
A Bayesian neural network is a network which provides the true posterior predictive density of targets given data .
Failure of traditionally trained neural networks
As described above, given a set of training pairs, , and validation pairs, , we can find the (local) maximum likelihood estimates of the weights, , and optimise the hyperparameters to which gives the best fit to both the training and validation datatarget pair sets. Since we fix both the parameters and hyperparameters, those values are set in stone and we degenerate the posterior distribution to a Dirac function, neglecting any information brought by the training data, i.e.
where is a prior distribution over the weights and hyperparameters. By making such a choice, we erase the entirety of the information about the distribution of data and work only with the best fit model, which may (or may not) be complete. As such, the predictive probability density of the targets given data is
i.e., the probability of obtaining an estimate from the network is zero everywhere apart from at the value of the output of the network,  the function is completely deterministic. Effectively, this means that the probability of obtaining given the fixed network parameters and hyperparameters and some data is impossibly small.
Consider a third test set, . One normally determines how well a neural network is trained using this unseen (blind) set. To test the network, all of the test data, , are passed through the network to get estimates which can be plotted against the known targets, (see above figure).
For any set of data, a trained neural network with fixed hyperparameters and network parameters at their maximum likelihood values, the probability of obtaining a target is a function. There is no knowledge of whether the output of the network will be equal to the target, and it is, in fact, improbably unlikely that they will be.
A network which produces which correlate very strongly with is probably a network that is in a very good local maximum for both the weights and the hyperparameters. However, there is no assurance that the true should be obtained by the network, and due to the complexity of the likelihood , there is also no way of ensuring that should be similar to . Simply, for complex models, it is not possible to prove that the neural network is equivalent to the model, , and so there is no trust that the network will provide . In fact, because , it is improbably unlikely to ever find . For extremely simple architectures it may be possible to prove that at the global maximum likelihood estimates of the weights that , but unfortunately, such simple networks are much less likely to contain the exact representation of . Therefore, one can only prove in the limit of infinite data. This is because, in the limit of infinite training data and infinite validation data then we can assume (but not know) that a network could be found (via optimising the hyperparameters over the space of all possible architectures, activation functions, initial conditions of the weights, etc.) which has the capability to exactly reproduce the model by finding the true global maximum of the weights over the space of all possible weights in all possible architectures.
An interesting point to make, especially for regression to model parameters, is that one attempts to use the neural network to find a mapping from a manytoone value space since the same could produce a very large number of different , i.e. the forward model is stochastic. It is an extremely difficult procedure to undo stochastic processes, which is why the neural network will likely never achieve the target function.
Variational inference using approximate weight priors
A neural network can be trained via variational inference where parameters of the network predict the parameters of a variational distribution from which the weights for the forward propagation are drawn.
All of the problems with the traditional picture arise due to degenerating the probability of the weights and hyperparameters . We can recover variational inference by assuming the posterior distribution of the weights becomes an approximate variational distribution, , which approximates posterior of given a secondary set of network parameters which define the shape of the variational distribution, , a set of hyperparameters, , and a set of training data and target pairs, . The posterior predictive density for the targets is then written
In practice, the parameters controlling the shape of the variational distribution, and the hyperparameters, are optimised iteratively using a training and validation set as with the traditional training framework and as such the posterior predictive density becomes
When the posterior distribution for the weights and hyperparameters of a neural network are approximated using a variational distribution, the posterior predictive density for the targets given some data has a form dictated mostly by the shape of the variational distribution. This shape is not necessarily correct since only simple distributions are usually used for the variational distribution and the distribution of weights can be extremely complex.
In principle, if well represents the true posterior of the weights and hyperparameters, , then this can be a good approximation. However, this is very dependent on the distributions which can represent. is normally chosen to be Gaussian, or perhaps a mixture of Gaussians. As discussed already, the likelihood of obtaining any set of weights, , is actually extremely bumpy and degenerate and, as such, must be chosen to be able to properly represent this. If is poorly proposed then the posterior predictive density of the targets, , will be incorrect.
The variational distribution often does not have enough complexity to fully model the intricate nature of the true posterior distribution of weights and hyperparameters. This can lead variational inference te be misleading.
Bayesian neural networks
A Bayesian neural network is similar a traditional one apart from the distribution of the weights (and hyperparameters) of the network are characterised by the posterior for the weights and hyperparameters given a set of training data.
An effective Bayesian neural network can be be built if we use the true posterior of and given some training data, rather than degenerating it to a Dirac , and instead keeping
With this, the predictive probability density of given becomes
Obviously the Bayesian neural network comes at a much higher computational cost than just finding the maximum likelihood estimate for the weights, but it does provide a more reasoned posterior predictive probability density, . Notice that the prior, , still enters and so we need to make an informed decision on our belief for what the values of and should be. However, for enough training datatarget pairs (and enough time to sample through whatever chosen prior, ) the posterior becomes informative enough to obtain useful posterior predictions for the targets.
For small numbers of data points, the likelihood is poorly characterised and so can lead to biasing in the posterior predictive density. It is therefore important to have enough data to properly know the likelihood  it is not easy to determine how much this is.
In effect, to make use of Bayesian neural networks, one has to resort to sampling techniques, such as Markov chain Monte Carlo, to describe . Because of the (normally extremely large) dimension of the number of weights, techniques such as MetropolisHastings cannnot be considered. We proposed using a secondorder geometrical adaptation of Hamiltonian Monte Carlo (QNHMC) in Charnock et al. 2019 (read more). By using such a sampling technique, one could generate samples for the posterior predictive density, , whose distribution describes what was the probability of getting a target from data marginalised over all network parameters given a hyperparameter, ^{1}. It is difficult to sample when using the QNHMC since gradients of the likelihood need to be computed and the likelihood in the direction is often discrete. How to properly sample from is still up for debate.
So now lets say we have enough computational power to build a true Bayesian neural network. Are we guaranteed to obtain a correct posterior predictive density?
Source of the problem
Training on data
Notice how all of the techniques mentioned above are dependent on a set of training data and target pairs, (and possibly validation data and targets, ). It is in the posterior (or variational distribution) for the weights that the training data arises
and, as already explained, the last term in the integral contains the informative part about the posterior predictive density. As such, any biasing due to greatly affects .
When depending on a training set, is always unknowably biased until the limit of infinite data is reached. So, no method mentioned so far provides us with the correct probability of obtaining the target!
For networks, such as emulators (or generative networks as they are commonly called), where the probability distribution of generating targets, , with generated data and a latent distribution , should approximate the distribution of true data , then the above argument means that we cannot find by training a neural network without infinite training data^{2}.
Incorrect models
One interesting use for neural networks is the predicting of physical model parameters, , for a model . In this case, even for infinite data, we cannot obtain true posterior distributions for the parameters. Take a network which maps , where are estimates of the model parameters, , which generate the data. Even if there is infinite training data, , if the original model is incorrect, then the neural network will be conditioned on the wrong map from data, , to parameters, , and so any observed data, , passed through the network will be passed through the incorrect approximation of the model and provide a poor estimate of the incorrect model parameter values. This means that true posteriors on the model parameters can only be obtained with the exact model which generates the observed data and an infinite amount of training data from that model, to be able to correctly provide parameter estimates.
This is not realistic!
Solutions
We have so far built a description of how to obtain the probability to obtain targets, , from data, , passed through a neural network… and unfortunately, we have learned that it is not possible to obtain.
There is still one problem where we can use neural networks safely despite all of the above. This is to do model parameter inference.
So far we have only considered a neural network as an approximation to a model . Now lets say we have a physical model, , which generates the data, from a set of model parameters, , dependent on a set of initial conditions , we can safely use a neural network, , to infer the model parameters of some observed data, . Note that we cannot use a network to predict model parameters directly due to all of the arguments above. Instead we need to set up a statistical inference framework which encompasses the neural network.
Charnock et al. 2019 and Charnock, Lavaux and Wandelt 2018 show two different methods to perform physical model parameter inference using neural networks, in a well justified way.
Writing down the likelihood
I should mention an extremely rare case where the model , is simple enough to be parameterised by an extremely simple network with very few parameters, which are nondegenerate and well behaved and for which the hyperparameters, , can be well designed to avoid needing to sample over this space.
For this case, the likelihood could be written, and therefore, fully established and sampled from, and biases from training datatarget pairs could be totaly avoided.
It is pretty unlikely that such a network could be found without considering physical principles.
Model extension
In Charnock et al. 2019, the connection between the observed data and the output of the physical model is not known, i.e. the data from a model given initial conditions, , is . This does not look like although we know that want the posterior distribution of . In Charnock et al. 2019, we know we can observe the universe and model the underlying dark matter of the universe, but the complex astrophysics which maps the dark matter of the universe to the observable tracers is unknown. We do, however, know some physical properties of this mapping. In this case, we build a neural network with the physically motivated symmetries to take the output of the physical model to the distribution which is as close to the observed data as possible (read more). In the language used previously, thanks to the problems we deal with in cosmology and astrophysics we can actually choose the hyperparameters of a neural network, , in a reasoned manner. These physically motivated neural networks therefore massively reduce the volume of the domain. With a careful choice of we can also build a network whose priors on the network paremeters, , can be (at least reasonably) well informed.
We can write the parameter inference as
That is, the posterior distribution for the model parameters given some observed data is proportional to the marginal distribution of how likely the observed data is given the initial conditions of the model, , which depend on the model parameters, , which generate the initial conditions and evolve the model forward to the input of the neural network with network parameters and hyperparameters and .
In this presented case, there is no training data for the network, instead the data needed to obtain the posterior is part of the statistical framework. Therefore, the network provides nonagnostic posterior parameter inference because we do not learn the posterior distribution, using training data. In essence, this defines the procedure to perform zeroshot training.
It should be noted that this procedure is difficult. It necessitates a sampling scheme for the neural network and the physical model. In Charnock et al. 2019, we use an advanced Hamiltonian Monte Carlo sampling technique on a model where we have calculated the adjoint gradient and the neural network whose architecture is well informed but fixed.
Likelihoodfree inference
The model extension method works well, but still depends on knowing the form of the likelihood of the observed data. In practice, this could be extremely difficult. It also depends on a choice of hyperparameters (or at least a well defined prior based on physical principles). In Charnock, Lavaux and Wandelt 2018, we showed another model extension method which allows use to obtain optimal model parameter inference using neural networks by (semi)classically training a neural network, , where the target distribution is the set of Gaussianly distributed summaries which maximise the Fisher information matrix. Although the network in this work is, in some way, optimal  the main point of this paper is that parameter inference can be done using likelihoodfree inference by extending the physical model to where is any set of summaries.
Likelihoodfree inference is a framework where, via generating data using the physical model, , the joint probablity of data and parameters, , can be characterised. Once this space is well defined, a slice through the distribution at any gives the posterior distribution  likewise the slice through the joint distribution at any parameter gives the likelihood distribution . This works for any system where we can model the data!
The neural networks become essential as functions which perform data compression (although, it should be noted that any summary of the data will work). Since, in general, the dimensionality of the data is much larger than the number of model parameters, a neural network can be trained to compress the data in some way, . We can train this in any way to give us some absolute summaries, , where we, essentially, do not care what the summaries are. Note that and do not need to be maximum likelihood estimates. By pushing all the generated data from the physical model through this fixed network we can characterise the probability distribution of parameters and compressed summaries, , which we can slice at any to give the likelihood of obtaining any summaries, , or (more interestingly) slice at any observed data pushed through the network, , to get the posterior,
This posterior, whilst conditional on the network parameters and hyperparameters, is unbiased in the sense that when the neural network, is not optimal, the posterior can only become inflated (and not incorrectly biased).
The information maximising neural network, presented in Charnock, Lavaux and Wandelt 2018, provides the optimal summaries^{3} for the likelihoodfree inference  but any neural network can be used in this inference framework. In particular, any neural network which looks like it provides good estimates of the targets for a model (as discussed throughout), will likely have extremely informative summaries, even if their outputs are improbably unlikely to be equal to the true target values (see traditionally training neural networks)!
Conclusions
Presented here is a thorough statistical diagnostic of neural networks. I have shown that, by design, neural networks cannot provide realistic posterior predictive densities for arbitrary targets. This essentially makes all neural networks unusable in science.
However, I have presented how my previous works can undermine this previous statment for model parameter inference. Since either a statistical interpretation or a fully trained neural network can be appended to a physical model, we can build a statistical framework around both the model and the neural network to allow us to do rigorous, scientific analysis of model parameters, which is one of the essential tasks in science today.
Tom Charnock, Guilhem Lavaux, Benjamin D. Wandelt, Supranta Sarma Boruah, Jens Jasche, Michael J. Hudson, 2019, submitted to MNRAS, arXiv:1909.06379
Tom Charnock, Guilhem Lavaux, Benjamin D. Wandelt, 2018, Physical Review D 97, 083004 (2018), arxiv:1802.03537

It should be noted that the work in Charnock et al. 2019 was tackling a larger problem and asking a different question than the one stated here for Bayesian neural networks. Bayesian neural networks are a subset of the techniques from that paper, although closely linked. ↩

We can hope that the generated target distribution gets close to the true data distribution and decide we are not bothered about statistics anymore. Maybe a dangerous situation for science‽ ↩

Optimal in the sense that the Fisher information is maximised. This has some assumptions such as the unimodality (but not necessarily Gaussianity) of the posterior, and the fact that the neural network being maximised is capable of finding a function which Gaussianises the data. ↩
Authored by T. Charnock
Post identifier: /method/machine%20learning/nn