1 #ifndef __JFIT__JGRADIENT__
2 #define __JFIT__JGRADIENT__
21 namespace JPP {
using namespace JFIT; }
40 virtual void apply(
const double step) = 0;
48 public std::shared_ptr<JParameter_t>
87 const double debug = 3) :
116 return numeric_limits<double>::max();
121 const size_t N = this->size();
126 for (
size_t i = 0; i !=
N; ++i) {
132 size_t number_of_iterations = 0;
134 for ( ; number_of_iterations !=
Nmax; ++number_of_iterations) {
136 DEBUG(
"chi2[0] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) <<
chi2[0] << endl);
145 for (
double ds = 1.0; ds > 1.0e-3; ) {
147 this->
move(+1.0 * ds);
151 DEBUG(
"chi2[3] " << setw(4) << m <<
' ' <<
FIXED(12,5) <<
chi2[3] <<
' ' <<
FIXED(12,5) << ds << endl);
177 for ( ; m != 0; --m) {
178 this->
move(-1.0 * ds);
185 this->
move(-1.0 * ds);
195 const double f21 =
chi2[2] -
chi2[1];
196 const double f23 = chi2[2] - chi2[3];
198 const double xs = 0.5 * (f21 - f23) / (f23 + f21);
200 this->
move(+1.0 * xs * ds);
204 if (chi2[3] < chi2[2]) {
210 this->
move(-1.0 * xs * ds);
215 DEBUG(
"chi2[2] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) << chi2[2] <<
' ' <<
SCIENTIFIC(12,5) << ds << endl);
237 for (
size_t i = 0; i !=
N; ++i){
248 for (
size_t i = 0; i !=
N; ++i){
250 H[i] = G[i] + dgg * H[i];
255 DEBUG(
"chi2[0] " << setw(4) << number_of_iterations <<
' ' <<
FIXED(12,5) <<
chi2[0] << endl);
276 const size_t N = this->size();
288 for (
size_t i = 0; i !=
N; ++i) {
289 if ((*
this)[i].
name.size() > width) {
290 width = (*this)[i].name.size();
296 for (
size_t i = 0; i !=
N; ++i) {
298 if ((*
this)[i].value != 0.0) {
300 (*this)[i]->apply(+0.5 * (*
this)[i].value);
304 (*this)[i]->apply(-0.5 * (*
this)[i].value);
305 (*this)[i]->apply(-0.5 * (*
this)[i].value);
311 (*this)[i]->apply(+0.5 * (*
this)[i].value);
313 DEBUG(setw(width) << left << (*
this)[i].
name << right <<
' ' <<
FIXED(12,5) << (*
this)[i].value <<
' ' <<
FIXED(12,5) <<
gradient[i] << endl);
323 DEBUG(setw(width) << left <<
"|gradient|" << right <<
' ' <<
FIXED(12,5) << sqrt(
V) << endl);
335 for (
size_t i = 0; i != this->size(); ++i) {
336 (*this)[ i ]->apply((*
this)[ i ].value *
gradient[ i ] * factor);
338 }
else if (factor < 0.0) {
339 for (
size_t i = this->size(); i != 0; --i) {
340 (*this)[i-1]->apply((*
this)[i-1].value *
gradient[i-1] * factor);
void move(const double factor)
Move.
virtual ~JParameter_t()
Virtual destructor.
JGradient(const size_t Nmax=std::numeric_limits< size_t >::max(), const size_t Nextra=0, const double epsilon=1.0e-4, const double debug=3)
Constructor.
then echo Enter input within $TIMEOUT_S seconds echo n User name
double operator()(const T &getChi2)
Fit.
static const double H
Planck constant [eV s].
void evaluate(const T &getChi2)
Evaluate gradient.
Auxiliary data structure for floating point format specification.
V(JDAQEvent-JTriggerReprocessor)*1.0/(JDAQEvent+1.0e-10)
size_t Nextra
maximum number of extra steps
do set_variable OUTPUT_DIRECTORY $WORKDIR T
std::vector< double > gradient
virtual void apply(const double step)=0
Apply step.
size_t Nmax
maximum number of iterations
Auxiliary data structure for fit parameter.
General purpose messaging.
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Auxiliary data structure for editable parameter.
double getChi2(const double P)
Get chi2 corresponding to given probability.
Auxiliary data structure for floating point format specification.
#define DEBUG(A)
Message macros.
JEditor_t(const std::string &name, JParameter_t *parameter, const double value)
Constructor.