52 DbgLv(1) <<
"Define improve=0";
95 DbgLv(1) <<
"FWk: fit_iterations";
101 while( k_iter < mxiters && variance > tolerance )
162 nlsmeth = ( autocnvg &&
164 ( nlsmeth == 0 || nlsmeth == 3 ) ) ?
166 DbgLv(1) <<
"EOI autocnvg" << autocnvg <<
" nlsmeth ftol" << nlsmeth << fltolr;
187 for (
int ii = 0; ii <
nfpars; ii++ )
214 DbgLv(1) <<
"FWk: ii tguess guess BB" << 0
216 DbgLv(1) <<
"FWk: ii tguess guess BB" << 1
231 int lgdl = qRound( log10(
max( dlt1, dltn ) ) );
232 double dlmx = pow( 10.0, lgdl );
233 fitpars.
infomsg = tr(
"Huge Variance w/ ydelta max %1" ).arg( dlmx );
234 DbgLv(1) <<
"FWk: *** VARI<0: lgd dlm dl1 dln" << lgdl << dlmx << dlt1 << dltn;
239 if ( qAbs( dv ) < dv_toler )
242 DbgLv(1) <<
"FWk: old,new vari" << old_vari <<
variance << dv << dv_toler;
258 ( ( dv == 0.0 ) ? tr(
"zero" ) : tr(
"near zero" ) );
271 for (
int ii = 0; ii <
nfpars; ii++ )
312 QVector< double > vsearch(
nfpars );
313 QVector< double > vgamma (
nfpars );
314 QVector< double > vdelta (
nfpars );
315 double* search = vsearch.data();
316 double* gamma = vgamma .data();
317 double* delta = vdelta .data();
321 QVector< double* > vminf;
322 QVector< double > vdinf;
329 DbgLv(1) <<
"FW:QN: calc_jac";
333 DbgLv(1) <<
"FW:QN: calc_AtA";
343 DbgLv(1) <<
"FW:QN: ChoInv";
348 DbgLv(1) <<
"FW:QN: End iter0";
358 test_vari = ( test_vari > 0.0 ) ? sqrt( test_vari ) : test_vari;
360 DbgLv(1) <<
"FW:QN: test_vari" << test_vari;
361 if ( test_vari > 0.0 && sqrt( test_vari ) <
tolerance )
370 DbgLv(1) <<
"FW:QN: search0 gamma0" << search[0] << gamma[0];
374 DbgLv(1) <<
"FW:QN: linesearch return - alpha" << alpha;
386 for (
int ii = 0; ii <
nfpars; ii++ )
392 DbgLv(1) <<
"FW:QN: calc_model return";
397 DbgLv(1) <<
"FW:QN: calc_jac return";
405 DbgLv(1) <<
"FW:QN: calc_B return";
408 for (
int ii = 0; ii <
nfpars; ii++ )
411 delta[ ii ] = search[ ii ] * alpha;
416 DbgLv(1) <<
"FW:QN: updateQN return";
449 qApp->processEvents();
468 if ( f1 < 0.0 )
return( 0.0 );
471 if ( f2 < 0.0 )
return( 0.0 );
473 while( f0 >= 10000.0 || f0 < 0.0 ||
474 f1 >= 10000.0 || f1 < 0.0 ||
475 f2 >= 10000.0 || f2 < 0.0 )
481 if ( f1 < 0.0 )
return( 0.0 );
484 if ( f2 < 0.0 )
return( 0.0 );
486 if ( x1 <
dflt_min )
return( -1.0 );
489 bool check_flag =
true;
498 if ( ( qAbs( f2 - old_f2 ) <
dflt_min ) &&
499 ( qAbs( f1 - old_f1 ) <
dflt_min ) &&
500 ( qAbs( f0 - old_f0 ) <
dflt_min ) )
507 if ( ( ( qAbs( f2 - f0 ) <
dflt_min ) &&
518 if ( ( ( qAbs( f0 - f1 ) <
dflt_min ) &&
524 if ( f0 > f1 && f2 > f1 )
530 else if ( ( f2 > f1 && f1 > f0 ) ||
531 ( f1 > f0 && f1 > f2 ) ||
532 ( f1 == f1 && f1 > f0 ) )
536 x1 = ( x0 + x2 ) * 0.5;
539 if ( f1 < 0.0 )
return( 0.0 );
542 else if ( f0 > f1 && f1 > f2 )
548 x2 = x2 + ( pow( 2.0, (
double)( iter + 2 ) ) * hh );
551 if ( f2 < 0.0 )
return( 0.0 );
557 x1 = ( x0 + x2 ) * 0.5;
561 if ( f1 < 0.0 )
return( 0.0 );
574 if ( f0 < 0.0 )
break;
586 if ( f2 < 0.0 )
break;
589 if ( qAbs( f0 - f1 * 2.0 + f2 ) <
dflt_min )
591 double xmin = x1 + ( hh * ( f0 - f2 ) ) / ( 2. * ( f0 - f1 * 2. + f2 ) );
593 if ( fmin < 0.0 )
break;
602 if ( hh <
tolerance ) { alpha = x1;
break; }
608 if ( f0 < 0.0 )
break;
610 if ( f2 < 0.0 )
break;
621 for (
int ii = 0; ii <
nfpars; ii++ )
626 for (
int ii = 0; ii <
nfpars; ii++ )
640 QVector< double > vhgamma(
nfpars );
641 QVector< double > vvv (
nfpars );
642 QVector< double* > mvvtrns(
nfpars );
643 QVector< double* > mhgtrns(
nfpars );
644 QVector< double* > mdatrns(
nfpars );
646 QVector< double > dhgtrns( nfpars * nfpars );
647 QVector< double > ddatrns( nfpars * nfpars );
648 double* hgamma = vhgamma.data();
649 double* vv = vvv .data();
664 for (
int ii = 0; ii <
nfpars; ii++ )
665 vv[ ii ] = ( delta[ ii ] / deltgam ) - ( hgamma[ ii ] /
lambda );
668 for (
int ii = 0; ii <
nfpars; ii++ )
670 double rowvv = vv [ ii ];
671 double rowda = delta [ ii ];
672 double rowhg = hgamma[ ii ];
674 for (
int jj = 0; jj <
nfpars; jj++ )
676 vvtrns[ ii ][ jj ] = vv [ jj ] * rowvv;
677 datrns[ ii ][ jj ] = delta [ jj ] * rowda;
678 hgtrns[ ii ][ jj ] = hgamma[ jj ] * rowhg;
683 for (
int ii = 0; ii <
nfpars; ii++ )
684 for (
int jj = 0; jj <
nfpars; jj++ )
686 - ( hgtrns [ ii ][ jj ] / lambda )
687 + ( datrns [ ii ][ jj ] / deltgam )
688 + ( vvtrns [ ii ][ jj ] * lambda );
695 if ( value != value )
return true;
696 double aval = qAbs( value );
697 return ( aval < dflt_min || aval >
dflt_max );