4176 |
01 Jun 22 |
peter |
// $Id$ |
4176 |
01 Jun 22 |
peter |
2 |
|
4346 |
24 Apr 23 |
peter |
3 |
/* |
4346 |
24 Apr 23 |
peter |
Copyright (C) 2022, 2023 Peter Johansson |
4346 |
24 Apr 23 |
peter |
5 |
|
4346 |
24 Apr 23 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4346 |
24 Apr 23 |
peter |
7 |
|
4346 |
24 Apr 23 |
peter |
The yat library is free software; you can redistribute it and/or |
4346 |
24 Apr 23 |
peter |
modify it under the terms of the GNU General Public License as |
4346 |
24 Apr 23 |
peter |
published by the Free Software Foundation; either version 3 of the |
4346 |
24 Apr 23 |
peter |
License, or (at your option) any later version. |
4346 |
24 Apr 23 |
peter |
12 |
|
4346 |
24 Apr 23 |
peter |
The yat library is distributed in the hope that it will be useful, |
4346 |
24 Apr 23 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4346 |
24 Apr 23 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4346 |
24 Apr 23 |
peter |
General Public License for more details. |
4346 |
24 Apr 23 |
peter |
17 |
|
4346 |
24 Apr 23 |
peter |
You should have received a copy of the GNU General Public License |
4346 |
24 Apr 23 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4346 |
24 Apr 23 |
peter |
20 |
*/ |
4346 |
24 Apr 23 |
peter |
21 |
|
4176 |
01 Jun 22 |
peter |
22 |
#include <config.h> |
4176 |
01 Jun 22 |
peter |
23 |
|
4176 |
01 Jun 22 |
peter |
24 |
#include "MultiMinimizerDerivative.h" |
4176 |
01 Jun 22 |
peter |
25 |
|
4176 |
01 Jun 22 |
peter |
26 |
namespace theplu { |
4176 |
01 Jun 22 |
peter |
27 |
namespace yat { |
4176 |
01 Jun 22 |
peter |
28 |
namespace utility { |
4176 |
01 Jun 22 |
peter |
29 |
|
4176 |
01 Jun 22 |
peter |
30 |
MultiMinimizerDerivative::MultiMinimizerDerivative(const gsl_multimin_fdfminimizer_type* t, |
4176 |
01 Jun 22 |
peter |
31 |
size_t size) |
4176 |
01 Jun 22 |
peter |
32 |
: type_(t), size_(size), |
4176 |
01 Jun 22 |
peter |
33 |
solver_(gsl_multimin_fdfminimizer_alloc(t, size)), |
4176 |
01 Jun 22 |
peter |
34 |
step_size_(0.01), |
4176 |
01 Jun 22 |
peter |
35 |
tol_(0.1) |
4176 |
01 Jun 22 |
peter |
36 |
{ |
4176 |
01 Jun 22 |
peter |
37 |
assert(solver_); |
4176 |
01 Jun 22 |
peter |
38 |
} |
4176 |
01 Jun 22 |
peter |
39 |
|
4176 |
01 Jun 22 |
peter |
40 |
|
4176 |
01 Jun 22 |
peter |
41 |
unsigned int MultiMinimizerDerivative::epochs(void) const |
4176 |
01 Jun 22 |
peter |
42 |
{ |
4176 |
01 Jun 22 |
peter |
43 |
return epochs_; |
4176 |
01 Jun 22 |
peter |
44 |
} |
4176 |
01 Jun 22 |
peter |
45 |
|
4176 |
01 Jun 22 |
peter |
46 |
|
4176 |
01 Jun 22 |
peter |
47 |
double MultiMinimizerDerivative::step_size(void) const |
4176 |
01 Jun 22 |
peter |
48 |
{ |
4176 |
01 Jun 22 |
peter |
49 |
return step_size_; |
4176 |
01 Jun 22 |
peter |
50 |
} |
4176 |
01 Jun 22 |
peter |
51 |
|
4176 |
01 Jun 22 |
peter |
52 |
|
4176 |
01 Jun 22 |
peter |
53 |
void MultiMinimizerDerivative::step_size(double ss) |
4176 |
01 Jun 22 |
peter |
54 |
{ |
4176 |
01 Jun 22 |
peter |
55 |
step_size_ = ss; |
4176 |
01 Jun 22 |
peter |
56 |
} |
4176 |
01 Jun 22 |
peter |
57 |
|
4176 |
01 Jun 22 |
peter |
58 |
|
4176 |
01 Jun 22 |
peter |
59 |
double MultiMinimizerDerivative::tolerance(void) const |
4176 |
01 Jun 22 |
peter |
60 |
{ |
4176 |
01 Jun 22 |
peter |
61 |
return tol_; |
4176 |
01 Jun 22 |
peter |
62 |
} |
4176 |
01 Jun 22 |
peter |
63 |
|
4176 |
01 Jun 22 |
peter |
64 |
|
4176 |
01 Jun 22 |
peter |
65 |
void MultiMinimizerDerivative::tolerance(double tol) |
4176 |
01 Jun 22 |
peter |
66 |
{ |
4176 |
01 Jun 22 |
peter |
67 |
tol_ = tol; |
4176 |
01 Jun 22 |
peter |
68 |
} |
4176 |
01 Jun 22 |
peter |
69 |
|
4176 |
01 Jun 22 |
peter |
70 |
|
4252 |
18 Nov 22 |
peter |
71 |
MultiMinimizerDerivative::Gradient::Gradient(double epsabs) |
4252 |
18 Nov 22 |
peter |
72 |
: epsabs_(epsabs) |
4252 |
18 Nov 22 |
peter |
73 |
{} |
4252 |
18 Nov 22 |
peter |
74 |
|
4252 |
18 Nov 22 |
peter |
75 |
|
4252 |
18 Nov 22 |
peter |
76 |
bool |
4252 |
18 Nov 22 |
peter |
77 |
MultiMinimizerDerivative::Gradient::operator()(const gsl_multimin_fdfminimizer* m) |
4252 |
18 Nov 22 |
peter |
78 |
{ |
4252 |
18 Nov 22 |
peter |
79 |
return gsl_multimin_test_gradient(m->gradient,epsabs_) != GSL_CONTINUE; |
4252 |
18 Nov 22 |
peter |
80 |
} |
4252 |
18 Nov 22 |
peter |
81 |
|
4252 |
18 Nov 22 |
peter |
82 |
|
4176 |
01 Jun 22 |
peter |
83 |
void |
4176 |
01 Jun 22 |
peter |
84 |
MultiMinimizerDerivative::GslFree::operator()(gsl_multimin_fdfminimizer* p) const |
4176 |
01 Jun 22 |
peter |
85 |
{ |
4176 |
01 Jun 22 |
peter |
86 |
gsl_multimin_fdfminimizer_free(p); |
4176 |
01 Jun 22 |
peter |
87 |
} |
4176 |
01 Jun 22 |
peter |
88 |
|
4176 |
01 Jun 22 |
peter |
89 |
|
4176 |
01 Jun 22 |
peter |
90 |
}}} |