Skip to content

Commit

Permalink
minor changes, test, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Dec 18, 2024
1 parent dcb4fdd commit 82c7e4e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 11 deletions.
7 changes: 7 additions & 0 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ Metida.SpatialPowerD
Metida.ScaledWeightedCov
```

### Metida.ACOV

```@docs
Metida.ACOV
```


### Metida.dof_contain

```@docs
Expand Down
1 change: 1 addition & 0 deletions src/Metida.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SPPOW, SpatialPower,
SPGAU, SpatialGaussian, RawCoding,
UN, Unstructured,
CovarianceType,
ACOV,
fit, fit!, LMM, VarEffect, theta, logreml, m2logreml, m2logml, logml, thetalength, dof_satter, dof_contain, rankx, caic, lcontrast, typeiii, estimate, contrast,
gmatrix, rmatrix, vmatrix!, responsename, nblocks, raneff,
AbstractCovarianceType, AbstractCovmatMethod, MetidaModel,
Expand Down
54 changes: 46 additions & 8 deletions src/rmat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,31 +344,69 @@ function rmat!(mx, θ, rz::AbstractMatrix, ::UN_, ::Int)
end

# ACOV (AR)
function rmat!(mx, θ, ::AbstractMatrix, ::ACOV_{AR_}, ::Int)
function rmat!(mx::AbstractMatrix{T}, θ, ::AbstractMatrix, ct::ACOV_{AR_}, ::Int) where T
s = size(mx, 1)
ρ = θ[1]
if s > 1
for n = 2:s
mxnn = sqrt(mx[n, n])
mxnn = mx[n, n]
@inbounds @simd for m = 1:n-1
mxmm = sqrt(mx[m, m])
mx[m, n] += mxnn * mxmm * ρ ^ (n - m)
mxmm = mx[m, m]
mxmn = mx[m, n]
cov = sqrt(mxnn * mxmm) * ρ ^ (n - m)
if ct.a != 0
if ct.a == 1
mxmn = zero(T)
elseif ct.a == 2
cov = zero(T)
elseif ct.a == 3
@warn "covariance have existed value!"
elseif ct.a == 4
@warn "covariance have existed value! replaced..."
mxmn = zero(T)
elseif ct.a == 5
@warn "covariance have existed value! Save existed..."
cov = zero(T)

Check warning on line 369 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L358-L369

Added lines #L358 - L369 were not covered by tests
else
error("covariance have existed value!")

Check warning on line 371 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L371

Added line #L371 was not covered by tests
end
end
mx[m, n] = mxmn + cov
end

Check warning on line 375 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L375

Added line #L375 was not covered by tests
end
end
return mx
end

# ACOV (CS)
function rmat!(mx, θ, ::AbstractMatrix, ::ACOV_{CS_}, ::Int)
function rmat!(mx::AbstractMatrix{T}, θ, ::AbstractMatrix, ct::ACOV_{CS_}, ::Int) where T
s = size(mx, 1)
ρ = θ[1]
if s > 1
for n = 2:s
mxnn = sqrt(mx[n, n])
mxnn = mx[n, n]
@inbounds @simd for m = 1:n-1
mxmm = sqrt(mx[m, m])
mx[m, n] += mxnn * mxmm * ρ
mxmm = mx[m, m]
mxmn = mx[m, n]
cov = sqrt(mxnn * mxmm) * ρ
if ct.a != 0
if ct.a == 1
mxmn = zero(T)
elseif ct.a == 2
cov = zero(T)
elseif ct.a == 3
@warn "covariance have existed value!"
elseif ct.a == 4
@warn "covariance have existed value! replaced..."
mxmn = zero(T)
elseif ct.a == 5
@warn "covariance have existed value! Save existed..."
cov = zero(T)

Check warning on line 404 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L393-L404

Added lines #L393 - L404 were not covered by tests
else
error("covariance have existed value!")

Check warning on line 406 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L406

Added line #L406 was not covered by tests
end
end
mx[m, n] = mxmn + cov
end

Check warning on line 410 in src/rmat.jl

View check run for this annotation

Codecov / codecov/patch

src/rmat.jl#L410

Added line #L410 was not covered by tests
end
end
Expand Down
23 changes: 20 additions & 3 deletions src/vartypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,27 @@ const UN = Unstructured()


"""
ACOV(c)
ACOV(c, action = 0)
!!! warning
Experimental
Augmented (adjusted) covariance. Add additional correlations to existed R-part of variance covariance matrix.
Can be used with `AR` or `CS` types.
`action` if existed covariance not equal sero:
* 0 - add
* 1 - replace
* 2 - do nothing (use existed value)
* 3 - warning and add
* 4 - warning and replace
* 5 - warning and use existed value
* other - error
"""
function ACOV(c)
CovarianceType(ACOV_(c.s, 0))
function ACOV(c; action = 0)
CovarianceType(ACOV_(c.s, action))
end

function RZero()
Expand Down
3 changes: 3 additions & 0 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,9 @@ end
Metida.fit!(lmm2)
@test Metida.m2logreml(lmm1) Metida.m2logreml(lmm2)

io = IOBuffer();

@test_nowarn show(io, lmm2)
end


Expand Down

0 comments on commit 82c7e4e

Please sign in to comment.