Skip to content

Commit

Permalink
Improve memory efficiency (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
biona001 authored Dec 2, 2024
1 parent bab54f4 commit 81be700
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GhostKnockoffGWAS"
uuid = "28dc8d00-4921-4061-9921-3f423e4be5cc"
authors = ["Benjamin Chu <[email protected]>"]
version = "0.2.3"
version = "0.2.4"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
12 changes: 9 additions & 3 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ function sample_mvn_efficient(C::AbstractMatrix{T}, D::AbstractMatrix{T}, m::Int
end
e2_avg = 1/m * sum(e2)
Zko = T[]
storage = zeros(p)
for i in 1:m
append!(Zko, L.L*e1 + e2[i] - e2_avg)
e2[i] .-= e2_avg
mul!(storage, L.U', e1) # faster than L.L*e1 since L.L makes a copy
e2[i] .+= storage
append!(Zko, e2[i])
end
return Zko
end
Expand Down Expand Up @@ -338,8 +342,10 @@ function ghost_knockoffs(Zscores::AbstractVector{T}, D::AbstractMatrix{T},
DΣinv = D * Σinv
C = 2D - DΣinv * D
v = sample_mvn_efficient(C, D, m) # Jiaqi's trick
P = repeat(I - DΣinv, m)
return P*Zscores + v
DΣinv .*= -1
DΣinv += I
Pz = DΣinv * Zscores
return repeat(Pz, m) + v
end

"""
Expand Down

0 comments on commit 81be700

Please sign in to comment.