Skip to content

Commit

Permalink
Simplify σ, revert to 'retry' method for moving changepoints
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Nov 22, 2022
1 parent e17819e commit 388e6ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/ZrnHeInversionVartCryst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@

## --- Prepare problem

burnin = 350000
burnin = 350_000
model = (
nsteps = 500000, # How many steps of the Markov chain should we run?
nsteps = 500_000, # How many steps of the Markov chain should we run?
burnin = burnin, # How long should we wait for MC to converge (become stationary)
dr = 1.0, # Radius step, in microns
dt = 10.0, # time step size in Myr
dTmax = 10.0, # Maximum reheating/burial per model timestep
dTmax = 15.0, # Maximum reheating/burial per model timestep
TInit = 400.0, # Initial model temperature (in C) (i.e., crystallization temperature)
ΔTInit = -50.0, # TInit can vary from TInit to TInit+ΔTinit
TNow = 0.0, # Current surface temperature (in C)
ΔTNow = 10.0, # TNow may vary from TNow to TNow+ΔTNow
tInitMax = 4000.0, # Ma -- forbid anything older than this
minPoints = 5, # Minimum allowed number of t-T points
minPoints = 10, # Minimum allowed number of t-T points
maxPoints = 50, # Maximum allowed number of t-T points
simplified = false, # Prefer simpler tT paths?
# Diffusion parameters
Expand Down
15 changes: 12 additions & 3 deletions src/inversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
# Simulated annealing of uncertainty
simannealmodel = (σModel=T(model.σModel), σAnnealing=T(model.σAnnealing), λAnnealing=T(model.λAnnealing))
σₐ = simannealsigma.(1, HeAge_sigma; simannealmodel)::DenseVector{T}
σₙ = simannealsigma.(nsteps, HeAge_sigma; simannealmodel)::DenseVector{T}
σ = sqrt.(T(model.σModel)^2 .+ HeAge_sigma.^2)

# Log-likelihood for initial proposal
ll = normpdf_ll(HeAge, σₐ, calcHeAges)
Expand Down Expand Up @@ -195,6 +195,10 @@

# Retry unless we have satisfied the maximum reheating rate
(maxdiff(TStepsₚ) < dTmax) && break

# Copy last accepted solution to re-modify if we don't break
copyto!(agePointsₚ, agePoints)
copyto!(TPointsₚ, TPoints)
end
elseif (r < move+birth) && (nPointsₚ < maxPoints)
# Birth: add a new model point
Expand Down Expand Up @@ -246,6 +250,11 @@

# Retry unless we have satisfied the maximum reheating rate
(maxdiff(TStepsₚ) < dTmax) && break

# Copy last accepted solution to re-modify if we don't break
copyto!(unconf.agePointsₚ, unconf.agePoints)
copyto!(unconf.TPointsₚ, unconf.TPoints)
copyto!(boundary.TPointsₚ, boundary.TPoints)
end
end

Expand Down Expand Up @@ -283,13 +292,13 @@
copyto!(boundary.TPoints, boundary.TPointsₚ)
copyto!(calcHeAges, calcHeAgesₚ)

# This is saved for ouput, but not critical to the function of the MCMC loop
# Not critical to the function of the MCMC loop, but critical for recording stationary distribution!
copyto!(TSteps, TStepsₚ)
acceptancedist[n] = true
end

# Record results for analysis and troubleshooting
lldist[n] = normpdf_ll(HeAge, σₙ, calcHeAges) # Recalculated to constant baseline
lldist[n] = normpdf_ll(HeAge, σ, calcHeAges) # Recalculated to constant baseline
ndist[n] = nPoints # distribution of # of points
HeAgedist[:,n] .= calcHeAges # distribution of He ages

Expand Down

2 comments on commit 388e6ac

@brenhinkeller
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register
Release notes:

  • Fix major bug in recording of stationary distribution
  • Various minor bugfixes and type stability improvements

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/72720

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.6 -m "<description of version>" 388e6ac773360f432e7194ba0b2129294bc98b41
git push origin v0.4.6

Please sign in to comment.