本文整理汇总了C++中math::Vector::gsl方法的典型用法代码示例。如果您正苦于以下问题:C++ Vector::gsl方法的具体用法?C++ Vector::gsl怎么用?C++ Vector::gsl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math::Vector
的用法示例。
在下文中一共展示了Vector::gsl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run () {
size_t niter = 10000;
float target_power = 2.0;
Options opt = get_options ("power");
if (opt.size())
target_power = opt[0][0];
opt = get_options ("niter");
if (opt.size())
niter = opt[0][0];
ndirs = to<int> (argument[0]);
if (get_options ("unipolar").size())
bipolar = false;
Math::RNG rng;
Math::Vector<double> v (2*ndirs);
for (size_t n = 0; n < 2*ndirs; n+=2) {
v[n] = Math::pi * (2.0 * rng.uniform() - 1.0);
v[n+1] = std::asin (2.0 * rng.uniform() - 1.0);
}
gsl_multimin_function_fdf fdf;
fdf.f = energy_f;
fdf.df = energy_df;
fdf.fdf = energy_fdf;
fdf.n = 2*ndirs;
gsl_multimin_fdfminimizer* minimizer =
gsl_multimin_fdfminimizer_alloc (gsl_multimin_fdfminimizer_conjugate_fr, 2*ndirs);
{
ProgressBar progress ("Optimising directions...");
for (power = -1.0; power >= -target_power/2.0; power *= 2.0) {
INFO ("setting power = " + str (-power*2.0));
gsl_multimin_fdfminimizer_set (minimizer, &fdf, v.gsl(), 0.01, 1e-4);
for (size_t iter = 0; iter < niter; iter++) {
int status = gsl_multimin_fdfminimizer_iterate (minimizer);
//for (size_t n = 0; n < 2*ndirs; ++n)
//std::cout << gsl_vector_get (minimizer->x, n) << " " << gsl_vector_get (minimizer->gradient, n) << "\n";
if (iter%10 == 0)
INFO ("[ " + str (iter) + " ] (pow = " + str (-power*2.0) + ") E = " + str (minimizer->f)
+ ", grad = " + str (gsl_blas_dnrm2 (minimizer->gradient)));
if (status) {
INFO (std::string ("iteration stopped: ") + gsl_strerror (status));
break;
}
progress.update ([&]() { return "Optimising directions (power " + str(-2.0*power) + ", current energy: " + str(minimizer->f, 8) + ")..."; });
}
gsl_vector_memcpy (v.gsl(), minimizer->x);
}
}
Math::Matrix<double> directions (ndirs, 2);
for (size_t n = 0; n < ndirs; n++) {
double az = gsl_vector_get (minimizer->x, 2*n);
double el = gsl_vector_get (minimizer->x, 2*n+1);
range (az, el);
directions (n, 0) = az;
directions (n, 1) = el;
}
gsl_multimin_fdfminimizer_free (minimizer);
DWI::Directions::save (directions, argument[1], get_options ("cartesian").size());
}