Repository navigation
Expand file tree
/
Copy pathfixed_param_sampler_test.cpp
More file actions
90 lines (72 loc) · 2.43 KB
/
Copy pathfixed_param_sampler_test.cpp
File metadata and controls
90 lines (72 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <test/utility.hpp>
#include <stan/io/stan_csv_reader.hpp>
#include <stan/mcmc/chains.hpp>
#include <stan/mcmc/fixed_param_sampler.hpp>
#include <gtest/gtest.h>
#include <fstream>
using cmdstan::test::convert_model_path;
using cmdstan::test::run_command;
using cmdstan::test::run_command_output;
void test_constant(const Eigen::VectorXd &samples) {
for (int i = 1; i < samples.size(); i++)
EXPECT_EQ(samples(0), samples(i));
}
TEST(McmcPersistentSampler, check_persistency) {
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("proper");
std::string command = convert_model_path(model_path);
command += " sample algorithm=fixed_param output file="
+ convert_model_path(model_path) + ".csv";
run_command_output command_output;
try {
command_output = run_command(command);
} catch (...) {
ADD_FAILURE() << "Failed running command: " << command;
}
std::ifstream output_stream;
output_stream.open((convert_model_path(model_path) + ".csv").data());
stan::io::stan_csv parsed_output
= stan::io::stan_csv_reader::parse(output_stream, 0);
stan::mcmc::chains<> chains(parsed_output);
for (int i = 0; i < chains.num_params(); ++i) {
test_constant(chains.samples(0, i));
}
}
TEST(McmcFixedParamSampler, check_empty) {
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("empty");
std::string command = convert_model_path(model_path);
command += " sample algorithm=fixed_param 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);
}
TEST(McmcFixedParamSampler, check_empty_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("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);
}