|
4 | 4 | """
|
5 | 5 | ```julia
|
6 | 6 | StratMetropolis(smpl::ChronAgeData, [hiatus::HiatusData,] config::StratAgeModelConfiguration)
|
| 7 | + StratMetropolis(smpl::GeneralAgeData, [hiatus::HiatusData,] config::StratAgeModelConfiguration) |
7 | 8 | ```
|
8 | 9 | Runs the main Chron.jl age-depth model routine for a stratigraphic set of
|
9 | 10 | samples defined by sample heights and simple Gaussian age constraints in the
|
|
39 | 40 | Height = copy(smpl.Height)::Vector{Float64}
|
40 | 41 | Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues
|
41 | 42 | Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age
|
42 |
| - Chronometer = smpl.Chronometer |
| 43 | + chronometer = smpl.Chronometer |
43 | 44 | (bottom, top) = extrema(Height)
|
44 | 45 | model_heights = bottom:resolution:top
|
45 | 46 |
|
|
60 | 61 | Height_sigma = [0; Height_sigma; 0] .+ 1E-9 # Avoid divide-by-zero issues
|
61 | 62 | Age_Sidedness = [-1.0; Age_Sidedness; 1.0;] # Bottom is a maximum age and top is a minimum age
|
62 | 63 | model_heights = (bottom-offset):resolution:(top+offset)
|
63 |
| - Chronometer = (:None, Chronometer..., :None) |
| 64 | + chronometer = (:None, chronometer..., :None) |
64 | 65 | end
|
65 | 66 | active_height_t = bottom .<= model_heights .<= top
|
66 | 67 |
|
|
77 | 78 |
|
78 | 79 | # Run the Markov chain
|
79 | 80 | ages = Normal.(Age, Age_sigma)
|
80 |
| - agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, Chronometer, systematic) |
| 81 | + agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, chronometer, systematic) |
81 | 82 |
|
82 | 83 | # Crop the result
|
83 | 84 | agedist = agedist[active_height_t,:]
|
|
86 | 87 |
|
87 | 88 | return mdl, agedist, lldist
|
88 | 89 | end
|
89 |
| - function StratMetropolis(smpl::ChronAgeData, hiatus::HiatusData, config::StratAgeModelConfiguration) |
| 90 | + function StratMetropolis(smpl::ChronAgeData, hiatus::HiatusData, config::StratAgeModelConfiguration, systematic=nothing) |
90 | 91 | # Run stratigraphic MCMC model, with hiata
|
91 | 92 | @info "Generating stratigraphic age-depth model..."
|
92 | 93 |
|
|
103 | 104 | Height = copy(smpl.Height)::Vector{Float64}
|
104 | 105 | Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues
|
105 | 106 | Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age
|
| 107 | + chronometer = smpl.Chronometer |
106 | 108 | (bottom, top) = extrema(Height)
|
107 | 109 | model_heights = bottom:resolution:top
|
108 | 110 |
|
|
123 | 125 | Height_sigma = [0; Height_sigma; 0] .+ 1E-9 # Avoid divide-by-zero issues
|
124 | 126 | Age_Sidedness = [-1.0; Age_Sidedness; 1.0;] # Bottom is a maximum age and top is a minimum age
|
125 | 127 | model_heights = (bottom-offset):resolution:(top+offset)
|
| 128 | + chronometer = (:None, chronometer..., :None) |
126 | 129 | end
|
127 | 130 | active_height_t = bottom .<= model_heights .<= top
|
128 | 131 | npoints = length(model_heights)
|
|
140 | 143 |
|
141 | 144 | # Run the Markov chain
|
142 | 145 | ages = Normal.(Age, Age_sigma)
|
143 |
| - agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve) |
| 146 | + agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, chronometer, systematic) |
| 147 | + |
| 148 | + # Crop the result |
| 149 | + agedist = agedist[active_height_t,:] |
| 150 | + model_heights = model_heights[active_height_t] |
| 151 | + mdl = StratAgeModel(model_heights, agedist) |
| 152 | + |
| 153 | + return mdl, agedist, hiatusdist, lldist |
| 154 | + end |
| 155 | + function StratMetropolis(smpl::GeneralAgeData, config::StratAgeModelConfiguration, systematic=nothing) |
| 156 | + # Run stratigraphic MCMC model |
| 157 | + @info "Generating stratigraphic age-depth model..." |
| 158 | + |
| 159 | + # Model configuration -- read from struct |
| 160 | + resolution = config.resolution |
| 161 | + burnin = config.burnin |
| 162 | + nsteps = config.nsteps |
| 163 | + sieve = config.sieve |
| 164 | + bounding = config.bounding |
| 165 | + |
| 166 | + # Stratigraphic age constraints |
| 167 | + ages = unionize(smpl.Age_Distribution)::Vector{<:Union{<:Distribution{Univariate, Continuous}}} |
| 168 | + Height = copy(smpl.Height)::Vector{Float64} |
| 169 | + Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues |
| 170 | + Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age |
| 171 | + chronometer = smpl.Chronometer |
| 172 | + (bottom, top) = extrema(Height) |
| 173 | + model_heights = bottom:resolution:top |
| 174 | + |
| 175 | + aveuncert = nanmean(std.(ages)) |
| 176 | + absdiff = diff(sort!(mean.(ages[Age_Sidedness.==0]))) |
| 177 | + maxdiff = isempty(absdiff) ? 0.0 : nanmaximum(absdiff) |
| 178 | + proposal_sigma = sqrt(aveuncert^2 + (maxdiff/10)^2) |
| 179 | + |
| 180 | + if bounding>0 |
| 181 | + # If bounding is requested, add extrapolated top and bottom bounds to avoid |
| 182 | + # issues with the stratigraphic markov chain wandering off to +/- infinity |
| 183 | + (youngest, oldest) = extrema(mean.(ages)) |
| 184 | + dt_dH = (oldest-youngest)/(top-bottom) |
| 185 | + offset = round((top-bottom)*bounding/resolution)*resolution |
| 186 | + ages = unionize([Normal(oldest+offset*dt_dH, aveuncert/10); |
| 187 | + ages; |
| 188 | + Normal(youngest-offset*dt_dH, aveuncert/10)]) |
| 189 | + Height = [bottom-offset; Height; top+offset] |
| 190 | + Height_sigma = [0; Height_sigma; 0] .+ 1E-9 # Avoid divide-by-zero issues |
| 191 | + Age_Sidedness = [-1.0; Age_Sidedness; 1.0;] # Bottom is a maximum age and top is a minimum age |
| 192 | + model_heights = (bottom-offset):resolution:(top+offset) |
| 193 | + chronometer = (:None, chronometer..., :None) |
| 194 | + end |
| 195 | + active_height_t = bottom .<= model_heights .<= top |
| 196 | + |
| 197 | + # Start with a linear fit as an initial proposal |
| 198 | + (a,b) = hcat(fill!(similar(Height), 1), Height) \ mean.(ages) |
| 199 | + model_ages = a .+ b .* collect(model_heights) |
| 200 | + |
| 201 | + # Select sidedness method |
| 202 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 203 | + FastSidedness(Age_Sidedness) |
| 204 | + else |
| 205 | + CDFSidedness(Age_Sidedness) |
| 206 | + end |
| 207 | + |
| 208 | + # Run the Markov chain |
| 209 | + agedist, lldist = stratmetropolis(Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, chronometer, systematic) |
| 210 | + |
| 211 | + # Crop the result |
| 212 | + agedist = agedist[active_height_t,:] |
| 213 | + model_heights = model_heights[active_height_t] |
| 214 | + mdl = StratAgeModel(model_heights, agedist) |
| 215 | + |
| 216 | + return mdl, agedist, lldist |
| 217 | + end |
| 218 | + function StratMetropolis(smpl::GeneralAgeData, hiatus::HiatusData, config::StratAgeModelConfiguration, systematic=nothing) |
| 219 | + # Run stratigraphic MCMC model |
| 220 | + @info "Generating stratigraphic age-depth model..." |
| 221 | + |
| 222 | + # Model configuration -- read from struct |
| 223 | + resolution = config.resolution |
| 224 | + burnin = config.burnin |
| 225 | + nsteps = config.nsteps |
| 226 | + sieve = config.sieve |
| 227 | + bounding = config.bounding |
| 228 | + |
| 229 | + # Stratigraphic age constraints |
| 230 | + ages = unionize(smpl.Age_Distribution)::Vector{<:Union{<:Distribution{Univariate, Continuous}}} |
| 231 | + Height = copy(smpl.Height)::Vector{Float64} |
| 232 | + Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues |
| 233 | + Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age |
| 234 | + chronometer = smpl.Chronometer |
| 235 | + (bottom, top) = extrema(Height) |
| 236 | + model_heights = bottom:resolution:top |
| 237 | + |
| 238 | + aveuncert = nanmean(std.(ages)) |
| 239 | + absdiff = diff(sort!(mean.(ages[Age_Sidedness.==0]))) |
| 240 | + maxdiff = isempty(absdiff) ? 0.0 : nanmaximum(absdiff) |
| 241 | + proposal_sigma = sqrt(aveuncert^2 + (maxdiff/10)^2) |
| 242 | + |
| 243 | + if bounding>0 |
| 244 | + # If bounding is requested, add extrapolated top and bottom bounds to avoid |
| 245 | + # issues with the stratigraphic markov chain wandering off to +/- infinity |
| 246 | + (youngest, oldest) = extrema(mean.(ages)) |
| 247 | + dt_dH = (oldest-youngest)/(top-bottom) |
| 248 | + offset = round((top-bottom)*bounding/resolution)*resolution |
| 249 | + ages = unionize([Normal(oldest+offset*dt_dH, aveuncert/10); |
| 250 | + ages; |
| 251 | + Normal(youngest-offset*dt_dH, aveuncert/10)]) |
| 252 | + Height = [bottom-offset; Height; top+offset] |
| 253 | + Height_sigma = [0; Height_sigma; 0] .+ 1E-9 # Avoid divide-by-zero issues |
| 254 | + Age_Sidedness = [-1.0; Age_Sidedness; 1.0;] # Bottom is a maximum age and top is a minimum age |
| 255 | + model_heights = (bottom-offset):resolution:(top+offset) |
| 256 | + chronometer = (:None, chronometer..., :None) |
| 257 | + end |
| 258 | + active_height_t = bottom .<= model_heights .<= top |
| 259 | + |
| 260 | + # Start with a linear fit as an initial proposal |
| 261 | + (a,b) = hcat(fill!(similar(Height), 1), Height) \ mean.(ages) |
| 262 | + model_ages = a .+ b .* collect(model_heights) |
| 263 | + |
| 264 | + # Select sidedness method |
| 265 | + sidedness = if smpl.Sidedness_Method === :fast || all(iszero, smpl.Age_Sidedness) |
| 266 | + FastSidedness(Age_Sidedness) |
| 267 | + else |
| 268 | + CDFSidedness(Age_Sidedness) |
| 269 | + end |
| 270 | + |
| 271 | + # Run the Markov chain |
| 272 | + agedist, lldist, hiatusdist = stratmetropolis(hiatus, Height, Height_sigma, model_heights, sidedness, ages, model_ages, proposal_sigma, burnin, nsteps, sieve, chronometer, systematic) |
144 | 273 |
|
145 | 274 | # Crop the result
|
146 | 275 | agedist = agedist[active_height_t,:]
|
|
401 | 530 |
|
402 | 531 | return mdl, agedist, lldist
|
403 | 532 | end
|
404 |
| - |
405 |
| -## --- Stratigraphic MCMC model with hiatus, for radiocarbon ages # # # # # # |
406 |
| - |
407 | 533 | function StratMetropolis14C(smpl::ChronAgeData, hiatus::HiatusData, config::StratAgeModelConfiguration)
|
408 | 534 | # Run stratigraphic MCMC model, with hiata
|
409 | 535 | @info "Generating stratigraphic age-depth model..."
|
|
0 commit comments