Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of fastica #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/ica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ function fastica!(W::DenseMatrix{T}, # initialized component matrix, size (
# normalize each column
for j = 1:k
w = view(W,:,j)
rmul!(w, 1.0 / sqrt(sum(abs2, w)))
rmul!(w, one(T) / sqrt(sum(abs2, w)))
end

# main loop
chg = NaN
chg = T(NaN)
t = 0
converged = false
while !converged && t < maxiter
@inbounds while !converged && t < maxiter
t += 1
copyto!(Wp, W)

# apply W of previous step
mul!(U, transpose(X), W) # u <- w'x

# compute g(w'x) --> U and E{g'(w'x)} --> E1
_s = 0.0
_s = zero(T)
for j = 1:k
for i = 1:n
u, v = evaluate(fun, U[i,j])
Expand All @@ -105,14 +105,14 @@ function fastica!(W::DenseMatrix{T}, # initialized component matrix, size (
end

# compute E{x g(w'x)} --> Y
rmul!(mul!(Y, X, U), 1.0 / n)
rmul!(mul!(Y, X, U), one(T) / n)

# update w: E{x g(w'x)} - E{g'(w'x)} w := y - e1 * w
for j = 1:k
w = view(W,:,j)
y = view(Y,:,j)
e1 = E1[j]
for i = 1:m
@simd for i = 1:m
w[i] = y[i] - e1 * w[i]
end
end
Expand Down