Skip to content

Conversation

WardBrian
Copy link
Member

@WardBrian WardBrian commented Aug 14, 2025

Submission Checklist

  • Run unit tests
  • Declare copyright holder and open-source license: see below

Summary

Closes #803

This renames the metric property of CmdStanMCMC to inv_metric, with the old property still available but raising a warning.

Secondly, it updates how the initial inverse metric is provided. The pre-existing metric argument is split into two, metric which still exists to specify only the metric type (e.g. "diag_e"), and a new inv_metric which specifies the value. This handling is written from-scratch using some of the helpers that already existed for e.g. init files. Besides the existing types, it can also now accept numpy arrays, meaning it is valid to write

model.sample(..., inv_metric=old_fit.inv_metric)

I am not completely confident that the error handling is as robust as previous, it's probably possible to come up with a bad argument that wouldn't be caught until actually running cmdstan, rather than trapped as a nicer error in the Python level.

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):

Simons Foundation

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@WardBrian WardBrian changed the title d Deprecate metric argument and property, rename to inv_metric Aug 14, 2025
@WardBrian WardBrian force-pushed the deprecations/rename-to-inv_metric branch from 249c9a6 to 4db7ecb Compare August 14, 2025 19:49
@WardBrian WardBrian requested a review from mitzimorris August 22, 2025 13:47
@WardBrian
Copy link
Member Author

@mitzimorris I'd appreciate a review if you are able!

Copy link
Member

@mitzimorris mitzimorris left a comment

Choose a reason for hiding this comment

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

If I understand correctly: the metric is specified by the inverse mass matrix which is either unit, dense, or diagonal, therefore the only property name we change is "metric" to "inv_metric" which holds, directly or indirectly, a matrix or list of matrices?

Therefore we should say "inverse mass matrix" in the doc comments and messages when talking about the matrix and its contents.

Otherwise this looks good and I like the encapsulated functions for dealing with metric files.

a valid filepath to a JSON or Rdump file which contains an entry
'inv_metric' whose value is either the diagonal vector or
the full covariance matrix.
:param metric: Specify the type of the mass matrix. Options are
Copy link
Member

Choose a reason for hiding this comment

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

type of the inverse mass matrix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Corrected!

@WardBrian WardBrian requested a review from mitzimorris August 28, 2025 17:59
@bob-carpenter
Copy link
Member

The mass matrix and metric are the same matrix. For a multivariate normal, the best value is the covariance, as that preconditions the multivariate normal back to unit covariance. See page 31 of Betancourt's conceptual intro to HMC.

For years, I'd had a bunch of this turned around in my head and in our doc and on the board as in the Stan meeting. Sorry!

Copy link
Member

@mitzimorris mitzimorris left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

Name confusion between inverse metric, metric
3 participants