Skip to content

Commit 2e928e9

Browse files
committed
Rel 4.5.4 - log_lik -> loglik, doc fixes
1 parent 4e2bed0 commit 2e928e9

7 files changed

Lines changed: 39 additions & 38 deletions

File tree

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d"
2626
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
2727
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2828
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
29+
StanSample = "c1514b29-d3a0-5178-b312-660c88baa699"
2930
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3031
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
3132
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"

research/sr_loo_compare.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ model {
4040
D ~ normal(mu , sigma); // Likelihood
4141
}
4242
generated quantities {
43-
vector[N] log_lik;
43+
vector[N] loglik;
4444
for (i in 1:N)
45-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
45+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
4646
}
4747
";
4848

@@ -70,9 +70,9 @@ model {
7070
D ~ normal( mu , sigma );
7171
}
7272
generated quantities {
73-
vector[N] log_lik;
73+
vector[N] loglik;
7474
for (i in 1:N)
75-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
75+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
7676
}
7777
";
7878

@@ -102,9 +102,9 @@ model {
102102
D ~ normal( mu , sigma );
103103
}
104104
generated quantities{
105-
vector[N] log_lik;
105+
vector[N] loglik;
106106
for (i in 1:N)
107-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
107+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
108108
}
109109
";
110110

@@ -127,7 +127,7 @@ function to_paretosmooth(ll, pd = [3, 1, 2])
127127
end
128128

129129
function loo_compare1(models::Vector{SampleModel};
130-
loglikelihood_name="log_lik",
130+
loglikelihood_name="loglik",
131131
model_names=nothing,
132132
sort_models=true,
133133
show_psis=true)

src/require/stan/stan_axiskeys.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using AxisKeys
22

3-
function psis_loo(model::SampleModel; loglikelihood_name="log_lik")
3+
function psis_loo(model::SampleModel; loglikelihood_name="loglik")
44
chains = read_samples(model, :keyedarray) # Obtain KeyedArray chains
55
psis_loo(chains; loglikelihood_name)
66
end
77

8-
function psis_loo(chains::T; loglikelihood_name="log_lik") where {T <: KeyedArray}
9-
ll = Array(matrix(chains, loglikelihood_name)) # Extract log_lik matrix
8+
function psis_loo(chains::T; loglikelihood_name="loglik") where {T <: KeyedArray}
9+
ll = Array(matrix(chains, loglikelihood_name)) # Extract loglik matrix
1010
ll_p = to_paretosmooth(ll) # Permute dims for ParetoSmooth
1111
psis = psis_loo(ll_p) # Compute PsisLoo for model
1212
end
@@ -18,7 +18,7 @@ function to_paretosmooth(ll, pd = [3, 1, 2])
1818
end
1919

2020
function loo_compare(models::Vector{SampleModel};
21-
loglikelihood_name="log_lik",
21+
loglikelihood_name="loglik",
2222
model_names=nothing,
2323
sort_models=true,
2424
show_psis=true)
@@ -31,14 +31,14 @@ function loo_compare(models::Vector{SampleModel};
3131
end
3232

3333
function loo_compare(chains_vec::Vector{<: KeyedArray};
34-
loglikelihood_name="log_lik",
34+
loglikelihood_name="loglik",
3535
model_names=nothing,
3636
sort_models=true,
3737
show_psis=true)
3838

3939
nmodels = length(chains_vec)
4040

41-
ll_vec = Array.(matrix.(chains_vec, loglikelihood_name)) # Extract log_lik matrix
41+
ll_vec = Array.(matrix.(chains_vec, loglikelihood_name)) # Extract loglik matrix
4242
ll_vecp = map(to_paretosmooth, ll_vec) # Permute dims for ParetoSmooth
4343
psis_vec = psis_loo.(ll_vecp) # Compute PsisLoo for all models
4444

src/require/stan/stan_compare.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ function compare(models::Vector{SampleModel}, type::Symbol)
2222
lps = Matrix{Float64}[]
2323
for m in models
2424
nt = read_samples(m, :namedtuple)
25-
if :log_lik in keys(nt)
25+
if :loglik in keys(nt)
2626
append!(mnames, [m.name])
27-
append!(lps, [Matrix(nt.log_lik')])
27+
append!(lps, [Matrix(nt.loglik')])
2828
else
29-
@warn "Model $(m.name) does not produce a log_lik matrix."
29+
@warn "Model $(m.name) does not produce a loglik matrix."
3030
end
3131
end
3232
compare(lps, type; mnames)

src/require/stan/stan_psis.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import ParetoSmoothedImportanceSampling: psisloo, waic
22

33
function psisloo(m::SampleModel, wcpp::Int64=20, wtrunc::Float64=3/4)
44
nt = read_samples(m, :namedtuple)
5-
if :log_lik in keys(nt)
6-
lp = Matrix(nt.log_lik')
5+
if :loglik in keys(nt)
6+
lp = Matrix(nt.loglik')
77
else
8-
@warn "Model $(m.name) does not compute a log_lik matrix."
8+
@warn "Model $(m.name) does not compute a loglik matrix."
99
end
1010

1111
psisloo(lp, wcpp, wtrunc)
1212
end
1313

1414
function waic(m::SampleModel; pointwise=false)
1515
nt = read_samples(m, :namedtuple)
16-
if :log_lik in keys(nt)
17-
lp = Matrix(nt.log_lik')
16+
if :loglik in keys(nt)
17+
lp = Matrix(nt.loglik')
1818
else
19-
@warn "Model $(m.name) does not compute a log_lik matrix."
19+
@warn "Model $(m.name) does not compute a loglik matrix."
2020
end
2121

2222
waic(lp; pointwise)

test/test_wd-loo-compare-2.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ model {
3333
D ~ normal(mu , sigma); // Likelihood
3434
}
3535
generated quantities {
36-
vector[N] log_lik;
36+
vector[N] loglik;
3737
for (i in 1:N)
38-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
38+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
3939
}
4040
";
4141

@@ -63,9 +63,9 @@ model {
6363
D ~ normal( mu , sigma );
6464
}
6565
generated quantities {
66-
vector[N] log_lik;
66+
vector[N] loglik;
6767
for (i in 1:N)
68-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
68+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
6969
}
7070
";
7171

@@ -95,9 +95,9 @@ model {
9595
D ~ normal( mu , sigma );
9696
}
9797
generated quantities{
98-
vector[N] log_lik;
98+
vector[N] loglik;
9999
for (i in 1:N)
100-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
100+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
101101
}
102102
";
103103

@@ -111,7 +111,7 @@ m5_3s = SampleModel("m5.3s", stan5_3)
111111
rc5_3s = stan_sample(m5_3s; data)
112112

113113
function loo_compare2(models::Vector{SampleModel};
114-
loglikelihood_name="log_lik",
114+
loglikelihood_name="loglik",
115115
model_names=nothing,
116116
sort_models=true,
117117
show_psis=true)
@@ -120,7 +120,7 @@ function loo_compare2(models::Vector{SampleModel};
120120
model_names = [models[i].name for i in 1:nmodels]
121121

122122
chains_vec = read_samples.(models, :dataframe) # Obtain KeyedArray chains
123-
chains_vec = DataFrame.(chains_vec, :log_lik)
123+
chains_vec = DataFrame.(chains_vec, :loglik)
124124
chains_vec = Array.(chains_vec)
125125
println(length(chains_vec))
126126
println(typeof(chains_vec[1]))
@@ -140,14 +140,14 @@ function loo_compare2(models::Vector{SampleModel};
140140
end
141141

142142
function loo_compare2(ll_vec::Vector{<: Array};
143-
loglikelihood_name="log_lik",
143+
loglikelihood_name="loglik",
144144
model_names=nothing,
145145
sort_models=true,
146146
show_psis=true)
147147

148148
nmodels = length(ll_vec)
149149

150-
#ll_vec = Array.(matrix.(chains_vec, loglikelihood_name)) # Extract log_lik matrix
150+
#ll_vec = Array.(matrix.(chains_vec, loglikelihood_name)) # Extract loglik matrix
151151
#ll_vecp = map(to_paretosmooth, ll_vec) # Permute dims for ParetoSmooth
152152
psis_vec = psis_loo.(ll_vec) # Compute PsisLoo for all models
153153

test/test_wd-loo-compare.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ model {
3333
D ~ normal(mu , sigma); // Likelihood
3434
}
3535
generated quantities {
36-
vector[N] log_lik;
36+
vector[N] loglik;
3737
for (i in 1:N)
38-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
38+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
3939
}
4040
";
4141

@@ -63,9 +63,9 @@ model {
6363
D ~ normal( mu , sigma );
6464
}
6565
generated quantities {
66-
vector[N] log_lik;
66+
vector[N] loglik;
6767
for (i in 1:N)
68-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
68+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
6969
}
7070
";
7171

@@ -95,9 +95,9 @@ model {
9595
D ~ normal( mu , sigma );
9696
}
9797
generated quantities{
98-
vector[N] log_lik;
98+
vector[N] loglik;
9999
for (i in 1:N)
100-
log_lik[i] = normal_lpdf(D[i] | mu[i], sigma);
100+
loglik[i] = normal_lpdf(D[i] | mu[i], sigma);
101101
}
102102
";
103103

0 commit comments

Comments
 (0)