Jpp  19.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
JFIT::JRegressor< JPoint4D, JGandalf > Struct Template Reference

#include <JPoint4DRegressor.hh>

Inheritance diagram for JFIT::JRegressor< JPoint4D, JGandalf >:
JFIT::JAbstractRegressor< JPoint4D, JGandalf > JFIT::JGandalf< JPoint4D > JEEP::JMessage< T >

Public Types

typedef JGandalf< JPoint4Dminimiser_type
 
typedef JRegressor< JPoint4D,
JGandalf
regressor_type
 
typedef minimiser_type::result_type result_type
 
typedef JFIT_LOCAL::JTypedef_t
< JPoint4D >::parameter_type 
parameter_type
 Data type of fit parameter. More...
 

Public Member Functions

 JRegressor (double sigma)
 Constructor. More...
 
template<class JHit_t >
result_type operator() (const JPoint4D &vx, const JHit_t &hit) const
 
result_type operator() (const JPoint4D &value, T __begin, T __end)
 Global fit. More...
 
result_type operator() (const JFunction_t &fit, T __begin, T __end, Args...args)
 Multi-dimensional fit of multiple data sets. More...
 

Public Attributes

JLANG::JSharedPointer
< JMEstimator
estimator
 M-Estimator function. More...
 
double sigma
 Time resolution [ns]. More...
 
std::vector< parameter_typeparameters
 fit parameters More...
 
int numberOfIterations
 number of iterations More...
 
double lambda
 control parameter More...
 
JPoint4D value
 value More...
 
JPoint4D error
 error More...
 
JMATH::JMatrixNS V
 Hesse matrix. More...
 
result_type result
 

Static Public Attributes

static int MAXIMUM_ITERATIONS
 maximal number of iterations More...
 
static double EPSILON
 maximal distance to minimum More...
 
static double LAMBDA_MIN
 minimal value control parameter More...
 
static double LAMBDA_MAX
 maximal value control parameter More...
 
static double LAMBDA_UP
 multiplication factor control parameter More...
 
static double LAMBDA_DOWN
 multiplication factor control parameter More...
 
static double PIVOT
 minimal value diagonal element of Hesse matrix More...
 
static int debug = 0
 debug level (default is off). More...
 

Detailed Description

template<>
struct JFIT::JRegressor< JPoint4D, JGandalf >

Definition at line 67 of file JPoint4DRegressor.hh.

Member Typedef Documentation

Definition at line 80 of file JRegressor.hh.

Definition at line 81 of file JRegressor.hh.

typedef minimiser_type::result_type JFIT::JAbstractRegressor< JPoint4D , JGandalf >::result_type
inherited

Definition at line 82 of file JRegressor.hh.

Data type of fit parameter.

Definition at line 95 of file JGandalf.hh.

Constructor & Destructor Documentation

JFIT::JRegressor< JPoint4D, JGandalf >::JRegressor ( double  sigma)
inline

Constructor.

Definition at line 75 of file JPoint4DRegressor.hh.

76  {
77  this->sigma = sigma;
78  }
double sigma
Time resolution [ns].

Member Function Documentation

template<class JHit_t >
result_type JFIT::JRegressor< JPoint4D, JGandalf >::operator() ( const JPoint4D vx,
const JHit_t &  hit 
) const
inline

Definition at line 89 of file JPoint4DRegressor.hh.

90  {
91  using namespace JPP;
92 
93  const double dt = hit.getT() - vx.getT(hit.getPosition());
94 
95  const double u = dt / sigma;
97  result.chi2 = estimator->getRho(u) * hit.getW();
98 
99  JVector3D d = hit.getPosition() - vx.getPosition();
100 
101  double weight = getIndexOfRefraction() * getInverseSpeedOfLight()/(d.getLength() * sigma);
102 
103  result.gradient = hit.getW() * JPoint4D( d * weight,
104  -1/sigma);
105  result.gradient.mul(0.5 * estimator->getPsi(u));
106 
107  return result;
108  }
double getIndexOfRefraction()
Get average index of refraction of water corresponding to group velocity.
minimiser_type::result_type result_type
Definition: JRegressor.hh:82
JLANG::JSharedPointer< JMEstimator > estimator
M-Estimator function.
double sigma
Time resolution [ns].
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonStart.sh:47
const double getInverseSpeedOfLight()
Get inverse speed of light.
double u[N+1]
Definition: JPolint.hh:865
result_type JFIT::JAbstractRegressor< JPoint4D , JGandalf >::operator() ( const JPoint4D value,
T  __begin,
T  __end 
)
inlineinherited

Global fit.

Parameters
valuestart value
__beginbegin of data set
__endend of data set
Returns
chi2

Definition at line 94 of file JRegressor.hh.

95  {
96  static_cast<minimiser_type&>(*this).value = value;
97 
98  return static_cast<minimiser_type&>(*this)(static_cast<regressor_type&>(*this), __begin, __end);
99  }
JModel_t value
value
Definition: JGandalf.hh:346
JRegressor< JPoint4D, JGandalf > regressor_type
Definition: JRegressor.hh:81
result_type JFIT::JGandalf< JPoint4D >::operator() ( const JFunction_t &  fit,
T  __begin,
T  __end,
Args...  args 
)
inlineinherited

Multi-dimensional fit of multiple data sets.

The fit function should return the chi2 as well as the partial derivatives for the current value of the model and a given data point.

Parameters
fitfit function
__beginbegin of data
__endend of data
argsoptional data
Returns
chi2 and gradient

Definition at line 160 of file JGandalf.hh.

161  {
162  using namespace std;
163  using namespace JPP;
164 
165  // note that all model values should be assigned to the start value of the model before use
166  // because the actual list of model parameters can vary from fit to fit
167  // (e.g. if model consists of a container).
168 
169  const size_t N = parameters.size();
170 
171  V.resize(N);
172  h.resize(N);
173  x.resize(N);
174 
175  previous.result.chi2 = numeric_limits<double>::max();
176 
177  current.result.chi2 = numeric_limits<double>::max();
178  current.result.gradient = value;
179  current.result.gradient = zero;
180 
181  error = value;
182  error = zero;
183 
184  lambda = LAMBDA_MIN;
185 
187 
188  DEBUG("step: " << numberOfIterations << endl);
189 
190  reset();
191 
192  update(fit, __begin, __end, args...);
193 
194  DEBUG("lambda: " << FIXED(12,5) << lambda << endl);
195  DEBUG("chi2: " << FIXED(12,5) << current.result.chi2 << endl);
196 
197  if (current.result.chi2 < previous.result.chi2) {
198 
199  if (numberOfIterations != 0) {
200 
201  if (fabs(previous.result.chi2 - current.result.chi2) < EPSILON*fabs(previous.result.chi2)) {
202 
203  // normal end
204 
205  const result_type result = current.result;
206 
207  lambda = LAMBDA_MIN;
208 
209  reset();
210 
211  update(fit, __begin, __end, args...);
212 
213  try {
214  V.invert();
215  }
216  catch (const exception& error) {
217  V.reset();
218  }
219 
220  for (size_t i = 0; i != N; ++i) {
221  get(error, parameters[i]) = sqrt(V(i,i));
222  }
223 
224  return result;
225  }
226 
227  if (lambda > LAMBDA_MIN) {
228  lambda /= LAMBDA_DOWN;
229  }
230  }
231 
232  // store current values
233 
234  previous.value = value;
235  previous.result = current.result;
236 
237  } else {
238 
239  value = previous.value; // restore value
240 
241  lambda *= LAMBDA_UP;
242 
243  if (lambda > LAMBDA_MAX) {
244  break;
245  }
246 
247  reset();
248 
249  update(fit, __begin, __end, args...);
250  }
251 
252  DEBUG("Hesse matrix:" << endl << V << endl);
253 
254  // force definite positiveness
255 
256  for (size_t i = 0; i != N; ++i) {
257 
258  if (V(i,i) < PIVOT) {
259  V(i,i) = PIVOT;
260  }
261 
262  h[i] = 1.0 / sqrt(V(i,i));
263  }
264 
265  // normalisation
266 
267  for (size_t row = 0; row != N; ++row) {
268  for (size_t col = 0; col != row; ++col) {
269  V(row,col) *= h[row] * h[col];
270  V(col,row) = V(row,col);
271  }
272  }
273 
274  for (size_t i = 0; i != N; ++i) {
275  V(i,i) = 1.0 + lambda;
276  }
277 
278  // solve A x = b
279 
280  for (size_t col = 0; col != N; ++col) {
281  x[col] = h[col] * get(current.result.gradient, parameters[col]);
282  }
283 
284  try {
285  V.solve(x);
286  }
287  catch (const exception& error) {
288 
289  ERROR("JGandalf: " << error.what() << endl << V << endl);
290 
291  break;
292  }
293 
294  // update value
295 
296  for (size_t row = 0; row != N; ++row) {
297 
298  DEBUG("u[" << noshowpos << setw(3) << row << "] = " << showpos << FIXED(15,5) << get(value, parameters[row]));
299 
300  get(value, parameters[row]) -= h[row] * x[row];
301 
302  DEBUG(" -> " << FIXED(15,5) << get(value, parameters[row]) << noshowpos << endl);
303  }
304 
305  model(value);
306  }
307 
308  // abnormal end
309 
310  const result_type result = previous.result;
311 
312  value = previous.value; // restore value
313 
314  lambda = LAMBDA_MIN;
315 
316  reset();
317 
318  update(fit, __begin, __end, args...);
319 
320  try {
321  V.invert();
322  }
323  catch (const exception& error) {
324  V.reset();
325  }
326 
327  for (size_t i = 0; i != N; ++i) {
328  get(error, parameters[i]) = sqrt(V(i,i));
329  }
330 
331  return result;
332  }
double lambda
control parameter
Definition: JGandalf.hh:345
static double EPSILON
maximal distance to minimum
Definition: JGandalf.hh:336
JMATH::JVectorND x
Definition: JGandalf.hh:488
JPoint4D value
value
Definition: JGandalf.hh:346
static double PIVOT
minimal value diagonal element of Hesse matrix
Definition: JGandalf.hh:341
JMATH::JMatrixNS V
Hesse matrix.
Definition: JGandalf.hh:348
static const JZero zero
Function object to assign zero value.
Definition: JZero.hh:105
JMatrixND & reset()
Set matrix to the null matrix.
Definition: JMatrixND.hh:459
Auxiliary data structure for floating point format specification.
Definition: JManip.hh:446
std::vector< parameter_type > parameters
fit parameters
Definition: JGandalf.hh:343
void resize(const size_t size)
Resize matrix.
Definition: JMatrixND.hh:446
static double LAMBDA_MIN
minimal value control parameter
Definition: JGandalf.hh:337
static double LAMBDA_DOWN
multiplication factor control parameter
Definition: JGandalf.hh:340
void reset()
Reset current parameters.
Definition: JGandalf.hh:354
#define ERROR(A)
Definition: JMessage.hh:66
void update(const JFunction_t &fit, T __begin, T __end, Args...args)
Recursive method to update current parameters.
Definition: JGandalf.hh:374
struct JFIT::JGandalf::@10 current
static double LAMBDA_UP
multiplication factor control parameter
Definition: JGandalf.hh:339
void invert()
Invert matrix according LDU decomposition.
Definition: JMatrixNS.hh:75
then usage $script< input file >[option[primary[working directory]]] nWhere option can be N
Definition: JMuonPostfit.sh:40
void solve(JVectorND_t &u)
Get solution of equation A x = b.
Definition: JMatrixNS.hh:308
static int MAXIMUM_ITERATIONS
maximal number of iterations
Definition: JGandalf.hh:335
int numberOfIterations
number of iterations
Definition: JGandalf.hh:344
static double LAMBDA_MAX
maximal value control parameter
Definition: JGandalf.hh:338
JPoint4D error
error
Definition: JGandalf.hh:347
struct JFIT::JGandalf::@11 previous
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
std::vector< double > h
Definition: JGandalf.hh:487

Member Data Documentation

M-Estimator function.

Definition at line 110 of file JPoint4DRegressor.hh.

double JFIT::JRegressor< JPoint4D, JGandalf >::sigma

Time resolution [ns].

Definition at line 111 of file JPoint4DRegressor.hh.

int JFIT::JGandalf< JPoint4D >::MAXIMUM_ITERATIONS
staticinherited

maximal number of iterations

maximal number of iterations.

Definition at line 335 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::EPSILON
staticinherited

maximal distance to minimum

maximal distance to minimum.

Definition at line 336 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::LAMBDA_MIN
staticinherited

minimal value control parameter

Definition at line 337 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::LAMBDA_MAX
staticinherited

maximal value control parameter

Definition at line 338 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::LAMBDA_UP
staticinherited

multiplication factor control parameter

Definition at line 339 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::LAMBDA_DOWN
staticinherited

multiplication factor control parameter

Definition at line 340 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::PIVOT
staticinherited

minimal value diagonal element of Hesse matrix

minimal value diagonal element of matrix

Definition at line 341 of file JGandalf.hh.

fit parameters

Definition at line 343 of file JGandalf.hh.

int JFIT::JGandalf< JPoint4D >::numberOfIterations
inherited

number of iterations

Definition at line 344 of file JGandalf.hh.

double JFIT::JGandalf< JPoint4D >::lambda
inherited

control parameter

Definition at line 345 of file JGandalf.hh.

JPoint4D JFIT::JGandalf< JPoint4D >::value
inherited

value

Definition at line 346 of file JGandalf.hh.

JPoint4D JFIT::JGandalf< JPoint4D >::error
inherited

error

Definition at line 347 of file JGandalf.hh.

Hesse matrix.

Definition at line 348 of file JGandalf.hh.

result_type JFIT::JGandalf< JPoint4D >::result
inherited

Definition at line 491 of file JGandalf.hh.

template<class T>
int JEEP::JMessage< T >::debug = 0
staticinherited

debug level (default is off).

Definition at line 45 of file JMessage.hh.


The documentation for this struct was generated from the following file: