-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from bonStats:dual-error
Dual-error
- Loading branch information
Showing
7 changed files
with
37 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,40 @@ | ||
include("pd-chol-helper.jl") | ||
|
||
mutable struct CholeskyAffine{N} <: Transform{N} | ||
L::LowerTriangular | ||
b::Vector{<:Real} | ||
function CholeskyAffine(L::LowerTriangular, b::Vector{<:Real}) | ||
mutable struct CholeskyAffine{N,T<:Real} <: Transform{N} | ||
L::LowerTriangular{T, Matrix{T}} | ||
b::Vector{T} | ||
function CholeskyAffine(L::LowerTriangular{T, Matrix{T}}, b::Vector{T}) where {T<:Real} | ||
@assert length(b) == size(L, 1) | ||
new{length(b)}(L, b) | ||
new{length(b),T}(L, b) | ||
end | ||
end | ||
|
||
CholeskyAffine(vL::Vector{<:Real}, b::Vector{<:Real}) = CholeskyAffine(vec2chol(vL), b) | ||
CholeskyAffine(vL::Vector{T}, b::Vector{T}) where {T<:Real} = CholeskyAffine(vec2chol(vL), b) | ||
CholeskyAffine(vLb::Vector{<:Real}, d::Int64) = CholeskyAffine(vLb[1:(end-d)], vLb[(end-d+1):end]) | ||
function CholeskyAffine(d::Int64) | ||
par_zero = zeros(Int((d^2 + d)/2 + d)) | ||
CholeskyAffine(par_zero, d) | ||
end | ||
|
||
dimension(::CholeskyAffine{N}) where {N} = (N,) # object dimension | ||
length(::CholeskyAffine{N}) where {N} = N # for internal use (within CholeskyAffine functions) | ||
nparam(::CholeskyAffine{N}) where {N} = N*(N + 3)/2 # number of params | ||
dimension(::CholeskyAffine{N,T}) where {N,T} = (N,) # object dimension | ||
length(::CholeskyAffine{N,T}) where {N,T} = N # for internal use (within CholeskyAffine functions) | ||
nparam(::CholeskyAffine{N,T}) where {N,T} = N*(N + 3)/2 # number of params | ||
|
||
function update!(chaf::CholeskyAffine, vL::Vector{<:Real}, b::Vector{<:Real}) | ||
chaf.L = vec2chol(vL) | ||
chaf.b = b | ||
return chaf | ||
# for update! CholeskyAffine may not have same type as other arguments (e.g. Float64 -> Dual) | ||
function update!(chaf::CholeskyAffine{N,T}, vL::Vector{T}, b::Vector{T}) where {N,T<:Real} | ||
chaf.L .= vec2chol(vL) | ||
chaf.b .= b | ||
end | ||
|
||
function update!(chaf::CholeskyAffine, vLb::Vector{<:Real}) | ||
n = length(chaf) | ||
chaf.L = vec2chol(vLb[1:(end-n)]) | ||
chaf.b = vLb[(end-n+1):end] | ||
return chaf | ||
end | ||
update!(chaf::CholeskyAffine{N,T}, vLb::Vector{T}) where {N,T<:Real} = update!(chaf, vLb[1:(end-N)], vLb[(end-N+1):end]) | ||
|
||
maketransform(::CholeskyAffine{N,Ti}, vLb::Vector{To}) where {N,Ti<:Real,To<:Real} = CholeskyAffine(vLb, N) | ||
|
||
scaleparamvec(tf::CholeskyAffine) = chol2vec(tf.L) | ||
biasparamvec(tf::CholeskyAffine) = tf.b | ||
paramvec(tf::CholeskyAffine) = [chol2vec(tf.L); tf.b] | ||
|
||
# for (::CholeskyAffine) may not have same type as input (e.g. Float64 -> Dual) | ||
(chaf::CholeskyAffine)(x::T, μs::T) where {T} = chaf.L * (x - μs) + μs + chaf.b | ||
|
||
(chaf::CholeskyAffine)(cal::Calibration{T}) where {T} = Calibration(cal.values, hcat([chaf.(clm, [cal.μs[i]]) for (i, clm) in enumerate(eachcol(cal.samples))]...)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters