Skip to content

Commit

Permalink
Merge pull request #23 from PharmCat/dev-2
Browse files Browse the repository at this point in the history
- v1.0.11
  • Loading branch information
PharmCat authored Sep 15, 2020
2 parents 18bad9b + dfbb9e7 commit 70f23ca
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 157 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# Validation
validation/
examples/
docs/build/
docs/img/
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ after_success:

jobs:
allow_failures:
- julia: 1.4
- julia:
- 1.4
- 1.5
include:
- stage: "Documentation"
julia: 1.0
Expand All @@ -35,3 +37,7 @@ jobs:
Pkg.instantiate()'
- julia --project=docs/ docs/make.jl
after_success: skip

script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- travis_wait 30 julia --project -e 'using Pkg; Pkg.build(); Pkg.test(; coverage=true)'
10 changes: 4 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "ReplicateBE"
uuid = "671d9d50-c343-11e9-1a9c-fdd992682823"
keywords = ["bioequivalence", "mixedmodel"]
desc = "Mixed model solution for replicate designed bioequivalence study."
version = "1.0.10"
version = "1.0.11"


[deps]
Expand All @@ -19,7 +19,6 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[extras]
Expand All @@ -31,14 +30,13 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
test = ["CSV", "Test", "StatsBase"]

[compat]
CategoricalArrays = "0.7"
CategoricalArrays = "0.7, 0.8"
julia = "1.0, 1.1, 1.2, 1.3, 1.4, 1.5"
StatsBase = "0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33"
DataFrames = "0.19, 0.20"
DataFrames = "0.19, 0.20, 0.21"
StatsModels = "0.6"
Distributions = "0.20, 0.21, 0.22, 0.23"
PDMats = "0.9, 0.10"
ForwardDiff = "0.10"
Optim = "0.19, 0.20, 0.21"
Optim = "0.19, 0.20, 0.21, 0.22, 1.0, 1.1, 1.2"
LineSearches = "7.0"
StaticArrays = "0.11, 0.12"
7 changes: 7 additions & 0 deletions chagelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- v1.0.11
* Optimizations
* Cosmetics
* PDMats exclude
* Fix experimental sigmoid function
* Add in initial variance estimate (OLS via QR decomposition) function

- v1.0.10
* Cosmetics
* StatsBase.coeftable
Expand Down
122 changes: 122 additions & 0 deletions examples/benchmark.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
using BenchmarkTools, CSV, DataFrames
using ReplicateBE

datapath = joinpath(dirname(pathof(ReplicateBE)))*"/../test/csv/df6.csv"

df6 = CSV.File(datapath) |> DataFrame

#@benchmark be = ReplicateBE.rbe!(df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10)
@benchmark be = ReplicateBE.rbe!($df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10) seconds = 25 samples = 200 evals = 5

#=
julia> @benchmark be = ReplicateBE.rbe!(datadf, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10)
BenchmarkTools.Trial:
memory estimate: 6.15 MiB
allocs estimate: 66530
--------------
minimum time: 24.307 ms (0.00% GC)
median time: 27.732 ms (0.00% GC)
mean time: 29.258 ms (3.78% GC)
maximum time: 47.647 ms (0.00% GC)
--------------
samples: 172
evals/sample: 1
julia>
=#

#v1.5
#=
julia> @benchmark be = ReplicateBE.rbe!(df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10)
BenchmarkTools.Trial:
memory estimate: 5.40 MiB
allocs estimate: 48564
--------------
minimum time: 16.528 ms (0.00% GC)
median time: 18.803 ms (0.00% GC)
mean time: 20.431 ms (4.65% GC)
maximum time: 53.102 ms (50.43% GC)
--------------
samples: 245
evals/sample: 1
=#

#v1.0.11 Julia 1.4
#=
julia> @benchmark be = ReplicateBE.rbe!(df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol
= 1e-10)
BenchmarkTools.Trial:
memory estimate: 4.34 MiB
allocs estimate: 46670
--------------
minimum time: 10.112 ms (0.00% GC)
median time: 18.371 ms (0.00% GC)
mean time: 19.176 ms (2.40% GC)
maximum time: 83.157 ms (74.30% GC)
--------------
samples: 261
evals/sample: 1
=#

#v1.0.11d Julia 1.5.1
#=
julia> @benchmark be = ReplicateBE.rbe!(df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol
= 1e-10)
BenchmarkTools.Trial:
memory estimate: 4.48 MiB
allocs estimate: 43228
--------------
minimum time: 17.604 ms (0.00% GC)
median time: 19.636 ms (0.00% GC)
mean time: 20.833 ms (2.70% GC)
maximum time: 47.499 ms (0.00% GC)
--------------
samples: 240
evals/sample: 1
=#

#=
julia> @benchmark be = ReplicateBE.rbe!($df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10) seconds = 25 samples = 200 evals = 5
BenchmarkTools.Trial:
memory estimate: 4.47 MiB
allocs estimate: 43136
--------------
minimum time: 17.257 ms (0.00% GC)
median time: 19.049 ms (0.00% GC)
mean time: 19.897 ms (3.34% GC)
maximum time: 29.502 ms (32.83% GC)
--------------
samples: 200
evals/sample: 5
=#

#=
julia> @benchmark be = ReplicateBE.rbe!($df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10) seconds = 25 samples = 200 evals = 5
BenchmarkTools.Trial:
memory estimate: 4.44 MiB
allocs estimate: 43179
--------------
minimum time: 16.638 ms (0.00% GC)
median time: 19.191 ms (0.00% GC)
mean time: 20.705 ms (2.86% GC)
maximum time: 48.517 ms (14.31% GC)
--------------
samples: 200
evals/sample: 5
=#

#initvar2
#=
julia> @benchmark be = ReplicateBE.rbe!($df6, dvar = :var, subject = :subject, formulation = :formulation, period = :period, sequence = :sequence, g_tol = 1e-10) seconds = 25 samples = 200 evals = 5
BenchmarkTools.Trial:
memory estimate: 4.97 MiB
allocs estimate: 48656
--------------
minimum time: 18.353 ms (0.00% GC)
median time: 21.240 ms (0.00% GC)
mean time: 22.810 ms (2.87% GC)
maximum time: 43.109 ms (10.80% GC)
--------------
samples: 200
evals/sample: 5
=#
2 changes: 1 addition & 1 deletion src/ReplicateBE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

module ReplicateBE

using DataFrames, Distributions, StatsModels, StatsBase, ForwardDiff, LinearAlgebra, Random, PDMats, Optim, LineSearches, CategoricalArrays, Printf, StaticArrays
using DataFrames, Distributions, StatsModels, StatsBase, ForwardDiff, LinearAlgebra, Random, Optim, LineSearches, CategoricalArrays, Printf, StaticArrays

export rbe, rbe!, reml2, nobs, coef, stderror, dof, coefnum, fixed, theta, typeiii, design, show, confint, contrast, estimate, optstat, randrbeds, randrbetask
import Base.show
Expand Down
79 changes: 52 additions & 27 deletions src/algebra.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
A' * B * A -> + θ (cache)
"""
function mulαtβαinc!(θ, A::AbstractMatrix, B::Matrix, c)
function mulαtβαinc!(θ, A::AbstractMatrix, B, c)
q = size(B, 1)
p = size(A, 2)
for i = 1:p
c .= 0
fill!(c, zero(eltype(θ)))
for n = 1:q
for m = 1:q
@inbounds c[n] += B[m, n] * A[m, i]
Expand All @@ -25,9 +25,9 @@ A' * B * A -> + θ
function mulαtβαinc!(θ, A::AbstractMatrix, B::AbstractMatrix)
q = size(B, 1)
p = size(A, 2)
c = zeros(eltype(B), q)
c = zeros(eltype(θ), q)
for i = 1:p
c .= 0
fill!(c, zero(eltype(θ)))
for n = 1:q
for m = 1:q
@inbounds c[n] += B[m, n] * A[m, i]
Expand All @@ -50,7 +50,7 @@ function mulθβinc!(θ, β, A::AbstractMatrix, B::AbstractMatrix, C::AbstractVe
q = size(B, 1)
p = size(A, 2)
for i = 1:p
c .= 0
fill!(c, zero(eltype(θ)))
for n = 1:q
for m = 1:q
@inbounds c[n] += B[m, n] * A[m, i]
Expand All @@ -69,11 +69,12 @@ end
"""
(y - X * β)' * V * (y - X * β) (cache)
"""
function mulθ₃(y::Vector, X::AbstractMatrix, β::Vector, V::AbstractMatrix, c)
function mulθ₃(y, X, β, V, c)
q = size(V, 1)
p = size(X, 2)
θ = 0
c .= 0
θ = zero(eltype(β))
#c .= 0
fill!(c, zero(eltype(β)))
for n = 1:q
for m = 1:p
@inbounds c[n] += X[n, m] * β[m]
Expand All @@ -90,54 +91,78 @@ end
"""
A * B * A' + C
"""
function mulαβαtc(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix)
function mulαβαtc(A, B, C)::Symmetric
q = size(B, 1)
p = size(A, 1)
c = zeros(eltype(B), q)
mx = zeros(eltype(B), p, p)
for i = 1:p
c .= 0
for n = 1:q
for m = 1:q
fill!(c, zero(eltype(c)))
@simd for n = 1:q
@simd for m = 1:q
@inbounds c[n] += A[i, m] * B[n, m]
end
end
for n = 1:p
for m = 1:q
@simd for n = i:p
@simd for m = 1:q
@inbounds mx[i, n] += A[n, m] * c[m]
end
@inbounds mx[i, n] += C[i, n]
end
end
mx .+= C
#Symmetric(mx)
#SMatrix{p,p}(mx)
#mx .+= C
Symmetric(mx)
end
"""
A * B * A' + C (cache)
"""
function mulαβαtc(A::AbstractMatrix, B::AbstractMatrix, C::AbstractMatrix, c::AbstractVector)
q = size(B, 1)
p = size(A, 1)
#c = mem.svec[p]
mx = zeros(eltype(B), p, p)
for i = 1:p
c .= 0
for n = 1:q
for m = 1:q
fill!(c, zero(eltype(c)))
@simd for n = 1:q
@simd for m = 1:q
@inbounds c[n] += A[i, m] * B[n, m]
end
end
for n = 1:p
for m = 1:q
@simd for n = i:p
@simd for m = 1:q
@inbounds mx[i, n] += A[n, m] * c[m]
end
@inbounds mx[i, n] += C[i, n]
end
end
mx .+= C
#SMatrix{p,p,eltype(mx)}(mx)

#mx .+= C
Symmetric(mx)
end
"""
A * B * A' + Diagonal(A*C) (cache)
"""
function mulαβαtc(A::AbstractMatrix, B::AbstractMatrix, C::AbstractVector, c::AbstractVector)::Symmetric
q = size(B, 1)
p = size(A, 1)
mx = zeros(eltype(B), p, p)
for i = 1:p
fill!(c, zero(eltype(c)))
@simd for n = 1:q
@simd for m = 1:q
@inbounds c[n] += A[i, m] * B[n, m]
end
end
@simd for n = i:p
@simd for m = 1:q
@inbounds mx[i, n] += A[n, m] * c[m]
end
end
@simd for m = 1:length(C)
@inbounds mx[i, i] += A[i, m] * C[m]
end
end
#mx
Symmetric(mx)
end

function invchol(M)
q = size(M, 1)
v = zeros(eltype(M), q, q)
Expand Down
4 changes: 0 additions & 4 deletions src/design.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ struct RBEDataStructure
mem::MemCache
end

function rebuildcache(data, type)
data.mem.svec[1] = zeros(type, data.maxobs)
end

struct RBEResults{T <: AbstractFloat}
reml::T # logREML
β::Vector{T} # β Vector
Expand Down
Loading

2 comments on commit 70f23ca

@PharmCat
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

v1.0.11

Optimizations
Cosmetics
PDMats exclude
Fix experimental sigmoid function
Add in initial variance estimate (OLS via QR decomposition) function

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/21396

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.11 -m "<description of version>" 70f23ca4f51f03bdca222ce64124f859e8fc0967
git push origin v1.0.11

Please sign in to comment.