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

feat(dbscan1d): Support sample weight #11 #12

Merged
merged 1 commit into from
Aug 17, 2024

Conversation

lizeyan
Copy link
Contributor

@lizeyan lizeyan commented Aug 8, 2024

No description provided.

@lizeyan lizeyan force-pushed the master branch 2 times, most recently from 877530a to eb1dc5f Compare August 8, 2024 11:32
Copy link
Owner

@d-chambers d-chambers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @lizeyan, Thanks for the contribution! There is just one small issue with sorting the weights to make sure they apply to the correct samples then it should be good to go.

if sample_weight is None:
sample_weight = np.ones_like(ar, dtype=np.float64)
else:
sample_weight = np.asarray(sample_weight, dtype=np.float64)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when sample_weight is defined, it also needs to be sorted like the array, otherwise the weights might not be applied to the points the user intended.

I suggest replacing lines 102-13 with this:

sort_inds = np.argsort(ar)
ar_sorted = ar[sort_inds]
sample_weight_sorted = sample_weight[sort_inds]
undo_sort = np.argsort(sort_inds)

Then passing sample_weight_sorted to self_get_is_core in line 106.

Copy link
Contributor Author

@lizeyan lizeyan Aug 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I have fix it

@d-chambers
Copy link
Owner

Looks good, thanks @lizeyan

@d-chambers d-chambers merged commit 5057859 into d-chambers:master Aug 17, 2024
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

Successfully merging this pull request may close these issues.

2 participants