Skip to content

Commit a816d4f

Browse files
committed
Move utility functions out of StratMetropolis.jl
1 parent ec24946 commit a816d4f

File tree

5 files changed

+36
-34
lines changed

5 files changed

+36
-34
lines changed

src/Chron.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ module Chron
3434
using Distributions
3535
using QuadGK
3636

37+
# Custom objects for holding Chron age data
38+
include("Objects.jl")
39+
# General utility functions
3740
include("Utilities.jl")
3841
# Functions for propagating systematic uncertainties
3942
include("Systematic.jl")
40-
# Custom objects for holding Chron age data
41-
include("Objects.jl")
4243
# Intcal2013 calibration curve for radiocarbion
4344
include("Intcal.jl")
4445
# Functions for estimating extrema of a finite-range distribution

src/Objects.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
Name::NTuple{N, String}
5151
Height::Vector{Float64}
5252
Height_sigma::Vector{Float64}
53-
Age::Vector{Distribution{Univariate, Continuous}}
53+
Age_Distribution::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
5454
Age_Sidedness::Vector{Float64}
5555
Chronometer::NTuple{N, Symbol}
5656
Age_Unit::String

src/StratMetropolis.jl

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -433,33 +433,6 @@
433433

434434
## --- # Internals of the Markov chain
435435

436-
# Use dispatch to let us reduce duplication
437-
strat_ll(x, ages::AbstractVector{<:Radiocarbon}) = interpolate_ll(x, ages)
438-
strat_ll(x, ages::AbstractVector{<:Normal}) = normpdf_ll(x, ages)
439-
strat_ll(x::Real, age::Distribution) = logpdf(age, x)
440-
function strat_ll(x, ages)
441-
ll = zero(float(eltype(x)))
442-
@inbounds for i in eachindex(x, ages)
443-
ll += logpdf(ages[i], x[i])
444-
end
445-
return ll
446-
end
447-
448-
adjust!(ages, chronometer, systematic::Nothing) = ages
449-
function adjust!(ages, chronometer, systematic::SystematicUncertainty)
450-
systUPb = randn()*systematic.UPb
451-
systArAr = randn()*systematic.ArAr
452-
@assert eachindex(ages)==eachindex(chronometer)
453-
@inbounds for i eachindex(ages)
454-
if chronometer[i] === :UPb
455-
ages[i] += systUPb
456-
elseif chronometer[i] === :ArAr
457-
ages[i] += systArAr
458-
end
459-
end
460-
return ages
461-
end
462-
463436
function stratmetropolis(Height, Height_sigma, model_heights::AbstractRange, Age_Sidedness, ages, model_ages, proposal_sigma, burnin::Integer, nsteps::Integer, sieve::Integer, Chronometer=nothing, systematic=nothing)
464437
resolution = step(model_heights)
465438
npoints = length(model_heights)

src/Systematic.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
## --- Dealing with systematic uncertainty
1+
## --- Adjust distributions for systematic uncertainty
2+
3+
adjust!(ages, chronometer, systematic::Nothing) = ages
4+
function adjust!(ages, chronometer, systematic::SystematicUncertainty)
5+
systUPb = randn()*systematic.UPb
6+
systArAr = randn()*systematic.ArAr
7+
@assert eachindex(ages)==eachindex(chronometer)
8+
@inbounds for i eachindex(ages)
9+
if chronometer[i] === :UPb
10+
ages[i] += systUPb
11+
elseif chronometer[i] === :ArAr
12+
ages[i] += systArAr
13+
end
14+
end
15+
return ages
16+
end
17+
18+
## --- Add systematic uncertainty when given an already-generated age or age-depth distribution
219

320
function add_systematic_uncert_UPb(agedistmyr::Vector{<:AbstractFloat})
421
λ238 = val(λ238U) # Jaffey decay constant, 1/Myr

src/Utilities.jl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
## --- Dealing with arbitrary distributions
2-
3-
41
## --- "bilinear exponential" distribution type
52

63
"""
@@ -280,4 +277,18 @@
280277
return ll
281278
end
282279

280+
## --- log likelihood functions allowing for arbitrary Distributions
281+
282+
# Use dispatch to let us reduce duplication
283+
strat_ll(x, ages::AbstractVector{<:Radiocarbon}) = interpolate_ll(x, ages)
284+
strat_ll(x, ages::AbstractVector{<:Normal}) = normpdf_ll(x, ages)
285+
strat_ll(x::Real, age::Distribution) = logpdf(age, x)
286+
function strat_ll(x, ages)
287+
ll = zero(float(eltype(x)))
288+
@inbounds for i in eachindex(x, ages)
289+
ll += logpdf(ages[i], x[i])
290+
end
291+
return ll
292+
end
293+
283294
## --- End of File

0 commit comments

Comments
 (0)