4222 |
10 Sep 22 |
peter |
// $Id$ |
4222 |
10 Sep 22 |
peter |
2 |
|
4222 |
10 Sep 22 |
peter |
3 |
/* |
4222 |
10 Sep 22 |
peter |
Copyright (C) 2022 Peter Johansson |
4222 |
10 Sep 22 |
peter |
5 |
|
4222 |
10 Sep 22 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4222 |
10 Sep 22 |
peter |
7 |
|
4222 |
10 Sep 22 |
peter |
The yat library is free software; you can redistribute it and/or |
4222 |
10 Sep 22 |
peter |
modify it under the terms of the GNU General Public License as |
4222 |
10 Sep 22 |
peter |
published by the Free Software Foundation; either version 3 of the |
4222 |
10 Sep 22 |
peter |
License, or (at your option) any later version. |
4222 |
10 Sep 22 |
peter |
12 |
|
4222 |
10 Sep 22 |
peter |
The yat library is distributed in the hope that it will be useful, |
4222 |
10 Sep 22 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4222 |
10 Sep 22 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4222 |
10 Sep 22 |
peter |
General Public License for more details. |
4222 |
10 Sep 22 |
peter |
17 |
|
4222 |
10 Sep 22 |
peter |
You should have received a copy of the GNU General Public License |
4222 |
10 Sep 22 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4222 |
10 Sep 22 |
peter |
20 |
*/ |
4222 |
10 Sep 22 |
peter |
21 |
|
4222 |
10 Sep 22 |
peter |
22 |
#include <config.h> |
4222 |
10 Sep 22 |
peter |
23 |
|
4222 |
10 Sep 22 |
peter |
24 |
#include "Minimizer.h" |
4222 |
10 Sep 22 |
peter |
25 |
|
4222 |
10 Sep 22 |
peter |
26 |
#include <cassert> |
4222 |
10 Sep 22 |
peter |
27 |
|
4222 |
10 Sep 22 |
peter |
28 |
namespace theplu { |
4222 |
10 Sep 22 |
peter |
29 |
namespace yat { |
4222 |
10 Sep 22 |
peter |
30 |
namespace utility { |
4222 |
10 Sep 22 |
peter |
31 |
|
4222 |
10 Sep 22 |
peter |
32 |
Minimizer::Minimizer(const gsl_min_fminimizer_type* t) |
4222 |
10 Sep 22 |
peter |
33 |
: type_(t), solver_(gsl_min_fminimizer_alloc(type_)), |
4224 |
13 Sep 22 |
peter |
34 |
epochs_(0), epsabs_(0), epsrel_(1.0e-3) |
4222 |
10 Sep 22 |
peter |
35 |
{ |
4222 |
10 Sep 22 |
peter |
36 |
} |
4222 |
10 Sep 22 |
peter |
37 |
|
4222 |
10 Sep 22 |
peter |
38 |
|
4222 |
10 Sep 22 |
peter |
39 |
unsigned int Minimizer::epochs(void) const |
4222 |
10 Sep 22 |
peter |
40 |
{ |
4222 |
10 Sep 22 |
peter |
41 |
return epochs_; |
4222 |
10 Sep 22 |
peter |
42 |
} |
4222 |
10 Sep 22 |
peter |
43 |
|
4222 |
10 Sep 22 |
peter |
44 |
|
4247 |
24 Sep 22 |
peter |
45 |
Minimizer::Interval::Interval(double epsabs, double epsrel) |
4247 |
24 Sep 22 |
peter |
46 |
: epsabs_(epsabs), epsrel_(epsrel) |
4247 |
24 Sep 22 |
peter |
47 |
{} |
4222 |
10 Sep 22 |
peter |
48 |
|
4222 |
10 Sep 22 |
peter |
49 |
|
4247 |
24 Sep 22 |
peter |
50 |
bool Minimizer::Interval::operator()(const gsl_min_fminimizer* solver) |
4222 |
10 Sep 22 |
peter |
51 |
{ |
4247 |
24 Sep 22 |
peter |
52 |
double lower = gsl_min_fminimizer_x_lower(solver); |
4247 |
24 Sep 22 |
peter |
53 |
double upper = gsl_min_fminimizer_x_upper(solver); |
4247 |
24 Sep 22 |
peter |
54 |
int status = gsl_min_test_interval(lower, upper, epsabs_, epsrel_); |
4247 |
24 Sep 22 |
peter |
55 |
return status != GSL_CONTINUE; |
4222 |
10 Sep 22 |
peter |
56 |
} |
4222 |
10 Sep 22 |
peter |
57 |
|
4222 |
10 Sep 22 |
peter |
58 |
|
4222 |
10 Sep 22 |
peter |
59 |
void |
4222 |
10 Sep 22 |
peter |
60 |
Minimizer::GslFree::operator()(gsl_min_fminimizer* p) const |
4222 |
10 Sep 22 |
peter |
61 |
{ |
4222 |
10 Sep 22 |
peter |
62 |
gsl_min_fminimizer_free(p); |
4222 |
10 Sep 22 |
peter |
63 |
} |
4222 |
10 Sep 22 |
peter |
64 |
|
4222 |
10 Sep 22 |
peter |
65 |
}}} |