Skip to content

Commit

Permalink
Check for algorithm=fixed_param when there are no model parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksvanhorn committed Feb 11, 2014
1 parent 51be3e0 commit df6c9ff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/stan/gm/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ namespace stan {
//////////////////////////////////////////////////

Model model(data_var_context, &std::cout);

Eigen::VectorXd cont_params = Eigen::VectorXd::Zero(model.num_params_r());

if (output_stream) {
Expand Down Expand Up @@ -804,6 +804,13 @@ namespace stan {
parser.arg("method")->arg("sample")->arg("adapt"));
bool adapt_engaged = dynamic_cast<bool_argument*>(adapt->arg("engaged"))->value();

if (model.num_params_r() == 0 && algo->value() != "fixed_param") {
std::cout
<< "Must use algorithm=fixed_param for model that has no parameters."
<< std::endl;
return -1;
}

if (algo->value() == "fixed_param") {

sampler_ptr = new stan::mcmc::fixed_param_sampler();
Expand Down
29 changes: 29 additions & 0 deletions src/test/CmdStan/fixed_param_sampler_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,32 @@ TEST(McmcFixedParamSampler, check_empty) {
EXPECT_EQ(success, true);

}

TEST(McmcFixedParamSampler, check_empty_but_algorithm_not_fixed_param) {

std::vector<std::string> model_path;
model_path.push_back("src");
model_path.push_back("test");
model_path.push_back("test-models");
model_path.push_back("compiled");
model_path.push_back("CmdStan");
model_path.push_back("empty");

std::string command = convert_model_path(model_path);
command += " sample output file=" + convert_model_path(model_path) + ".csv";
run_command_output command_output;

bool success = true;

try {
command_output = run_command(command);
} catch(...) {
success = false;
}

EXPECT_EQ(success, true);
EXPECT_NE(0, command_output.err_code);
char const * errmsg =
"Must use algorithm=fixed_param for model that has no parameters";
EXPECT_NE(std::string::npos, command_output.output.find(errmsg));
}

0 comments on commit df6c9ff

Please sign in to comment.