Base class for constrained fitter. More...
#include <Base_Constrainer.h>
Public Member Functions | |
Base_Constrainer (const Base_Constrainer_Args &args) | |
virtual double | fit (Constraint_Calculator &constraint_calculator, const Column_Vector &xm, Column_Vector &x, const Column_Vector &ym, Column_Vector &y, const Matrix &G_i, const Diagonal_Matrix &Y, Column_Vector &pullx, Column_Vector &pully, Matrix &Q, Matrix &R, Matrix &S)=0 |
Perform the constrained fit. | |
virtual std::ostream & | print (std::ostream &s) const |
Print out internal state to output stream. | |
virtual | ~Base_Constrainer () |
Protected Member Functions | |
bool | call_constraint_fcn (Constraint_Calculator &constraint_calculator, const Column_Vector &x, const Column_Vector &y, Row_Vector &F, Matrix &Bx, Matrix &By) const |
Helper function to evaluate constraints. This takes care of checking what the user function returns againts numerical derivatives, it that was requested. | |
Private Attributes | |
const Base_Constrainer_Args | _args |
Friends | |
std::ostream & | operator<< (std::ostream &s, const Base_Constrainer &f) |
Output stream operator, print the content of this Base_Constrainer to an output stream. |
Base class for constrained fitter.
Definition at line 229 of file Base_Constrainer.h.
hitfit::Base_Constrainer::Base_Constrainer | ( | const Base_Constrainer_Args & | args | ) |
Constructor.
args | Contains the parameter settings for this instance. |
Definition at line 175 of file Base_Constrainer.cc.
virtual hitfit::Base_Constrainer::~Base_Constrainer | ( | ) | [inline, virtual] |
bool hitfit::Base_Constrainer::call_constraint_fcn | ( | Constraint_Calculator & | constraint_calculator, |
const Column_Vector & | x, | ||
const Column_Vector & | y, | ||
Row_Vector & | F, | ||
Matrix & | Bx, | ||
Matrix & | By | ||
) | const [protected] |
Helper function to evaluate constraints. This takes care of checking what the user function returns againts numerical derivatives, it that was requested.
constraint_calculator | the User-supplied object to evaluate the constraints. |
x | Vector of well-measured quantities where we evaluate the constraints. Has dimension of Nw. |
y | Vector of poorly-measured quantities where we evaluate the the constraints. Has dimension of Np. |
F | Results of the constraint functions. |
Bx | Gradients of F with respect to x, has dimension (Nw,Nc). |
By | Gradients of F with respect to y, has dimension (Np,Nc). |
Definition at line 231 of file Base_Constrainer.cc.
References gather_cfg::cout, F(), i, j, x, and detailsBasic3DVector::y.
Referenced by hitfit::Chisq_Constrainer::fit().
{ // Call the user's function. bool val = constraint_calculator.eval (x, y, F, Bx, By); // If we're not doing gradients numerically, we're done. if (!_args.test_gradient()) return val; // Bail if the point was rejected. if (!val) return false; int Nw = x.num_row(); int Np = y.num_row(); int Nc = F.num_col(); // Numerically check Bx. for (int i=1; i<=Nc; i++) { // Step a little along variable I. Column_Vector step_x (Nw, 0); step_x(i) = _args.test_step(); Column_Vector new_x = x + step_x; // Evaluate the constraints at the new point. Matrix new_Bx (Nw, Nc); Matrix new_By (Np, Nc); Row_Vector new_F (Nc); if (! constraint_calculator.eval (new_x, y, new_F, new_Bx, new_By)) return false; // Calculate what we expect the constraints to be at this point, // given the user's gradients. Row_Vector test_F = F + step_x.T() * Bx; // Check the results. for (int j=1; j<=Nc; j++) { if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) { cout << "bad gradient x " << i << " " << j << "\n"; cout << x; cout << y; cout << new_x; cout << F; cout << new_F; cout << Bx; cout << (test_F - new_F); abort (); } } } // Numerically check By. for (int i=1; i<=Np; i++) { // Step a little along variable I. Column_Vector step_y (Np, 0); step_y(i) = _args.test_step(); Column_Vector new_y = y + step_y; // Evaluate the constraints at the new point. Matrix new_Bx (Nw, Nc); Matrix new_By (Np, Nc); Row_Vector new_F (Nc); if (! constraint_calculator.eval (x, new_y, new_F, new_Bx, new_By)) return false; // Calculate what we expect the constraints to be at this point, // given the user's gradients. Row_Vector test_F = F + step_y.T() * By; // Check the results. for (int j=1; j<=Nc; j++) { if (test_different (test_F(j), new_F(j), F(j), _args.test_eps())) { cout << "bad gradient y " << i << " " << j << "\n"; cout << x; cout << y; cout << new_y; cout << F; cout << new_F; cout << Bx; cout << (test_F - new_F); abort (); } } } // Done! return true; }
virtual double hitfit::Base_Constrainer::fit | ( | Constraint_Calculator & | constraint_calculator, |
const Column_Vector & | xm, | ||
Column_Vector & | x, | ||
const Column_Vector & | ym, | ||
Column_Vector & | y, | ||
const Matrix & | G_i, | ||
const Diagonal_Matrix & | Y, | ||
Column_Vector & | pullx, | ||
Column_Vector & | pully, | ||
Matrix & | Q, | ||
Matrix & | R, | ||
Matrix & | S | ||
) | [pure virtual] |
Perform the constrained fit.
constraint_calculator | The object that will be used to evaluate the constraints. |
xm | Measured values of the well-measured variables, has dimension Nw. |
x | Before the fit: starting value of the well-measured variables for the fit, has dimension Nw. After the fit: final values of the well-measured variables. |
ym | Measured values of the poorly-measured variables, has dimension Np. |
y | Before the fit: starting value of the poorly-measured variables for the fit, has dimension Np. After the fit: final values of the poorly-measured variables. |
G_i | Error matrix for the well-measured variables, has dimension Nw,Nw. |
Y | Inverse error matrix for the poorly-measured variables, has dimension Np,Np. |
pullx | Pull quantities for the well-measured variables, has dimension Nw. |
pully | Pull quantities for the poorly-measured variables, has dimension Np. |
Q | Error matrix for the well-measured variables, has dimension Nw,Nw. |
R | Error matrix for the poorly-measured variables, has dimension Np,Np. |
S | Error matrix for the correlation between well-measured variables and poorly-measured variables, has dimension Nw,Np. |
Implemented in hitfit::Chisq_Constrainer.
std::ostream & hitfit::Base_Constrainer::print | ( | std::ostream & | s | ) | const [virtual] |
Print out internal state to output stream.
s | Output stream to which to write. |
Reimplemented in hitfit::Chisq_Constrainer.
Definition at line 187 of file Base_Constrainer.cc.
References alignCSCRings::s.
Referenced by hitfit::operator<<(), and hitfit::Chisq_Constrainer::print().
std::ostream& operator<< | ( | std::ostream & | s, |
const Base_Constrainer & | f | ||
) | [friend] |
Output stream operator, print the content of this Base_Constrainer to an output stream.
s | The output stream to which to write. |
f | The instance of Base_Constrainer to be printed. |
Definition at line 215 of file Base_Constrainer.cc.
const Base_Constrainer_Args hitfit::Base_Constrainer::_args [private] |
Parameter settings for this instance of Base_Constrainer.
Reimplemented in hitfit::Chisq_Constrainer.
Definition at line 356 of file Base_Constrainer.h.