Skip to content

Commit

Permalink
acov experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Nov 16, 2024
1 parent 4b71eb2 commit fc34d09
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/rmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,38 @@ function rmat!(mx, θ, rz::AbstractMatrix, ::UN_, ::Int)
mulαβαtinc!(mx, rz, rcov)
return mx
end

# ACOV (AR)
function rmat!(mx, θ, ::AbstractMatrix, ::ACOV_{AR_}, ::Int)
s = size(mx, 1)
ρ = θ[1]
if s > 1
for n = 2:s
mxnn = mx[n, n]
@inbounds @simd for m = 1:n-1
mxmm = mx[m, m]
mx[m, n] += mxnn * mxmm * ρ ^ (n - m)
end
end
end
return mx
end

# ACOV (CS)
function rmat!(mx, θ, ::AbstractMatrix, ::ACOV_{CS_}, ::Int)
s = size(mx, 1)
ρ = θ[1]
if s > 1
for n = 2:s
mxnn = mx[n, n]
@inbounds @simd for m = 1:n-1
mxmm = mx[m, m]
mx[m, n] += mxnn * mxmm * ρ
end
end
end
return mx
end
###############################################################################
###############################################################################
###############################################################################
Expand Down
3 changes: 3 additions & 0 deletions src/varstruct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ struct CovStructure{T, T2} <: AbstractCovarianceStructure
subjblockdict = sabjcrossdicts(subjblockdict, dicts[i])
end
end
if isa(repeated[1].covtype.s, ACOV_)
@warn "Using ACOV covariance additional effect at first position is meaningless."
end
else
subjblockdict = nothing
end
Expand Down
26 changes: 26 additions & 0 deletions src/vartypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct SPGAUD_ <: AbstractCovarianceType end
struct UN_ <: AbstractCovarianceType end
struct ZERO <: AbstractCovarianceType end

struct ACOV_{C <: AbstractCovarianceType} <: AbstractCovarianceType
c::C
a::Int
end

################################################################################
# COVARIANCE TYPE
################################################################################
Expand Down Expand Up @@ -399,10 +404,20 @@ function Unstructured()
end
const UN = Unstructured()


"""
ACOV(c)
"""
function ACOV(c)
CovarianceType(ACOV_(c.s, 0))
end

function RZero()
CovarianceType(ZERO(), false)
end

#######################################################################################

function covstrparam(ct::SI_, ::Int)::Tuple{Int, Int}
return (1, 0)
end
Expand Down Expand Up @@ -446,6 +461,10 @@ function covstrparam(ct::SPPOWD_, ::Int)::Tuple{Int, Int}
return (2, 1)
end

function covstrparam(ct::ACOV_{<:Union{CS_, AR_, SPPOW_}}, ::Int)::Tuple{Int, Int}
return (0, 1)
end

function covstrparam(ct::ZERO, ::Int)::Tuple{Int, Int}
return (0, 0)
end
Expand Down Expand Up @@ -555,6 +574,10 @@ function rcoefnames(s, t, ct::UN_)
return v
end

function rcoefnames(s, t, ct::ACOV_{<: Union{CS_, AR_}})
return ["ρ "]
end

function rcoefnames(s, t, ct::AbstractCovarianceType)
v = Vector{String}(undef, t)
v .= "Val "
Expand Down Expand Up @@ -643,6 +666,9 @@ end
function Base.show(io::IO, ct::UN_)
print(io, "UN")
end
function Base.show(io::IO, ct::ACOV_)
print(io, "ACOV(", ct.c, ")")
end
function Base.show(io::IO, ct::ZERO)
print(io, "No effect")
end

0 comments on commit fc34d09

Please sign in to comment.