2. What is AD Model Builder
ˆ Tool for development and optimization of nonlinear models
ˆ Structured template for C++ programming
ˆ Support library containing:
– A quasi-Newton minimizer aided by automatic differentiation
– Data objects (number, vector, matrix, 3darray,
ragged arrays, strings, ...)
– Model parameters (unbounded, bounded, fixed, summing to zero,
vectors of, matrix of, ...)
– A simple way to set up optimization in phases
– Standard ways to quantify uncertainty (Hessian based delta method, profile like-
lihood, MCMC sampling)
– Tools for random effects (AD aided Laplace approximation, sparse ma-
trix, importance sampling, ...)
– Lots of helper functions (gammaln, choleski decomp, inv, det, eigenvalues, RNG,
... )
3. What is it used for?
ˆ Not enough
ˆ Our web-site lists (at my last count):
— 110 peer reviewed publications based on AD Model Builder applications
— 18 Theses and Dissertations
— Countless reports and fish stock assessments
ˆ Those are only the users who remembered to report back
ˆ Models in fisheries science are typically:
— Non-standard
— Non-linear
— High dimensional
ˆ Often they also contain random effects
ˆ They should preferably run in minutes
Dave Fournier receiving the AFS Ricker award
4. Quick example
ˆ Assume that these 15 numbers follow a negative binomial distribution:
# Number of observations
15
# Observations
13 5 28 28 15 4 13 4 10 17 11 13 12 17 3
ˆ Estimate the two unknown parameters.
ˆ Entire AD Model Builder Program:
DATA_SECTION
init_int N
init_vector X(1,N);
PARAMETER_SECTION
init_number logsize;
init_bounded_number p(0,1);
sdreport_number size;
objective_function_value nll;
PROCEDURE_SECTION
size=exp(logsize);
nll=-sum(gammln(X+size))+N*gammln(size)+
sum(gammln(X+1.0))-N*size*log(p)-sum(X)*log(1.0-p);
ˆ Compile: <filename>.tpl
makeadm
−→ <filename>.cpp
g++
−→ binary
index name value std dev
1 logsize 1.3017e+00 4.7101e-01
2 p 2.2218e-01 8.5571e-02
3 size 3.6754e+00 1.7312e+00
5. A fisheries catch-at-age model
ˆ Data is the yearly catch in 7 age classes and 45 years Cay, and a yearly index of fishing
effort ey
ˆ The model has 107 model parameters to be estimated (small for an assessment model)
ˆ The model is non-linear
ˆ In AD Model Builder that takes 0.3 seconds to optimize and compute and write all
output
6. Random effects — no problem
DATA_SECTION
init_int N
init_vector Y(1,N)
PARAMETER_SECTION
init_number logr0
init_number logtheta
init_bounded_number logK(4.6,7.6)
init_number logQ
init_number logR
random_effects_vector X(1,N);
sdreport_number r0
sdreport_number theta
sdreport_number K
sdreport_number Q
sdreport_number R
objective_function_value jnll
PROCEDURE_SECTION
for(int i=2; i<=N; ++i){
step(X(i-1),X(i),logr0,logK,logtheta,logQ);
}
for(int i=1; i<=N; ++i){
obs(X(i),logR,i);
}
r0=exp(logr0); theta=exp(logtheta); K=exp(logK); Q=exp(logQ); R=exp(logR);
SEPARABLE_FUNCTION void step(const dvariable& x1, const dvariable& x2, const dvariable& logr0, const dv
dvariable var=exp(logQ);
dvariable m=x1 + exp(logr0) * (1.0 - pow(exp(x1)/exp(logK),exp(logtheta)));
jnll+=0.5*(log(2.0*M_PI*var)+square(x2-m)/var);
SEPARABLE_FUNCTION void obs(const dvariable& x, const dvariable& logR, int i)
dvariable var=exp(logR);
jnll+=0.5*(log(2.0*M_PI*var)+square(x-Y(i))/var);
A theta logistic population model is defined
for the log-transformed population size as a
nonlinear function of its previous size in the
following way:
Xt = Xt−1 + r0 1 −
exp(Xt−1)
K
θ
+ et,
Yt = Xt + ut,
where et ∼ N(0, Q) and ut ∼ N(0, R).