-
Notifications
You must be signed in to change notification settings - Fork 23
feat: k-means algorithm #75
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
Conversation
packages/graph/src/utils.ts
Outdated
| let distance = 0; | ||
| switch (distanceType) { | ||
| case DistanceType.EuclideanDistance: | ||
| distance = new Vector(item).euclideanDistance(new Vector(otherItem)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉 new 两个 vector 有点浪费性能,还不如直接数值计算一下
packages/graph/src/k-means.ts
Outdated
| // When the number of nodes or the length of the attribute set is less than k, k will be adjusted to the smallest of them | ||
| const finalK = Math.min(k, nodes.length, allPropertiesWeightUniq.length); | ||
| for (let i = 0; i < nodes.length; i++) { | ||
| nodes[i].data.originIndex = i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在做了数据隔离,这种写到数据里面的方式不太好了,是不是可以另外存到一个 map 里面
packages/graph/src/k-means.ts
Outdated
| id: `${i}`, | ||
| nodes: [nodes[maxDistanceNodeIndex]] | ||
| }; | ||
| nodes[maxDistanceNodeIndex].data.clusterId = String(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,可以用一个 Map<ID, string> 存储这些信息,key 是节点 id, value 是聚类 id
|
感谢 PR ~ |
…nd return it from k-means func
Description
propertiesKeyis a param to detect whether the relevant property used in k-means is in nodes.dataproperty collects all of the properties of nodes,propertiesKeyparam have been removed in v5 algorithm.