Skip to content

Commit

Permalink
Fix #83
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Aug 26, 2014
1 parent 84b5575 commit 79220e6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/linpred.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


## Return the linear predictor vector
linpred(p::LinPred, f::Real=1.) = p.X * (f == 0. ? p.beta0 : fma(p.beta0, p.delbeta, f))

Expand All @@ -24,8 +22,6 @@ type DensePredQR{T<:BlasReal} <: DensePred
end
DensePredQR{T<:BlasReal}(X::Matrix{T}) = DensePredQR{T}(X, zeros(T,size(X,2)))

cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky{T}(p.qr[:R],'U')

delbeta!{T<:BlasReal}(p::DensePredQR{T}, r::Vector{T}) = (p.delbeta = p.qr\r; p)

type DensePredChol{T<:BlasReal} <: DensePred
Expand All @@ -40,20 +36,23 @@ type DensePredChol{T<:BlasReal} <: DensePred
end
DensePredChol{T<:BlasReal}(X::Matrix{T}) = DensePredChol{T}(X, zeros(T,size(X,2)))

solve!{T<:BlasReal}(C::Cholesky{T}, B::StridedVecOrMat{T}) = potrs!(C.uplo, C.UL, B)

cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; Cholesky{T}(copy(c.UL),c.uplo))
if VERSION >= v"0.4.0-dev+122"
cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky{T,Matrix{T},:U}(p.qr[:R])
cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; typeof(c)(copy(c.UL)))
else
cholfact{T<:FP}(p::DensePredQR{T}) = Cholesky(p.qr[:R], :U)
cholfact{T<:FP}(p::DensePredChol{T}) = (c = p.chol; Cholesky(copy(c.UL),c.uplo))
end

function delbeta!{T<:BlasReal}(p::DensePredChol{T}, r::Vector{T})
solve!(p.chol, gemv!('T', 1.0, p.X, r, 0.0, p.delbeta))
A_ldiv_B!(p.chol, At_mul_B!(p.delbeta, p.X, r))
p
end

function delbeta!{T<:BlasReal}(p::DensePredChol{T}, r::Vector{T}, wt::Vector{T}, scr::Matrix{T})
vbroadcast!(Multiply(), scr, p.X, wt, 1)
fac, info = potrf!('U', gemm!('T', 'N', 1.0, scr, p.X, 0.0, p.chol.UL))
info == 0 || error("Singularity detected at column $info of weighted model matrix")
solve!(p.chol, gemv!('T', 1.0, scr, r, 0.0, p.delbeta))
cholfact!(At_mul_B!(p.chol.UL, scr, p.X), :U)
A_ldiv_B!(p.chol, At_mul_B!(p.delbeta, scr, r))
p
end

Expand Down

0 comments on commit 79220e6

Please sign in to comment.