Skip to content

Commit

Permalink
Merge pull request #3319 from stan-dev/cleanup/3316-median-abs-dev
Browse files Browse the repository at this point in the history
Cleanup/3316 median abs dev
  • Loading branch information
mitzimorris authored Nov 29, 2024
2 parents 185f368 + dad3486 commit 42731ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/stan/mcmc/chainset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class chainset {
double median(const std::string& name) const { return median(index(name)); }

/**
* Compute maximum absolute deviation (mad) for specified parameter.
* Compute median absolute deviation (mad) for specified parameter.
*
* Follows R implementation: constant * median(abs(x - center))
* where the value of center is median(x) and the constant is 1.4826,
Expand All @@ -263,7 +263,7 @@ class chainset {
* @param index parameter index
* @return sample mad
*/
double max_abs_deviation(const int index) const {
double med_abs_deviation(const int index) const {
Eigen::MatrixXd draws = samples(index);
auto center = median(index);
Eigen::MatrixXd abs_dev = (draws.array() - center).abs();
Expand All @@ -272,7 +272,7 @@ class chainset {
}

/**
* Compute maximum absolute deviation (mad) for specified parameter.
* Compute median absolute deviation (mad) for specified parameter.
*
* Follows R implementation: constant * median(abs(x - center))
* where the value of center is median(x) and the constant is 1.4826,
Expand All @@ -282,8 +282,8 @@ class chainset {
* @param name parameter name
* @return sample mad
*/
double max_abs_deviation(const std::string& name) const {
return max_abs_deviation(index(name));
double med_abs_deviation(const std::string& name) const {
return med_abs_deviation(index(name));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/mcmc/chainset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ TEST_F(McmcChains, summary_stats) {
EXPECT_NEAR(theta_sd_expect, bern_chains.sd("theta"), 1e-5);

double theta_mad_expect = 0.12309;
EXPECT_NEAR(theta_mad_expect, bern_chains.max_abs_deviation("theta"), 1e-5);
EXPECT_NEAR(theta_mad_expect, bern_chains.med_abs_deviation("theta"), 1e-5);

double theta_mcse_mean_expect = 0.003234;
EXPECT_NEAR(theta_mcse_mean_expect, bern_chains.mcse_mean("theta"), 1e-4);
Expand Down

0 comments on commit 42731ba

Please sign in to comment.