Skip to content

Commit f4236bc

Browse files
Setting up MCMC structure
1 parent 3b959ef commit f4236bc

File tree

3 files changed

+457
-0
lines changed

3 files changed

+457
-0
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ set(FSTATS_SOURCES
1818
${dir}/fstats_sampling.f90
1919
${dir}/fstats_smoothing.f90
2020
${dir}/fstats_types.f90
21+
${dir}/fstats_mcmc.f90
2122
)
2223
set(FSTATS_SOURCES ${FSTATS_SOURCES} PARENT_SCOPE)

src/fstats_distributions.f90

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ pure function multivariate_distribution_function(this, x) result(rst)
182182
contains
183183
procedure, public :: initialize => mvnd_init
184184
procedure, public :: pdf => mvnd_pdf
185+
procedure, public :: set_means => mvnd_update_mean
185186
end type
186187

187188
contains
@@ -802,6 +803,50 @@ pure function mvnd_pdf(this, x) result(rst)
802803
rst = exp(-0.5d0 * arg) / sqrt((2.0d0 * pi)**n * this%m_covDet)
803804
end function
804805

806+
! ------------------------------------------------------------------------------
807+
subroutine mvnd_update_mean(this, x, err)
808+
!! Updates the mean value array.
809+
class(multivariate_normal_distribution), intent(inout) :: this
810+
!! The multivariate_normal_distribution object.
811+
real(real64), intent(in), dimension(:) :: x
812+
!! The N-element array of new mean values.
813+
class(errors), intent(inout), optional, target :: err
814+
!! The error handling object. This is referenced only in the event that
815+
!! the size of x is not compatible with the existing state.
816+
817+
! Local Variables
818+
integer(int32) :: n, nc, flag
819+
class(errors), pointer :: errmgr
820+
type(errors), target :: deferr
821+
822+
! Initialization
823+
if (present(err)) then
824+
errmgr => err
825+
else
826+
errmgr => deferr
827+
end if
828+
n = size(x)
829+
nc = size(this%m_means)
830+
831+
! Process
832+
if (.not.allocated(this%m_means)) then
833+
! This is an initial set-up - just store the values and be done
834+
allocate(this%m_means(n), stat = flag, source = x)
835+
if (flag /= 0) then
836+
call report_memory_error(errmgr, "mvnd_update_mean", flag)
837+
return
838+
end if
839+
return
840+
end if
841+
842+
! Else, ensure the array is of the correct size before updating
843+
if (n /= nc) then
844+
call report_array_size_error(errmgr, "mvnd_update_mean", "x", nc, n)
845+
return
846+
end if
847+
this%m_means = x
848+
end subroutine
849+
805850
! ******************************************************************************
806851
! SUPPORTING ROUTINES
807852
! ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)