Skip to content

PCA Whitening #182

Description

@wildart

Provide a separate implementation of PCA whitening similar to Whitening, and remove duplicated code:

function _invsqrtm!(C::AbstractMatrix{<:Real})
n = size(C, 1)
size(C, 2) == n || error("C must be a square matrix.")
E = eigen!(Symmetric(C))
U = E.vectors
evs = E.values
for i = 1:n
@inbounds evs[i] = 1.0 / sqrt(sqrt(evs[i]))
end
rmul!(U, Diagonal(evs))
return U * transpose(U)
end

Note: double sqrt application

C = rmul!(Z * transpose(Z), 1.0 / (n - 1))
Efac = eigen(C)
ord = sortperm(Efac.values; rev=true)
(v, P) = extract_kv(Efac, ord, k)
W0 = rmul!(P, Diagonal(1 ./ sqrt.(v)))
Z = W0'Z

function _lda_whitening!(C::AbstractMatrix{T}, regcoef::T) where T<:Real
n = size(C,1)
E = eigen!(Symmetric(C))
v = E.values
a = regcoef * maximum(v)
for i = 1:n
@inbounds v[i] = 1.0 / sqrt(v[i] + a)
end
return rmul!(E.vectors, Diagonal(v))
end

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions