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

Add an id to clusters created by hcluster #17

Open
jdfekete opened this issue May 5, 2015 · 2 comments
Open

Add an id to clusters created by hcluster #17

jdfekete opened this issue May 5, 2015 · 2 comments

Comments

@jdfekete
Copy link

jdfekete commented May 5, 2015

I think there is currently no way to relate the nodes/clusters created by the hcluster function to rows in the vector passed to the hcluster function once the clustering is computed.
Adding an attribute "id" or "index" to the clusters created would allow to link them back to their related vector indices.
It adds 3 lined to the code, initializing a variable id=0 and, e.g. line 59:
id: id++,
line 86:
id: id++,

leaf clusters would have an id < vectors.length, the others would be interior nodes.

@jasondavies
Copy link
Owner

I agree this could be made more intuitive, but you can currently retrieve the original vector objects via the centroid property of leaf nodes. So for a given node, you can traverse any children to until you reach the leaves to obtain the vector objects. Example code:

function traverse(node, vectors) {
  if (node.left || tree.right) {
    if (node.left) traverse(node.left, vectors);
    if (node.right) traverse(node.right, vectors);
  } else vectors.push(node.centroid);
}

@jdfekete
Copy link
Author

jdfekete commented May 6, 2015

Almost, but not completely. You have the value extracted at index "i" from the vectors parameter but not the index itself. You still have to chase for the index in the vectors argument then.

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

2 participants