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 #41

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
improve performance by removing a pow and branches
  • Loading branch information
tomhaber committed Mar 23, 2021
commit 86d899aca59cb9798817a075d18b756d6db9956a
16 changes: 6 additions & 10 deletions src/embeddings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ function optimize_embedding(graph::SparseMatrixCSC{T},
xj = view(ref_embedding, :, j)

sdist = evaluate(SqEuclidean(), xi, xj)
if sdist > 0
delta = (-2 * a * b * sdist^(b-1))/(1 + a*sdist^b)
else
delta = 0
end
sdist = max(sdist, eps())
delta = (-2 * a * b * sdist^b)/(sdist*(1 + a*sdist^b))

@simd for d in eachindex(xi)
grad = clamp(delta * (xi[d] - xj[d]), -4, 4)
xi[d] += alpha * grad
Expand All @@ -128,11 +126,9 @@ function optimize_embedding(graph::SparseMatrixCSC{T},
xk = view(ref_embedding, :, k)

sdist = evaluate(SqEuclidean(), xi, xk)
if sdist > 0
delta = (2 * gamma * b) / ((1//1000 + sdist)*(1 + a*sdist^b))
else
delta = 0
end
sdist = max(sdist, eps())
delta = (2 * gamma * b) / ((1//1000 + sdist)*(1 + a*sdist^b))

@simd for d in eachindex(xi)
if delta > 0
grad = clamp(delta * (xi[d] - xk[d]), -4, 4)
Expand Down