Skip to content

Commit

Permalink
Px to Vx, Py to Vy
Browse files Browse the repository at this point in the history
  • Loading branch information
mlesnoff committed Jan 10, 2025
1 parent 08964a9 commit 1c99c10
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 69 deletions.
6 changes: 4 additions & 2 deletions docs/src/news.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# News

## *Version 0.7.1*

## *Version 0.8.0*

- Breaking
- Object 'P' in the code and outputs (matrix of laodings in Pca,
Pls etc.): renamed to 'V'.

## *Version 0.7.0*

Expand Down
8 changes: 4 additions & 4 deletions src/_structures_fun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ end
struct Ccawold
Tx::Matrix
Ty::Matrix
Px::Matrix
Py::Matrix
Vx::Matrix
Vy::Matrix
Rx::Matrix
Ry::Matrix
Wx::Matrix
Expand All @@ -207,8 +207,8 @@ end
struct Plscan
Tx::Matrix
Ty::Matrix
Px::Matrix
Py::Matrix
Vx::Matrix
Vy::Matrix
Rx::Matrix
Ry::Matrix
Wx::Matrix
Expand Down
34 changes: 17 additions & 17 deletions src/ccawold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ function ccawold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
Ty = copy(Tx)
Wx = similar(X, p, nlv)
Wy = similar(X, q, nlv)
Px = copy(Wx)
Py = copy(Wy)
Vx = copy(Wx)
Vy = copy(Wy)
TTx = similar(X, nlv)
TTy = copy(TTx)
tx = similar(X, n)
Expand All @@ -162,8 +162,8 @@ function ccawold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
wxtild = copy(wx)
wy = similar(X, q)
wytild = copy(wy)
px = copy(wx)
py = copy(wy)
vx = copy(wx)
vy = copy(wy)
niter = zeros(nlv)
# End
@inbounds for a = 1:nlv
Expand Down Expand Up @@ -205,13 +205,13 @@ function ccawold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
end
end
niter[a] = iter - 1
mul!(px, X', tx)
px ./= ttx
mul!(py, Y', ty)
py ./= tty
mul!(vx, X', tx)
vx ./= ttx
mul!(vy, Y', ty)
vy ./= tty
# Deflation
X .-= tx * px'
Y .-= ty * py'
X .-= tx * vx'
Y .-= ty * vy'
# Same as:
#b = tx' * X / ttx
#X .-= tx * b
Expand All @@ -222,16 +222,16 @@ function ccawold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
Ty[:, a] .= ty
Wx[:, a] .= wx
Wy[:, a] .= wy
Px[:, a] .= px
Py[:, a] .= py
Vx[:, a] .= vx
Vy[:, a] .= vy
TTx[a] = ttx
TTy[a] = tty
end
Tx .= (1 ./ sqrtw) .* Tx
Ty .= (1 ./ sqrtw) .* Ty
Rx = Wx * inv(Px' * Wx)
Ry = Wy * inv(Py' * Wy)
Ccawold(Tx, Ty, Px, Py, Rx, Ry, Wx, Wy, TTx, TTy, bscales, xmeans, xscales,
Rx = Wx * inv(Vx' * Wx)
Ry = Wy * inv(Vy' * Wy)
Ccawold(Tx, Ty, Vx, Vy, Rx, Ry, Wx, Wy, TTx, TTy, bscales, xmeans, xscales,
ymeans, yscales, weights, niter, par)
end

Expand Down Expand Up @@ -271,7 +271,7 @@ function Base.summary(object::Ccawold, X, Y)
# X
tt = object.TTx
sstot = frob(X, object.weights)^2
tt_adj = colsum(object.Px.^2) .* tt
tt_adj = colsum(object.Vx.^2) .* tt
pvar = tt_adj / sstot
cumpvar = cumsum(pvar)
xvar = tt_adj / n
Expand All @@ -280,7 +280,7 @@ function Base.summary(object::Ccawold, X, Y)
# Y
tt = object.TTy
sstot = frob(Y, object.weights)^2
tt_adj = colsum(object.Py.^2) .* tt
tt_adj = colsum(object.Vy.^2) .* tt
pvar = tt_adj / sstot
cumpvar = cumsum(pvar)
xvar = tt_adj / n
Expand Down
8 changes: 4 additions & 4 deletions src/comdim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ function comdim!(Xbl::Vector, weights::Weight; kwargs...)
@inbounds for k = 1:nbl
Xbl[k] .-= u * (u' * Xbl[k])
# Same as:
#Px = sqrt(lb[k, a]) * Wbl[k][:, a]'
#Xbl[k] .-= u * Px
#Vx = sqrt(lb[k, a]) * Wbl[k][:, a]'
#Xbl[k] .-= u * Vx
end
end
T = Diagonal(1 ./ sqrtw) * (sqrt.(mu)' .* U)
Expand Down Expand Up @@ -254,8 +254,8 @@ function transf_all(object::Comdim, Xbl; nlv = nothing)
u .= 1 / sqrt(object.mu[a]) * TB * object.W[:, a]
U[:, a] .= u
@inbounds for k = 1:nbl
Px = sqrt(object.lb[k, a]) * object.Wbl[k][:, a]'
zXbl[k] .-= u * Px
Vx = sqrt(object.lb[k, a]) * object.Wbl[k][:, a]'
zXbl[k] .-= u * Vx
end
end
T = sqrt.(object.mu[1:nlv])' .* U
Expand Down
4 changes: 2 additions & 2 deletions src/mbpca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ function transf_all(object::Mbpca, Xbl; nlv = nothing)
u .= 1 / sqrt(object.mu[a]) * TB * object.W[:, a]
U[:, a] .= u
@inbounds for k = 1:nbl
Px = sqrt(object.lb[k, a]) * object.Wbl[k][:, a]'
zXbl[k] -= u * Px
Vx = sqrt(object.lb[k, a]) * object.Wbl[k][:, a]'
zXbl[k] -= u * Vx
end
end
T = sqrt.(object.mu[1:nlv])' .* U
Expand Down
14 changes: 7 additions & 7 deletions src/mbplswest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ function mbplswest!(Xbl::Vector, Y::Matrix, weights::Weight; kwargs...)
Tx = similar(Xbl[1], n, nlv)
Wx = similar(Xbl[1], sum(p), nlv)
Wytild = similar(Xbl[1], q, nlv)
Px = copy(Wx)
Vx = copy(Wx)
tk = similar(Xbl[1], n)
tx = copy(tk)
ty = copy(tk)
wx = similar(Xbl[1], sum(p))
px = copy(wx)
vx = copy(wx)
wy = similar(Xbl[1], q)
wytild = copy(wy)
TTx = similar(Xbl[1], nlv)
Expand Down Expand Up @@ -178,13 +178,13 @@ function mbplswest!(Xbl::Vector, Y::Matrix, weights::Weight; kwargs...)
X .= reduce(hcat, Xbl)
wx .= X' * ty / dot(ty, ty)
wx ./= normv(wx)
mul!(px, X', tx)
px ./= ttx
mul!(vx, X', tx)
vx ./= ttx
wytild .= Y' * tx / ttx
# End
Tx[:, a] .= tx
Wx[:, a] .= wx
Px[:, a] .= px
Vx[:, a] .= vx
Wytild[:, a] .= wytild
TTx[a] = ttx
@inbounds for k = 1:nbl
Expand All @@ -193,9 +193,9 @@ function mbplswest!(Xbl::Vector, Y::Matrix, weights::Weight; kwargs...)
Y .-= tx * wytild'
end
Tx .= (1 ./ sqrtw) .* Tx
Rx = Wx * inv(Px' * Wx)
Rx = Wx * inv(Vx' * Wx)
lb = nothing
Mbplswest(Tx, Px, Rx, Wx, Wytild, Tbl, Tb, Pbl, TTx, fitmbl, ymeans, yscales,
Mbplswest(Tx, Vx, Rx, Wx, Wytild, Tbl, Tb, Pbl, TTx, fitmbl, ymeans, yscales,
weights, lb, niter, par)
end

Expand Down
34 changes: 17 additions & 17 deletions src/plscan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function plscan!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
Ty = copy(Tx)
Wx = similar(X, p, nlv)
Wy = similar(X, q, nlv)
Px = copy(Wx)
Py = copy(Wy)
Vx = copy(Wx)
Vy = copy(Wy)
TTx = similar(X, nlv)
TTy = copy(TTx)
tx = similar(X, n)
Expand All @@ -131,8 +131,8 @@ function plscan!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
dty = copy(tx)
wx = similar(X, p)
wy = similar(X, q)
px = copy(wx)
py = copy(wy)
vx = copy(wx)
vy = copy(wy)
delta = copy(TTx)
# End
@inbounds for a = 1:nlv
Expand All @@ -144,8 +144,8 @@ function plscan!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
mul!(tx, X, wx)
dtx .= weights.w .* tx
ttx = dot(tx, dtx)
mul!(px, X', dtx)
px ./= ttx
mul!(vx, X', dtx)
vx ./= ttx
# Y
wy .= V[:, 1]
# Same as:
Expand All @@ -155,24 +155,24 @@ function plscan!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
mul!(ty, Y, wy)
dty .= weights.w .* ty
tty = dot(ty, dty)
mul!(py, Y', dty)
py ./= tty
mul!(vy, Y', dty)
vy ./= tty
# Deflation
X .-= tx * px'
Y .-= ty * py'
X .-= tx * vx'
Y .-= ty * vy'
# End
Px[:, a] .= px
Py[:, a] .= py
Vx[:, a] .= vx
Vy[:, a] .= vy
Tx[:, a] .= tx
Ty[:, a] .= ty
Wx[:, a] .= wx
Wy[:, a] .= wy
TTx[a] = ttx
TTy[a] = tty
end
Rx = Wx * inv(Px' * Wx)
Ry = Wy * inv(Py' * Wy)
Plscan(Tx, Ty, Px, Py, Rx, Ry, Wx, Wy, TTx, TTy, delta, bscales, xmeans, xscales,
Rx = Wx * inv(Vx' * Wx)
Ry = Wy * inv(Vy' * Wy)
Plscan(Tx, Ty, Vx, Vy, Rx, Ry, Wx, Wy, TTx, TTy, delta, bscales, xmeans, xscales,
ymeans, yscales, weights, par)
end

Expand Down Expand Up @@ -213,14 +213,14 @@ function Base.summary(object::Plscan, X, Y)
tty = object.TTy
## X
sstot = frob(X, object.weights)^2
tt_adj = colsum(object.Px.^2) .* ttx
tt_adj = colsum(object.Vx.^2) .* ttx
pvar = tt_adj / sstot
cumpvar = cumsum(pvar)
xvar = tt_adj / n
explvarx = DataFrame(nlv = 1:nlv, var = xvar, pvar = pvar, cumpvar = cumpvar)
## Y
sstot = frob(Y, object.weights)^2
tt_adj = colsum(object.Py.^2) .* tty
tt_adj = colsum(object.Vy.^2) .* tty
pvar = tt_adj / sstot
cumpvar = cumsum(pvar)
xvar = tt_adj / n
Expand Down
16 changes: 8 additions & 8 deletions src/plswold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ function plswold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
Tx = similar(X, n, nlv)
Wx = similar(X, p, nlv)
Wytild = similar(X, q, nlv)
Px = copy(Wx)
Vx = copy(Wx)
TTx = similar(X, nlv)
tx = similar(X, n)
ty = copy(tx)
wx = similar(X, p)
wy = similar(X, q)
wytild = copy(wy)
px = copy(wx)
vx = copy(wx)
niter = zeros(nlv)
# End
@inbounds for a = 1:nlv
Expand All @@ -100,19 +100,19 @@ function plswold!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
end
niter[a] = iter - 1
ttx = dot(tx, tx)
mul!(px, X', tx)
px ./= ttx
mul!(vx, X', tx)
vx ./= ttx
# Deflation
X .-= tx * px'
X .-= tx * vx'
Y .-= tx * wytild'
# End
Tx[:, a] .= tx
Wx[:, a] .= wx
Px[:, a] .= px
Vx[:, a] .= vx
Wytild[:, a] .= wytild
TTx[a] = ttx
end
fweight!(Tx, 1 ./ sqrtw)
Rx = Wx * inv(Px' * Wx)
Plsr(Tx, Px, Rx, Wx, Wytild, TTx, xmeans, xscales, ymeans, yscales, weights, niter, par)
Rx = Wx * inv(Vx' * Wx)
Plsr(Tx, Vx, Rx, Wx, Wytild, TTx, xmeans, xscales, ymeans, yscales, weights, niter, par)
end
16 changes: 8 additions & 8 deletions src/rrr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function rrr!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
Wx = similar(X, p, nlv)
Wy = similar(X, q, nlv)
Wytild = copy(Wy)
Px = similar(X, p, nlv)
Vx = similar(X, p, nlv)
Cx = similar(X, p, p)
invCx = copy(Cx)
Ix = Diagonal(ones(Q, p))
Expand All @@ -135,7 +135,7 @@ function rrr!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
wx = similar(X, p)
wy = similar(X, q)
wytild = copy(wy)
px = similar(X, p)
vx = similar(X, p)
lambda = copy(TTx)
covtot = copy(TTx)
niter = Int.(ones(nlv))
Expand Down Expand Up @@ -171,27 +171,27 @@ function rrr!(X::Matrix, Y::Matrix, weights::Weight; kwargs...)
lambda[a] = ty' * X * invCx * X' * ty
covtot[a] = tr(Y' * X * invCx * X' * Y)
ttx = dot(tx, tx)
mul!(px, X', tx)
px ./= ttx
mul!(vx, X', tx)
vx ./= ttx
mul!(wytild, Y', tx)
wytild ./= ttx
# For Rx
tty = dot(ty, ty)
wx .= invCx * X' * ty / tty
wx .= wx / normv(wx)
# Deflation
X .-= tx * px'
X .-= tx * vx'
Y .-= tx * wytild'
# End
Tx[:, a] .= tx
Px[:, a] .= px
Vx[:, a] .= vx
Wx[:, a] .= wx
Wytild[:, a] .= wytild
TTx[a] = ttx
end
Rx = Wx * inv(Px' * Wx)
Rx = Wx * inv(Vx' * Wx)
Tx .= (1 ./ sqrtw) .* Tx
Plsr(Tx, Px, Rx, Wx, Wytild, TTx, xmeans, xscales, ymeans, yscales, weights, niter, par)
Plsr(Tx, Vx, Rx, Wx, Wytild, TTx, xmeans, xscales, ymeans, yscales, weights, niter, par)
end


0 comments on commit 1c99c10

Please sign in to comment.