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

log_prob - allow only constrained or unconstrained inputs; allow multiple constrained inputs #1133

Closed
mitzimorris opened this issue Nov 22, 2022 · 1 comment · Fixed by #1134

Comments

@mitzimorris
Copy link
Member

mitzimorris commented Nov 22, 2022

Summary:

  • Revise the log_prob implementation to allow only constrained or only unconstrained params, in accord with the documentation

  • Allow multiple constrained parameter inputs in the form of a CSV file, similar to standalone_gqs

Description:

The log_prob method exposes a Stan model's log_prob function which takes as an input the vector of parameter values on the unconstrained scale and returns the gradients.

Desiderata

  • To amortize the cost of instantiating the model, the log_prob method should be able to accept an array of parameter vectors and then call the model's log_prob method on each.

  • Depending on the use case, the input parameters may be available on the constrained or unconstrained scale.

Current implementation

  • Constrained parameters are specified as a JSON object with entries for all parameters in the model, structured accordingly. Because the input file can only contain one JSON object, the current implementation doesn't admit of getting radients for more than one set of parameters on the constrained scale.

  • The documentation states that the user can only specify one or the other.

  • The code, as written, allows for inputs in the form of a file of one or more sets of parameters on the unconstrained scale and/or a file of a single set of parameter values on the constrained scale. If both are present, the logic will first computes the gradients for all unconstrained parameter sets, then compute the gradients for the constrained parameter set. This means that the last row of the output corresponds to the constrained parameters, if constrained parameter input file is present.

TEST_F(CmdStan, log_prob_good_rdump) {
std::stringstream ss;
ss << convert_model_path(bern_log_prob_model)
<< " data file=" << convert_model_path(bern_data)
<< " output file=" << convert_model_path(dev_null_path)
<< " method=log_prob unconstrained_params="
<< convert_model_path(bern_unconstrained_params_rdump)
<< " constrained_params="
<< convert_model_path(bern_constrained_params_rdump);
std::string cmd = ss.str();
run_command_output out = run_command(cmd);
ASSERT_FALSE(out.hasError);
}

Reproducible Steps:

Changed CmdStan code to check for this; unit tests fail.
.

Current Version:

v2.31.0

@mitzimorris mitzimorris changed the title log_prop unit tests contradict documentation log_prop implementation allows un- and constrained param input files, but will clobber former with latter Nov 22, 2022
@mitzimorris mitzimorris changed the title log_prop implementation allows un- and constrained param input files, but will clobber former with latter log_prop implementation allows un- and constrained param input files, but docs say only one or the other. Nov 22, 2022
@mitzimorris mitzimorris changed the title log_prop implementation allows un- and constrained param input files, but docs say only one or the other. log_prob - allow only constrained or unconstrained inputs; allow multiple constrained inputs Nov 22, 2022
@mitzimorris mitzimorris self-assigned this Nov 22, 2022
@mitzimorris
Copy link
Member Author

checking the header - all other methods output lp__ - two underscores - log_prob CSV output has only one - lp_.
technically OK, but inconsistent.

@mitzimorris mitzimorris linked a pull request Nov 25, 2022 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant