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

Fix weird behavior of MaxPointCountDataPointsFilter #464

Merged
merged 5 commits into from
Jul 7, 2021

Conversation

aguenette
Copy link
Member

fixes #463

Like mentioned in the issues #463, this is the fix that I'm proposing in order to get better and more consistent results with the filter.

Here's a video showing the results:

Fixed results video

Use C++ random library to generate random indexes
Use the more efficient swapCols method from DataPoints's class to swap j and index
@aguenette aguenette self-assigned this May 31, 2021
@ethzasl-jenkins
Copy link

Can one of the admins verify this patch?

pointmatcher/DataPointsFilters/MaxPointCount.cpp Outdated Show resolved Hide resolved
pointmatcher/DataPointsFilters/MaxPointCount.cpp Outdated Show resolved Hide resolved
cloud.times.col(j) = cloud.times.col(idx);
cloud.times.col(idx) = time;
}
std::uniform_int_distribution<size_t> distribution(j, N);
Copy link
Contributor

Choose a reason for hiding this comment

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

How expensive is this operation?

std::srand(seed);

for(size_t j=0; j<maxCount; ++j)
std::default_random_engine randomNumberGenerator(seed);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default random engine? Did you evaluate it against other options?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the documentation, it says that the default_random_engine is implementation-defined and on my computer (gcc 7.5.0) it says that it's std::minstd_rand0.

I did some benchmark to evaluate the different ways random numbers can be generated:

int_vs_real_minstd_rand0

int_vs_real_minstd_rand

real_minimal_standard_vs_mersenne_twister_double

real_minimal_standard_vs_mersenne_twister_float

From that, we can clearly see that only modifying the old algorithm to use the C++11 random library is faster than using C rand function, and it also produce better results at shuffling DataPoints.

const size_t index = distribution(randomNumberGenerator);

//Switch columns j and index
cloud.swapCols(j, index);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can it happen that you swap a point that has already been swapped?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is a possibility, but I don't know if it can be a problem. To avoid this, we would need keep track of the points that has been already swapped. Do you think it can be a problem?

aguenette and others added 3 commits July 6, 2021 13:33
Change the random number generator to std::minstd_rand instead of default_random_generator
Change the location of the uniform distribution outside the for loop
Change from uniform_int_distribution<size_t> for uniform_real_distribution<float>
@pomerlef
Copy link
Collaborator

pomerlef commented Jul 7, 2021

Don't hesitate to open new issues if needed. I'll assume that this PR is ready for merge.

@pomerlef pomerlef merged commit f588527 into norlab-ulaval:master Jul 7, 2021
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.

Getting weird results/behavior from MaxPointCountDataPointsFilter
4 participants