Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
renoult-2020
Manage
Activity
Members
Labels
Plan
Issues
483
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bolin Centre for Climate Research
renoult-2020
Commits
54083424
Commit
54083424
authored
4 years ago
by
Martin Renoult
Browse files
Options
Downloads
Patches
Plain Diff
Update Bayesian_for_mPWP_PlioMIP.py
parent
3abcfd70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Bayesian_for_mPWP_PlioMIP.py
+26
-7
26 additions, 7 deletions
Bayesian_for_mPWP_PlioMIP.py
with
26 additions
and
7 deletions
Bayesian_for_mPWP_PlioMIP.py
+
26
−
7
View file @
54083424
...
...
@@ -104,20 +104,39 @@ pliomip2y = [0.9211941,2.1174774, 1.3736095]
## MCMC model
with
Model
()
as
model
:
# model specifications in PyMC3 are wrapped in a with-statement
# Define priors
# Define prior means, sd or precision (see conjugate for precision)
mn_intercept
=
0.0
mn_slope
=
1.0
sd_reg
=
1.0
precis_intercept
=
np
.
sqrt
(
0.5
)
precis_slope
=
np
.
sqrt
(
0.5
)
# Define priors: Non-conjugate approach
sigma
=
HalfCauchy
(
'
Sigma
'
,
beta
=
5
,
testval
=
1.
)
intercept
=
Normal
(
'
Intercept
'
,
0
,
sd
=
1
)
x_coeff
=
Normal
(
'
x
'
,
1
,
sd
=
1
)
intercept
=
Normal
(
'
Intercept
'
,
mn_intercept
,
sd
=
sd_reg
)
x_coeff
=
Normal
(
'
x
'
,
mn_slope
,
sd
=
sd_reg
)
# Priors for a Normal-Inverse Gamma conjugate approach.
# In conjugate approach, priors on intercept and slope depends on a scaled sigma
# and need to be defined that way to match mathematical equations.
# This part should be mainly used for comparison / check with the conjugate approach code
# sigma = InverseGamma('Sigma',alpha=0.5,beta=0.5)
# intercept = Normal('Intercept', mn_intercept, sd=sigma/precis_intercept)
# x_coeff = Normal('x', mn_slope, sd=sigma/precis_slope)
# Define likelihood
likelihood
=
Normal
(
'
y
'
,
mu
=
intercept
+
x_coeff
*
x
,
sd
=
sigma
,
observed
=
y
)
#
4 chains in parallel
#
Inference! 4 jobs in parallel (convergence check)
# By default, the sampling method is NUTS
# The following line will not work with PyMC3 older than 3.8. If you use an
# older version, replace "cores=4" by "njobs=4"
trace
=
sample
(
progressbar
=
False
,
draws
=
100000
,
cores
=
4
)
trace
=
sample
(
progressbar
=
True
,
draws
=
30000
,
cores
=
2
,
tune
=
2000
)
# Extract the data of the trace
values_x
=
trace
[
'
x
'
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment