Skip to content

Commit

Permalink
v0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Mar 25, 2021
1 parent b43dae1 commit ce91dc0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Metida"
uuid = "a1dec852-9fe5-11e9-361f-8d9fde67cfa2"
authors = ["Vladimir Arnautov <[email protected]>"]
version = "0.8.0"
version = "0.9.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand Down
4 changes: 4 additions & 0 deletions change.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v0.9.0
* remove redundant code
* change in nlopt solver keyword handling

v0.8.0
* BLAS syrk REML keyword
* documentation fix
Expand Down
6 changes: 2 additions & 4 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ function fit!(lmm::LMM{T};
if lmm.result.fit lmmlog!(io, lmm, verbose, LMMLogMsg(:INFO, "Refit model...")) end
lmm.result.fit = false

if solver == :nlopt
return fit_nlopt!(lmm; solver = :nlopt, verbose = verbose, varlinkf = varlinkf, rholinkf = rholinkf, aifirst = aifirst, g_tol = g_tol, x_tol = x_tol, f_tol = f_tol, hes = false, init = init, io = io)
elseif solver == :cuda
return fit_nlopt!(lmm; solver = :cuda, verbose = verbose, varlinkf = varlinkf, rholinkf = rholinkf, aifirst = aifirst, g_tol = g_tol, x_tol = x_tol, f_tol = f_tol, hes = false, init = init, io = io)
if solver != :default
return fit_nlopt!(lmm; solver = solver, verbose = verbose, varlinkf = varlinkf, rholinkf = rholinkf, aifirst = aifirst, g_tol = g_tol, x_tol = x_tol, f_tol = f_tol, hes = false, init = init, io = io)
end

if verbose == :auto
Expand Down
2 changes: 1 addition & 1 deletion src/lmm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function Base.show(io::IO, lmm::LMM)
continue
end
println(io, " Model: $(lmm.covstr.random[i].model === nothing ? "nothing" : string(lmm.covstr.random[i].model, "|", lmm.covstr.random[i].subj))")
println(io, " Type: $(lmm.covstr.random[i].covtype.s) ($(lmm.covstr.t[i])), Subjects: $(length(lmm.covstr.block[i]))")
println(io, " Type: $(lmm.covstr.random[i].covtype.s) ($(lmm.covstr.t[i])), Subjects: $(lmm.covstr.sn[i])")
#println(io, " Coefnames: $(coefnames(lmm.covstr.schema[i]))")
end
println(io, "Repeated: ")
Expand Down
52 changes: 14 additions & 38 deletions src/varstruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,6 @@ struct CovStructure{T} <: AbstractCovarianceStructure
repeated::VarEffect
schema::Vector{Union{Tuple, AbstractTerm}}
rcnames::Vector{String}
# subject (local) blocks for each effect
block::Vector{Vector{Vector{UInt32}}}
# blocks for vcov matrix / variance blocking factor (subject)
vcovblock::Vector{Vector{UInt32}}
# number of random effect
Expand Down Expand Up @@ -436,7 +434,6 @@ struct CovStructure{T} <: AbstractCovarianceStructure
t = Vector{Int}(undef, alleffl)
tr = Vector{UnitRange{Int}}(undef, alleffl)
schema = Vector{Union{AbstractTerm, Tuple}}(undef, alleffl)
block = Vector{Vector{Vector{UInt32}}}(undef, alleffl)
z = Matrix{Float64}(undef, size(data, 1), 0)
subjz = Vector{BitMatrix}(undef, alleffl)
zrndur = Vector{UnitRange{Int}}(undef, alleffl - 1)
Expand All @@ -449,12 +446,12 @@ struct CovStructure{T} <: AbstractCovarianceStructure
#
sn = zeros(Int, alleffl)
if rn > 1
for i = 2:rn
@inbounds for i = 2:rn
if random[i].covtype.s == :ZERO error("One of the random effect have zero type!") end
end
end
# RANDOM EFFECTS
for i = 1:rn
@inbounds for i = 1:rn
if length(random[i].coding) == 0
fill_coding_dict!(random[i].model, random[i].coding, data)
end
Expand All @@ -467,9 +464,8 @@ struct CovStructure{T} <: AbstractCovarianceStructure
fillur!(zrndur, i, q)
fillur!(tr, i, t)

subjz[i] = modelcols(MatrixTerm(apply_schema(random[i].subj, StatsModels.schema(data, fulldummycodingdict(random[i].subj)))), data)
block[i] = makeblocks(subjz[i])

subjz[i] = convert(BitMatrix, modelcols(MatrixTerm(apply_schema(random[i].subj, StatsModels.schema(data, fulldummycodingdict(random[i].subj)))), data))
sn[i] = size(subjz[i], 2)
updatenametype!(ct, rcnames, csp, schema[i], random[i].covtype.s)
end
# REPEATED EFFECTS
Expand All @@ -480,9 +476,8 @@ struct CovStructure{T} <: AbstractCovarianceStructure
schema[end] = apply_schema(repeated.model, StatsModels.schema(data, repeated.coding))
rz = modelcols(MatrixTerm(schema[end]), data)

subjz[end] = modelcols(MatrixTerm(apply_schema(repeated.subj, StatsModels.schema(data, fulldummycodingdict(repeated.subj)))), data)
block[end] = makeblocks(subjz[end])

subjz[end] = convert(BitMatrix, modelcols(MatrixTerm(apply_schema(repeated.subj, StatsModels.schema(data, fulldummycodingdict(repeated.subj)))), data))
sn[end] = size(subjz[end], 2)
q[end] = size(rz, 2)
csp = covstrparam(repeated.covtype, q[end], repeated.p)
t[end] = csp[1] + csp[2]
Expand All @@ -507,15 +502,13 @@ struct CovStructure{T} <: AbstractCovarianceStructure
blocks = makeblocks(subjblockmat) #vcovblock
sblock = Vector{Vector{Vector{Vector{UInt32}}}}(undef, length(blocks))
########################################################################
for i = 1:length(blocks)
@inbounds for i = 1:length(blocks)
sblock[i] = Vector{Vector{Vector{UInt32}}}(undef, alleffl)
for s = 1:alleffl
@inbounds for s = 1:alleffl
sblock[i][s] = Vector{Vector{UInt32}}(undef, 0)
for col in eachcol(view(subjz[s], blocks[i], :))
#if any(col) push!(sblock[i][s], sort!(findall(x->x==true, col))) end
if any(col) push!(sblock[i][s], findall(x->x==true, col)) end
@inbounds for col in eachcol(view(subjz[s], blocks[i], :))
if any(col) push!(sblock[i][s], findall(col)) end
end
sn[s] += length(sblock[i][s])
end
end
#
Expand All @@ -524,7 +517,7 @@ struct CovStructure{T} <: AbstractCovarianceStructure
lvcb = length(i)
if lvcb > maxn maxn = lvcb end
end
new{eltype(z)}(random, repeated, schema, rcnames, block, blocks, rn, z, sblock, zrndur, rz, q, t, tr, tl, ct, sn, maxn)
new{eltype(z)}(random, repeated, schema, rcnames, blocks, rn, z, sblock, zrndur, rz, q, t, tr, tl, ct, sn, maxn)
end
end
################################################################################
Expand Down Expand Up @@ -597,23 +590,6 @@ function rcoefnames(s, t, ve)
return v
end
end

#=
function subjmatrix!(subj, data, subjz, i)
if length(subj) > 0
if length(subj) == 1
subjterm = Term(subj[1])
else
subjterm = InteractionTerm(Tuple(Term.(subj)))
end
subjdict = Dict{Symbol, AbstractContrasts}()
fill_coding_dict!(subjterm, subjdict, data)
subjz[i] = BitArray(modelcols(apply_schema(subjterm, StatsModels.schema(data, subjdict)), data))
else
subjz[i] = trues(size(data, 1),1)
end
end
=#
################################################################################
function makeblocks(subjz)
blocks = Vector{Vector{UInt32}}(undef, 0)
Expand All @@ -624,9 +600,10 @@ function makeblocks(subjz)
blocks
end
################################################################################
function noncrossmodelmatrix(mx::AbstractArray{T}, my::AbstractArray{T}) where T
function noncrossmodelmatrix(mx::AbstractArray, my::AbstractArray)
size(mx, 2) > size(my, 2) ? (mat = mx' * my; a = mx) : (mat = my' * mx; a = my)
#mat = mat * mat'
T = eltype(mat)
@inbounds for n = 1:size(mat, 2)-1
fr = findfirst(x->!iszero(x), view(mat, n, :))
if !isnothing(fr)
Expand Down Expand Up @@ -654,8 +631,7 @@ function noncrossmodelmatrix(mx::AbstractArray{T}, my::AbstractArray{T}) where T
end
end
res = replace(x -> iszero(x) ? 0 : 1, view(mat, :, cols))
result = a * res
result
a * res
end
################################################################################
# CONTRAST CODING
Expand Down

2 comments on commit ce91dc0

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release notes:

v0.9.0

  • remove redundant code
  • change in nlopt solver keyword handling

@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/32835

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 v0.9.0 -m "<description of version>" ce91dc07649a4ea2c509680ea11f301ffd30a0e1
git push origin v0.9.0

Please sign in to comment.