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

Speedup when threshold < 1 #47

Open
SamGG opened this issue Oct 25, 2021 · 0 comments
Open

Speedup when threshold < 1 #47

SamGG opened this issue Oct 25, 2021 · 0 comments

Comments

@SamGG
Copy link
Contributor

SamGG commented Oct 25, 2021

Hi,
I read the following code and I am wondering about the following proposal.

FlowSOM/src/som.c

Lines 120 to 141 in 1e5650e

nearest = 0;
/* calculate distances in x and y spaces, and keep track of the
nearest code */
for (cd = 0; cd < ncodes; cd++) {
xdists[cd] = distf(&data[i], &codes[cd], px, n, ncodes);
if (xdists[cd] < xdists[nearest]) nearest = cd;
}
if (threshold < 1.0) threshold = 0.5;
alpha = alphas[0] - (alphas[0] - alphas[1]) * (double)k/(double)niter;
for (cd = 0; cd < ncodes; cd++) {
if(nhbrdist[cd + ncodes*nearest] > threshold) continue;
for(j = 0; j < px; j++) {
tmp = data[i + j*n] - codes[cd + j*ncodes];
change += fabs(tmp);
codes[cd + j*ncodes] += tmp * alpha;
}
}
threshold -= thresholdStep;

When threshold reaches 1, only the best matching unit is updated. The loop L131-L139 looking for the nearest units below the threshold is useless. Only the calculation of the inner loop L134-L138 is needed with cd being nearest. The code at L128 is a weird shortcut IMHO. With the default parameters (grid xdim = ydim = 10, radius is 6), the gain applies in the last 2 loops out of 10 (rlen = 10).
Let me know if there is something I misunderstood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant