Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SystemIdentification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Fredrik Bagge Carlson
SystemIdentification
Commits
9c47a071
Commit
9c47a071
authored
Oct 13, 2015
by
Fredrik Bagge Carlson
Browse files
Options
Downloads
Patches
Plain Diff
initial work on incorporating Stan.jl
parent
469572fa
No related branches found
No related tags found
1 merge request
!1
Dev
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/MCMC/testStan.jl
+109
-0
109 additions, 0 deletions
src/MCMC/testStan.jl
with
109 additions
and
0 deletions
src/MCMC/testStan.jl
0 → 100644
+
109
−
0
View file @
9c47a071
######### Stan program example ###########
# module Tmp
const
σw0
=
1.0
const
σw
=
1
const
σv
=
1.0
const
theta0
=
[
0.5
,
25
,
8
]
s2piσv
=
log
(
sqrt
(
2
*
pi
)
*
σv
)
ProjDir
=
pwd
()
function
f_sample
(
x
::
Vector
,
t
::
Int64
)
c
=
8
*
cos
(
1.2
*
(
t
-
1
))
@inbounds
for
i
=
1
:
length
(
x
)
x
[
i
]
=
0.5
*
x
[
i
]
+
25
*
x
[
i
]
./
(
1
+
x
[
i
]
^
2
)
+
c
+
σw
*
randn
()
end
return
x
end
f_sample
(
x
::
Float64
,
t
::
Int64
)
=
0.5
*
x
+
25
*
x
/
(
1
+
x
^
2
)
+
8
*
cos
(
1.2
*
(
t
-
1
))
+
σw
*
randn
()
T
=
100
M
=
1
x
=
Array
(
Float64
,
T
)
y
=
Array
(
Float64
,
T
)
x0
=
0
x
[
1
]
=
σw
*
randn
()
y
[
1
]
=
σv
*
randn
()
for
t
=
1
:
T
-
1
x
[
t
+
1
]
=
f_sample
(
x
[
t
],
t
)
y
[
t
+
1
]
=
0.05
x
[
t
+
1
]
^
2
+
σv
*
randn
()
end
# t
using
Stan
,
Mamba
odemodel
=
"
data {
int<lower=1> T;
real y[T];
}
parameters {
real theta[3];
real sigma[2];
real x[T];
}
model {
sigma[1] ~ cauchy(1,1);
sigma[2] ~ cauchy(1,1);
theta[1] ~ cauchy(0.5,0.5);
theta[2] ~ cauchy(25,25);
theta[3] ~ cauchy(8,8);
x[1] ~ normal(0,1);
y[1] ~ normal(0.05*x[1]*x[1], sigma);
for (t in 1:(T-1)){
x[t+1] ~ normal(theta[1]*x[t] + theta[2]*x[t]/(1+x[t]*x[t]) + theta[3]*cos(1.2*(t-1)),sigma[1]);
y[t+1] ~ normal(0.05*x[t+1]*x[t+1], sigma[2]);
}
}
"
odedict
=
Dict
(
"T"
=>
T
,
"y"
=>
y
)
stanmodel
=
Stanmodel
(
name
=
"ode"
,
model
=
odemodel
,
nchains
=
4
,
update
=
10000
)
@time
sim1
=
stan
(
stanmodel
,
[
odedict
],
ProjDir
,
diagnostics
=
false
,
CmdStanDir
=
CMDSTAN_HOME
)
## Subset Sampler Output to variables suitable for describe().
monitor
=
[
"lp__"
,
"accept_stat__"
]
sim
=
sim1
[
1
:
size
(
sim1
,
1
),
monitor
,
1
:
size
(
sim1
,
3
)]
describe
(
sim
)
println
()
p
=
plot
(
sim
,
[
:
trace
,
:
mean
,
:
density
,
:
autocor
],
legend
=
true
)
draw
(
p
,
ncol
=
4
,
filename
=
"
$
(stanmodel.name)-infoplot"
,
fmt
=:
pdf
)
## Subset Sampler Output to variables suitable for describe().
monitor
=
[
"theta.1"
,
"theta.2"
,
"theta.3"
]
sim
=
sim1
[
1
:
size
(
sim1
,
1
),
monitor
,
1
:
size
(
sim1
,
3
)]
describe
(
sim
)
println
()
p
=
plot
(
sim
,
[
:
trace
,
:
mean
,
:
density
,
:
autocor
],
legend
=
true
)
draw
(
p
,
ncol
=
4
,
filename
=
"
$
(stanmodel.name)-thetaplot"
,
fmt
=:
pdf
)
## Subset Sampler Output to variables suitable for describe().
monitor
=
[
"sigma.1"
,
"sigma.2"
]
sim
=
sim1
[
:
,
monitor
,
:
]
describe
(
sim
)
println
()
p
=
plot
(
sim
,
[
:
trace
,
:
mean
,
:
density
,
:
autocor
],
legend
=
true
)
draw
(
p
,
nrow
=
4
,
ncol
=
4
,
filename
=
"
$
(stanmodel.name)-sigmaplot"
,
fmt
=:
pdf
)
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