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

Update log_prob method to take constrained_params in init format #1108

Merged
merged 14 commits into from Nov 7, 2022
Merged

Update log_prob method to take constrained_params in init format #1108

merged 14 commits into from Nov 7, 2022

Conversation

andrjohns
Copy link
Contributor

Submisison Checklist

  • Run tests: ./runCmdStanTests.py src/test
  • Declare copyright holder and open-source license: see below

Summary:

Updates the recently added log_prob method so that the constrained_params argument expects its inputs to follow the same format/structure as the init argument for sampling/optimisation

Intended Effect:

Simpler usage of the log_prob method

How to Verify:

Additional tests included

Side Effects:

N/A

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

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

@WardBrian
Copy link
Member

Thanks for looking into this @andrjohns. I guess the downside to this approach is losing the ability to 'batch' calls?

@andrjohns
Copy link
Contributor Author

Thanks for looking into this @andrjohns. I guess the downside to this approach is losing the ability to 'batch' calls?

Yeah pretty much. I was thinking an option would be to have multiple files, like how the inits are handled, but I'm not sure if that would be just as messy

Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

thanks for adding the doc strings for the classes. just a few minor issues left that go beyond the doc and then this is good to go

src/cmdstan/command.hpp Outdated Show resolved Hide resolved
src/cmdstan/command.hpp Outdated Show resolved Hide resolved
src/cmdstan/command.hpp Show resolved Hide resolved
src/cmdstan/command.hpp Outdated Show resolved Hide resolved
src/cmdstan/arguments/arg_log_prob_constrained_params.hpp Outdated Show resolved Hide resolved
@andrjohns
Copy link
Contributor Author

Sorry for the delay in getting to this @bob-carpenter! Ready for another look now

Copy link
Contributor

@bob-carpenter bob-carpenter left a comment

Choose a reason for hiding this comment

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

I've never understood the design of CmdStan and find the code almost impossible to read as the boundary conditions all seems strange.

My main concern is that none of this seems to be tested, but then there may be tests elsewhere.

I'd be much more comfortable if you found someone other than me who actually understands the C++ in CmdStan to review.

src/cmdstan/arguments/arg_log_prob_constrained_params.hpp Outdated Show resolved Hide resolved
src/cmdstan/command.hpp Outdated Show resolved Hide resolved
src/cmdstan/command.hpp Show resolved Hide resolved
src/cmdstan/command.hpp Show resolved Hide resolved
src/cmdstan/command.hpp Show resolved Hide resolved
src/cmdstan/command.hpp Outdated Show resolved Hide resolved
src/cmdstan/command.hpp Outdated Show resolved Hide resolved
@andrjohns
Copy link
Contributor Author

@WardBrian I've updated the test model to include various containers (to make that the un-constraining works correctly), and verified that the returned values are consistent with those returned by cmdstanr

@bob-carpenter
Copy link
Contributor

The doc needs work here.

  1. The doc says

The file can be in JSON or R Dump format, using the same structure as the 'init' argument.

What does this mean? The init argument takes a specification for a single point, whereas it looks like this function is going to allow multiple points. Something needs to specify what that format is.

  1. The doc needs to be super clear about what happens to the Jacobian adjustment. Stan defines an unconstrained density by including the Jacobian for transforming from unconstrained back to constrained. This would naturally be false for providing log densities on the constrained scale, because that's the log density the user defines over constrained parameters in the model block. On the other hand, if users are expecting this to match the lp__ value that is output when the Jacobian flag is on, then that won't happen if we turn it off.

@bob-carpenter
Copy link
Contributor

bob-carpenter commented Oct 20, 2022

  1. I think having the error messages talk about having wrong number of unconstrained parameters is going to be very confusing if the user has only specified parameters on the constrained scale.

Digging deeper through the source, it looks like there's an option to include or not include the Jacobian adjustment. I still think this is going to be confusing unless there is very clear doc about what the user should expect.

I see everything got changed at one point to propto = true and the gradient functional is called. This does a lot of extra work in propagating gradients that doesn't need to be done if just cast the input to var and then take the value. Then the backward pass isn't carried out.

Finally, I've never understood the structure of CmdStan, so I'd rather not be the reviewer here.

@WardBrian
Copy link
Member

If you’d like to not be the reviewer, you will still need to remove your existing “request changes”. We can then ask @rok-cesnovar to review?

@bob-carpenter bob-carpenter dismissed their stale review October 20, 2022 15:08

I don't feel qualified to review CmdStan code.

@bob-carpenter
Copy link
Contributor

Thanks for letting me know. I just dismissed my review. I'd forgotten I looked at this a month ago and that suggestions submitted that way shouldn't be in the form of a review.

It does look like there are tests now, which is great. And the user-facing doc I think is important to clarify should go in the CmdStan docs, not here in the code.

@WardBrian WardBrian removed the request for review from bob-carpenter October 20, 2022 15:21
Copy link
Member

@rok-cesnovar rok-cesnovar left a comment

Choose a reason for hiding this comment

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

Looks good to me. Some user facing doc would be great, but that is outside of the scope of this repo.

@rok-cesnovar rok-cesnovar merged commit d0a98ac into stan-dev:develop Nov 7, 2022
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.

None yet

6 participants