53 ZeroBufferFit::ZeroBufferFit(
const HiCalConf &conf) :
57 _timet.setBin(
ToInteger(prof(
"Summing")));
58 _timet.setLineTime(
ToDouble(prof(
"ScanExposureDuration")));
60 _skipFit =
IsEqual(
ConfKey(prof,
"ZeroBufferFitSkipFit", QString(
"TRUE")),
"TRUE");
61 _useLinFit =
IsTrueValue(prof,
"ZeroBufferFitOnFailUseLinear");
67 _sWidth =
toInt(
ConfKey(prof,
"GuessFilterWidth", QString(
"17")));
68 _sIters =
toInt(
ConfKey(prof,
"GuessFilterIterations", QString(
"1")));
70 if ( prof.
exists(
"MaximumIterations") ) {
76 _minLines =
toInt(
ConfKey(prof,
"ZeroBufferFitMinimumLines", QString(
"100")));
79 QString histstr =
"ZeroBufferFit(AbsErr[" +
ToString(_absErr) +
116 hist <<
"NotEnoughLines(GoodLines[" <<
goodLines(d)
117 <<
"],MinimumLines[" << _minLines <<
"]);";
120 hist <<
"SkipFit(TRUE: Not using LMFit)";
130 <<
"],DoF[" <<
DoF() <<
"])";
147 hist <<
"Failed::Reason("<<
statusstr() <<
"),#Iters[" 155 _history.add(
"OnFailureUse(LinearFit(Zf))");
159 _history.add(
"OnFailureUse(ZfBuffer)");
179 int nb = n - _badLines;
181 HiVector b1 = _data.subarray(0, nb-1);
193 int n0 =
MIN(nb, 20);
194 for (
int k = 0 ; k < n0 ; k++ ) {
195 double d = _b2[k] - (cc[0] + cc[1] * _timet(k));
202 n0 = (int) (0.9 * nb);
203 for (
int l = n0 ; l < nb ; l++ ) {
204 double d = _b2[l] - (cc[0] + cc[1] * _timet(l));
214 g[3] = -5.0/_timet(nb-1);
235 const NLVector &uncerts,
double cplxconj,
237 _chisq = pow(cplxconj, 2.0);
250 for (
int i = 0 ; i < n ; i++) {
251 double lt = _timet(i);
253 double Yi = a0 + (a1 * lt) + a2 * exp(
MIN(et,_maxLog));
254 f[i] = (Yi - _b2[i]);
268 for (
int i = 0; i < n; i++) {
269 double lt = _timet(i);
271 double p0 = exp (
MIN(et,_maxLog));
275 J[i][3] = a2 * lt * p0;
283 return (_data.copy());
288 for (
int i = 0 ; i < dcorr.dim() ; i++ ) {
289 double lt = _timet(i);
290 dcorr[i] = a[0] + (a[1] * lt) + a[2] * exp(a[3] * lt);
301 for (
int i = 0 ; i < v.dim() ; i++ ) {
302 vNorm[i] = v[i] - v0;
324 for (
int i = 0 ; i < n ; i++ ) {
325 double t = _timet(line0+i);
335 o <<
"# History = " <<
_history << endl;
343 for (
int i = 0 ; i < _data.dim() ; i++) {
const HiVector & ref() const
Return data via a const reference.
HiVector Yfit() const
Computes the solution vector using current coefficents.
int _fmtWidth
Default field with of double.
void LinearRegression(double &a, double &b) const
Fits a line through the data.
int maxIters() const
Maximum number iterations for valid solution.
int nIterations() const
Return number of iterations from last fit processing.
int toInt(const QString &string)
Global function to convert from a string to an integer.
Namespace for the standard library.
HiVector poly_fit(const HiVector &d, const double line0=0.0) const
Compute a polyonomial fit using multivariate statistics.
bool exists(const QString &key) const
Checks for the existance of a keyword.
HiHistory _history
Hierarchial component history.
double toDouble(const QString &string)
Global function to convert from a string to a double.
int DoF() const
Returns the Degrees of Freedom.
NonLinearLSQ Computes a fit using a Levenberg-Marquardt algorithm.
A DbProfile is a container for access parameters to a database.
std::string statusstr() const
Return error message pertaining to last fit procesing.
HiVector Normalize(const HiVector &v)
Compute normalized solution vector from result.
NLVector uncert() const
Return uncertainties from last fit processing.
bool IsEqual(const QString &v1, const QString &v2="TRUE")
Shortened string equality test.
QString formatDbl(const double &value) const
Properly format values that could be special pixels.
This class is used to accumulate statistics on double arrays.
int checkIteration(const int Iter, const NLVector &fitcoefs, const NLVector &uncerts, double cplxconj, int Istatus)
Computes the interation check for convergence.
int ToInteger(const T &value)
Helper function to convert values to Integers.
virtual void printOn(std::ostream &o) const
Provides virtualized dump of data from this module.
bool IsTrueValue(const DbProfile &prof, const QString &key, const QString &value="TRUE")
Determines if the keyword value is the expected value.
Container of multivariate statistics.
void Reset()
Reset all accumulators and counters to zero.
Compute a low pass filter from a Module class content.
Module manages HiRISE calibration vectors from various sources.
double Chisq() const
Returns the Chi-Square value of the fit solution.
bool gotGoodLines(const HiVector &d) const
Determines if the vector contains any valid lines.
double ToDouble(const T &value)
Helper function to convert values to doubles.
NLMatrix df_x(const NLVector &a)
Computes the first derivative of the function at the current iteration.
Namespace for ISIS/Bullet specific routines.
void AddData(const double *x, const double *y, const unsigned int count)
Add two arrays of doubles to the accumulators and counters.
T ConfKey(const DbProfile &conf, const QString &keyname, const T &defval, int index=0)
Find a keyword in a profile using default for non-existant keywords.
QString Name() const
Returns the name of this property.
bool success() const
Determine success from last fit processing.
int goodLines(const HiVector &d) const
Returns the number of good lines in the image.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
NLVector f_x(const NLVector &a)
Computes the function value at the current iteration.
NLVector guess()
Compute the initial guess of the fit.
QString ToString(const T &value)
Helper function to convert values to strings.
double Average() const
Computes and returns the average.
NLVector coefs() const
Return coefficients from last fit processing.
HiVector Solve(const HiVector &d)
Compute non-linear fit to (typically) ZeroBufferSmooth module.
T MIN(const T &A, const T &B)
Implement templatized MIN fumnction.
TNT::Array1D< double > HiVector
1-D Buffer
void setMaxIters(int m)
Sets the maximum number of iterations.