Closed aleksgorica closed 5 months ago
Hi, @aleksgorica and welcome to the Stan project.
In terms of process, there should be an issue specifying the feature which this PR addresses. Please add an issue.
I would also suggest not removing the old functionality but instead just adding new functionality for the ranked version. That way, it won't break backward compatibility when it's added.
When it's ready to review for inclusion, please ping me and I can do it.
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.22 | 0.2 | 1.13 | 11.26% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 0.92 | -8.7% slower |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 0.97 | -2.6% slower |
gp_regr/gp_regr.stan | 0.11 | 0.11 | 0.98 | -1.79% slower |
sir/sir.stan | 80.14 | 78.73 | 1.02 | 1.76% faster |
irt_2pl/irt_2pl.stan | 4.27 | 3.94 | 1.08 | 7.62% faster |
eight_schools/eight_schools.stan | 0.06 | 0.05 | 1.05 | 4.36% faster |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.26 | 0.26 | 1.01 | 1.3% faster |
pkpd/one_comp_mm_elim_abs.stan | 18.89 | 18.45 | 1.02 | 2.3% faster |
garch/garch.stan | 0.49 | 0.46 | 1.07 | 6.46% faster |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.87 | 2.83 | 1.01 | 1.44% faster |
arK/arK.stan | 1.67 | 1.65 | 1.01 | 1.07% faster |
gp_pois_regr/gp_pois_regr.stan | 2.59 | 2.5 | 1.03 | 3.35% faster |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 9.41 | 9.21 | 1.02 | 2.2% faster |
performance.compilation | 176.71 | 180.14 | 0.98 | -1.94% slower |
Mean result: 1.0212747855344297
Jenkins Console Log Blue Ocean Commit hash: f70fb84db501edcbf822691c02664c43b76287b2
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.25 | 0.23 | 1.1 | 9.39% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.02 | 0.62 | -60.65% slower |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 0.98 | -1.8% slower |
gp_regr/gp_regr.stan | 0.12 | 0.13 | 0.93 | -7.72% slower |
sir/sir.stan | 87.69 | 85.71 | 1.02 | 2.25% faster |
irt_2pl/irt_2pl.stan | 4.56 | 4.42 | 1.03 | 3.16% faster |
eight_schools/eight_schools.stan | 0.06 | 0.07 | 0.83 | -20.07% slower |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.28 | 0.26 | 1.08 | 7.16% faster |
pkpd/one_comp_mm_elim_abs.stan | 20.41 | 20.05 | 1.02 | 1.78% faster |
garch/garch.stan | 0.59 | 0.51 | 1.15 | 13.25% faster |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 3.38 | 2.99 | 1.13 | 11.56% faster |
arK/arK.stan | 1.83 | 1.75 | 1.05 | 4.45% faster |
gp_pois_regr/gp_pois_regr.stan | 2.82 | 2.66 | 1.06 | 5.78% faster |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 10.38 | 10.44 | 0.99 | -0.55% slower |
performance.compilation | 209.61 | 208.84 | 1.0 | 0.37% faster |
Mean result: 1.0006665985989671
Jenkins Console Log Blue Ocean Commit hash: 728ec0a53bd4cce07bf159a426e13512de0b0263
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.23 | 0.2 | 1.18 | 15.25% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 0.94 | -6.03% slower |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 1.04 | 3.99% faster |
gp_regr/gp_regr.stan | 0.11 | 0.11 | 1.02 | 2.19% faster |
sir/sir.stan | 80.8 | 79.38 | 1.02 | 1.76% faster |
irt_2pl/irt_2pl.stan | 3.97 | 4.19 | 0.95 | -5.65% slower |
eight_schools/eight_schools.stan | 0.06 | 0.06 | 1.0 | -0.04% slower |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.27 | 0.26 | 1.05 | 4.59% faster |
pkpd/one_comp_mm_elim_abs.stan | 18.7 | 18.64 | 1.0 | 0.36% faster |
garch/garch.stan | 0.46 | 0.47 | 0.97 | -3.19% slower |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.87 | 2.92 | 0.98 | -1.77% slower |
arK/arK.stan | 1.68 | 1.69 | 0.99 | -0.68% slower |
gp_pois_regr/gp_pois_regr.stan | 2.64 | 2.64 | 1.0 | 0.18% faster |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 10.08 | 9.62 | 1.05 | 4.56% faster |
performance.compilation | 191.68 | 185.64 | 1.03 | 3.15% faster |
Mean result: 1.015320661964545
Jenkins Console Log Blue Ocean Commit hash: 14dfa9321f82f4102f9b572c68f1e7440177abf4
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.2 | 0.24 | 0.86 | -16.9% slower |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 1.09 | 8.21% faster |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 1.08 | 7.31% faster |
gp_regr/gp_regr.stan | 0.11 | 0.1 | 1.06 | 5.56% faster |
sir/sir.stan | 77.99 | 75.3 | 1.04 | 3.45% faster |
irt_2pl/irt_2pl.stan | 3.85 | 3.74 | 1.03 | 2.7% faster |
eight_schools/eight_schools.stan | 0.05 | 0.05 | 1.03 | 2.73% faster |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.25 | 0.24 | 1.01 | 1.24% faster |
pkpd/one_comp_mm_elim_abs.stan | 18.27 | 17.61 | 1.04 | 3.62% faster |
garch/garch.stan | 0.46 | 0.44 | 1.04 | 3.64% faster |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.79 | 2.75 | 1.02 | 1.63% faster |
arK/arK.stan | 1.63 | 1.59 | 1.02 | 2.16% faster |
gp_pois_regr/gp_pois_regr.stan | 2.54 | 2.45 | 1.04 | 3.65% faster |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 9.07 | 8.92 | 1.02 | 1.65% faster |
performance.compilation | 179.41 | 180.07 | 1.0 | -0.37% slower |
Mean result: 1.0234405050935638
Jenkins Console Log Blue Ocean Commit hash: 0fcf10855f923eb24c8e9958f1f19fde97572810
@aleksgorica this code all looks good! The only thing to fix now is the API. We want to keep all the old code and functions the same for backwards compatibility and have all of this in new functions. For instance compute_potential_scale_reduction()
should have the same results as previously.
So the new code you have in compute_potential_scale_reduction_rank
etc. is good and you can revert your changes to compute_potential_scale_reduction
. New code in the future can use your compute_potential_scale_reduction_rank
for the new estimate.
Once that is changed then I think you are good to merge!
@aleksgorica this code all looks good! The only thing to fix now is the API. We want to keep all the old code and functions the same for backwards compatibility and have all of this in new functions. For instance
compute_potential_scale_reduction()
should have the same results as previously.So the new code you have in
compute_potential_scale_reduction_rank
etc. is good and you can revert your changes tocompute_potential_scale_reduction
. New code in the future can use yourcompute_potential_scale_reduction_rank
for the new estimate.Once that is changed then I think you are good to merge!
Okay, I hope I have understood correctly, I have just reverted the changes in the original non-rank functions to the previous code. However, I would like to know why that is necessary since I believe the new code yields the same results as the previous code according to the tests, and it is also a bit better written.
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.26 | 0.19 | 1.35 | 25.96% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 1.08 | 7.44% faster |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 1.04 | 4.04% faster |
gp_regr/gp_regr.stan | 0.11 | 0.1 | 1.04 | 3.42% faster |
sir/sir.stan | 78.12 | 75.68 | 1.03 | 3.12% faster |
irt_2pl/irt_2pl.stan | 3.87 | 3.93 | 0.99 | -1.51% slower |
eight_schools/eight_schools.stan | 0.05 | 0.05 | 1.0 | 0.17% faster |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.25 | 0.25 | 0.99 | -0.58% slower |
pkpd/one_comp_mm_elim_abs.stan | 18.03 | 18.27 | 0.99 | -1.28% slower |
garch/garch.stan | 0.45 | 0.46 | 0.98 | -2.51% slower |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.78 | 2.83 | 0.98 | -1.99% slower |
arK/arK.stan | 1.64 | 1.69 | 0.97 | -3.19% slower |
gp_pois_regr/gp_pois_regr.stan | 2.5 | 2.61 | 0.96 | -4.57% slower |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 9.11 | 9.43 | 0.97 | -3.52% slower |
performance.compilation | 178.35 | 179.15 | 1.0 | -0.45% slower |
Mean result: 1.0234807232212786
Jenkins Console Log Blue Ocean Commit hash: ffae22a76851e3b49ca43f31234eeada692f1d9b
Okay, I hope I have understood correctly, I have just reverted the changes in the original non-rank functions to the previous code. However, I would like to know why that is necessary since I believe the new code yields the same results.
There's no need to keep the old code, but we need to keep the old interfaces so we don't break anyone's existing code. The new code should be doing ranked R-hat, right? That won't provide the same answers. If you wrote general enough code to do both, you can have the old interface delegate to the new code. Then we can rewrite the interfaces to use the new code and get rid of the old code. @SteveBronder will know more about the specifics here.
@bob-carpenter I rewrote this to dispatch to the old cold from the previous API
@aleksgorica there's one signature missing for split_potential_scale_reduction_rank
so it matches the API of split_potential_scale_reduction
. See below. Can you add that signature and have the current split_potential_scale_reduction
signature call your new split_potential_scale_reduction_rank
returning bulk rhat?
https://github.com/stan-dev/stan/blob/develop/src/stan/mcmc/chains.hpp#L219
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.22 | 0.2 | 1.09 | 8.35% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 0.95 | -5.09% slower |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 0.99 | -0.75% slower |
gp_regr/gp_regr.stan | 0.12 | 0.11 | 1.06 | 5.76% faster |
sir/sir.stan | 81.19 | 82.66 | 0.98 | -1.81% slower |
irt_2pl/irt_2pl.stan | 4.15 | 4.03 | 1.03 | 2.92% faster |
eight_schools/eight_schools.stan | 0.05 | 0.05 | 1.01 | 0.63% faster |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.25 | 0.25 | 1.01 | 0.65% faster |
pkpd/one_comp_mm_elim_abs.stan | 18.61 | 18.33 | 1.01 | 1.47% faster |
garch/garch.stan | 0.48 | 0.47 | 1.03 | 2.79% faster |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.91 | 2.83 | 1.03 | 2.6% faster |
arK/arK.stan | 1.66 | 1.67 | 0.99 | -0.59% slower |
gp_pois_regr/gp_pois_regr.stan | 2.6 | 2.61 | 1.0 | -0.35% slower |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 9.39 | 9.48 | 0.99 | -0.94% slower |
performance.compilation | 190.84 | 190.77 | 1.0 | 0.04% faster |
Mean result: 1.011567169879977
Jenkins Console Log Blue Ocean Commit hash: d8ac1c67d08c8b579e1b20ed5747abacce87c6fc
Actually I reverted my old PR. Changing all the old functions to use the new one causes cmdstan tests to fail.
Let's have the _rank
versions like you made here. We just need one last signature for
double split_potential_scale_reduction(
const Eigen::Matrix<Eigen::VectorXd, Dynamic, 1>& samples)
Then we are good! After this is in we can then change cmdstan etc. to use the new ranked version. I think this is better because we need to change the output anyway to report back both the bulk and tail rhat
Name | Old Result | New Result | Ratio | Performance change( 1 - new / old ) |
---|---|---|---|---|
arma/arma.stan | 0.2 | 0.19 | 1.07 | 6.13% faster |
low_dim_corr_gauss/low_dim_corr_gauss.stan | 0.01 | 0.01 | 1.12 | 10.43% faster |
gp_regr/gen_gp_data.stan | 0.02 | 0.02 | 1.1 | 8.7% faster |
gp_regr/gp_regr.stan | 0.11 | 0.1 | 1.06 | 5.37% faster |
sir/sir.stan | 77.58 | 75.31 | 1.03 | 2.92% faster |
irt_2pl/irt_2pl.stan | 3.76 | 3.75 | 1.0 | 0.26% faster |
eight_schools/eight_schools.stan | 0.05 | 0.05 | 1.02 | 1.8% faster |
pkpd/sim_one_comp_mm_elim_abs.stan | 0.25 | 0.24 | 1.04 | 3.67% faster |
pkpd/one_comp_mm_elim_abs.stan | 17.97 | 17.57 | 1.02 | 2.27% faster |
garch/garch.stan | 0.45 | 0.45 | 1.0 | -0.12% slower |
low_dim_gauss_mix/low_dim_gauss_mix.stan | 2.77 | 2.73 | 1.02 | 1.55% faster |
arK/arK.stan | 1.63 | 1.6 | 1.02 | 2.0% faster |
gp_pois_regr/gp_pois_regr.stan | 2.48 | 2.5 | 0.99 | -0.79% slower |
low_dim_gauss_mix_collapse/low_dim_gauss_mix_collapse.stan | 9.05 | 9.02 | 1.0 | 0.4% faster |
performance.compilation | 173.78 | 176.46 | 0.98 | -1.54% slower |
Mean result: 1.030804841038834
Jenkins Console Log Blue Ocean Commit hash: 934e17704b703a32c4c29f9ab5ae1913c4a58a57
Actually I reverted my old PR. Changing all the old functions to use the new one causes cmdstan tests to fail.
Let's have the
_rank
versions like you made here. We just need one last signature fordouble split_potential_scale_reduction( const Eigen::Matrix<Eigen::VectorXd, Dynamic, 1>& samples)
Then we are good! After this is in we can then change cmdstan etc. to use the new ranked version. I think this is better because we need to change the output anyway to report back both the bulk and tail rhat
Ok, but why should we even keep double split_potential_scale_reduction( const Eigen::Matrix<Eigen::VectorXd, Dynamic, 1>& samples)
or add double split_potential_scale_reduction_rank( const Eigen::Matrix<Eigen::VectorXd, Dynamic, 1>& samples)
, when it is declared private and there are no written tests for the function and no known references? Would we break backward compatibility by removing the function?
Oh, your right I didn't see that it was a private member that is never called. Let's leave it for now but idt you need to write a rank version for that one.
@aleksgorica you should have received an email that adds you to the stan project :) clicking on the link in that email from github should then allow you to press the "merge pull request" button
Thank you all for accepting me to Stan project :). I had really great time working on the pull request. Also thank you @SteveBronder and @bob-carpenter for mentoring.
But github doesn't allow me to merge pull request.
I just verified that Steve gave you permission to merge. Can you verify that works on your end by merging this?
Thanks, and welcome to the Stan team!
Did you click on the link in the email that was sent to you from github? After you click that and refresh the page you should have permission to merge
Yes, I clicked multiple times, now it always redirects me to https://github.com/stan-dev/stan. But it still does not allow me to merge. If I go to https://github.com/settings/organizations, there is written that I am outside collaborator on 1 repository for Stan.
Sorry you should have just gotten a new email that should give you the right permissions
Submission Checklist
./runTests.py src/test/unit
make cpplint
Summary
Solving issue #3269 Changes in compute_potential_scale_reduction, based on Vehtari Rhat computattion moved in rhat function Added function rank_transform Changed tests values to match new output
Intended Effect
rank_transform: Computes normalized average ranks for draws. Transforming them to normal scores using inverse normal transformation and a fractional offset.
rhat: computes rhat like before, the computatoinal part is just moved in a new function.
compute_potential_scale_reduction: copies draws in matrix object, then computes bulk rhat and tail rhat and returns the maximum
How to Verify
Compare the results with Arviz rhat function arviz
Side Effects
Documentation
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Aleks Stepančič
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: