-
Notifications
You must be signed in to change notification settings - Fork 0
/
st2013.cpp
74 lines (62 loc) · 2.44 KB
/
st2013.cpp
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
/*
Copyright (C) 2009-2021 by Synge Todo <[email protected]>,
Hidemaro Suwa <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <iostream>
#include <random>
#include <vector>
#include "bcl.hpp"
static const unsigned int n = 8;
int main() {
try {
std::cout << "number of bins = " << n << std::endl;
// random number generator
typedef std::mt19937 engine_type;
engine_type eng(29411);
std::uniform_real_distribution<> dist;
// generate weights
std::vector<double> weights(n);
for (auto& w : weights) w = dist(eng);
std::cout << "[weights]\n";
for (std::size_t i = 0; i < n; ++i) std::cout << weights[i] << ' ';
std::cout << std::endl;
// generate transtition matrix
std::vector<std::vector<double> > transition_matrix;
bcl::st2013::generate_transition_matrix_resize(weights, transition_matrix);
std::cout << "[transition matrix]\n";
for (std::size_t i = 0; i < n; ++i) {
for (std::size_t j = 0; j < n; ++j) {
std::cout << transition_matrix[i][j] << ' ';
}
std::cout << std::endl;
}
// check transition matrix
std::cout << "[check transition matrix]\n";
std::cout << "probability conservation = "
<< (bcl::check_probability_conservation(transition_matrix) ? "pass" : "fail")
<< std::endl;
std::cout << "detailed balance condition = "
<< (bcl::check_detailed_balance(weights, transition_matrix) ? "pass" : "fail")
<< std::endl;
std::cout << "balance condition = "
<< (bcl::check_balance_condition(weights, transition_matrix) ? "pass" : "fail")
<< std::endl;
std::cout << "average rejection = " << bcl::average_rejection(weights, transition_matrix)
<< std::endl;
}
catch (const std::exception& excp) {
std::cerr << excp.what() << std::endl;
std::exit(-1); }
catch (...) {
std::cerr << "Unknown exception occurred!" << std::endl;
std::exit(-1); }
}