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

median_absolute_deviation bug fix for non-zero center #997

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix median_absolute_deviation center!=0 bug
Fix bug causing median_absolute_deviation to return incorrect values
when a non-zero center (such as median which is the default) was used.
rasmushenningsson committed Jun 16, 2023
commit 22757a9278dd68d90295cf86e2f00628e0ccf8d3
8 changes: 4 additions & 4 deletions include/boost/math/statistics/univariate_statistics.hpp
Original file line number Diff line number Diff line change
@@ -505,14 +505,14 @@ auto median_absolute_deviation(ExecutionPolicy&& exec, RandomAccessIterator firs
{
auto middle = first + (num_elems - 1)/2;
std::nth_element(exec, first, middle, last, comparator);
return abs(*middle);
return abs(*middle-center);
}
else
{
auto middle = first + num_elems/2 - 1;
std::nth_element(exec, first, middle, last, comparator);
std::nth_element(exec, middle, middle+1, last, comparator);
return (abs(*middle) + abs(*(middle+1)))/abs(static_cast<Real>(2));
return (abs(*middle-center) + abs(*(middle+1)-center))/abs(static_cast<Real>(2));
}
}

@@ -1043,14 +1043,14 @@ Real median_absolute_deviation(RandomAccessIterator first, RandomAccessIterator
{
auto middle = first + (num_elems - 1)/2;
std::nth_element(first, middle, last, comparator);
return abs(*middle);
return abs(*middle-center);
}
else
{
auto middle = first + num_elems/2 - 1;
std::nth_element(first, middle, last, comparator);
std::nth_element(middle, middle+1, last, comparator);
return (abs(*middle) + abs(*(middle+1)))/abs(static_cast<Real>(2));
return (abs(*middle-center) + abs(*(middle+1)-center))/abs(static_cast<Real>(2));
}
}