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

[ml] Fix un-initialized centroids bug (k-means) #4570

Merged
merged 2 commits into from
Jan 26, 2021

Conversation

Yuki992411
Copy link
Contributor

I added a function that initializes centroids in kmeans.

@mvieth
Copy link
Member

mvieth commented Jan 11, 2021

How about putting the for-loop inside computeCentroids, at line 98? That would in my opinion make logically the most sense: set centroids to zero - sum up points - divide by number of points. Otherwise the function computeCentroids would still have the requirement that the centroids are initialized to zero before calling the function.

@mvieth mvieth added changelog: fix Meta-information for changelog generation module: ml needs: code review Specify why not closed/merged yet labels Jan 11, 2021
@Yuki992411
Copy link
Contributor Author

Thank you for your feedback.
Oh, I missed it. It's more natural to add initialization at line 98.
I made a code with low maintainability because I tried to reduce the number of initializations.
As you pointed out, I will correct it.

Copy link
Member

@mvieth mvieth left a comment

Choose a reason for hiding this comment

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

Thanks!

@mvieth mvieth requested a review from larshg January 12, 2021 17:19
@larshg
Copy link
Contributor

larshg commented Jan 13, 2021

Should we make a issue about creating a unit test?
Unless you, @Yuki992411, are up for the task to add a test?

@Yuki992411
Copy link
Contributor Author

Thank you for your PR approval.
This is my first time to write test code.
However, it is a very good opportunity, so I will create a unit test myself and add it to issue #4569.
If you find any mistakes, please give me feedback.

@Yuki992411 Yuki992411 changed the title [ml] Fix un-initialized centroids bug [ml] Fix un-initialized centroids bug (k-means) Jan 16, 2021
test/ml/CMakeLists.txt Outdated Show resolved Hide resolved
@larshg
Copy link
Contributor

larshg commented Jan 16, 2021

You are missing:

/* ---[ */
int
main (int argc, char** argv)
{
  testing::InitGoogleTest (&argc, argv);
  return (RUN_ALL_TESTS ());
}

In the end of the test file.

@larshg
Copy link
Contributor

larshg commented Jan 16, 2021

And you can uses the short spdx version of the copyright:

/*
 * SPDX-License-Identifier: BSD-3-Clause
 *
 *  Point Cloud Library (PCL) - www.pointclouds.org
 *  Copyright (c) 2020-, Open Perception
 *
 *  All rights reserved
 */

beside the small changes, its looking good!

test/ml/test_kmeans.cpp Outdated Show resolved Hide resolved
test/ml/test_kmeans.cpp Outdated Show resolved Hide resolved
@larshg
Copy link
Contributor

larshg commented Jan 16, 2021

Looking good. Lets wait for CI's and @mvieth review on the unit test.
If no further changes are required, you can do a interactive rebase and set two of respective commits as fixups.

Then we have one commit with correction and one with the addition of unit test.

@Yuki992411
Copy link
Contributor Author

OK!
Thank you for first review 😁

@larshg larshg requested a review from mvieth January 17, 2021 20:20
Copy link
Member

@mvieth mvieth left a comment

Choose a reason for hiding this comment

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

Just two minor suggestions:

  1. Switch the Case1/2 and Kmeans_computeCentroids. Usually it goes from general to specififc
  2. We could also e.g. test if the number of computed centroids is as requested, i.e. 9 and 1.

@Yuki992411
Copy link
Contributor Author

Thank you for your suggestion and review. @larshg @mvieth
In addition to the above suggestions, I have made some corrections.

  • According to primer.md it was written that the TEST() arguments should not contain any underscores (_). So, I changed Kmeans_computeCentroids to ComputeCentroids.
  • I fixed public indent at line 23.
  • I summarized commits only in fix code and unit tests.

Please check my commit.

Copy link
Member

@mvieth mvieth left a comment

Choose a reason for hiding this comment

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

Very nice, thanks again.
@larshg do you want to have a last look at the changes?

@larshg
Copy link
Contributor

larshg commented Jan 26, 2021

Looks ready 🚀

@mvieth mvieth merged commit 77a1239 into PointCloudLibrary:master Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Meta-information for changelog generation module: ml needs: code review Specify why not closed/merged yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants