本文整理汇总了C++中Generator::get_size方法的典型用法代码示例。如果您正苦于以下问题:C++ Generator::get_size方法的具体用法?C++ Generator::get_size怎么用?C++ Generator::get_size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generator
的用法示例。
在下文中一共展示了Generator::get_size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: local_search_simple_expm
void local_search_simple_expm(
const SummedCdf& desired,
Generator& gen_optimal,
int maxiters,
double tol)
{
const double TOLERANCE = 1e-3;
// Create random devices...
std::random_device rd;
std::mt19937 gen{rd()};
std::normal_distribution<> normal{0, 1};
std::uniform_real_distribution<> unif{0, 1};
// Create generators...
Generator gen_current{gen_optimal.get_size()};
SummedCdf cdf_optimal {desired.bounds()};
SummedCdf cdf_current {desired.bounds()};
GslContext context{gen_optimal.get_size()};
set_cdf(gen_optimal, cdf_optimal, context);
MarkovChain test_chain{gen_optimal.get_size()};
int improvement_count = 0;
double current_distance = 1.0;
double radius = 2;
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
while (radius >= tol)
{
std::cout << "radius = " << radius << std::endl;
int count_since_improved = 0;
while (count_since_improved++ < maxiters)
{
gen_current.randomize([&normal, &gen]() { return normal(gen); });
gen_current.set_radius_from(gen_optimal, radius);
set_cdf(gen_current, cdf_current, context);
double diff = cdf_current.compare(desired);
if (diff >= current_distance)
{
continue;
}
std::cout << count_since_improved << " failed searches." << std::endl;
current_distance = diff;
gen_optimal = gen_current;
count_since_improved = 0;
improvement_count++;
char name_buffer[256];
char file_buffer[256];
sprintf(name_buffer, "improvement_%d", improvement_count);
sprintf(file_buffer, "output/improvement_%ld_%d.m", ms, improvement_count);
std::ofstream outfile;
outfile.open(file_buffer);
{
outfile << std::scientific << std::setprecision(std::numeric_limits<double>::digits10 + 1);
outfile << "x = [";
for (int i = 0; i < desired.bounds().N; i++)
outfile << desired.bounds().unmap(i) << " ";
outfile << "];\n";
outfile << "y_current_" << improvement_count << " = [";
for (int i = 0; i < desired.bounds().N; i++)
outfile << cdf_current.get(i) << " ";
outfile << "];\n";
outfile << "y_desired_" << improvement_count << " = [";
for (int i = 0; i < desired.bounds().N; i++)
outfile << desired.get(i) << " ";
outfile << "];\n";
outfile << "plot(x, y_current_" << improvement_count << ", x, y_desired_" << improvement_count << ");\n";
outfile << "saveas(gcf, '" << ms << "_" << improvement_count << ".png');\n";
}
outfile.close();
}
radius /= 2;
}
}