2323- `lb`: lower bounds for `vec(B)`
2424- `ub`: upper bounds for `vec(B)`
2525"""
26- type VarianceComponentModel{T <: AbstractFloat , M,
26+ mutable struct VarianceComponentModel{T <: AbstractFloat , M,
2727 BT <: AbstractVecOrMat , ΣT <: AbstractMatrix }
2828 # model parameters
2929 B:: BT
@@ -34,12 +34,6 @@ type VarianceComponentModel{T <: AbstractFloat, M,
3434 b:: Union{T, Vector{T}}
3535 lb:: Union{T, Vector{T}}
3636 ub:: Union{T, Vector{T}}
37- # inner constructor
38- function VarianceComponentModel (B:: AbstractVecOrMat{T} ,
39- Σ:: NTuple{M, AbstractMatrix{T}} , A:: Matrix{T} , sense:: Union{Char, Vector{Char}} ,
40- b:: Union{T, Vector{T}} , lb:: Union{T, Vector{T}} , ub:: Union{T, Vector{T}} )
41- new (B, Σ, A, sense, b, lb, ub)
42- end
4337end
4438
4539"""
4842
4943Default constructor of [`VarianceComponentModel`](@ref) type.
5044"""
51- function VarianceComponentModel {M} (
45+ function VarianceComponentModel (
5246 B:: AbstractVecOrMat ,
5347 Σ:: NTuple{M, AbstractMatrix} ,
5448 A:: Matrix = zeros (eltype (B), 0 , length (B)),
5549 sense:: Union{Char, Vector{Char}} = Array {Char} (0 ),
5650 b:: Union{Number, Vector} = zeros (eltype (B), 0 ),
5751 lb:: Union{Number, Vector} = convert (eltype (B), - Inf ),
5852 ub:: Union{Number, Vector} = convert (eltype (B), Inf ),
59- )
53+ ) where {M}
6054
6155 VarianceComponentModel {eltype(B), M, typeof(B), eltype(Σ)} (B, Σ, A, sense, b,
6256 lb, ub)
6761
6862Construct [`VarianceComponentModel`](@ref) from `Σ` alone. `B` is treated empty.
6963"""
70- function VarianceComponentModel {M} (Σ:: NTuple{M, AbstractMatrix} )
64+ function VarianceComponentModel (Σ:: NTuple{M, AbstractMatrix} ) where {M}
7165 B = zeros (eltype (Σ[1 ]), 0 , size (Σ[1 ], 1 ))
7266 VarianceComponentModel (B, Σ)
7367end
8175- `eigvec`: eigenvectors of `eig(Σ[1], Σ[2])`
8276- `logdetΣ2`: log-determinant of `Σ[2]`
8377"""
84- immutable TwoVarCompModelRotate{T <: AbstractFloat , BT <: AbstractVecOrMat }
78+ struct TwoVarCompModelRotate{T <: AbstractFloat , BT <: AbstractVecOrMat }
8579 Brot:: BT
8680 eigval:: Vector{T}
8781 eigvec:: Matrix{T}
8882 logdetΣ2:: T
89- function TwoVarCompModelRotate (Brot:: AbstractVecOrMat{T} ,
90- eigval:: Vector{T} , eigvec:: Matrix{T} , logdetΣ2:: T )
91- new (Brot, eigval, eigvec, logdetΣ2)
92- end
9383end
9484
9585"""
@@ -137,17 +127,12 @@ model.
137127- `X`: `n x p` predictors
138128- `V`: tuple of `n x n` covariance matrices
139129"""
140- type VarianceComponentVariate{T <: AbstractFloat , M,
130+ mutable struct VarianceComponentVariate{T <: AbstractFloat , M,
141131 YT <: AbstractVecOrMat , XT <: AbstractVecOrMat , VT <: AbstractMatrix }
142132 # data
143133 Y:: YT
144134 X:: XT
145135 V:: NTuple{M, VT}
146- # inner constructor
147- function VarianceComponentVariate (Y:: AbstractVecOrMat{T} ,
148- X:: AbstractVecOrMat{T} , V:: NTuple{M, AbstractMatrix{T}} )
149- new (Y, X, V)
150- end
151136end
152137
153138"""
@@ -189,20 +174,14 @@ end
189174- `eigvec`: eigenvectors of `eig(V[1], V[2])`
190175- `logdetV2`: log-determinant of `V[2]`
191176"""
192- immutable TwoVarCompVariateRotate{T <: AbstractFloat , YT <: AbstractVecOrMat ,
177+ struct TwoVarCompVariateRotate{T <: AbstractFloat , YT <: AbstractVecOrMat ,
193178 XT <: AbstractVecOrMat }
194179 # data
195180 Yrot:: YT
196181 Xrot:: XT
197182 eigval:: Vector{T}
198183 eigvec:: Matrix{T}
199184 logdetV2:: T
200-
201- # inner constructor
202- function TwoVarCompVariateRotate (Yrot:: AbstractVecOrMat{T} ,
203- Xrot:: AbstractVecOrMat{T} , eigval:: Vector{T} , eigvec:: Matrix{T} , logdetV2:: T )
204- new (Yrot, Xrot, eigval, eigvec, logdetV2)
205- end
206185end
207186
208187"""
@@ -268,7 +247,7 @@ Construct a [`VarianceComponentModel`](@ref) instance from a [`VarianceComponent
268247instance. `B` is initialized to zero; `Σ` is initialized to a tupe of identity
269248matrices.
270249"""
271- function VarianceComponentModel {T, M} (vcobs:: VarianceComponentVariate{T, M} )
250+ function VarianceComponentModel (vcobs:: VarianceComponentVariate{T, M} ) where {T, M}
272251
273252 p, d, m = size (vcobs. X, 2 ), size (vcobs. Y, 2 ), length (vcobs. V)
274253 B = zeros (T, p, d)
295274Auxillary data for variance component model. This can be used as pre-allocated
296275intermediate variable in iterative algorithm.
297276"""
298- immutable VarianceComponentAuxData{
277+ struct VarianceComponentAuxData{
299278 T1 <: AbstractMatrix ,
300279 T2 <: AbstractVector
301280 }
@@ -485,10 +464,10 @@ function residual(vcm::VarianceComponentModel, vcobs::VarianceComponentVariate)
485464 return isempty (vcobs. X)? vcobs. Y : vcobs. Y - vcobs. X * vcm. B
486465end
487466
488- function residual {T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate} (
467+ function residual (
489468 vcm:: T1 ,
490469 vcdata:: Array{T2}
491- )
470+ ) where {T1 <: VarianceComponentModel , T2 <: VarianceComponentVariate }
492471
493472 map (x -> residual (vcm, x), vcdata)
494473end
@@ -509,11 +488,11 @@ function residual!(
509488 resid
510489end
511490
512- function residual! {T1 <: VarianceComponentModel, T2 <: VarianceComponentVariate} (
491+ function residual! (
513492 resid:: AbstractArray ,
514493 vcm:: T1 ,
515494 vcdata:: Array{T2}
516- )
495+ ) where {T1 <: VarianceComponentModel , T2 <: VarianceComponentVariate }
517496
518497 map (x -> residual! (x[1 ], vcm, x[2 ]), zip (resid, vcdata))
519498end
@@ -531,10 +510,10 @@ function residual(vcmrot::TwoVarCompModelRotate, vcobsrot::TwoVarCompVariateRota
531510 end
532511end
533512
534- function residual {T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate} (
513+ function residual (
535514 vcmrot:: T1 ,
536515 vcdatarot:: Array{T2}
537- )
516+ ) where {T1 <: TwoVarCompModelRotate , T2 <: TwoVarCompVariateRotate }
538517
539518 map (x -> residual (vcmrot, x), vcdatarot)
540519end
@@ -556,10 +535,10 @@ function residual!(
556535 resid
557536end
558537
559- function residual! {T1 <: TwoVarCompModelRotate, T2 <: TwoVarCompVariateRotate} (
538+ function residual! (
560539 resid:: Array{AbstractMatrix} ,
561540 vcmrot:: T1 ,
562- vcdatarot:: Array{T2} )
541+ vcdatarot:: Array{T2} ) where {T1 <: TwoVarCompModelRotate , T2 <: TwoVarCompVariateRotate }
563542
564543 map! (x -> residual (vcmrot, x), resid, vcdatarot)
565544end
0 commit comments