Skip to content

Commit dbc838b

Browse files
A bit more clean up
1 parent 7ef42a3 commit dbc838b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/fstats_mcmc.f90

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ subroutine mh_push(this, x, err)
185185
end subroutine
186186

187187
! ------------------------------------------------------------------------------
188-
subroutine mh_proposal_sampler(this, mu, x, x1, x2)
188+
subroutine mh_proposal_sampler(this, mu, x, f, x1, x2)
189189
!! A sampler capable of generating the next proposed step in the chain. The
190190
!! default sampler is a multivariate Gaussian of the form.
191191
!!
@@ -201,6 +201,9 @@ subroutine mh_proposal_sampler(this, mu, x, x1, x2)
201201
!! An N-element array containing the current state.
202202
real(real64), intent(out), dimension(size(mu)) :: x
203203
!! An N-element array containing the proposed state.
204+
real(real64), intent(out) :: f
205+
!! The value of the probability distribution function at the proposed
206+
!! state centered around the current state.
204207
real(real64), intent(in), optional, dimension(size(mu)) :: x1
205208
!! An optional N-element array containing the lower limits for the state
206209
!! variables. If not supplied, no limits are imposed.
@@ -236,6 +239,9 @@ subroutine mh_proposal_sampler(this, mu, x, x1, x2)
236239
! upper limits
237240
x = min(x, x2)
238241
end if
242+
243+
! Evaluate the pdf
244+
f = this%m_sampleDist%pdf(x)
239245
end subroutine
240246

241247
! ------------------------------------------------------------------------------
@@ -349,7 +355,7 @@ subroutine mh_eval(this, fcn, x, y, mdl, niter, x1, x2, err)
349355

350356
! Local Variables
351357
integer(int32) :: i, n, flag, maxiter
352-
real(real64) :: alpha, pc, pp, r, a
358+
real(real64) :: alpha, pc, pp, r, a, a1, a2, gc, gp
353359
real(real64), allocatable, dimension(:) :: xp, xc
354360
real(real64), allocatable, dimension(:,:) :: sigma
355361
class(errors), pointer :: errmgr
@@ -386,7 +392,7 @@ subroutine mh_eval(this, fcn, x, y, mdl, niter, x1, x2, err)
386392
if (errmgr%has_error_occurred()) return
387393

388394
! Evaluate the next step
389-
call this%proposal(xc, xp, x1, x2)
395+
call this%proposal(xc, xp, gc, x1, x2)
390396

391397
! Compute the target density
392398
pc = this%target_density(x, y, xc)
@@ -395,13 +401,15 @@ subroutine mh_eval(this, fcn, x, y, mdl, niter, x1, x2, err)
395401
! established
396402
do i = 2, maxiter
397403
! Define a new proposal
398-
call this%proposal(xc, xp, x1, x2)
404+
call this%proposal(xc, xp, gp, x1, x2)
399405

400406
! Compute the target density
401407
pp = this%target_density(x, y, xp)
402408

403409
! Compute the acceptance ratio & see if the step is good enough
404-
a = pp / pc
410+
a1 = pp / pc
411+
a2 = gp / gc
412+
a = a1 * a2
405413
alpha = min(1.0d0, a)
406414
call random_number(r)
407415
if (r < alpha) then
@@ -410,6 +418,7 @@ subroutine mh_eval(this, fcn, x, y, mdl, niter, x1, x2, err)
410418
if (errmgr%has_error_occurred()) return
411419
xc = xp
412420
pc = pp
421+
gc = gp
413422

414423
! Update the covariance matrix???
415424
end if

0 commit comments

Comments
 (0)