Conjugate gradient fit.
More...
#include <JGradient.hh>
Conjugate gradient fit.
Definition at line 73 of file JGradient.hh.
JFIT::JGradient::JGradient |
( |
const size_t |
Nmax = std::numeric_limits<size_t>::max() , |
|
|
const size_t |
Nextra = 0 , |
|
|
const double |
epsilon = 1.0e-4 , |
|
|
const int |
debug = 3 |
|
) |
| |
|
inline |
Constructor.
The number of iterations and epsilon refer to the number of steps and the distance to the minimum, respectively.
The number of extra steps can be used to overcome a possible hurdle on the way.
- Parameters
-
Nmax | maximum number of iterations |
Nextra | maximum number of extra steps |
epsilon | epsilon |
debug | debug |
Definition at line 88 of file JGradient.hh.
size_t Nextra
maximum number of extra steps
size_t Nmax
maximum number of iterations
template<class T >
double JFIT::JGradient::operator() |
( |
const T & |
getChi2 | ) |
|
|
inline |
Fit.
The template parameter should provide for the following function operator.
double operator()(int option);
The value of the option corresponds to the following cases.
- 0 => step wise improvement of the chi2;
- 1 => evaluation of the chi2 before the determination of the gradient of the chi2; and
- 2 => evaluation of the derivative of the chi2 to each fit parameter.
- Parameters
-
Definition at line 114 of file JGradient.hh.
120 return numeric_limits<double>::max();
125 const size_t N = this->size();
130 for (
size_t i = 0;
i !=
N; ++
i) {
136 size_t number_of_iterations = 0;
138 for ( ; number_of_iterations !=
Nmax; ++number_of_iterations) {
140 DEBUG(
"chi2[0] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) <<
chi2[0] << endl);
149 for (
double ds = 1.0; ds > 1.0e-3; ) {
151 this->
move(+1.0 * ds);
155 DEBUG(
"chi2[3] " << setw(4) << m <<
' ' <<
FIXED(12,5) <<
chi2[3] <<
' ' <<
FIXED(12,5) << ds << endl);
181 for ( ; m != 0; --m) {
182 this->
move(-1.0 * ds);
189 this->
move(-1.0 * ds);
199 const double f21 =
chi2[2] -
chi2[1];
200 const double f23 = chi2[2] - chi2[3];
202 const double xs = 0.5 * (f21 - f23) / (f23 + f21);
204 this->
move(+1.0 * xs * ds);
208 if (chi2[3] < chi2[2]) {
214 this->
move(-1.0 * xs * ds);
219 DEBUG(
"chi2[2] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) << chi2[2] <<
' ' <<
SCIENTIFIC(12,5) << ds << endl);
229 if (fabs(chi2[2] - chi2[0]) <
epsilon * 0.5 * (fabs(chi2[0]) + fabs(chi2[2]))) {
241 for (
size_t i = 0;
i !=
N; ++
i){
252 for (
size_t i = 0;
i !=
N; ++
i){
254 H[
i] = G[
i] + dgg *
H[
i];
259 DEBUG(
"chi2[0] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) << chi2[0] << endl);
void move(const double factor)
Move.
static const double H
Planck constant [eV s].
void evaluate(const T &getChi2)
Evaluate gradient.
Auxiliary data structure for floating point format specification.
size_t Nextra
maximum number of extra steps
std::vector< double > gradient
size_t Nmax
maximum number of iterations
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
double getChi2(const double P)
Get chi2 corresponding to given probability.
Auxiliary data structure for floating point format specification.
#define DEBUG(A)
Message macros.
template<class T >
void JFIT::JGradient::evaluate |
( |
const T & |
getChi2 | ) |
|
|
inlineprivate |
Evaluate gradient.
Definition at line 275 of file JGradient.hh.
280 const size_t N = this->size();
292 for (
size_t i = 0;
i !=
N; ++
i) {
293 if ((*
this)[
i].
name.size() > width) {
294 width = (*this)[
i].name.size();
300 for (
size_t i = 0;
i !=
N; ++
i) {
302 if ((*
this)[
i].value != 0.0) {
304 (*this)[
i]->apply(+0.5 * (*
this)[
i].value);
308 (*this)[
i]->apply(-0.5 * (*
this)[
i].value);
309 (*this)[
i]->apply(-0.5 * (*
this)[
i].value);
315 (*this)[
i]->apply(+0.5 * (*
this)[
i].value);
327 DEBUG(setw(width) << left <<
"|gradient|" << right <<
' ' <<
FIXED(12,5) << sqrt(
V) << endl);
then echo Enter input within $TIMEOUT_S seconds echo n User name
Auxiliary data structure for floating point format specification.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
std::vector< double > gradient
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
double getChi2(const double P)
Get chi2 corresponding to given probability.
#define DEBUG(A)
Message macros.
void JFIT::JGradient::move |
( |
const double |
factor | ) |
|
|
inlineprivate |
Move.
- Parameters
-
Definition at line 336 of file JGradient.hh.
339 for (
size_t i = 0;
i != this->size(); ++
i) {
340 (*this)[
i ]->apply((*
this)[
i ].value *
gradient[
i ] * factor);
342 }
else if (factor < 0.0) {
343 for (
size_t i = this->size();
i != 0; --
i) {
344 (*this)[
i-1]->apply((*
this)[
i-1].value *
gradient[
i-1] * factor);
std::vector< double > gradient
size_t JFIT::JGradient::Nmax |
size_t JFIT::JGradient::Nextra |
double JFIT::JGradient::epsilon |
int JFIT::JGradient::debug |
double JFIT::JGradient::chi2[5] |
|
private |
The documentation for this struct was generated from the following file: