Proposal of a Score Based Approach to Sampling Using Monte Carlo Estimation of Score and Oracle Access to Target Density
Abstract
Score based approaches to sampling have shown much success as a generative algorithm to produce new samples from a target density given a pool of initial samples.
In this work, we consider if we have no initial samples from the target density, but rather
th and 1 st order oracle access to the log likelihood.
Such problems may arise in Bayesian posterior sampling, or in approximate minimization of non-convex functions.
Using this knowledge alone, we propose a Monte Carlo method to estimate the score empirically as a particular expectation of a random variable.
Using this estimator, we can then run a discrete version of the backward ﬂow SDE to produce samples from the target density.
This approach has the beneﬁt of not relying on a pool of initial samples from the target density, and it does not rely on a neural network or other black box model to estimate the score.
Introduction
Producing samples from a known probability measure is a core problem in statistics and many machine learning applications.
Computing complicated integrals, determining the volume of a high dimensional set, or performing Bayesian inference on a posterior are all problems which require generating samples from a probability measure in question.
In this work, we consider sampling from a probability measure P 0 over θ ∈ R d absolutely continuous with respect to Lebesgue measure and admitting a probability density proportional to p
( θ ) ∝ e f ( θ ) − 12 θ T θ for some function f ( θ ) .
The form of the density is known and we are able to query f
( θ ) and ∇ f ( θ ) at will.
When f ( θ ) is concave, such a density is called log concave and can easily be sampled by known methods such as Langevin diffusion or other classical Markov Chain Monte Carlo (MCMC) methods. However, we are particularly interested in when f ( θ ) is non-concave having multiple separated maximizers.
Traditional MCMC methods for such a density have no guarantee of convergence to invariance in ﬁnite time. Two examples are if f ( θ ) represents the log likelihood of a mixture model (e.g. Gaussian mixture model) and p 0 ( θ ) is the posterior under a normal prior.
Under such a model, the posterior has multiple modes of equal likelihood which are difﬁcult for traditional methods to sample.
If f ( θ ) represents a non-concave objective we want to maximize under a L 2 penalty, θ ∗ = argmax θ f ( θ ) − 12 θ T θ
[-=
-], we may settle not for ﬁnding θ ∗ , but rather sampling θ ∼ p 0 ( θ ) and anticipating that f ( θ ∗ )
≈ f ([-Y i − tanh ( X Ti θ )) 
 + 12-] θ ) , that is our sampled point, while not the global maximizer, produces a function value close to the optimal value.
Thus, there remains non-log concave sampling problems yet to be sufﬁciently addressed by existing
MCMC algorithms. In recent years, score based methods have shown remarkable success as a generative model on complex multi-modal densities in high dimensions.
In this paper, we would like to transfer this success as a generative model into a successful algorithm for sampling a known density function. The main difference between a generative modelling problem and the sampling problem studied here is what “information” about the {+target density p 
+}
( θ ) the algorithm may access.
In the current applications of score based methods as a generative algorithm, one starts with an initial pool of samples drawn from the target measure, θ 0 , · · · , θ N ∼ P 0 , but one does not know the functional form of the target density nor can one query f ( θ ) and it’s gradient ∇ f ( θ ) directly. In this work, we have no initial samples from the target density, but do have direct axis to the density function p 0 =
e f ( θ ) − 12 θ T θ as well as access to f ( θ ) and ∇ f ( θ ) .
What connects both problems is the core theory of score based sampling.
Underlying all score based approaches to sampling is the dual relationship between the “forward ﬂow” and “backward ﬂow” stochastic differential equations (SDE).
Consider the forward ﬂow SDE
[Equation]
where the marginal distribution of θ t at time t is denoted P t with density p t .
Paired with this forward ﬂow SDE is a backward ﬂow SDE [1]
[Equation]
where we run time in reverse from t
= T to t = 0 .
The forward ﬂow SDE takes θ 0 ∼ P 0 to θ T ∼ P T , while the backward ﬂow SDE takes θ T ∼ P T to θ 0 ∼ P 0 .
If we can sample P T directly and implement the backward ﬂow SDE then we can produce samples from P 0 .
Crucial to the backward ﬂow SDE is the score function, ∇ log p t ( θ ) , which is not known and must be estimated.
Popular generative approaches have a large pool of initial samples drawn from P 0 .
They then train a model such as a neural network to approximate the score at different time scales t by minimizing an objective function using the initial samples and noisy perturbations as training data [10, 11].
Various related methods such as [3], [4] propose improved methods to estimate the score, but are also ultimately generative and thus rely on initial samples.
[5] applies score based diffusions as an approach to improve annealed importance sampling.
It is not a generative approach as it does not rely on initial samples from the target density, but it ultimately trains a neural network to estimate the score by minimizing relative entropy.
In this paper, we desire a method to estimate the score without any initial samples from P 0 and without appealing to a complex secondary model such as a neural network to estimate the score.
As a summary of what is to come, with knowledge of the functional form of the density p 0 and application of stochastic calculus, we can analytically express how p t changes over time and express p t as an expectation of a known function over a known density.
With some further analysis, the score ∇ log p t ( θ ) can also be expressed as the expectation of a function over a density, and thus the score can be computed by estimating this integral via a sub Monte Carlo (MC) sampling problem.
This replaces the need to estimate the score via a neural network with estimating the score via a MC average.
Speciﬁcally, we will consider the forward ﬂow SDE as the Ornstein–Uhlenbeck process with drift f
( θ, t ) = − θ and constant diffusion g ([-t ) = √ 
-]
[Equation]
= [Equation]
[Equation]
The invariant measure is standard normal and the conditional measure p t ( θ t | θ 0 ) can be expressed as
[Equation]
Thus the density p t ( θ t ) up to normalization can be computed by integrating p 0 ( θ 0 ) p t ( θ t | θ 0 ) over θand the score, which removes any dependence on normalizing constants, can be expressed as
[Equation]
With some manipulations, we can express the numerator and denominator as expectations over normal random variables, and thus can approximate each via averaging the integrand at normally drawn points, i.e. a MC estimator.
Results
Simplifying equation (5) (see appendix for full derivation) we can express the score as a ratio of two expectations,
[Equation]
applying integration by parts (see appendix) [Equation] this expression can equivalently be written as
[Equation]
Computing expressions (6) and (7) then amounts to computing expectations over normal random variables [Equation] and we will appeal to a MC estimator.
Say we draw K points U 1 , · · · , U K ∼ N (0 , I ) from a standard normal
[Equation]
and approximate the score in one of two ways.
Deﬁne weights w k which sum to
[Equation]
as the relative heights of the exponential of f evaluated at the sampled points. We can then approximate (6) and (7) as weighted averages using these weightings
[Equation]
There are two perspectives on how to estimate the ratio of expectations that deﬁne (6) and (7).
One could use a separate pool of samples to evaluate the numerator and denominator expectations and then take the ratio of these two estimates.
However, we may be dividing by a potentially small number in this method and have high variance as a result.
The authors here propose using the same pool of samples to estimate both the numerator and denominator, resulting in the weights w k where the normalizing constant of the weights represents the denominator in (6) and (7).
This has the advantage that the estimates will never become unbounded since all estimates are weighted averages of well behaved values, however proper analysis must be conducted on how such a sampling procedure effects the independence, bias, and variance of the estimators.
For small t , say t < 0 .
1 , we conjecture that ˆ s 2 ( θ, t ) is the better estimator as it will have lower variance since e − t √ 1 − e − 2 t can grow large as t → 0 .
Additionally, as t → 0 , ∇ f ( √ 1 − e − 2 t U + e − t θ ) → ∇ f ( θ ) and estimate ˆ s 2 ( θ, t ) approaches − θ + ∇ f ( θ ) for small t , that is the score of the target density.
For larger t , it would seem ˆ s 1 ( θ, t ) will have lower variance since U k is less variable than the gradient of the target ∇ f
( U k ) .
Additionally, as t → ∞ we have the weights w k approach a θ independent value due to the e − t θ , so the expectation is some ﬁnite vector while e
[Equation]
t √ 1 − e
[Equation]
2 t → 0 thus the score approaches − θ , the score of a standard normal.
The algorithm to generate a sample from P 0 is as follows.
Pick a terminal time T > 0 , step size δ > 0 , and MC sample size K ∈ N .
Initialize θ T ∼ N
0 , I ) and t = T .
While t > 0 , in each iteration draw K values U 1 , · · · , U K ∼ N (0 , I ) and compute weights w k .
For large times t > 0 . 1 estimate score as ˆ s ( θ t , t ) =
ˆ s 1 ( θ, t ) , otherwise set ˆ s ( θ t , t )
=
ˆ s 2 ( θ, t ) .
Update the point as θ t − δ = θ t − δ ( − θ t − 2ˆ s ( θ t , t ))
+ √ 2 δZ,
Z ∼ N (0 , I ) and decrease t = t − δ .
Finally, return θ 0 .
One could propose more complex methods such Stein’s method [2],[9] or multi-modal sampling methods such as Simulated Tempering [7] to estimate the quantities in (6) and (7), as these represent expectations over un-normalized densities (the denominator is the normalizing constant).
However, estimating these values is itself a sub problem of sampling the un-normalized density p 0 in the ﬁrst place, thus if we employ sufﬁciently complex methods to sample the sub problems we may have simply employed said methods on the original problem.
Additionally, for large t >> 0 and small t ≈
the simple estimators will have small variance, thus it is the middle region of t where it may require more involved estimation of quantities (6) and (7) to keep the estimates accurate. [Figure]
Example
Here we demonstrate the performance of the algorithm on a series of example problems.
These examples while low dimensional represent multi-modal targets with future work considering higher dimensional implementations. First, we sample a one dimensional multi-modal target density with asymmetric modes.
Using the log likelihood function f
[Equation]
In Figure 1a we see the histogram of n = 1000 points ran in parallel with terminal time T = 2 , K = 3000 samples per estimate, and step size δ = 0 . This requires K ∗ ( T/δ )
= 600 ,evaluations of f and ∇ f per point, a signiﬁcantly high number of evaluations per sample but the polynomial nature may see better gains in high dimensions compared with existing methods. Another typical problem to test multi-modal sampling is to sample the Himmelblau function [6] in two dimensions [Equation]
which has modes at (3 , 2) , ( − 2 . 81 , 3 . 13) , ( − 3 . 78 , − 3 . 28) , (3 . 58 , − 1 . 85) which are all separated by areas of low probability and asymmetric in their relative heights. Sampling n = 2000 points in parallel with T = 3 , K = 1000 , δ = 0 . this algorithm requires K ∗ ( T/δ )
= 300 , 000 evaluations of f and ∇ f per point. To test if each mode is sampled proportionally correct, we compute the proportion of points within ± 0 . 5 in each coordinate around each mode and normalize to sum to 1.
We then evaluate the target pdf at 10 , 000 points sampled uniformly around each mode as an estimate of the probability of the region around each mode and normalize to sum to 1.
If each more is sampled proportionally correctly, then these two vectors should be the same. The probability estimates of each mode’s immediate vicinity are (0.831, 0.009, 0.002, 0.158) while the proportion of points near each mode is (0.741, 0.053, 0.005, 0.201). We note that the modes are not sampled exactly in the correct proportions, but the proportions are reasonable close to each mode, and each mode is visited, so as an approximate sampling algorithm this may sufﬁce in certain situations.
Concluding remarks
This paper presents a score based sampling approach using Monte Carlo estimation of the score and knowledge of the functional form of the target density.
This method does not rely on any initial samples from the target density, nor on a model such as a neural network to estimate the score function.
Much work remains to be done on the the analysis of such a method, speciﬁcally on high dimensional target densities of interest.
The MC estimators may be of high variance, and theoretical guarantees on this variance must be provided.
Furthermore, the estimates of the score will never be perfect, they will have some standard error around the true value, thus analysis of the backward ﬂow
SDE under discretization and approximate drift such as the analysis in [8] will be also be required to guarantee convergence to the correct target measure.
Appendix
Here we derive the form of the expectations that deﬁne the score.
Deﬁne σ t = √ 1 − e − 2 t , we have
[Equation]
we now perform some completing the square on the θ 0 terms in the exponent to express it as a normal density over θ 0 .
Note by cancellation on the top and bottom of the fraction, we can ignore any constant terms in the integral and only focus on those terms which relate to θ 0 .
[Equation]
thus [Equation] the above function is proportional to e f ( θ 0 )
N ( e − t θ t , σ 2 t I ) and we can write the score as
[Equation]
then [Equation] consider if instead U ∼ N (0 , I ) and θ
= σ t U + e − t θ t [Equation] we could write the above as
[Equation]
We can also apply integration by parts in the numerator to arrive at an equivalent expression, e
[Equation]
and thus can express the score as
[Equation]