context_start_lineno int64 1 913 | line_no int64 16 984 | repo stringclasses 5
values | id int64 0 416 | target_function_prompt stringlengths 201 13.6k | function_signature stringlengths 201 13.6k | solution_position listlengths 2 2 | raw_solution stringlengths 201 13.6k | focal_code stringlengths 201 13.6k | function_name stringlengths 2 38 | start_line int64 1 913 | end_line int64 16 984 | file_path stringlengths 10 52 | context stringlengths 4.52k 9.85k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
843 | 908 | StatsBase.jl | 300 | function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
ordered::Bool=false)
Base.mightalias(a, x) &&
throw(ArgumentError("output array x must not share memory with i... | function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
ordered::Bool=false)
Base.mightalias(a, x) &&
throw(ArgumentError("output array x must not share memory with i... | [
843,
908
] | function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
ordered::Bool=false)
Base.mightalias(a, x) &&
throw(ArgumentError("output array x must not share memory with i... | function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
ordered::Bool=false)
Base.mightalias(a, x) &&
throw(ArgumentError("output array x must not share memory with i... | efraimidis_aexpj_wsample_norep! | 843 | 908 | src/sampling.jl | #CURRENT FILE: StatsBase.jl/src/sampling.jl
##CHUNK 1
k = length(x)
k > 0 || return x
# initialize priority queue
pq = Vector{Pair{Float64,Int}}(undef, k)
i = 0
s = 0
@inbounds for _s in 1:n
s = _s
w = wv.values[s]
w < 0 && error("Negative weight found in weight vect... |
913 | 942 | StatsBase.jl | 301 | function sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray;
replace::Bool=true, ordered::Bool=false)
1 == firstindex(a) == firstindex(wv) == firstindex(x) ||
throw(ArgumentError("non 1-based arrays are not supported"))
n = length(a)
k = length(x)
... | function sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray;
replace::Bool=true, ordered::Bool=false)
1 == firstindex(a) == firstindex(wv) == firstindex(x) ||
throw(ArgumentError("non 1-based arrays are not supported"))
n = length(a)
k = length(x)
... | [
913,
942
] | function sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray;
replace::Bool=true, ordered::Bool=false)
1 == firstindex(a) == firstindex(wv) == firstindex(x) ||
throw(ArgumentError("non 1-based arrays are not supported"))
n = length(a)
k = length(x)
... | function sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, x::AbstractArray;
replace::Bool=true, ordered::Bool=false)
1 == firstindex(a) == firstindex(wv) == firstindex(x) ||
throw(ArgumentError("non 1-based arrays are not supported"))
n = length(a)
k = length(x)
... | sample! | 913 | 942 | src/sampling.jl | #CURRENT FILE: StatsBase.jl/src/sampling.jl
##CHUNK 1
Optionally specify a random number generator `rng` as the first argument
(defaults to `Random.default_rng()`).
Output array `a` must not be the same object as `x` or `wv`
nor share memory with them, or the result may be incorrect.
"""
function sample!(rng::Abstrac... |
34 | 45 | StatsBase.jl | 302 | function genmean(a, p::Real)
if p == 0
return geomean(a)
end
# At least one of `x` or `p` must not be an int to avoid domain errors when `p` is a negative int.
# We choose `x` in order to exploit exponentiation by squaring when `p` is an int.
r = mean(a) do x
float(x)^p
end
... | function genmean(a, p::Real)
if p == 0
return geomean(a)
end
# At least one of `x` or `p` must not be an int to avoid domain errors when `p` is a negative int.
# We choose `x` in order to exploit exponentiation by squaring when `p` is an int.
r = mean(a) do x
float(x)^p
end
... | [
34,
45
] | function genmean(a, p::Real)
if p == 0
return geomean(a)
end
# At least one of `x` or `p` must not be an int to avoid domain errors when `p` is a negative int.
# We choose `x` in order to exploit exponentiation by squaring when `p` is an int.
r = mean(a) do x
float(x)^p
end
... | function genmean(a, p::Real)
if p == 0
return geomean(a)
end
# At least one of `x` or `p` must not be an int to avoid domain errors when `p` is a negative int.
# We choose `x` in order to exploit exponentiation by squaring when `p` is an int.
r = mean(a) do x
float(x)^p
end
... | genmean | 34 | 45 | src/scalarstats.jl | #FILE: StatsBase.jl/src/deviation.jl
##CHUNK 1
for i in eachindex(a, b)
@inbounds ai = a[i]
@inbounds bi = b[i]
if ai > 0
r += (ai * log(ai / bi) - ai + bi)
else
r += bi
end
end
return r::Float64
end
# MeanAD: mean absolute deviation
"""
... |
56 | 75 | StatsBase.jl | 303 | function mode(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
len = length(a)
r0 = r[1]
r1 = r[end]
cnts = zeros(Int, length(r))
mc = 0 # maximum count
mv = r0 # a value corresponding to maximum count... | function mode(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
len = length(a)
r0 = r[1]
r1 = r[end]
cnts = zeros(Int, length(r))
mc = 0 # maximum count
mv = r0 # a value corresponding to maximum count... | [
56,
75
] | function mode(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
len = length(a)
r0 = r[1]
r1 = r[end]
cnts = zeros(Int, length(r))
mc = 0 # maximum count
mv = r0 # a value corresponding to maximum count... | function mode(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
len = length(a)
r0 = r[1]
r1 = r[end]
cnts = zeros(Int, length(r))
mc = 0 # maximum count
mv = r0 # a value corresponding to maximum count... | mode | 56 | 75 | src/scalarstats.jl | #FILE: StatsBase.jl/src/counts.jl
##CHUNK 1
If a weighting vector `wv` is specified, the sum of weights is used rather than the
raw counts.
"""
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer})
# add counts of integers from x that fall within levels to r
checkbou... |
84 | 108 | StatsBase.jl | 304 | function modes(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
r0 = r[1]
r1 = r[end]
n = length(r)
cnts = zeros(Int, n)
# find the maximum count
mc = 0
for i = 1:length(a)
@inbounds x = a[i]
if r0 <= x <= r1
@inbounds c = (cnts[x - r0 + 1] += 1)
... | function modes(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
r0 = r[1]
r1 = r[end]
n = length(r)
cnts = zeros(Int, n)
# find the maximum count
mc = 0
for i = 1:length(a)
@inbounds x = a[i]
if r0 <= x <= r1
@inbounds c = (cnts[x - r0 + 1] += 1)
... | [
84,
108
] | function modes(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
r0 = r[1]
r1 = r[end]
n = length(r)
cnts = zeros(Int, n)
# find the maximum count
mc = 0
for i = 1:length(a)
@inbounds x = a[i]
if r0 <= x <= r1
@inbounds c = (cnts[x - r0 + 1] += 1)
... | function modes(a::AbstractArray{T}, r::UnitRange{T}) where T<:Integer
r0 = r[1]
r1 = r[end]
n = length(r)
cnts = zeros(Int, n)
# find the maximum count
mc = 0
for i = 1:length(a)
@inbounds x = a[i]
if r0 <= x <= r1
@inbounds c = (cnts[x - r0 + 1] += 1)
... | modes | 84 | 108 | src/scalarstats.jl | #FILE: StatsBase.jl/src/counts.jl
##CHUNK 1
If a weighting vector `wv` is specified, the sum of weights is used rather than the
raw counts.
"""
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer})
# add counts of integers from x that fall within levels to r
checkbou... |
111 | 135 | StatsBase.jl | 305 | function mode(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
mv, st = iterate(a)
cnts[mv] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y... | function mode(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
mv, st = iterate(a)
cnts[mv] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y... | [
111,
135
] | function mode(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
mv, st = iterate(a)
cnts[mv] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y... | function mode(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
mv, st = iterate(a)
cnts[mv] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y... | mode | 111 | 135 | src/scalarstats.jl | #CURRENT FILE: StatsBase.jl/src/scalarstats.jl
##CHUNK 1
function modes(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
x, st = iterate(a)
cnts[x] = 1
# find the mode along with table construction
y =... |
137 | 161 | StatsBase.jl | 306 | function modes(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
x, st = iterate(a)
cnts[x] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y
... | function modes(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
x, st = iterate(a)
cnts[x] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y
... | [
137,
161
] | function modes(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
x, st = iterate(a)
cnts[x] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y
... | function modes(a)
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
cnts = Dict{eltype(a),Int}()
# first element
mc = 1
x, st = iterate(a)
cnts[x] = 1
# find the mode along with table construction
y = iterate(a, st)
while y !== nothing
x, st = y
... | modes | 137 | 161 | src/scalarstats.jl | #FILE: StatsBase.jl/src/rankcorr.jl
##CHUNK 1
@inbounds for i = 2:n
if x[i - 1] == x[i]
k += 1
elseif k > 0
# Sort the corresponding chunk of y, so the rows of hcat(x,y) are
# sorted first on x, then (where x values are tied) on y. Hence
# double ties... |
164 | 184 | StatsBase.jl | 307 | function mode(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vect... | function mode(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vect... | [
164,
184
] | function mode(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vect... | function mode(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vect... | mode | 164 | 184 | src/scalarstats.jl | #FILE: StatsBase.jl/src/sampling.jl
##CHUNK 1
processing time to draw ``k`` elements. It consumes ``O(k \\log(n / k))`` random numbers.
"""
function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
... |
186 | 205 | StatsBase.jl | 308 | function modes(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vec... | function modes(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vec... | [
186,
205
] | function modes(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vec... | function modes(a::AbstractVector, wv::AbstractWeights{T}) where T <: Real
isempty(a) && throw(ArgumentError("mode is not defined for empty collections"))
isfinite(sum(wv)) || throw(ArgumentError("only finite weights are supported"))
length(a) == length(wv) ||
throw(ArgumentError("data and weight vec... | modes | 186 | 205 | src/scalarstats.jl | #FILE: StatsBase.jl/src/counts.jl
##CHUNK 1
If a weighting vector `wv` is specified, the sum of weights is used rather than the
raw counts.
"""
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer})
# add counts of integers from x that fall within levels to r
checkbou... |
450 | 486 | StatsBase.jl | 309 | function sem(x; mean=nothing)
if isempty(x)
# Return the NaN of the type that we would get for a nonempty x
T = eltype(x)
_mean = mean === nothing ? zero(T) / 1 : mean
z = abs2(zero(T) - _mean)
return oftype((z + z) / 2, NaN)
elseif mean === nothing
n = 0
... | function sem(x; mean=nothing)
if isempty(x)
# Return the NaN of the type that we would get for a nonempty x
T = eltype(x)
_mean = mean === nothing ? zero(T) / 1 : mean
z = abs2(zero(T) - _mean)
return oftype((z + z) / 2, NaN)
elseif mean === nothing
n = 0
... | [
450,
486
] | function sem(x; mean=nothing)
if isempty(x)
# Return the NaN of the type that we would get for a nonempty x
T = eltype(x)
_mean = mean === nothing ? zero(T) / 1 : mean
z = abs2(zero(T) - _mean)
return oftype((z + z) / 2, NaN)
elseif mean === nothing
n = 0
... | function sem(x; mean=nothing)
if isempty(x)
# Return the NaN of the type that we would get for a nonempty x
T = eltype(x)
_mean = mean === nothing ? zero(T) / 1 : mean
z = abs2(zero(T) - _mean)
return oftype((z + z) / 2, NaN)
elseif mean === nothing
n = 0
... | sem | 450 | 486 | src/scalarstats.jl | #FILE: StatsBase.jl/src/cov.jl
##CHUNK 1
Compute the standard deviation of the vector `x` using the estimator `ce`.
"""
std(ce::CovarianceEstimator, x::AbstractVector; kwargs...) = sqrt(var(ce, x; kwargs...))
"""
cor(ce::CovarianceEstimator, x::AbstractVector, y::AbstractVector)
Compute the correlation of the vec... |
621 | 634 | StatsBase.jl | 310 | function _zscore!(Z::AbstractArray, X::AbstractArray, μ::Real, σ::Real)
# Z and X are assumed to have the same size
iσ = inv(σ)
if μ == zero(μ)
for i = 1 : length(X)
@inbounds Z[i] = X[i] * iσ
end
else
for i = 1 : length(X)
@inbounds Z[i] = (X[i] - μ) * iσ... | function _zscore!(Z::AbstractArray, X::AbstractArray, μ::Real, σ::Real)
# Z and X are assumed to have the same size
iσ = inv(σ)
if μ == zero(μ)
for i = 1 : length(X)
@inbounds Z[i] = X[i] * iσ
end
else
for i = 1 : length(X)
@inbounds Z[i] = (X[i] - μ) * iσ... | [
621,
634
] | function _zscore!(Z::AbstractArray, X::AbstractArray, μ::Real, σ::Real)
# Z and X are assumed to have the same size
iσ = inv(σ)
if μ == zero(μ)
for i = 1 : length(X)
@inbounds Z[i] = X[i] * iσ
end
else
for i = 1 : length(X)
@inbounds Z[i] = (X[i] - μ) * iσ... | function _zscore!(Z::AbstractArray, X::AbstractArray, μ::Real, σ::Real)
# Z and X are assumed to have the same size
iσ = inv(σ)
if μ == zero(μ)
for i = 1 : length(X)
@inbounds Z[i] = X[i] * iσ
end
else
for i = 1 : length(X)
@inbounds Z[i] = (X[i] - μ) * iσ... | _zscore! | 621 | 634 | src/scalarstats.jl | #CURRENT FILE: StatsBase.jl/src/scalarstats.jl
##CHUNK 1
end
return Z
end
end
function _zscore_chksize(X::AbstractArray, μ::AbstractArray, σ::AbstractArray)
size(μ) == size(σ) || throw(DimensionMismatch("μ and σ should have the same size."))
for i=1:ndims(X)
dμ_i = size(μ,i)
... |
758 | 793 | StatsBase.jl | 311 | function renyientropy(p::AbstractArray{T}, α::Real) where T<:Real
α < 0 && throw(ArgumentError("Order of Rényi entropy not legal, $(α) < 0."))
s = zero(T)
z = zero(T)
scale = sum(p)
if α ≈ 0
for i = 1:length(p)
@inbounds pi = p[i]
if pi > z
s += 1
... | function renyientropy(p::AbstractArray{T}, α::Real) where T<:Real
α < 0 && throw(ArgumentError("Order of Rényi entropy not legal, $(α) < 0."))
s = zero(T)
z = zero(T)
scale = sum(p)
if α ≈ 0
for i = 1:length(p)
@inbounds pi = p[i]
if pi > z
s += 1
... | [
758,
793
] | function renyientropy(p::AbstractArray{T}, α::Real) where T<:Real
α < 0 && throw(ArgumentError("Order of Rényi entropy not legal, $(α) < 0."))
s = zero(T)
z = zero(T)
scale = sum(p)
if α ≈ 0
for i = 1:length(p)
@inbounds pi = p[i]
if pi > z
s += 1
... | function renyientropy(p::AbstractArray{T}, α::Real) where T<:Real
α < 0 && throw(ArgumentError("Order of Rényi entropy not legal, $(α) < 0."))
s = zero(T)
z = zero(T)
scale = sum(p)
if α ≈ 0
for i = 1:length(p)
@inbounds pi = p[i]
if pi > z
s += 1
... | renyientropy | 758 | 793 | src/scalarstats.jl | #FILE: StatsBase.jl/src/weights.jl
##CHUNK 1
eweights(n::Integer, λ::Real; kwargs...) = _eweights(1:n, λ, n; kwargs...)
eweights(t::AbstractVector, r::AbstractRange, λ::Real; kwargs...) =
_eweights(something.(indexin(t, r)), λ, length(r); kwargs...)
function _eweights(t::AbstractArray{<:Integer}, λ::Real, n::Integ... |
801 | 818 | StatsBase.jl | 312 | function crossentropy(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not " *
... | function crossentropy(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not " *
... | [
801,
818
] | function crossentropy(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not " *
... | function crossentropy(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not " *
... | crossentropy | 801 | 818 | src/scalarstats.jl | #FILE: StatsBase.jl/src/rankcorr.jl
##CHUNK 1
#######################################
"""
corspearman(x, y=x)
Compute Spearman's rank correlation coefficient. If `x` and `y` are vectors, the
output is a float, otherwise it's a matrix corresponding to the pairwise correlations
of the columns of `x` and `y`.
"""
fu... |
832 | 855 | StatsBase.jl | 313 | function kldivergence(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not "*
... | function kldivergence(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not "*
... | [
832,
855
] | function kldivergence(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not "*
... | function kldivergence(p::AbstractArray{<:Real}, q::AbstractArray{<:Real})
length(p) == length(q) || throw(DimensionMismatch("Inconsistent array length."))
# handle empty collections
if isempty(p)
Base.depwarn(
"support for empty collections will be removed since they do not "*
... | kldivergence | 832 | 855 | src/scalarstats.jl | #FILE: StatsBase.jl/src/rankcorr.jl
##CHUNK 1
n = length(x)
n == length(y) || throw(DimensionMismatch("vectors must have same length"))
(any(isnan, x) || any(isnan, y)) && return NaN
return cor(tiedrank(x), tiedrank(y))
end
function corspearman(X::AbstractMatrix{<:Real}, y::AbstractVector{<:Real})
... |
64 | 76 | StatsBase.jl | 314 | function autocov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | function autocov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | [
64,
76
] | function autocov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | function autocov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | autocov! | 64 | 76 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
return r
end
function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
chec... |
78 | 94 | StatsBase.jl | 315 | function autocov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | function autocov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | [
78,
94
] | function autocov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | function autocov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | autocov! | 78 | 94 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
zx::Vector{T} = demean ? x .- mean(x) : x
S = typeof(zero(eltype(y)) / 1)
zy = Vector{S}(undef... |
142 | 155 | StatsBase.jl | 316 | function autocor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | function autocor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | [
142,
155
] | function autocor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | function autocor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
length(r) == m || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z::Vector{T} = demean ? x .- mean(x) : x
... | autocor! | 142 | 155 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
"""
function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, la... |
157 | 174 | StatsBase.jl | 317 | function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | [
157,
174
] | function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | function autocor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
size(r) == (m, ns) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
z = Vector{T}(un... | autocor! | 157 | 174 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || thro... |
249 | 263 | StatsBase.jl | 318 | function crosscov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | function crosscov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | [
249,
263
] | function crosscov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | function crosscov!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | crosscov! | 249 | 263 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || thr... |
265 | 283 | StatsBase.jl | 319 | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | [
265,
283
] | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | crosscov! | 265 | 283 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
end
return r
end
function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && ... |
285 | 303 | StatsBase.jl | 320 | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | [
285,
303
] | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | crosscov! | 285 | 303 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
end
return r
end
function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && s... |
305 | 340 | StatsBase.jl | 321 | function crosscov!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | function crosscov!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | [
305,
340
] | function crosscov!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | function crosscov!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | crosscov! | 305 | 340 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
end
return r
end
function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && s... |
400 | 415 | StatsBase.jl | 322 | function crosscor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | function crosscor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | [
400,
415
] | function crosscor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | function crosscor!(r::AbstractVector{<:Real}, x::AbstractVector{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) /... | crosscor! | 400 | 415 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
m = length(lags)
(length(y) == lx && length(r) == m) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
zx::Vector{T} = demean ? x .- mean(x) : x
S = typeof(zero(eltype(y)) / 1)
zy::Vector{S} = demean ? ... |
417 | 437 | StatsBase.jl | 323 | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | [
417,
437
] | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | crosscor! | 417 | 437 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
end
return r
end
function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && s... |
439 | 459 | StatsBase.jl | 324 | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | [
439,
459
] | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | function crosscor!(r::AbstractMatrix{<:Real}, x::AbstractVector{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = length(x)
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T =... | crosscor! | 439 | 459 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
end
return r
end
function crosscov!(r::AbstractMatrix{<:Real}, x::AbstractMatrix{<:Real}, y::AbstractVector{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
ns = size(x, 2)
m = length(lags)
(length(y) == lx && s... |
461 | 501 | StatsBase.jl | 325 | function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | [
461,
501
] | function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | function crosscor!(r::AbstractArray{<:Real,3}, x::AbstractMatrix{<:Real}, y::AbstractMatrix{<:Real}, lags::AbstractVector{<:Integer}; demean::Bool=true)
lx = size(x, 1)
nx = size(x, 2)
ny = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, nx, ny)) || throw(DimensionMismatch())
che... | crosscor! | 461 | 501 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
zx::Vector{T} = demean ? x .- mean(x) : x
S = typeof(zero(eltype(y)) / 1)
... |
593 | 608 | StatsBase.jl | 326 | function pacf!(r::AbstractMatrix{<:Real}, X::AbstractMatrix{T}, lags::AbstractVector{<:Integer}; method::Symbol=:regression) where T<:Union{Float32, Float64}
lx = size(X, 1)
m = length(lags)
minlag, maxlag = extrema(lags)
(0 <= minlag && 2maxlag < lx) || error("Invalid lag value.")
size(r) == (m, si... | function pacf!(r::AbstractMatrix{<:Real}, X::AbstractMatrix{T}, lags::AbstractVector{<:Integer}; method::Symbol=:regression) where T<:Union{Float32, Float64}
lx = size(X, 1)
m = length(lags)
minlag, maxlag = extrema(lags)
(0 <= minlag && 2maxlag < lx) || error("Invalid lag value.")
size(r) == (m, si... | [
593,
608
] | function pacf!(r::AbstractMatrix{<:Real}, X::AbstractMatrix{T}, lags::AbstractVector{<:Integer}; method::Symbol=:regression) where T<:Union{Float32, Float64}
lx = size(X, 1)
m = length(lags)
minlag, maxlag = extrema(lags)
(0 <= minlag && 2maxlag < lx) || error("Invalid lag value.")
size(r) == (m, si... | function pacf!(r::AbstractMatrix{<:Real}, X::AbstractMatrix{T}, lags::AbstractVector{<:Integer}; method::Symbol=:regression) where T<:Union{Float32, Float64}
lx = size(X, 1)
m = length(lags)
minlag, maxlag = extrema(lags)
(0 <= minlag && 2maxlag < lx) || error("Invalid lag value.")
size(r) == (m, si... | pacf! | 593 | 608 | src/signalcorr.jl | #CURRENT FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
regression models, and `:yulewalker`, which computes the partial autocorrelations
using the Yule-Walker equations.
If `x` is a vector, return a vector of the same length as `lags`.
If `x` is a matrix, return a matrix of size `(length(lags), size(x, 2))`,
where ea... |
2 | 24 | StatsBase.jl | 327 | function durbin!(r::AbstractVector{T}, y::AbstractVector{T}) where T<:BlasReal
n = length(r)
n <= length(y) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
y[1] = -r[1]
β = one(T)
α = -r[1]
for k = 1:n-1
β *= one(T) - α*α
α = -r[k+1]
for... | function durbin!(r::AbstractVector{T}, y::AbstractVector{T}) where T<:BlasReal
n = length(r)
n <= length(y) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
y[1] = -r[1]
β = one(T)
α = -r[1]
for k = 1:n-1
β *= one(T) - α*α
α = -r[k+1]
for... | [
2,
24
] | function durbin!(r::AbstractVector{T}, y::AbstractVector{T}) where T<:BlasReal
n = length(r)
n <= length(y) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
y[1] = -r[1]
β = one(T)
α = -r[1]
for k = 1:n-1
β *= one(T) - α*α
α = -r[k+1]
for... | function durbin!(r::AbstractVector{T}, y::AbstractVector{T}) where T<:BlasReal
n = length(r)
n <= length(y) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
y[1] = -r[1]
β = one(T)
α = -r[1]
for k = 1:n-1
β *= one(T) - α*α
α = -r[k+1]
for... | durbin! | 2 | 24 | src/toeplitzsolvers.jl | #FILE: StatsBase.jl/src/cov.jl
##CHUNK 1
"""
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C))))
Base.require_one_based_indexing(C, s)
n = length(s)
size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions"))
for j = 1:n
sj = s[j]
for i = ... |
27 | 65 | StatsBase.jl | 328 | function levinson!(r::AbstractVector{T}, b::AbstractVector{T}, x::AbstractVector{T}) where T<:BlasReal
n = length(b)
n == length(r) || throw(DimensionMismatch("Vectors must have same length"))
n <= length(x) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
x[1] = b[1]
... | function levinson!(r::AbstractVector{T}, b::AbstractVector{T}, x::AbstractVector{T}) where T<:BlasReal
n = length(b)
n == length(r) || throw(DimensionMismatch("Vectors must have same length"))
n <= length(x) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
x[1] = b[1]
... | [
27,
65
] | function levinson!(r::AbstractVector{T}, b::AbstractVector{T}, x::AbstractVector{T}) where T<:BlasReal
n = length(b)
n == length(r) || throw(DimensionMismatch("Vectors must have same length"))
n <= length(x) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
x[1] = b[1]
... | function levinson!(r::AbstractVector{T}, b::AbstractVector{T}, x::AbstractVector{T}) where T<:BlasReal
n = length(b)
n == length(r) || throw(DimensionMismatch("Vectors must have same length"))
n <= length(x) || throw(DimensionMismatch("Auxiliary vector cannot be shorter than data vector"))
x[1] = b[1]
... | levinson! | 27 | 65 | src/toeplitzsolvers.jl | #FILE: StatsBase.jl/src/cov.jl
##CHUNK 1
"""
function cov2cor!(C::AbstractMatrix, s::AbstractArray = map(sqrt, view(C, diagind(C))))
Base.require_one_based_indexing(C, s)
n = length(s)
size(C) == (n, n) || throw(DimensionMismatch("inconsistent dimensions"))
for j = 1:n
sj = s[j]
for i = ... |
111 | 130 | StatsBase.jl | 329 | function fit(::Type{ZScoreTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, center::Bool=true, scale::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
if dims == 1
n, l = s... | function fit(::Type{ZScoreTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, center::Bool=true, scale::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
if dims == 1
n, l = s... | [
111,
130
] | function fit(::Type{ZScoreTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, center::Bool=true, scale::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
if dims == 1
n, l = s... | function fit(::Type{ZScoreTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, center::Bool=true, scale::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
if dims == 1
n, l = s... | fit | 111 | 130 | src/transformations.jl | #FILE: StatsBase.jl/src/cov.jl
##CHUNK 1
function cov(sc::SimpleCovariance, X::AbstractMatrix; dims::Int=1, mean=nothing)
dims ∈ (1, 2) || throw(ArgumentError("Argument dims can only be 1 or 2 (given: $dims)"))
if mean === nothing
return cov(X; dims=dims, corrected=sc.corrected)
else
return ... |
141 | 171 | StatsBase.jl | 330 | function transform!(y::AbstractMatrix{<:Real}, t::ZScoreTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimensions.... | function transform!(y::AbstractMatrix{<:Real}, t::ZScoreTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimensions.... | [
141,
171
] | function transform!(y::AbstractMatrix{<:Real}, t::ZScoreTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimensions.... | function transform!(y::AbstractMatrix{<:Real}, t::ZScoreTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimensions.... | transform! | 141 | 171 | src/transformations.jl | #FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
zx::Vector{T} = demean ? x .- mean(x) : x
S = typeof(zero(eltype(y)) / 1)
zy = Vec... |
173 | 203 | StatsBase.jl | 331 | function reconstruct!(x::AbstractMatrix{<:Real}, t::ZScoreTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimension... | function reconstruct!(x::AbstractMatrix{<:Real}, t::ZScoreTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimension... | [
173,
203
] | function reconstruct!(x::AbstractMatrix{<:Real}, t::ZScoreTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimension... | function reconstruct!(x::AbstractMatrix{<:Real}, t::ZScoreTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimension... | reconstruct! | 173 | 203 | src/transformations.jl | #FILE: StatsBase.jl/src/signalcorr.jl
##CHUNK 1
ns = size(y, 2)
m = length(lags)
(size(y, 1) == lx && size(r) == (m, ns)) || throw(DimensionMismatch())
check_lags(lx, lags)
T = typeof(zero(eltype(x)) / 1)
zx::Vector{T} = demean ? x .- mean(x) : x
S = typeof(zero(eltype(y)) / 1)
zy = Vec... |
267 | 278 | StatsBase.jl | 332 | function fit(::Type{UnitRangeTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, unit::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
dims ∈ (1, 2) || throw(DomainError(dims, "fit ... | function fit(::Type{UnitRangeTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, unit::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
dims ∈ (1, 2) || throw(DomainError(dims, "fit ... | [
267,
278
] | function fit(::Type{UnitRangeTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, unit::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
dims ∈ (1, 2) || throw(DomainError(dims, "fit ... | function fit(::Type{UnitRangeTransform}, X::AbstractMatrix{<:Real};
dims::Union{Integer,Nothing}=nothing, unit::Bool=true)
if dims === nothing
Base.depwarn("fit(t, x) is deprecated: use fit(t, x, dims=2) instead", :fit)
dims = 2
end
dims ∈ (1, 2) || throw(DomainError(dims, "fit ... | fit | 267 | 278 | src/transformations.jl | #CURRENT FILE: StatsBase.jl/src/transformations.jl
##CHUNK 1
tmin = similar(X, l)
tmax = similar(X, l)
for i in 1:l
@inbounds tmin[i], tmax[i] = extrema(@view(X[:, i]))
end
return tmin, tmax
end
function fit(::Type{UnitRangeTransform}, X::AbstractVector{<:Real};
dims::Integer=1... |
301 | 321 | StatsBase.jl | 333 | function transform!(y::AbstractMatrix{<:Real}, t::UnitRangeTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(x,1)
size(y,1) == n || throw(DimensionMismatch("Inconsistent dimensio... | function transform!(y::AbstractMatrix{<:Real}, t::UnitRangeTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(x,1)
size(y,1) == n || throw(DimensionMismatch("Inconsistent dimensio... | [
301,
321
] | function transform!(y::AbstractMatrix{<:Real}, t::UnitRangeTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(x,1)
size(y,1) == n || throw(DimensionMismatch("Inconsistent dimensio... | function transform!(y::AbstractMatrix{<:Real}, t::UnitRangeTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(x,1)
size(y,1) == n || throw(DimensionMismatch("Inconsistent dimensio... | transform! | 301 | 321 | src/transformations.jl | #CURRENT FILE: StatsBase.jl/src/transformations.jl
##CHUNK 1
function reconstruct!(x::AbstractMatrix{<:Real}, t::UnitRangeTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
... |
323 | 343 | StatsBase.jl | 334 | function reconstruct!(x::AbstractMatrix{<:Real}, t::UnitRangeTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimens... | function reconstruct!(x::AbstractMatrix{<:Real}, t::UnitRangeTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimens... | [
323,
343
] | function reconstruct!(x::AbstractMatrix{<:Real}, t::UnitRangeTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimens... | function reconstruct!(x::AbstractMatrix{<:Real}, t::UnitRangeTransform, y::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(y,1)
size(x,1) == n || throw(DimensionMismatch("Inconsistent dimens... | reconstruct! | 323 | 343 | src/transformations.jl | #CURRENT FILE: StatsBase.jl/src/transformations.jl
##CHUNK 1
function transform!(y::AbstractMatrix{<:Real}, t::UnitRangeTransform, x::AbstractMatrix{<:Real})
if t.dims == 1
l = t.len
size(x,2) == size(y,2) == l || throw(DimensionMismatch("Inconsistent dimensions."))
n = size(x,1)
siz... |
626 | 691 | StatsBase.jl | 335 | function quantile(v::AbstractVector{<:Real}{V}, w::AbstractWeights{W}, p::AbstractVector{<:Real}) where {V,W<:Real}
# checks
isempty(v) && throw(ArgumentError("quantile of an empty array is undefined"))
isempty(p) && throw(ArgumentError("empty quantile array"))
isfinite(sum(w)) || throw(ArgumentError("o... | function quantile(v::AbstractVector{<:Real}{V}, w::AbstractWeights{W}, p::AbstractVector{<:Real}) where {V,W<:Real}
# checks
isempty(v) && throw(ArgumentError("quantile of an empty array is undefined"))
isempty(p) && throw(ArgumentError("empty quantile array"))
isfinite(sum(w)) || throw(ArgumentError("o... | [
626,
691
] | function quantile(v::AbstractVector{<:Real}{V}, w::AbstractWeights{W}, p::AbstractVector{<:Real}) where {V,W<:Real}
# checks
isempty(v) && throw(ArgumentError("quantile of an empty array is undefined"))
isempty(p) && throw(ArgumentError("empty quantile array"))
isfinite(sum(w)) || throw(ArgumentError("o... | function quantile(v::AbstractVector{<:Real}{V}, w::AbstractWeights{W}, p::AbstractVector{<:Real}) where {V,W<:Real}
# checks
isempty(v) && throw(ArgumentError("quantile of an empty array is undefined"))
isempty(p) && throw(ArgumentError("empty quantile array"))
isfinite(sum(w)) || throw(ArgumentError("o... | quantile | 626 | 691 | src/weights.jl | #FILE: StatsBase.jl/src/sampling.jl
##CHUNK 1
processing time to draw ``k`` elements. It consumes ``O(k \\log(n / k))`` random numbers.
"""
function efraimidis_aexpj_wsample_norep!(rng::AbstractRNG, a::AbstractArray,
wv::AbstractWeights, x::AbstractArray;
... |
20 | 30 | Turing.jl | 336 | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
N::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, model, Sampler(alg), N; kwargs...)
end | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
N::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, model, Sampler(alg), N; kwargs...)
end | [
20,
30
] | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
N::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, model, Sampler(alg), N; kwargs...)
end | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
N::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, model, Sampler(alg), N; kwargs...)
end | AbstractMCMC.sample | 20 | 30 | src/mcmc/abstractmcmc.jl | #FILE: Turing.jl/src/mcmc/particle_mcmc.jl
##CHUNK 1
else
return AbstractMCMC.mcmcsample(
rng,
model,
sampler,
N;
chain_type,
initial_state,
progress=progress,
nparticles=N,
kwargs...,
)
e... |
32 | 43 | Turing.jl | 337 | function AbstractMCMC.sample(
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
kwargs...,
)
return AbstractMCMC.sample(
Random.default_rng(), model, alg, ensemble, N, n_chains; kwargs...
)
end | function AbstractMCMC.sample(
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
kwargs...,
)
return AbstractMCMC.sample(
Random.default_rng(), model, alg, ensemble, N, n_chains; kwargs...
)
end | [
32,
43
] | function AbstractMCMC.sample(
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
kwargs...,
)
return AbstractMCMC.sample(
Random.default_rng(), model, alg, ensemble, N, n_chains; kwargs...
)
end | function AbstractMCMC.sample(
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
kwargs...,
)
return AbstractMCMC.sample(
Random.default_rng(), model, alg, ensemble, N, n_chains; kwargs...
)
end | AbstractMCMC.sample | 32 | 43 | src/mcmc/abstractmcmc.jl | #FILE: Turing.jl/src/mcmc/particle_mcmc.jl
##CHUNK 1
else
return AbstractMCMC.mcmcsample(
rng,
model,
sampler,
N;
chain_type,
initial_state,
progress=progress,
nparticles=N,
kwargs...,
)
e... |
45 | 57 | Turing.jl | 338 | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, ... | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, ... | [
45,
57
] | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, ... | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
alg::InferenceAlgorithm,
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
check_model::Bool=true,
kwargs...,
)
check_model && _check_model(model, alg)
return AbstractMCMC.sample(rng, ... | AbstractMCMC.sample | 45 | 57 | src/mcmc/abstractmcmc.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
states::S
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return... |
59 | 81 | Turing.jl | 339 | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
sampler::Union{Sampler{<:InferenceAlgorithm},RepeatSampler},
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
chain_type=MCMCChains.Chains,
progress=PROGRESS[],
kwargs...,
)
return Ab... | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
sampler::Union{Sampler{<:InferenceAlgorithm},RepeatSampler},
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
chain_type=MCMCChains.Chains,
progress=PROGRESS[],
kwargs...,
)
return Ab... | [
59,
81
] | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
sampler::Union{Sampler{<:InferenceAlgorithm},RepeatSampler},
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
chain_type=MCMCChains.Chains,
progress=PROGRESS[],
kwargs...,
)
return Ab... | function AbstractMCMC.sample(
rng::AbstractRNG,
model::AbstractModel,
sampler::Union{Sampler{<:InferenceAlgorithm},RepeatSampler},
ensemble::AbstractMCMC.AbstractMCMCEnsemble,
N::Integer,
n_chains::Integer;
chain_type=MCMCChains.Chains,
progress=PROGRESS[],
kwargs...,
)
return Ab... | AbstractMCMC.sample | 59 | 81 | src/mcmc/abstractmcmc.jl | #FILE: Turing.jl/src/mcmc/particle_mcmc.jl
##CHUNK 1
model::DynamicPPL.Model,
sampler::Sampler{<:SMC},
N::Integer;
chain_type=DynamicPPL.default_chain_type(sampler),
resume_from=nothing,
initial_state=DynamicPPL.loadstate(resume_from),
progress=PROGRESS[],
kwargs...,
)
if resume_from... |
34 | 76 | Turing.jl | 340 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return AbstractMCMC.step(rng, model, spl, state; kwargs...)
end
... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return AbstractMCMC.step(rng, model, spl, state; kwargs...)
end
... | [
34,
76
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return AbstractMCMC.step(rng, model, spl, state; kwargs...)
end
... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return AbstractMCMC.step(rng, model, spl, state; kwargs...)
end
... | length | 34 | 76 | src/mcmc/emcee.jl | #FILE: Turing.jl/src/mcmc/Inference.jl
##CHUNK 1
return transitions_from_chain(Random.default_rng(), model, chain; kwargs...)
end
function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarI... |
78 | 99 | Turing.jl | 341 | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:Emcee}, state::EmceeState; kwargs...
)
# Generate a log joint function.
vi = state.vi
densitymodel = AMH.DensityModel(
Base.Fix1(LogDensityProblems.logdensity, DynamicPPL.LogDensityFunction(model, vi))
)
# Comput... | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:Emcee}, state::EmceeState; kwargs...
)
# Generate a log joint function.
vi = state.vi
densitymodel = AMH.DensityModel(
Base.Fix1(LogDensityProblems.logdensity, DynamicPPL.LogDensityFunction(model, vi))
)
# Comput... | [
78,
99
] | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:Emcee}, state::EmceeState; kwargs...
)
# Generate a log joint function.
vi = state.vi
densitymodel = AMH.DensityModel(
Base.Fix1(LogDensityProblems.logdensity, DynamicPPL.LogDensityFunction(model, vi))
)
# Comput... | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:Emcee}, state::EmceeState; kwargs...
)
# Generate a log joint function.
vi = state.vi
densitymodel = AMH.DensityModel(
Base.Fix1(LogDensityProblems.logdensity, DynamicPPL.LogDensityFunction(model, vi))
)
# Comput... | AbstractMCMC.step | 78 | 99 | src/mcmc/emcee.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
vi = DynamicPPL.setlogp!!(vi, Q.ℓq)
# Create first sample and state.
sample = Turing.Inference.Transition(model, vi)
state = DynamicNUTSState(ℓ, vi, Q, steps.H.κ, steps.ϵ)
return sample, state
end
function AbstractMCMC.step(
rng::Random.Ab... |
101 | 163 | Turing.jl | 342 | function AbstractMCMC.bundle_samples(
samples::Vector{<:Vector},
model::AbstractModel,
spl::Sampler{<:Emcee},
state::EmceeState,
chain_type::Type{MCMCChains.Chains};
save_state=false,
sort_chain=false,
discard_initial=0,
thinning=1,
kwargs...,
)
# Convert transitions to array... | function AbstractMCMC.bundle_samples(
samples::Vector{<:Vector},
model::AbstractModel,
spl::Sampler{<:Emcee},
state::EmceeState,
chain_type::Type{MCMCChains.Chains};
save_state=false,
sort_chain=false,
discard_initial=0,
thinning=1,
kwargs...,
)
# Convert transitions to array... | [
101,
163
] | function AbstractMCMC.bundle_samples(
samples::Vector{<:Vector},
model::AbstractModel,
spl::Sampler{<:Emcee},
state::EmceeState,
chain_type::Type{MCMCChains.Chains};
save_state=false,
sort_chain=false,
discard_initial=0,
thinning=1,
kwargs...,
)
# Convert transitions to array... | function AbstractMCMC.bundle_samples(
samples::Vector{<:Vector},
model::AbstractModel,
spl::Sampler{<:Emcee},
state::EmceeState,
chain_type::Type{MCMCChains.Chains};
save_state=false,
sort_chain=false,
discard_initial=0,
thinning=1,
kwargs...,
)
# Convert transitions to array... | AbstractMCMC.bundle_samples | 101 | 163 | src/mcmc/emcee.jl | #FILE: Turing.jl/src/mcmc/Inference.jl
##CHUNK 1
sort_chain=false,
include_varname_to_symbol=true,
discard_initial=0,
thinning=1,
kwargs...,
)
# Convert transitions to array format.
# Also retrieve the variable names.
varnames, vals = _params_to_array(model, ts)
varnames_symbol = map... |
37 | 65 | Turing.jl | 343 | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:ESS}, vi::AbstractVarInfo; kwargs...
)
# obtain previous sample
f = vi[:]
# define previous sampler state
# (do not use cache to avoid in-place sampling from prior)
oldstate = EllipticalSliceSampling.ESSState(f, getlogp(... | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:ESS}, vi::AbstractVarInfo; kwargs...
)
# obtain previous sample
f = vi[:]
# define previous sampler state
# (do not use cache to avoid in-place sampling from prior)
oldstate = EllipticalSliceSampling.ESSState(f, getlogp(... | [
37,
65
] | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:ESS}, vi::AbstractVarInfo; kwargs...
)
# obtain previous sample
f = vi[:]
# define previous sampler state
# (do not use cache to avoid in-place sampling from prior)
oldstate = EllipticalSliceSampling.ESSState(f, getlogp(... | function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:ESS}, vi::AbstractVarInfo; kwargs...
)
# obtain previous sample
f = vi[:]
# define previous sampler state
# (do not use cache to avoid in-place sampling from prior)
oldstate = EllipticalSliceSampling.ESSState(f, getlogp(... | AbstractMCMC.step | 37 | 65 | src/mcmc/ess.jl | #FILE: Turing.jl/src/mcmc/sghmc.jl
##CHUNK 1
velocity::T
end
function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !Dynamic... |
74 | 85 | Turing.jl | 344 | function ESSPrior{M,S,V}(
model::M, sampler::S, varinfo::V
) where {M<:Model,S<:Sampler{<:ESS},V<:AbstractVarInfo}
vns = keys(varinfo)
μ = mapreduce(vcat, vns) do vn
dist = getdist(varinfo, vn)
EllipticalSliceSampling.isgaussian(typeof(dist)) ||
error(... | function ESSPrior{M,S,V}(
model::M, sampler::S, varinfo::V
) where {M<:Model,S<:Sampler{<:ESS},V<:AbstractVarInfo}
vns = keys(varinfo)
μ = mapreduce(vcat, vns) do vn
dist = getdist(varinfo, vn)
EllipticalSliceSampling.isgaussian(typeof(dist)) ||
error(... | [
74,
85
] | function ESSPrior{M,S,V}(
model::M, sampler::S, varinfo::V
) where {M<:Model,S<:Sampler{<:ESS},V<:AbstractVarInfo}
vns = keys(varinfo)
μ = mapreduce(vcat, vns) do vn
dist = getdist(varinfo, vn)
EllipticalSliceSampling.isgaussian(typeof(dist)) ||
error(... | function ESSPrior{M,S,V}(
model::M, sampler::S, varinfo::V
) where {M<:Model,S<:Sampler{<:ESS},V<:AbstractVarInfo}
vns = keys(varinfo)
μ = mapreduce(vcat, vns) do vn
dist = getdist(varinfo, vn)
EllipticalSliceSampling.isgaussian(typeof(dist)) ||
error(... | ESSPrior{M,S,V} | 74 | 85 | src/mcmc/ess.jl | #FILE: Turing.jl/src/mcmc/is.jl
##CHUNK 1
function DynamicPPL.initialstep(
rng::AbstractRNG, model::Model, spl::Sampler{<:IS}, vi::AbstractVarInfo; kwargs...
)
return Transition(model, vi), nothing
end
function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:IS}, ::Nothing; kwargs.... |
96 | 106 | Turing.jl | 345 | function Base.rand(rng::Random.AbstractRNG, p::ESSPrior)
sampler = p.sampler
varinfo = p.varinfo
# TODO: Surely there's a better way of doing this now that we have `SamplingContext`?
vns = keys(varinfo)
for vn in vns
set_flag!(varinfo, vn, "del")
end
p.model(rng, varinfo, sampler)
... | function Base.rand(rng::Random.AbstractRNG, p::ESSPrior)
sampler = p.sampler
varinfo = p.varinfo
# TODO: Surely there's a better way of doing this now that we have `SamplingContext`?
vns = keys(varinfo)
for vn in vns
set_flag!(varinfo, vn, "del")
end
p.model(rng, varinfo, sampler)
... | [
96,
106
] | function Base.rand(rng::Random.AbstractRNG, p::ESSPrior)
sampler = p.sampler
varinfo = p.varinfo
# TODO: Surely there's a better way of doing this now that we have `SamplingContext`?
vns = keys(varinfo)
for vn in vns
set_flag!(varinfo, vn, "del")
end
p.model(rng, varinfo, sampler)
... | function Base.rand(rng::Random.AbstractRNG, p::ESSPrior)
sampler = p.sampler
varinfo = p.varinfo
# TODO: Surely there's a better way of doing this now that we have `SamplingContext`?
vns = keys(varinfo)
for vn in vns
set_flag!(varinfo, vn, "del")
end
p.model(rng, varinfo, sampler)
... | Base.rand | 96 | 106 | src/mcmc/ess.jl | #FILE: Turing.jl/src/mcmc/particle_mcmc.jl
##CHUNK 1
if e == KeyError(:task_variable)
return rng
else
rethrow(e)
end
end
end
function DynamicPPL.assume(
rng, ::Sampler{<:Union{PG,SMC}}, dist::Distribution, vn::VarName, _vi::AbstractVarInfo
)
vi = trace_local_... |
28 | 39 | Turing.jl | 346 | function ExternalSampler(
sampler::AbstractSampler,
adtype::ADTypes.AbstractADType,
::Val{unconstrained}=Val(true),
) where {unconstrained}
if !(unconstrained isa Bool)
throw(
ArgumentError("Expected Val{true} or Val{false}, got Val{$unconstrained}")
... | function ExternalSampler(
sampler::AbstractSampler,
adtype::ADTypes.AbstractADType,
::Val{unconstrained}=Val(true),
) where {unconstrained}
if !(unconstrained isa Bool)
throw(
ArgumentError("Expected Val{true} or Val{false}, got Val{$unconstrained}")
... | [
28,
39
] | function ExternalSampler(
sampler::AbstractSampler,
adtype::ADTypes.AbstractADType,
::Val{unconstrained}=Val(true),
) where {unconstrained}
if !(unconstrained isa Bool)
throw(
ArgumentError("Expected Val{true} or Val{false}, got Val{$unconstrained}")
... | function ExternalSampler(
sampler::AbstractSampler,
adtype::ADTypes.AbstractADType,
::Val{unconstrained}=Val(true),
) where {unconstrained}
if !(unconstrained isa Bool)
throw(
ArgumentError("Expected Val{true} or Val{false}, got Val{$unconstrained}")
... | ExternalSampler | 28 | 39 | src/mcmc/external_sampler.jl | #FILE: Turing.jl/test/ad.jl
##CHUNK 1
adtypes = (
AutoForwardDiff(),
AutoReverseDiff(),
# Don't need to test Mooncake as it doesn't use tracer types
)
for actual_adtype in adtypes
sampler = HMC(0.1, 5; adtype=actual_adtype)
for expected_adtype in adtypes
c... |
102 | 146 | Turing.jl | 347 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler};
initial_state=nothing,
initial_params=nothing,
kwargs...,
)
alg = sampler_wrapper.alg
sampler = alg.sampler
# Initialise varinfo with initial params and link th... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler};
initial_state=nothing,
initial_params=nothing,
kwargs...,
)
alg = sampler_wrapper.alg
sampler = alg.sampler
# Initialise varinfo with initial params and link th... | [
102,
146
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler};
initial_state=nothing,
initial_params=nothing,
kwargs...,
)
alg = sampler_wrapper.alg
sampler = alg.sampler
# Initialise varinfo with initial params and link th... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler};
initial_state=nothing,
initial_params=nothing,
kwargs...,
)
alg = sampler_wrapper.alg
sampler = alg.sampler
# Initialise varinfo with initial params and link th... | AbstractMCMC.step | 102 | 146 | src/mcmc/external_sampler.jl | #FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler... |
148 | 165 | Turing.jl | 348 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler},
state::TuringState;
kwargs...,
)
sampler = sampler_wrapper.alg.sampler
f = state.ldf
# Then just call `AdvancedHMC.step` with the right arguments.
transition_in... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler},
state::TuringState;
kwargs...,
)
sampler = sampler_wrapper.alg.sampler
f = state.ldf
# Then just call `AdvancedHMC.step` with the right arguments.
transition_in... | [
148,
165
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler},
state::TuringState;
kwargs...,
)
sampler = sampler_wrapper.alg.sampler
f = state.ldf
# Then just call `AdvancedHMC.step` with the right arguments.
transition_in... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler},
state::TuringState;
kwargs...,
)
sampler = sampler_wrapper.alg.sampler
f = state.ldf
# Then just call `AdvancedHMC.step` with the right arguments.
transition_in... | AbstractMCMC.step | 148 | 165 | src/mcmc/external_sampler.jl | #FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler... |
142 | 199 | Turing.jl | 349 | function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
child_context = DynamicPPL.childcontext(context)
# Note that `child_context` may contain `PrefixContext`s -- in which case
# we need to make sure that vn is appropriately prefixed before we handle
# the `GibbsContext` behaviour belo... | function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
child_context = DynamicPPL.childcontext(context)
# Note that `child_context` may contain `PrefixContext`s -- in which case
# we need to make sure that vn is appropriately prefixed before we handle
# the `GibbsContext` behaviour belo... | [
142,
199
] | function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
child_context = DynamicPPL.childcontext(context)
# Note that `child_context` may contain `PrefixContext`s -- in which case
# we need to make sure that vn is appropriately prefixed before we handle
# the `GibbsContext` behaviour belo... | function DynamicPPL.tilde_assume(context::GibbsContext, right, vn, vi)
child_context = DynamicPPL.childcontext(context)
# Note that `child_context` may contain `PrefixContext`s -- in which case
# we need to make sure that vn is appropriately prefixed before we handle
# the `GibbsContext` behaviour belo... | inner | 142 | 199 | src/mcmc/gibbs.jl | #FILE: Turing.jl/test/optimisation/Optimisation.jl
##CHUNK 1
# The `stats` field is populated only in newer versions of OptimizationOptimJL and
# similar packages. Hence we end up doing this check a lot
hasstats(result) = result.optim_result.stats !== nothing
# Issue: https://discourse.julialang.org/t... |
202 | 228 | Turing.jl | 350 | function DynamicPPL.tilde_assume(
rng::Random.AbstractRNG, context::GibbsContext, sampler, right, vn, vi
)
# See comment in the above, rng-less version of this method for an explanation.
child_context = DynamicPPL.childcontext(context)
vn, child_context = DynamicPPL.prefix_and_strip_contexts(child_conte... | function DynamicPPL.tilde_assume(
rng::Random.AbstractRNG, context::GibbsContext, sampler, right, vn, vi
)
# See comment in the above, rng-less version of this method for an explanation.
child_context = DynamicPPL.childcontext(context)
vn, child_context = DynamicPPL.prefix_and_strip_contexts(child_conte... | [
202,
228
] | function DynamicPPL.tilde_assume(
rng::Random.AbstractRNG, context::GibbsContext, sampler, right, vn, vi
)
# See comment in the above, rng-less version of this method for an explanation.
child_context = DynamicPPL.childcontext(context)
vn, child_context = DynamicPPL.prefix_and_strip_contexts(child_conte... | function DynamicPPL.tilde_assume(
rng::Random.AbstractRNG, context::GibbsContext, sampler, right, vn, vi
)
# See comment in the above, rng-less version of this method for an explanation.
child_context = DynamicPPL.childcontext(context)
vn, child_context = DynamicPPL.prefix_and_strip_contexts(child_conte... | DynamicPPL.tilde_assume | 202 | 228 | src/mcmc/gibbs.jl | #FILE: Turing.jl/test/ad.jl
##CHUNK 1
end
# A bunch of tilde_assume/tilde_observe methods that just call the same method on the child
# context, and then call check_adtype on the result before returning the results from the
# child context.
function DynamicPPL.tilde_assume(context::ADTypeCheckContext, right, vn, vi)
... |
248 | 259 | Turing.jl | 351 | function make_conditional(
model::DynamicPPL.Model, target_variables::AbstractVector{<:VarName}, varinfo
)
# Insert the `GibbsContext` just before the leaf.
# 1. Extract the `leafcontext` from `model` and wrap in `GibbsContext`.
gibbs_context_inner = GibbsContext(
target_variables, Ref(varinfo),... | function make_conditional(
model::DynamicPPL.Model, target_variables::AbstractVector{<:VarName}, varinfo
)
# Insert the `GibbsContext` just before the leaf.
# 1. Extract the `leafcontext` from `model` and wrap in `GibbsContext`.
gibbs_context_inner = GibbsContext(
target_variables, Ref(varinfo),... | [
248,
259
] | function make_conditional(
model::DynamicPPL.Model, target_variables::AbstractVector{<:VarName}, varinfo
)
# Insert the `GibbsContext` just before the leaf.
# 1. Extract the `leafcontext` from `model` and wrap in `GibbsContext`.
gibbs_context_inner = GibbsContext(
target_variables, Ref(varinfo),... | function make_conditional(
model::DynamicPPL.Model, target_variables::AbstractVector{<:VarName}, varinfo
)
# Insert the `GibbsContext` just before the leaf.
# 1. Extract the `leafcontext` from `model` and wrap in `GibbsContext`.
gibbs_context_inner = GibbsContext(
target_variables, Ref(varinfo),... | make_conditional | 248 | 259 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
the child context that tilde calls will eventually be passed onto.
"""
context::Ctx
function GibbsContext(target_varnames, global_varinfo, context)
if !can_be_wrapped(context)
error("GibbsContext can only wrap a leaf or prefix con... |
302 | 317 | Turing.jl | 352 | function Gibbs(varnames, samplers)
if length(varnames) != length(samplers)
throw(ArgumentError("Number of varnames and samplers must match."))
end
for spl in samplers
if !isgibbscomponent(spl)
msg = "All samplers must be valid Gibbs components, $(spl) is ... | function Gibbs(varnames, samplers)
if length(varnames) != length(samplers)
throw(ArgumentError("Number of varnames and samplers must match."))
end
for spl in samplers
if !isgibbscomponent(spl)
msg = "All samplers must be valid Gibbs components, $(spl) is ... | [
302,
317
] | function Gibbs(varnames, samplers)
if length(varnames) != length(samplers)
throw(ArgumentError("Number of varnames and samplers must match."))
end
for spl in samplers
if !isgibbscomponent(spl)
msg = "All samplers must be valid Gibbs components, $(spl) is ... | function Gibbs(varnames, samplers)
if length(varnames) != length(samplers)
throw(ArgumentError("Number of varnames and samplers must match."))
end
for spl in samplers
if !isgibbscomponent(spl)
msg = "All samplers must be valid Gibbs components, $(spl) is ... | Gibbs | 302 | 317 | src/mcmc/gibbs.jl | #FILE: Turing.jl/test/mcmc/gibbs.jl
##CHUNK 1
end
end
end
@testset "Invalid Gibbs constructor" begin
# More samplers than varnames or vice versa
@test_throws ArgumentError Gibbs((@varname(s), @varname(m)), (NUTS(), NUTS(), NUTS()))
@test_throws ArgumentError Gibbs(
(@varname(s), @varnam... |
338 | 352 | Turing.jl | 353 | function initial_varinfo(rng, model, spl, initial_params)
vi = DynamicPPL.default_varinfo(rng, model, spl)
# Update the parameters if provided.
if initial_params !== nothing
vi = DynamicPPL.initialize_parameters!!(vi, initial_params, model)
# Update joint log probability.
# This is... | function initial_varinfo(rng, model, spl, initial_params)
vi = DynamicPPL.default_varinfo(rng, model, spl)
# Update the parameters if provided.
if initial_params !== nothing
vi = DynamicPPL.initialize_parameters!!(vi, initial_params, model)
# Update joint log probability.
# This is... | [
338,
352
] | function initial_varinfo(rng, model, spl, initial_params)
vi = DynamicPPL.default_varinfo(rng, model, spl)
# Update the parameters if provided.
if initial_params !== nothing
vi = DynamicPPL.initialize_parameters!!(vi, initial_params, model)
# Update joint log probability.
# This is... | function initial_varinfo(rng, model, spl, initial_params)
vi = DynamicPPL.default_varinfo(rng, model, spl)
# Update the parameters if provided.
if initial_params !== nothing
vi = DynamicPPL.initialize_parameters!!(vi, initial_params, model)
# Update joint log probability.
# This is... | initial_varinfo | 338 | 352 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/hmc.jl
##CHUNK 1
"failed to find valid initial parameters in $(max_attempts) tries. This may indicate an error with the model or AD backend; please open an issue at https://github.com/TuringLang/Turing.jl/issues",
)
end
function DynamicPPL.initialstep(
rng::AbstractRNG,
mo... |
354 | 377 | Turing.jl | 354 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, states = g... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, states = g... | [
354,
377
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, states = g... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, states = g... | AbstractMCMC.step | 354 | 377 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
return vi
end
end
function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers =... |
379 | 402 | Turing.jl | 355 | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, sta... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, sta... | [
379,
402
] | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, sta... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
vi = initial_varinfo(rng, model, spl, initial_params)
vi, sta... | AbstractMCMC.step_warmup | 379 | 402 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
return vi
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs};
initial_params=nothing,
kwargs...,
)
alg = spl.alg
varnames = alg.varnames
samplers = alg.sample... |
412 | 470 | Turing.jl | 356 | function gibbs_initialstep_recursive(
rng,
model,
step_function::Function,
varname_vecs,
samplers,
vi,
states=();
initial_params=nothing,
kwargs...,
)
# End recursion
if isempty(varname_vecs) && isempty(samplers)
return vi, states
end
varnames, varname_vecs_t... | function gibbs_initialstep_recursive(
rng,
model,
step_function::Function,
varname_vecs,
samplers,
vi,
states=();
initial_params=nothing,
kwargs...,
)
# End recursion
if isempty(varname_vecs) && isempty(samplers)
return vi, states
end
varnames, varname_vecs_t... | [
412,
470
] | function gibbs_initialstep_recursive(
rng,
model,
step_function::Function,
varname_vecs,
samplers,
vi,
states=();
initial_params=nothing,
kwargs...,
)
# End recursion
if isempty(varname_vecs) && isempty(samplers)
return vi, states
end
varnames, varname_vecs_t... | function gibbs_initialstep_recursive(
rng,
model,
step_function::Function,
varname_vecs,
samplers,
vi,
states=();
initial_params=nothing,
kwargs...,
)
# End recursion
if isempty(varname_vecs) && isempty(samplers)
return vi, states
end
varnames, varname_vecs_t... | gibbs_initialstep_recursive | 412 | 470 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/Inference.jl
##CHUNK 1
return transitions_from_chain(Random.default_rng(), model, chain; kwargs...)
end
function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarI... |
472 | 490 | Turing.jl | 357 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(samplers) == ... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(samplers) == ... | [
472,
490
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(samplers) == ... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(samplers) == ... | length | 472 | 490 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
end
function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = al... |
492 | 510 | Turing.jl | 358 | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(sample... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(sample... | [
492,
510
] | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(sample... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
states = state.states
@assert length(sample... | length | 492 | 510 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
... |
526 | 537 | Turing.jl | 359 | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:MH},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob.
# NOTE: Using `leafcontext(model.context)` here is a ... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:MH},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob.
# NOTE: Using `leafcontext(model.context)` here is a ... | [
526,
537
] | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:MH},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob.
# NOTE: Using `leafcontext(model.context)` here is a ... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:MH},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob.
# NOTE: Using `leafcontext(model.context)` here is a ... | setparams_varinfo!! | 526 | 537 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/external_sampler.jl
##CHUNK 1
function make_updated_varinfo(
f::DynamicPPL.LogDensityFunction, external_transition, external_state
)
# Set the parameters.
# NOTE: This is Turing.Inference.getparams, not AbstractMCMC.getparams (!!!!!)
# The latter uses the state rather than the... |
539 | 550 | Turing.jl | 360 | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ESS},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob. To do this, we have to call evaluate!! with the sampler,... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ESS},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob. To do this, we have to call evaluate!! with the sampler,... | [
539,
550
] | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ESS},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob. To do this, we have to call evaluate!! with the sampler,... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ESS},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob. To do this, we have to call evaluate!! with the sampler,... | setparams_varinfo!! | 539 | 550 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/ess.jl
##CHUNK 1
ESSPrior(model, spl, vi),
DynamicPPL.LogDensityFunction(
model, vi, DynamicPPL.SamplingContext(spl, DynamicPPL.DefaultContext())
),
),
EllipticalSliceSampling.ESS(),
oldstate,
)
# update sampl... |
552 | 565 | Turing.jl | 361 | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler.alg.adtype
)
new_inner_state = setparams_... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler.alg.adtype
)
new_inner_state = setparams_... | [
552,
565
] | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler.alg.adtype
)
new_inner_state = setparams_... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:ExternalSampler},
state::TuringState,
params::AbstractVarInfo,
)
logdensity = DynamicPPL.LogDensityFunction(
model, state.ldf.varinfo, state.ldf.context; adtype=sampler.alg.adtype
)
new_inner_state = setparams_... | setparams_varinfo!! | 552 | 565 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/external_sampler.jl
##CHUNK 1
)
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler_wrapper::Sampler{<:ExternalSampler},
state::TuringState;
kwargs...,
)
sampler = sampler_wrapper.alg.sampler
f = state.ldf
# Then just ... |
567 | 582 | Turing.jl | 362 | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:Hamiltonian},
state::HMCState,
params::AbstractVarInfo,
)
θ_new = params[:]
hamiltonian = get_hamiltonian(model, sampler, params, state, length(θ_new))
# Update the parameter values in `state.z`.
# TODO: Avoid mut... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:Hamiltonian},
state::HMCState,
params::AbstractVarInfo,
)
θ_new = params[:]
hamiltonian = get_hamiltonian(model, sampler, params, state, length(θ_new))
# Update the parameter values in `state.z`.
# TODO: Avoid mut... | [
567,
582
] | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:Hamiltonian},
state::HMCState,
params::AbstractVarInfo,
)
θ_new = params[:]
hamiltonian = get_hamiltonian(model, sampler, params, state, length(θ_new))
# Update the parameter values in `state.z`.
# TODO: Avoid mut... | function setparams_varinfo!!(
model::DynamicPPL.Model,
sampler::Sampler{<:Hamiltonian},
state::HMCState,
params::AbstractVarInfo,
)
θ_new = params[:]
hamiltonian = get_hamiltonian(model, sampler, params, state, length(θ_new))
# Update the parameter values in `state.z`.
# TODO: Avoid mut... | setparams_varinfo!! | 567 | 582 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/mcmc/hmc.jl
##CHUNK 1
transition = Transition(model, vi, t)
state = HMCState(vi, 1, kernel, hamiltonian, t.z, adaptor)
return transition, state
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nada... |
597 | 632 | Turing.jl | 363 | function match_linking!!(varinfo_local, prev_state_local, model)
prev_varinfo_local = varinfo(prev_state_local)
was_linked = DynamicPPL.istrans(prev_varinfo_local)
is_linked = DynamicPPL.istrans(varinfo_local)
if was_linked && !is_linked
varinfo_local = DynamicPPL.link!!(varinfo_local, model)
... | function match_linking!!(varinfo_local, prev_state_local, model)
prev_varinfo_local = varinfo(prev_state_local)
was_linked = DynamicPPL.istrans(prev_varinfo_local)
is_linked = DynamicPPL.istrans(varinfo_local)
if was_linked && !is_linked
varinfo_local = DynamicPPL.link!!(varinfo_local, model)
... | [
597,
632
] | function match_linking!!(varinfo_local, prev_state_local, model)
prev_varinfo_local = varinfo(prev_state_local)
was_linked = DynamicPPL.istrans(prev_varinfo_local)
is_linked = DynamicPPL.istrans(varinfo_local)
if was_linked && !is_linked
varinfo_local = DynamicPPL.link!!(varinfo_local, model)
... | function match_linking!!(varinfo_local, prev_state_local, model)
prev_varinfo_local = varinfo(prev_state_local)
was_linked = DynamicPPL.istrans(prev_varinfo_local)
is_linked = DynamicPPL.istrans(varinfo_local)
if was_linked && !is_linked
varinfo_local = DynamicPPL.link!!(varinfo_local, model)
... | match_linking!! | 597 | 632 | src/mcmc/gibbs.jl | #FILE: Turing.jl/src/optimisation/Optimisation.jl
##CHUNK 1
ctx = OptimizationContext(inner_context)
# Set its VarInfo to the initial parameters.
# TODO(penelopeysm): Unclear if this is really needed? Any time that logp is calculated
# (using `LogDensityProblems.logdensity(ldf, x)`) the parameters in t... |
641 | 697 | Turing.jl | 364 | function gibbs_step_recursive(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
step_function::Function,
varname_vecs,
samplers,
states,
global_vi,
new_states=();
kwargs...,
)
# End recursion.
if isempty(varname_vecs) && isempty(samplers) && isempty(states)
return gl... | function gibbs_step_recursive(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
step_function::Function,
varname_vecs,
samplers,
states,
global_vi,
new_states=();
kwargs...,
)
# End recursion.
if isempty(varname_vecs) && isempty(samplers) && isempty(states)
return gl... | [
641,
697
] | function gibbs_step_recursive(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
step_function::Function,
varname_vecs,
samplers,
states,
global_vi,
new_states=();
kwargs...,
)
# End recursion.
if isempty(varname_vecs) && isempty(samplers) && isempty(states)
return gl... | function gibbs_step_recursive(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
step_function::Function,
varname_vecs,
samplers,
states,
global_vi,
new_states=();
kwargs...,
)
# End recursion.
if isempty(varname_vecs) && isempty(samplers) && isempty(states)
return gl... | gibbs_step_recursive | 641 | 697 | src/mcmc/gibbs.jl | #CURRENT FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
# Take initial step with the current sampler.
_, new_state = step_function(
rng,
conditioned_model,
sampler;
# FIXME: This will cause issues if the sampler expects initial params in unconstrained space.
# This is not t... |
145 | 173 | Turing.jl | 365 | function find_initial_params(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
varinfo::DynamicPPL.AbstractVarInfo,
hamiltonian::AHMC.Hamiltonian;
max_attempts::Int=1000,
)
varinfo = deepcopy(varinfo) # Don't mutate
for attempts in 1:max_attempts
theta = varinfo[:]
z = AHM... | function find_initial_params(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
varinfo::DynamicPPL.AbstractVarInfo,
hamiltonian::AHMC.Hamiltonian;
max_attempts::Int=1000,
)
varinfo = deepcopy(varinfo) # Don't mutate
for attempts in 1:max_attempts
theta = varinfo[:]
z = AHM... | [
145,
173
] | function find_initial_params(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
varinfo::DynamicPPL.AbstractVarInfo,
hamiltonian::AHMC.Hamiltonian;
max_attempts::Int=1000,
)
varinfo = deepcopy(varinfo) # Don't mutate
for attempts in 1:max_attempts
theta = varinfo[:]
z = AHM... | function find_initial_params(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
varinfo::DynamicPPL.AbstractVarInfo,
hamiltonian::AHMC.Hamiltonian;
max_attempts::Int=1000,
)
varinfo = deepcopy(varinfo) # Don't mutate
for attempts in 1:max_attempts
theta = varinfo[:]
z = AHM... | find_initial_params | 145 | 173 | src/mcmc/hmc.jl | #FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
"""
Initialise a VarInfo for the Gibbs sampler.
This is straight up copypasta from DynamicPPL's src/sampler.jl. It is repeated here to
support calling both step and step_warmup as the initial step. DynamicPPL initialstep is
incompatible with step_warmup.
"""
function initi... |
175 | 255 | Turing.jl | 366 | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:Hamiltonian},
vi_original::AbstractVarInfo;
initial_params=nothing,
nadapts=0,
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
vi = DynamicPPL.li... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:Hamiltonian},
vi_original::AbstractVarInfo;
initial_params=nothing,
nadapts=0,
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
vi = DynamicPPL.li... | [
175,
255
] | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:Hamiltonian},
vi_original::AbstractVarInfo;
initial_params=nothing,
nadapts=0,
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
vi = DynamicPPL.li... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:Hamiltonian},
vi_original::AbstractVarInfo;
initial_params=nothing,
nadapts=0,
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
vi = DynamicPPL.li... | DynamicPPL.initialstep | 175 | 255 | src/mcmc/hmc.jl | #FILE: Turing.jl/test/mcmc/external_sampler.jl
##CHUNK 1
# expected_logpdf = logpdf(Beta(2, 2), a) + logpdf(Normal(a), b)
# @test all(chn[:lp] .== expected_logpdf)
# @test all(chn[:logprior] .== expected_logpdf)
# @test all(chn[:loglikelihood] .== 0.0)
end
function initialize_nuts(model::DynamicPPL.Mod... |
257 | 301 | Turing.jl | 367 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nadapts=0,
kwargs...,
)
# Get step size
@debug "current ϵ" getstepsize(spl, state)
# Compute transition.
hamiltonian = state.hamiltonian
z = state.z
t = AHMC.... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nadapts=0,
kwargs...,
)
# Get step size
@debug "current ϵ" getstepsize(spl, state)
# Compute transition.
hamiltonian = state.hamiltonian
z = state.z
t = AHMC.... | [
257,
301
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nadapts=0,
kwargs...,
)
# Get step size
@debug "current ϵ" getstepsize(spl, state)
# Compute transition.
hamiltonian = state.hamiltonian
z = state.z
t = AHMC.... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nadapts=0,
kwargs...,
)
# Get step size
@debug "current ϵ" getstepsize(spl, state)
# Compute transition.
hamiltonian = state.hamiltonian
z = state.z
t = AHMC.... | AbstractMCMC.step | 257 | 301 | src/mcmc/hmc.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:DynamicNUTS},
state::DynamicNUTSState;
kwargs...,
)
# Compute next sample.
vi = state.vi
ℓ = state.logdensity
steps = DynamicHMC.mcmc_steps(rng, spl.alg.s... |
303 | 318 | Turing.jl | 368 | function get_hamiltonian(model, spl, vi, state, n)
metric = gen_metric(n, spl, state)
ldf = DynamicPPL.LogDensityFunction(
model,
vi,
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we
# need to pass in the sampler? (In fact LogDensityFunction defaults to
... | function get_hamiltonian(model, spl, vi, state, n)
metric = gen_metric(n, spl, state)
ldf = DynamicPPL.LogDensityFunction(
model,
vi,
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we
# need to pass in the sampler? (In fact LogDensityFunction defaults to
... | [
303,
318
] | function get_hamiltonian(model, spl, vi, state, n)
metric = gen_metric(n, spl, state)
ldf = DynamicPPL.LogDensityFunction(
model,
vi,
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we
# need to pass in the sampler? (In fact LogDensityFunction defaults to
... | function get_hamiltonian(model, spl, vi, state, n)
metric = gen_metric(n, spl, state)
ldf = DynamicPPL.LogDensityFunction(
model,
vi,
# TODO(penelopeysm): Can we just use leafcontext(model.context)? Do we
# need to pass in the sampler? (In fact LogDensityFunction defaults to
... | get_hamiltonian | 303 | 318 | src/mcmc/hmc.jl | #FILE: Turing.jl/test/mcmc/external_sampler.jl
##CHUNK 1
# expected_logpdf = logpdf(Beta(2, 2), a) + logpdf(Normal(a), b)
# @test all(chn[:lp] .== expected_logpdf)
# @test all(chn[:logprior] .== expected_logpdf)
# @test all(chn[:loglikelihood] .== 0.0)
end
function initialize_nuts(model::DynamicPPL.Mod... |
427 | 437 | Turing.jl | 369 | function NUTS(
n_adapts::Int,
δ::Float64,
max_depth::Int,
Δ_max::Float64,
ϵ::Float64,
::Type{metricT};
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
) where {metricT}
return NUTS{typeof(adtype),metricT}(n_adapts, δ, max_depth, Δ_max, ϵ, adtype)
end | function NUTS(
n_adapts::Int,
δ::Float64,
max_depth::Int,
Δ_max::Float64,
ϵ::Float64,
::Type{metricT};
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
) where {metricT}
return NUTS{typeof(adtype),metricT}(n_adapts, δ, max_depth, Δ_max, ϵ, adtype)
end | [
427,
437
] | function NUTS(
n_adapts::Int,
δ::Float64,
max_depth::Int,
Δ_max::Float64,
ϵ::Float64,
::Type{metricT};
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
) where {metricT}
return NUTS{typeof(adtype),metricT}(n_adapts, δ, max_depth, Δ_max, ϵ, adtype)
end | function NUTS(
n_adapts::Int,
δ::Float64,
max_depth::Int,
Δ_max::Float64,
ϵ::Float64,
::Type{metricT};
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
) where {metricT}
return NUTS{typeof(adtype),metricT}(n_adapts, δ, max_depth, Δ_max, ϵ, adtype)
end | NUTS | 427 | 437 | src/mcmc/hmc.jl | #CURRENT FILE: Turing.jl/src/mcmc/hmc.jl
##CHUNK 1
return HMCDA(n_adapts, δ, λ; kwargs...)
end
function HMCDA(
n_adapts::Int,
δ::Float64,
λ::Float64;
init_ϵ::Float64=0.0,
metricT=AHMC.UnitEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return HMCDA(n_adapts, δ, ... |
443 | 453 | Turing.jl | 370 | function NUTS(
n_adapts::Int,
δ::Float64;
max_depth::Int=10,
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return NUTS(n_adapts, δ, max_depth, Δ_max, init_ϵ, metricT; adtype=adtype)
end | function NUTS(
n_adapts::Int,
δ::Float64;
max_depth::Int=10,
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return NUTS(n_adapts, δ, max_depth, Δ_max, init_ϵ, metricT; adtype=adtype)
end | [
443,
453
] | function NUTS(
n_adapts::Int,
δ::Float64;
max_depth::Int=10,
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return NUTS(n_adapts, δ, max_depth, Δ_max, init_ϵ, metricT; adtype=adtype)
end | function NUTS(
n_adapts::Int,
δ::Float64;
max_depth::Int=10,
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return NUTS(n_adapts, δ, max_depth, Δ_max, init_ϵ, metricT; adtype=adtype)
end | NUTS | 443 | 453 | src/mcmc/hmc.jl | #CURRENT FILE: Turing.jl/src/mcmc/hmc.jl
##CHUNK 1
return HMCDA(n_adapts, δ, λ; kwargs...)
end
function HMCDA(
n_adapts::Int,
δ::Float64,
λ::Float64;
init_ϵ::Float64=0.0,
metricT=AHMC.UnitEuclideanMetric,
adtype::ADTypes.AbstractADType=Turing.DEFAULT_ADTYPE,
)
return HMCDA(n_adapts, δ, ... |
527 | 543 | Turing.jl | 371 | function AHMCAdaptor(alg::AdaptiveHamiltonian, metric::AHMC.AbstractMetric; ϵ=alg.ϵ)
pc = AHMC.MassMatrixAdaptor(metric)
da = AHMC.StepSizeAdaptor(alg.δ, ϵ)
if iszero(alg.n_adapts)
adaptor = AHMC.Adaptation.NoAdaptation()
else
if metric == AHMC.UnitEuclideanMetric
adaptor = ... | function AHMCAdaptor(alg::AdaptiveHamiltonian, metric::AHMC.AbstractMetric; ϵ=alg.ϵ)
pc = AHMC.MassMatrixAdaptor(metric)
da = AHMC.StepSizeAdaptor(alg.δ, ϵ)
if iszero(alg.n_adapts)
adaptor = AHMC.Adaptation.NoAdaptation()
else
if metric == AHMC.UnitEuclideanMetric
adaptor = ... | [
527,
543
] | function AHMCAdaptor(alg::AdaptiveHamiltonian, metric::AHMC.AbstractMetric; ϵ=alg.ϵ)
pc = AHMC.MassMatrixAdaptor(metric)
da = AHMC.StepSizeAdaptor(alg.δ, ϵ)
if iszero(alg.n_adapts)
adaptor = AHMC.Adaptation.NoAdaptation()
else
if metric == AHMC.UnitEuclideanMetric
adaptor = ... | function AHMCAdaptor(alg::AdaptiveHamiltonian, metric::AHMC.AbstractMetric; ϵ=alg.ϵ)
pc = AHMC.MassMatrixAdaptor(metric)
da = AHMC.StepSizeAdaptor(alg.δ, ϵ)
if iszero(alg.n_adapts)
adaptor = AHMC.Adaptation.NoAdaptation()
else
if metric == AHMC.UnitEuclideanMetric
adaptor = ... | AHMCAdaptor | 527 | 543 | src/mcmc/hmc.jl | #FILE: Turing.jl/test/mcmc/external_sampler.jl
##CHUNK 1
hamiltonian = AdvancedHMC.Hamiltonian(metric, f)
# Define a leapfrog solver, with initial step size chosen heuristically
initial_ϵ = AdvancedHMC.find_good_stepsize(hamiltonian, initial_θ)
integrator = AdvancedHMC.Leapfrog(initial_ϵ)
# Define... |
167 | 183 | Turing.jl | 372 | function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
# NOTE: In the past, `invlink(vi, model)` + `values_as(vi, OrderedDict)` was used.
# Unfortunately, using `invlink` can cause issues in scenarios where the constraints
# of the parameters change depending on the realizations. Hence we have ... | function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
# NOTE: In the past, `invlink(vi, model)` + `values_as(vi, OrderedDict)` was used.
# Unfortunately, using `invlink` can cause issues in scenarios where the constraints
# of the parameters change depending on the realizations. Hence we have ... | [
167,
183
] | function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
# NOTE: In the past, `invlink(vi, model)` + `values_as(vi, OrderedDict)` was used.
# Unfortunately, using `invlink` can cause issues in scenarios where the constraints
# of the parameters change depending on the realizations. Hence we have ... | function getparams(model::DynamicPPL.Model, vi::DynamicPPL.VarInfo)
# NOTE: In the past, `invlink(vi, model)` + `values_as(vi, OrderedDict)` was used.
# Unfortunately, using `invlink` can cause issues in scenarios where the constraints
# of the parameters change depending on the realizations. Hence we have ... | getparams | 167 | 183 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/optimisation/Optimisation.jl
##CHUNK 1
ctx = OptimizationContext(inner_context)
# Set its VarInfo to the initial parameters.
# TODO(penelopeysm): Unclear if this is really needed? Any time that logp is calculated
# (using `LogDensityProblems.logdensity(ldf, x)`) the parameters in t... |
188 | 207 | Turing.jl | 373 | function _params_to_array(model::DynamicPPL.Model, ts::Vector)
names_set = OrderedSet{VarName}()
# Extract the parameter names and values from each transition.
dicts = map(ts) do t
nms_and_vs = getparams(model, t)
nms = map(first, nms_and_vs)
vs = map(last, nms_and_vs)
for nm... | function _params_to_array(model::DynamicPPL.Model, ts::Vector)
names_set = OrderedSet{VarName}()
# Extract the parameter names and values from each transition.
dicts = map(ts) do t
nms_and_vs = getparams(model, t)
nms = map(first, nms_and_vs)
vs = map(last, nms_and_vs)
for nm... | [
188,
207
] | function _params_to_array(model::DynamicPPL.Model, ts::Vector)
names_set = OrderedSet{VarName}()
# Extract the parameter names and values from each transition.
dicts = map(ts) do t
nms_and_vs = getparams(model, t)
nms = map(first, nms_and_vs)
vs = map(last, nms_and_vs)
for nm... | function _params_to_array(model::DynamicPPL.Model, ts::Vector)
names_set = OrderedSet{VarName}()
# Extract the parameter names and values from each transition.
dicts = map(ts) do t
nms_and_vs = getparams(model, t)
nms = map(first, nms_and_vs)
vs = map(last, nms_and_vs)
for nm... | _params_to_array | 188 | 207 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
kwargs...,
)
# Convert transitions to array format.
# Also retrieve the variable names.
params_vec = map(Base.Fix1(_params_to_array, model), samples)
# Extract names and values separately.
varnames = params_vec[1][1]
varnames_symbol = map(Symbol,... |
225 | 239 | Turing.jl | 374 | function names_values(xs::AbstractVector{<:NamedTuple})
# Obtain all parameter names.
names_set = Set{Symbol}()
for x in xs
for k in keys(x)
push!(names_set, k)
end
end
names_unique = collect(names_set)
# Extract all values as matrix.
values = [haskey(x, name) ? ... | function names_values(xs::AbstractVector{<:NamedTuple})
# Obtain all parameter names.
names_set = Set{Symbol}()
for x in xs
for k in keys(x)
push!(names_set, k)
end
end
names_unique = collect(names_set)
# Extract all values as matrix.
values = [haskey(x, name) ? ... | [
225,
239
] | function names_values(xs::AbstractVector{<:NamedTuple})
# Obtain all parameter names.
names_set = Set{Symbol}()
for x in xs
for k in keys(x)
push!(names_set, k)
end
end
names_unique = collect(names_set)
# Extract all values as matrix.
values = [haskey(x, name) ? ... | function names_values(xs::AbstractVector{<:NamedTuple})
# Obtain all parameter names.
names_set = Set{Symbol}()
for x in xs
for k in keys(x)
push!(names_set, k)
end
end
names_unique = collect(names_set)
# Extract all values as matrix.
values = [haskey(x, name) ? ... | names_values | 225 | 239 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/mcmc/mh.jl
##CHUNK 1
set_namedtuple!(vi::VarInfo, nt::NamedTuple)
Places the values of a `NamedTuple` into the relevant places of a `VarInfo`.
"""
function set_namedtuple!(vi::DynamicPPL.VarInfoOrThreadSafeVarInfo, nt::NamedTuple)
for (n, vals) in pairs(nt)
vns = vi.metadata[n].vns... |
245 | 305 | Turing.jl | 375 | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{MCMCChains.Chains};
save_state=false,
stats=missing,
sort_chain=false,
... | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{MCMCChains.Chains};
save_state=false,
stats=missing,
sort_chain=false,
... | [
245,
305
] | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{MCMCChains.Chains};
save_state=false,
stats=missing,
sort_chain=false,
... | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{MCMCChains.Chains};
save_state=false,
stats=missing,
sort_chain=false,
... | AbstractMCMC.bundle_samples | 245 | 305 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
# `hcat` first to ensure we get the right `eltype`.
x = hcat(first(vals_vec), first(extra_values_vec))
# Pre-allocate to minimize memory usage.
parray = Array{eltype(x),3}(undef, length(vals_vec), size(x, 2), size(x, 1))
for (i, (vals, extras)) in enumera... |
308 | 327 | Turing.jl | 376 | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{Vector{NamedTuple}};
kwargs...,
)
return map(ts) do t
# Construct a di... | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{Vector{NamedTuple}};
kwargs...,
)
return map(ts) do t
# Construct a di... | [
308,
327
] | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{Vector{NamedTuple}};
kwargs...,
)
return map(ts) do t
# Construct a di... | function AbstractMCMC.bundle_samples(
ts::Vector{<:Union{AbstractTransition,AbstractVarInfo}},
model::AbstractModel,
spl::Union{Sampler{<:InferenceAlgorithm},SampleFromPrior,RepeatSampler},
state,
chain_type::Type{Vector{NamedTuple}};
kwargs...,
)
return map(ts) do t
# Construct a di... | AbstractMCMC.bundle_samples | 308 | 327 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
function AbstractMCMC.bundle_samples(
samples::Vector{<:Vector},
model::AbstractModel,
spl::Sampler{<:Emcee},
state::EmceeState,
chain_type::Type{MCMCChains.Chains};
save_state=false,
sort_chain=false,
discard_initial=0,
thinning=1,
kw... |
340 | 350 | Turing.jl | 377 | function group_varnames_by_symbol(vns)
d = OrderedDict{Symbol,Vector{VarName}}()
for vn in vns
sym = DynamicPPL.getsym(vn)
if !haskey(d, sym)
d[sym] = VarName[]
end
push!(d[sym], vn)
end
return d
end | function group_varnames_by_symbol(vns)
d = OrderedDict{Symbol,Vector{VarName}}()
for vn in vns
sym = DynamicPPL.getsym(vn)
if !haskey(d, sym)
d[sym] = VarName[]
end
push!(d[sym], vn)
end
return d
end | [
340,
350
] | function group_varnames_by_symbol(vns)
d = OrderedDict{Symbol,Vector{VarName}}()
for vn in vns
sym = DynamicPPL.getsym(vn)
if !haskey(d, sym)
d[sym] = VarName[]
end
push!(d[sym], vn)
end
return d
end | function group_varnames_by_symbol(vns)
d = OrderedDict{Symbol,Vector{VarName}}()
for vn in vns
sym = DynamicPPL.getsym(vn)
if !haskey(d, sym)
d[sym] = VarName[]
end
push!(d[sym], vn)
end
return d
end | group_varnames_by_symbol | 340 | 350 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/optimisation/Optimisation.jl
##CHUNK 1
`m`. The return value is a `NamedTuple` with `var_symbols` as the key(s). The second
argument should be either a `Symbol` or a vector of `Symbol`s.
"""
function Base.get(m::ModeResult, var_symbols::AbstractVector{Symbol})
log_density = m.f.ldf
# Get al... |
446 | 465 | Turing.jl | 378 | function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarInfo(model)
iters = Iterators.product(1:size(chain, 1), 1:size(chain, 3))
transitions = map(iters) do (sample_idx, chain_idx)
... | function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarInfo(model)
iters = Iterators.product(1:size(chain, 1), 1:size(chain, 3))
transitions = map(iters) do (sample_idx, chain_idx)
... | [
446,
465
] | function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarInfo(model)
iters = Iterators.product(1:size(chain, 1), 1:size(chain, 3))
transitions = map(iters) do (sample_idx, chain_idx)
... | function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarInfo(model)
iters = Iterators.product(1:size(chain, 1), 1:size(chain, 3))
transitions = map(iters) do (sample_idx, chain_idx)
... | transitions_from_chain | 446 | 465 | src/mcmc/Inference.jl | #FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:Gibbs},
state::GibbsState;
kwargs...,
)
vi = varinfo(state)
alg = spl.alg
varnames = alg.varnames
samplers = alg.samplers
stat... |
110 | 139 | Turing.jl | 379 | function MH(proposals...)
prop_syms = Symbol[]
props = AMH.Proposal[]
for s in proposals
if s isa Pair || s isa Tuple
# Check to see whether it's a pair that specifies a kernel
# or a specific proposal distribution.
push!(prop_syms, s[... | function MH(proposals...)
prop_syms = Symbol[]
props = AMH.Proposal[]
for s in proposals
if s isa Pair || s isa Tuple
# Check to see whether it's a pair that specifies a kernel
# or a specific proposal distribution.
push!(prop_syms, s[... | [
110,
139
] | function MH(proposals...)
prop_syms = Symbol[]
props = AMH.Proposal[]
for s in proposals
if s isa Pair || s isa Tuple
# Check to see whether it's a pair that specifies a kernel
# or a specific proposal distribution.
push!(prop_syms, s[... | function MH(proposals...)
prop_syms = Symbol[]
props = AMH.Proposal[]
for s in proposals
if s isa Pair || s isa Tuple
# Check to see whether it's a pair that specifies a kernel
# or a specific proposal distribution.
push!(prop_syms, s[... | MH | 110 | 139 | src/mcmc/mh.jl | #FILE: Turing.jl/test/mcmc/mh.jl
##CHUNK 1
@test chain isa MCMCChains.Chains
end
@testset "proposal matrix" begin
mat = [1.0 -0.05; -0.05 1.0]
prop1 = mat # Matrix only constructor
prop2 = AdvancedMH.RandomWalkProposal(MvNormal(mat)) # Explicit proposal constructor
sp... |
299 | 326 | Turing.jl | 380 | function propose!!(
rng::AbstractRNG, vi::AbstractVarInfo, model::Model, spl::Sampler{<:MH}, proposal
)
# Retrieve distribution and value NamedTuples.
dt, vt = dist_val_tuple(spl, vi)
# Create a sampler and the previous transition.
mh_sampler = AMH.MetropolisHastings(dt)
prev_trans = AMH.Transi... | function propose!!(
rng::AbstractRNG, vi::AbstractVarInfo, model::Model, spl::Sampler{<:MH}, proposal
)
# Retrieve distribution and value NamedTuples.
dt, vt = dist_val_tuple(spl, vi)
# Create a sampler and the previous transition.
mh_sampler = AMH.MetropolisHastings(dt)
prev_trans = AMH.Transi... | [
299,
326
] | function propose!!(
rng::AbstractRNG, vi::AbstractVarInfo, model::Model, spl::Sampler{<:MH}, proposal
)
# Retrieve distribution and value NamedTuples.
dt, vt = dist_val_tuple(spl, vi)
# Create a sampler and the previous transition.
mh_sampler = AMH.MetropolisHastings(dt)
prev_trans = AMH.Transi... | function propose!!(
rng::AbstractRNG, vi::AbstractVarInfo, model::Model, spl::Sampler{<:MH}, proposal
)
# Retrieve distribution and value NamedTuples.
dt, vt = dist_val_tuple(spl, vi)
# Create a sampler and the previous transition.
mh_sampler = AMH.MetropolisHastings(dt)
prev_trans = AMH.Transi... | propose!! | 299 | 326 | src/mcmc/mh.jl | #FILE: Turing.jl/src/mcmc/sghmc.jl
##CHUNK 1
velocity::T
end
function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !Dynamic... |
329 | 358 | Turing.jl | 381 | function propose!!(
rng::AbstractRNG,
vi::AbstractVarInfo,
model::Model,
spl::Sampler{<:MH},
proposal::AdvancedMH.RandomWalkProposal,
)
# If this is the case, we can just draw directly from the proposal
# matrix.
vals = vi[:]
# Create a sampler and the previous transition.
mh_sa... | function propose!!(
rng::AbstractRNG,
vi::AbstractVarInfo,
model::Model,
spl::Sampler{<:MH},
proposal::AdvancedMH.RandomWalkProposal,
)
# If this is the case, we can just draw directly from the proposal
# matrix.
vals = vi[:]
# Create a sampler and the previous transition.
mh_sa... | [
329,
358
] | function propose!!(
rng::AbstractRNG,
vi::AbstractVarInfo,
model::Model,
spl::Sampler{<:MH},
proposal::AdvancedMH.RandomWalkProposal,
)
# If this is the case, we can just draw directly from the proposal
# matrix.
vals = vi[:]
# Create a sampler and the previous transition.
mh_sa... | function propose!!(
rng::AbstractRNG,
vi::AbstractVarInfo,
model::Model,
spl::Sampler{<:MH},
proposal::AdvancedMH.RandomWalkProposal,
)
# If this is the case, we can just draw directly from the proposal
# matrix.
vals = vi[:]
# Create a sampler and the previous transition.
mh_sa... | propose!! | 329 | 358 | src/mcmc/mh.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
AMH.Transition(vi[:], getlogp(vi), false)
end,
)
return transition, state
end
function AbstractMCMC.step(
rng::AbstractRNG, model::Model, spl::Sampler{<:Emcee}, state::EmceeState; kwargs...
)
# Generate a log joint function.
vi = sta... |
360 | 372 | Turing.jl | 382 | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:MH},
vi::AbstractVarInfo;
kwargs...,
)
# If we're doing random walk with a covariance matrix,
# just link everything before sampling.
vi = maybe_link!!(vi, spl, spl.alg.proposals, model)
return T... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:MH},
vi::AbstractVarInfo;
kwargs...,
)
# If we're doing random walk with a covariance matrix,
# just link everything before sampling.
vi = maybe_link!!(vi, spl, spl.alg.proposals, model)
return T... | [
360,
372
] | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:MH},
vi::AbstractVarInfo;
kwargs...,
)
# If we're doing random walk with a covariance matrix,
# just link everything before sampling.
vi = maybe_link!!(vi, spl, spl.alg.proposals, model)
return T... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:MH},
vi::AbstractVarInfo;
kwargs...,
)
# If we're doing random walk with a covariance matrix,
# just link everything before sampling.
vi = maybe_link!!(vi, spl, spl.alg.proposals, model)
return T... | DynamicPPL.initialstep | 360 | 372 | src/mcmc/mh.jl | #FILE: Turing.jl/src/mcmc/sghmc.jl
##CHUNK 1
velocity::T
end
function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !Dynamic... |
15 | 31 | Turing.jl | 383 | function TracedModel(
model::Model,
sampler::AbstractSampler,
varinfo::AbstractVarInfo,
rng::Random.AbstractRNG,
)
context = SamplingContext(rng, sampler, DefaultContext())
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
if kwargs !== nothing && !isempty(kwar... | function TracedModel(
model::Model,
sampler::AbstractSampler,
varinfo::AbstractVarInfo,
rng::Random.AbstractRNG,
)
context = SamplingContext(rng, sampler, DefaultContext())
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
if kwargs !== nothing && !isempty(kwar... | [
15,
31
] | function TracedModel(
model::Model,
sampler::AbstractSampler,
varinfo::AbstractVarInfo,
rng::Random.AbstractRNG,
)
context = SamplingContext(rng, sampler, DefaultContext())
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
if kwargs !== nothing && !isempty(kwar... | function TracedModel(
model::Model,
sampler::AbstractSampler,
varinfo::AbstractVarInfo,
rng::Random.AbstractRNG,
)
context = SamplingContext(rng, sampler, DefaultContext())
args, kwargs = DynamicPPL.make_evaluate_args_and_kwargs(model, varinfo, context)
if kwargs !== nothing && !isempty(kwar... | TracedModel | 15 | 31 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/gibbs.jl
##CHUNK 1
model::DynamicPPL.Model,
sampler::Sampler{<:ESS},
state::AbstractVarInfo,
params::AbstractVarInfo,
)
# The state is already a VarInfo, so we can just return `params`, but first we need to
# update its logprob. To do this, we have to call evaluate!! wi... |
62 | 72 | Turing.jl | 384 | function AdvancedPS.update_rng!(
trace::AdvancedPS.Trace{<:AdvancedPS.LibtaskModel{<:TracedModel}}
)
# Extract the `args`.
args = trace.model.ctask.args
# From `args`, extract the `SamplingContext`, which contains the RNG.
sampling_context = args[3]
rng = sampling_context.rng
trace.rng = rng... | function AdvancedPS.update_rng!(
trace::AdvancedPS.Trace{<:AdvancedPS.LibtaskModel{<:TracedModel}}
)
# Extract the `args`.
args = trace.model.ctask.args
# From `args`, extract the `SamplingContext`, which contains the RNG.
sampling_context = args[3]
rng = sampling_context.rng
trace.rng = rng... | [
62,
72
] | function AdvancedPS.update_rng!(
trace::AdvancedPS.Trace{<:AdvancedPS.LibtaskModel{<:TracedModel}}
)
# Extract the `args`.
args = trace.model.ctask.args
# From `args`, extract the `SamplingContext`, which contains the RNG.
sampling_context = args[3]
rng = sampling_context.rng
trace.rng = rng... | function AdvancedPS.update_rng!(
trace::AdvancedPS.Trace{<:AdvancedPS.LibtaskModel{<:TracedModel}}
)
# Extract the `args`.
args = trace.model.ctask.args
# From `args`, extract the `SamplingContext`, which contains the RNG.
sampling_context = args[3]
rng = sampling_context.rng
trace.rng = rng... | AdvancedPS.update_rng! | 62 | 72 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/test/essential/container.jl
##CHUNK 1
vi = DynamicPPL.VarInfo()
sampler = Sampler(PG(10))
model = test()
trace = AdvancedPS.Trace(model, sampler, vi, AdvancedPS.TracedRNG())
# Make sure the backreference from taped_globals to the trace is in place.
@test... |
187 | 220 | Turing.jl | 385 | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:SMC},
vi::AbstractVarInfo;
nparticles::Int,
kwargs...,
)
# Reset the VarInfo.
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
empty!!(vi)
# Create a new set of partic... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:SMC},
vi::AbstractVarInfo;
nparticles::Int,
kwargs...,
)
# Reset the VarInfo.
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
empty!!(vi)
# Create a new set of partic... | [
187,
220
] | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:SMC},
vi::AbstractVarInfo;
nparticles::Int,
kwargs...,
)
# Reset the VarInfo.
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
empty!!(vi)
# Create a new set of partic... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:SMC},
vi::AbstractVarInfo;
nparticles::Int,
kwargs...,
)
# Reset the VarInfo.
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
empty!!(vi)
# Create a new set of partic... | DynamicPPL.initialstep | 187 | 220 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/sghmc.jl
##CHUNK 1
end
function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ,... |
222 | 238 | Turing.jl | 386 | function AbstractMCMC.step(
::AbstractRNG, model::AbstractModel, spl::Sampler{<:SMC}, state::SMCState; kwargs...
)
# Extract the index of the current particle.
index = state.particleindex
# Extract the current particle and its weight.
particles = state.particles
particle = particles.vals[index]... | function AbstractMCMC.step(
::AbstractRNG, model::AbstractModel, spl::Sampler{<:SMC}, state::SMCState; kwargs...
)
# Extract the index of the current particle.
index = state.particleindex
# Extract the current particle and its weight.
particles = state.particles
particle = particles.vals[index]... | [
222,
238
] | function AbstractMCMC.step(
::AbstractRNG, model::AbstractModel, spl::Sampler{<:SMC}, state::SMCState; kwargs...
)
# Extract the index of the current particle.
index = state.particleindex
# Extract the current particle and its weight.
particles = state.particles
particle = particles.vals[index]... | function AbstractMCMC.step(
::AbstractRNG, model::AbstractModel, spl::Sampler{<:SMC}, state::SMCState; kwargs...
)
# Extract the index of the current particle.
index = state.particleindex
# Extract the current particle and its weight.
particles = state.particles
particle = particles.vals[index]... | AbstractMCMC.step | 222 | 238 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/hmc.jl
##CHUNK 1
transition = Transition(model, vi, t)
state = HMCState(vi, 1, kernel, hamiltonian, t.z, adaptor)
return transition, state
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Hamiltonian},
state::HMCState;
nada... |
322 | 355 | Turing.jl | 387 | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:PG},
vi::AbstractVarInfo;
kwargs...,
)
# Reset the VarInfo before new sweep
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
# Create a new set of particles
num_particles ... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:PG},
vi::AbstractVarInfo;
kwargs...,
)
# Reset the VarInfo before new sweep
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
# Create a new set of particles
num_particles ... | [
322,
355
] | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:PG},
vi::AbstractVarInfo;
kwargs...,
)
# Reset the VarInfo before new sweep
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
# Create a new set of particles
num_particles ... | function DynamicPPL.initialstep(
rng::AbstractRNG,
model::AbstractModel,
spl::Sampler{<:PG},
vi::AbstractVarInfo;
kwargs...,
)
# Reset the VarInfo before new sweep
reset_num_produce!(vi)
set_retained_vns_del!(vi)
resetlogp!!(vi)
# Create a new set of particles
num_particles ... | DynamicPPL.initialstep | 322 | 355 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/sghmc.jl
##CHUNK 1
end
function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ,... |
357 | 395 | Turing.jl | 388 | function AbstractMCMC.step(
rng::AbstractRNG, model::AbstractModel, spl::Sampler{<:PG}, state::PGState; kwargs...
)
# Reset the VarInfo before new sweep.
vi = state.vi
reset_num_produce!(vi)
resetlogp!!(vi)
# Create reference particle for which the samples will be retained.
reference = Adva... | function AbstractMCMC.step(
rng::AbstractRNG, model::AbstractModel, spl::Sampler{<:PG}, state::PGState; kwargs...
)
# Reset the VarInfo before new sweep.
vi = state.vi
reset_num_produce!(vi)
resetlogp!!(vi)
# Create reference particle for which the samples will be retained.
reference = Adva... | [
357,
395
] | function AbstractMCMC.step(
rng::AbstractRNG, model::AbstractModel, spl::Sampler{<:PG}, state::PGState; kwargs...
)
# Reset the VarInfo before new sweep.
vi = state.vi
reset_num_produce!(vi)
resetlogp!!(vi)
# Create reference particle for which the samples will be retained.
reference = Adva... | function AbstractMCMC.step(
rng::AbstractRNG, model::AbstractModel, spl::Sampler{<:PG}, state::PGState; kwargs...
)
# Reset the VarInfo before new sweep.
vi = state.vi
reset_num_produce!(vi)
resetlogp!!(vi)
# Create reference particle for which the samples will be retained.
reference = Adva... | AbstractMCMC.step | 357 | 395 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/Inference.jl
##CHUNK 1
return transitions_from_chain(Random.default_rng(), model, chain; kwargs...)
end
function transitions_from_chain(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
chain::MCMCChains.Chains;
sampler=DynamicPPL.SampleFromPrior(),
)
vi = Turing.VarI... |
431 | 455 | Turing.jl | 389 | function DynamicPPL.assume(
rng,
spl::Sampler{<:Union{PG,SMC}},
dist::Distribution,
vn::VarName,
_vi::AbstractVarInfo,
)
vi = trace_local_varinfo_maybe(_vi)
trng = trace_local_rng_maybe(rng)
if ~haskey(vi, vn)
r = rand(trng, dist)
push!!(vi, vn, r, dist)
elseif is_fl... | function DynamicPPL.assume(
rng,
spl::Sampler{<:Union{PG,SMC}},
dist::Distribution,
vn::VarName,
_vi::AbstractVarInfo,
)
vi = trace_local_varinfo_maybe(_vi)
trng = trace_local_rng_maybe(rng)
if ~haskey(vi, vn)
r = rand(trng, dist)
push!!(vi, vn, r, dist)
elseif is_fl... | [
431,
455
] | function DynamicPPL.assume(
rng,
spl::Sampler{<:Union{PG,SMC}},
dist::Distribution,
vn::VarName,
_vi::AbstractVarInfo,
)
vi = trace_local_varinfo_maybe(_vi)
trng = trace_local_rng_maybe(rng)
if ~haskey(vi, vn)
r = rand(trng, dist)
push!!(vi, vn, r, dist)
elseif is_fl... | function DynamicPPL.assume(
rng,
spl::Sampler{<:Union{PG,SMC}},
dist::Distribution,
vn::VarName,
_vi::AbstractVarInfo,
)
vi = trace_local_varinfo_maybe(_vi)
trng = trace_local_rng_maybe(rng)
if ~haskey(vi, vn)
r = rand(trng, dist)
push!!(vi, vn, r, dist)
elseif is_fl... | DynamicPPL.assume | 431 | 455 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/src/mcmc/is.jl
##CHUNK 1
return Transition(model, vi), nothing
end
# Calculate evidence.
function getlogevidence(samples::Vector{<:Transition}, ::Sampler{<:IS}, state)
return logsumexp(map(x -> x.lp, samples)) - log(length(samples))
end
function DynamicPPL.assume(rng, ::Sampler{<:IS}, dist::D... |
477 | 490 | Turing.jl | 390 | function AdvancedPS.Trace(
model::Model,
sampler::Sampler{<:Union{SMC,PG}},
varinfo::AbstractVarInfo,
rng::AdvancedPS.TracedRNG,
)
newvarinfo = deepcopy(varinfo)
DynamicPPL.reset_num_produce!(newvarinfo)
tmodel = TracedModel(model, sampler, newvarinfo, rng)
newtrace = AdvancedPS.Trace(t... | function AdvancedPS.Trace(
model::Model,
sampler::Sampler{<:Union{SMC,PG}},
varinfo::AbstractVarInfo,
rng::AdvancedPS.TracedRNG,
)
newvarinfo = deepcopy(varinfo)
DynamicPPL.reset_num_produce!(newvarinfo)
tmodel = TracedModel(model, sampler, newvarinfo, rng)
newtrace = AdvancedPS.Trace(t... | [
477,
490
] | function AdvancedPS.Trace(
model::Model,
sampler::Sampler{<:Union{SMC,PG}},
varinfo::AbstractVarInfo,
rng::AdvancedPS.TracedRNG,
)
newvarinfo = deepcopy(varinfo)
DynamicPPL.reset_num_produce!(newvarinfo)
tmodel = TracedModel(model, sampler, newvarinfo, rng)
newtrace = AdvancedPS.Trace(t... | function AdvancedPS.Trace(
model::Model,
sampler::Sampler{<:Union{SMC,PG}},
varinfo::AbstractVarInfo,
rng::AdvancedPS.TracedRNG,
)
newvarinfo = deepcopy(varinfo)
DynamicPPL.reset_num_produce!(newvarinfo)
tmodel = TracedModel(model, sampler, newvarinfo, rng)
newtrace = AdvancedPS.Trace(t... | AdvancedPS.Trace | 477 | 490 | src/mcmc/particle_mcmc.jl | #FILE: Turing.jl/test/essential/container.jl
##CHUNK 1
vi = DynamicPPL.VarInfo()
sampler = Sampler(PG(10))
model = test()
trace = AdvancedPS.Trace(model, sampler, vi, AdvancedPS.TracedRNG())
# Make sure the backreference from taped_globals to the trace is in place.
@test... |
8 | 23 | Turing.jl | 391 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler::DynamicPPL.Sampler{<:Prior},
state=nothing;
kwargs...,
)
vi = last(
DynamicPPL.evaluate!!(
model,
VarInfo(),
SamplingContext(rng, DynamicPPL.SampleFromPrior(), Dynam... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler::DynamicPPL.Sampler{<:Prior},
state=nothing;
kwargs...,
)
vi = last(
DynamicPPL.evaluate!!(
model,
VarInfo(),
SamplingContext(rng, DynamicPPL.SampleFromPrior(), Dynam... | [
8,
23
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler::DynamicPPL.Sampler{<:Prior},
state=nothing;
kwargs...,
)
vi = last(
DynamicPPL.evaluate!!(
model,
VarInfo(),
SamplingContext(rng, DynamicPPL.SampleFromPrior(), Dynam... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler::DynamicPPL.Sampler{<:Prior},
state=nothing;
kwargs...,
)
vi = last(
DynamicPPL.evaluate!!(
model,
VarInfo(),
SamplingContext(rng, DynamicPPL.SampleFromPrior(), Dynam... | AbstractMCMC.step | 8 | 23 | src/mcmc/prior.jl | #FILE: Turing.jl/test/mcmc/gibbs.jl
##CHUNK 1
::DynamicPPL.Sampler,
::VarInfoState,
params::DynamicPPL.AbstractVarInfo,
)
return VarInfoState(params)
end
function AbstractMCMC.step(
::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sample... |
49 | 61 | Turing.jl | 392 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step(rng, model, sampler.sampler, state; kwargs...)
for _ in 2:(sampler.num_repeat)
transition, state = AbstractMCMC.st... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step(rng, model, sampler.sampler, state; kwargs...)
for _ in 2:(sampler.num_repeat)
transition, state = AbstractMCMC.st... | [
49,
61
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step(rng, model, sampler.sampler, state; kwargs...)
for _ in 2:(sampler.num_repeat)
transition, state = AbstractMCMC.st... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step(rng, model, sampler.sampler, state; kwargs...)
for _ in 2:(sampler.num_repeat)
transition, state = AbstractMCMC.st... | AbstractMCMC.step | 49 | 61 | src/mcmc/repeat_sampler.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
states::S
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return... |
72 | 88 | Turing.jl | 393 | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step_warmup(
rng, model, sampler.sampler, state; kwargs...
)
for _ in 2:(sampler.num_repeat)
transit... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step_warmup(
rng, model, sampler.sampler, state; kwargs...
)
for _ in 2:(sampler.num_repeat)
transit... | [
72,
88
] | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step_warmup(
rng, model, sampler.sampler, state; kwargs...
)
for _ in 2:(sampler.num_repeat)
transit... | function AbstractMCMC.step_warmup(
rng::Random.AbstractRNG,
model::AbstractMCMC.AbstractModel,
sampler::RepeatSampler,
state;
kwargs...,
)
transition, state = AbstractMCMC.step_warmup(
rng, model, sampler.sampler, state; kwargs...
)
for _ in 2:(sampler.num_repeat)
transit... | AbstractMCMC.step_warmup | 72 | 88 | src/mcmc/repeat_sampler.jl | #FILE: Turing.jl/src/mcmc/emcee.jl
##CHUNK 1
states::S
end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:Emcee};
resume_from=nothing,
initial_params=nothing,
kwargs...,
)
if resume_from !== nothing
state = loadstate(resume_from)
return... |
54 | 78 | Turing.jl | 394 | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | [
54,
78
] | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | DynamicPPL.initialstep | 54 | 78 | src/mcmc/sghmc.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
vi = DynamicPPL.setlogp!!(vi, Q.ℓq)
# Create first sample and state.
sample = Turing.Inference.Transition(model, vi)
state = DynamicNUTSState(ℓ, vi, Q, steps.H.κ, steps.ϵ)
return sample, state
end
function AbstractMCMC.step(
rng::Random.Ab... |
80 | 110 | Turing.jl | 395 | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
state::SGHMCState;
kwargs...,
)
# Compute gradient of log density.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
# Update la... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
state::SGHMCState;
kwargs...,
)
# Compute gradient of log density.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
# Update la... | [
80,
110
] | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
state::SGHMCState;
kwargs...,
)
# Compute gradient of log density.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
# Update la... | function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGHMC},
state::SGHMCState;
kwargs...,
)
# Compute gradient of log density.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
# Update la... | AbstractMCMC.step | 80 | 110 | src/mcmc/sghmc.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:DynamicNUTS},
state::DynamicNUTSState;
kwargs...,
)
# Compute next sample.
vi = state.vi
ℓ = state.logdensity
steps = DynamicHMC.mcmc_steps(rng, spl.alg.s... |
217 | 241 | Turing.jl | 396 | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGLD},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGLD},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | [
217,
241
] | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGLD},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::Model,
spl::Sampler{<:SGLD},
vi::AbstractVarInfo;
kwargs...,
)
# Transform the samples to unconstrained space and compute the joint log probability.
if !DynamicPPL.islinked(vi)
vi = DynamicPPL.link!!(vi, model)
... | DynamicPPL.initialstep | 217 | 241 | src/mcmc/sghmc.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
function DynamicPPL.initialstep(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
spl::DynamicPPL.Sampler{<:DynamicNUTS},
vi::DynamicPPL.AbstractVarInfo;
kwargs...,
)
# Ensure that initial sample is in unconstrained space.
if !DynamicPPL... |
243 | 264 | Turing.jl | 397 | function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
step = state.step
stepsize = spl.alg.... | function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
step = state.step
stepsize = spl.alg.... | [
243,
264
] | function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
step = state.step
stepsize = spl.alg.... | function AbstractMCMC.step(
rng::Random.AbstractRNG, model::Model, spl::Sampler{<:SGLD}, state::SGLDState; kwargs...
)
# Perform gradient step.
ℓ = state.logdensity
vi = state.vi
θ = vi[:]
grad = last(LogDensityProblems.logdensity_and_gradient(ℓ, θ))
step = state.step
stepsize = spl.alg.... | AbstractMCMC.step | 243 | 264 | src/mcmc/sghmc.jl | #FILE: Turing.jl/ext/TuringDynamicHMCExt.jl
##CHUNK 1
vi = DynamicPPL.setlogp!!(vi, Q.ℓq)
# Create first sample and state.
sample = Turing.Inference.Transition(model, vi)
state = DynamicNUTSState(ℓ, vi, Q, steps.H.κ, steps.ϵ)
return sample, state
end
function AbstractMCMC.step(
rng::Random.Ab... |
79 | 89 | Turing.jl | 398 | function DynamicPPL.tilde_assume(ctx::OptimizationContext, dist, vn, vi)
r = vi[vn, dist]
lp = if ctx.context isa Union{DynamicPPL.DefaultContext,DynamicPPL.PriorContext}
# MAP
Distributions.logpdf(dist, r)
else
# MLE
0
end
return r, lp, vi
end | function DynamicPPL.tilde_assume(ctx::OptimizationContext, dist, vn, vi)
r = vi[vn, dist]
lp = if ctx.context isa Union{DynamicPPL.DefaultContext,DynamicPPL.PriorContext}
# MAP
Distributions.logpdf(dist, r)
else
# MLE
0
end
return r, lp, vi
end | [
79,
89
] | function DynamicPPL.tilde_assume(ctx::OptimizationContext, dist, vn, vi)
r = vi[vn, dist]
lp = if ctx.context isa Union{DynamicPPL.DefaultContext,DynamicPPL.PriorContext}
# MAP
Distributions.logpdf(dist, r)
else
# MLE
0
end
return r, lp, vi
end | function DynamicPPL.tilde_assume(ctx::OptimizationContext, dist, vn, vi)
r = vi[vn, dist]
lp = if ctx.context isa Union{DynamicPPL.DefaultContext,DynamicPPL.PriorContext}
# MAP
Distributions.logpdf(dist, r)
else
# MLE
0
end
return r, lp, vi
end | DynamicPPL.tilde_assume | 79 | 89 | src/optimisation/Optimisation.jl | #FILE: Turing.jl/src/mcmc/prior.jl
##CHUNK 1
"""
Prior()
Algorithm for sampling from the prior.
"""
struct Prior <: InferenceAlgorithm end
function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::DynamicPPL.Model,
sampler::DynamicPPL.Sampler{<:Prior},
state=nothing;
kwargs...,
)
vi = la... |
181 | 202 | Turing.jl | 399 | function (f::OptimLogDensity)(F, G, z)
if G !== nothing
# Calculate log joint and its gradient.
logp, ∇logp = LogDensityProblems.logdensity_and_gradient(f.ldf, z)
# Save the negative gradient to the pre-allocated array.
copyto!(G, -∇logp)
# If F is something, the negative l... | function (f::OptimLogDensity)(F, G, z)
if G !== nothing
# Calculate log joint and its gradient.
logp, ∇logp = LogDensityProblems.logdensity_and_gradient(f.ldf, z)
# Save the negative gradient to the pre-allocated array.
copyto!(G, -∇logp)
# If F is something, the negative l... | [
181,
202
] | function (f::OptimLogDensity)(F, G, z)
if G !== nothing
# Calculate log joint and its gradient.
logp, ∇logp = LogDensityProblems.logdensity_and_gradient(f.ldf, z)
# Save the negative gradient to the pre-allocated array.
copyto!(G, -∇logp)
# If F is something, the negative l... | function (f::OptimLogDensity)(F, G, z)
if G !== nothing
# Calculate log joint and its gradient.
logp, ∇logp = LogDensityProblems.logdensity_and_gradient(f.ldf, z)
# Save the negative gradient to the pre-allocated array.
copyto!(G, -∇logp)
# If F is something, the negative l... | unknown_function | 181 | 202 | src/optimisation/Optimisation.jl | #FILE: Turing.jl/test/mcmc/external_sampler.jl
##CHUNK 1
# expected_logpdf = logpdf(Beta(2, 2), a) + logpdf(Normal(a), b)
# @test all(chn[:lp] .== expected_logpdf)
# @test all(chn[:logprior] .== expected_logpdf)
# @test all(chn[:loglikelihood] .== 0.0)
end
function initialize_nuts(model::DynamicPPL.Mod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.