1 #include <QApplication>
20 QObject* parent ) : QObject( parent ), dsets( dsets )
23 edata = &dsets[ 0 ]->run_data;
40 st_mask = dsets[ 0 ]->solute_type;
44 double zcurr = dsets[ 0 ]->zcoeffs[ 0 ];
45 double vbar20 = dsets[ 0 ]->vbar20;
46 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
61 int nyp,
int res,
int typ,
int nth,
62 int noi,
int lmmxc,
int gfits,
63 double gfthr,
double alf )
65 DbgLv(1) <<
"PC(pcsaProc): start_fit()";
87 double vbar20 =
dsets[ 0 ]->vbar20;
88 double zcurr =
dsets[ 0 ]->zcoeffs[ 0 ];
89 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
96 if (
alpha == (-99.0) )
120 DbgLv(1) <<
"PC: alf alpha lm fx scn"
122 errMsg = tr(
"NO ERROR: start" );
184 int dfact = ( nsoln + 4 ) *
sizeof(
double );
185 int memneed = qRound( (
double)dsize * (
double)dfact / ( 1024. * 1024. ) );
187 DbgLv(1) <<
"PC:MEM(1): pav" << mempav <<
"ns dsz dfac mneed"
188 << nsoln << dsize << dfact << memneed;
189 memuse = memuse + memneed;
190 memava = memtot - memuse;
191 mempav = ( memava * 100 ) / memtot;
192 DbgLv(1) <<
"PC:MEM(1): pav" << mempav <<
"ava tot use"
193 << memava << memtot << memuse;
196 for (
int ktask = 0; ktask <
nmtasks; ktask++ )
201 double endy =
orig_sols[ ktask ][ mm ].y;
216 for (
int ii = 0; ii <
nthreads; ii++ )
231 tr(
"Starting computations of %1 models\n using %2 threads ..." )
232 .arg( nmtasks ).arg( nthreads ),
false );
236 memuse = memuse + memneed;
237 memava = memtot - memuse;
238 mempav = ( memava * 100 ) / memtot;
239 DbgLv(1) <<
"PC:MEM(2): pav" << mempav <<
"ava tot use"
240 << memava << memtot << memuse;
249 QMessageBox::warning( 0, tr(
"High Memory Usage" ),
250 tr(
"The available memory percent of\n"
251 "the total has fallen below 20%.\n"
252 "Total memory is %1 MB;\n"
253 "Available memory is %2 MB.\n\n"
254 "Re-parameterize the fit with adjusted\n"
255 "Curve Resolution Points and/or\n"
257 .arg( memtot ).arg( memava ) );
267 for (
int ii = 0; ii <
wthreads.size(); ii++ )
269 DbgLv(1) <<
"StopFit test Thread" << ii + 1;
272 if ( wthr != 0 && wthr->isRunning() )
276 DbgLv(1) <<
" STOPTHR: thread aborted";
279 else if ( wthr != 0 && ! wthr->isFinished() )
283 DbgLv(1) <<
" STOPTHR: thread deleted";
292 tr(
"All computations have been aborted." ),
false );
299 DbgLv(1) <<
"PC(pcsaProc): final_fit()";
322 for (
int rr = 0; rr <
npoints; rr++ )
333 for (
int ss = 0; ss <
nscans; ss++ )
341 int nsolutes = mrec.
csolutes.size();
347 for (
int cc = 0; cc < nsolutes; cc++ )
364 DbgLv(1) <<
" Bcc comp D" << mcomp.
D;
370 << mrec.
csolutes[qMax(0,nsolutes-1)].c <<
" nsols" << nsolutes;
378 DbgLv(1) <<
"FIN_FIN: simdat nsc npt"
380 DbgLv(1) <<
"FIN_FIN: resids nsc npt"
382 DbgLv(1) <<
"FIN_FIN: rdata nsc npt"
384 DbgLv(1) <<
"FIN_FIN: sdata nsc npt"
388 for (
int ss = 0; ss <
nscans; ss++ )
390 for (
int rr = 0; rr <
npoints; rr++ )
406 int ktimes = (
time_fg + 500 ) / 1000;
407 int ktimeh = ktimes / 3600;
408 int ktimem = ( ktimes - ktimeh * 3600 ) / 60;
409 double bvol =
dsets[0]->simparams.band_volume;
410 bvol=
dsets[0]->simparams.band_forming?bvol:0.0;
414 ktimes = ktimes - ktimeh * 3600 - ktimem * 60;
417 QString pmsg = tr(
"The Solution has converged...\n"
418 "Threads: %1 ; Models: %2 ; Iterations: %3 ."
423 pmsg += tr(
"%1 hr., %2 min., %3 sec.;" )
424 .arg( ktimeh ).arg( ktimem ).arg( ktimes );
427 pmsg += tr(
"%1 min., %2 sec.;" )
428 .arg( ktimem ).arg( ktimes );
431 int memmb = qRound( (
double)
maxrss / 1024.0 );
433 DbgLv(1) <<
"FIN_FIN: maxmem" << memmb <<
"kthr ksol" <<
nthreads << ksol;
435 pmsg += tr(
" Maximum memory used: " ) +
436 QString::number( memmb ) +
" MB\n\n" +
437 tr(
"The best model (RMSD=%1, %2 solutes, index %3) is:\n" )
438 .arg( mrec.
rmsd ).arg( nsolutes ).arg( mrec.
taskx );
441 double slopel = (double)( mrec.
end_y - mrec.
str_y )
443 pmsg += tr(
" the line from s,f/f0 %1, %2 to %3, %4 (slope %5)." )
449 pmsg += tr(
" the curve with par1=%1 and par2=%2." )
456 pmsg += tr(
" the line from x,y %1, %2 to %3, %4." )
462 pmsg += tr(
" the curve with a=%1, b=%2, c=%3\n"
463 " from x,y %4, %5 to %6, %7." )
471 DbgLv(1) <<
"FIN_FIN: Run Time: hr min sec" << ktimeh << ktimem << ktimes;
484 if ( fi_iter < fi_itermax && rd_frac > rd_thresh )
519 QStringList& modstats,
520 QVector< US_ModelRecord >& p_mrecs )
534 if ( (
noisflag & 1 ) != 0 && da_tin != 0 )
540 if ( (
noisflag & 2 ) != 0 && da_rin != 0 )
547 bm_ndx =
mrecs[ 0 ].taskx;
549 DbgLv(0) <<
" GET_RES: VARI,RMSD" <<
mrecs[0].variance <<
mrecs[0].rmsd
550 <<
"BM_NDX" << bm_ndx <<
"ALPHA" <<
alpha;
554 DbgLv(1) <<
"PC:GR: RTN";
579 int nmrecs =
mrecs.size();
580 int ntinoi =
mrecs[ 0 ].ti_noise.count();
581 int nrinoi =
mrecs[ 0 ].ri_noise.count();
582 DbgLv(1) <<
"PC:putMRs: nmrecs" << nmrecs <<
"rmsd" <<
mrecs[0].rmsd;
595 int v_ctype =
mrecs[ 0 ].v_ctype;
596 DbgLv(1) <<
"PC:putMRs: ctype v_ctype" <<
curvtype << v_ctype;
613 ? ( nmrecs - 1 ) : nmrecs;
618 ? ( qRound( sqrt( (
double)
nypts ) ) )
621 ? ( qRound( pow( (
double)
nypts, 0.3333333 ) ) )
625 DbgLv(1) <<
"PC:putMRs: m0 rmsd" <<
mrecs[0].rmsd;
627 for (
int ii = 0; ii < nmrecs; ii++ )
638 wtask.
thrn = thrx + 1;
664 int thrn = wresult.
thrn;
666 int taskx = wresult.
taskx;
667 int orecx =
mrecs.size();
668 DbgLv(1) <<
"PROCESS_JOB thrn" << thrn <<
"taskx orecx" << taskx << orecx;
671 if ( wresult.
csolutes[mm].c > 100.0 ) {
686 mrec.
rmsd = ( variance > 0.0 ) ? sqrt( variance ) : 99.9;
701 DbgLv(1) <<
"PJ: CLEAR: VARI VMIN ORECX" << variance <<
varimin << orecx;
727 int nsoln = mrec.isolutes.size();
730 int dsize = nscann * npointn;
731 int dfact = ( nsoln + 4 ) *
sizeof(
double );
732 int memneed = qRound( (
double)dsize * (
double)dfact / ( 1024. * 1024. ) );
733 DbgLv(1) <<
"PC:MEM: (4)nsol,nscn,npt,dsize,dfact,memneed"
734 << nsoln << nscann << npointn << dsize << dfact << memneed;
735 memuse = memuse + memneed;
736 memava = memtot - memuse;
737 mempav = ( memava * 100 ) / memtot;
738 DbgLv(1) <<
"PC:MEM: (4)AvPercent" << mempav;
747 DbgLv(1) <<
"THR_FIN: thrn" << thrn <<
" taskx orecx" << taskx << orecx
751 tr(
"Of %1 models, computations are complete for %2." )
759 tr(
"All models have now been completed. Evaluating..." ),
false );
781 DbgLv(1) <<
"THR_FIN: thrn" << thrn <<
" mrecs size" <<
mrecs.size()
782 <<
"mrec0 taskx,vari" <<
mrecs[0].taskx <<
mrecs[0].variance;
786 for (
int ii=0;ii<
mrecs.size();ii++)
788 DbgLv(1) <<
"MREC:rank" << ii <<
"taskx" <<
mrecs[ii].taskx
789 <<
"st_k en_k" <<
mrecs[ii].str_y <<
mrecs[ii].end_y
790 <<
"vari,rmsd" <<
mrecs[ii].variance <<
mrecs[ii].rmsd
791 <<
"ncsols" <<
mrecs[ii].csolutes.size();
800 int taskx,
int noisf, QVector< US_ZSolute > isolutes )
821 if ( tx >= 0 && tx <
wthreads.size() )
833 const char* ctp[] = {
"None",
835 "Increasing Sigmoid",
837 "Decreasing Sigmoid",
841 "Horizontal Line [ C(s) ]",
849 "Second-Order Power Law",
852 QString ctype = QString( ctp[
curvtype ] );
853 QString hmsg = tr(
"Analysis of %1 %2 %3-solute models.\n" )
856 for (
int ii = 1; ii <
fi_iter; ii++ )
857 hmsg += tr(
"Iteration %1 had a best RMSD of %2 ;\n" )
858 .arg( ii ).arg(
rmsds[ ii - 1 ] );
860 hmsg += tr(
"Grid Fit Iteration %1.\n" ).arg( fi_iter );
869 if (
job_queue.size() == 0 )
return wtask;
875 DbgLv(1) <<
"NEXTJ: jobx taskx taskx0"
878 DbgLv(1) <<
"NEXTJ: jobx taskx" << jobx << wtask.
taskx; }
881 job_queue.removeAt( jobx );
887 double ylo,
double yup,
int nyp,
int res )
889 DbgLv(1) <<
"SLMO: xlo xup ylo yup nyp res" << xlo << xup << ylo << yup
904 for (
int ii = 0; ii < nmodels; ii++ )
908 DbgLv(1) <<
"SLMO: orig_sols size" <<
orig_sols.size() <<
"nmodels" << nmodels;
915 double ylo,
double yup,
int nyp,
int nlpts )
917 DbgLv(1) <<
"SGMO: ctp xlo xup ylo yup nyp nlp" << ctp << xlo << xup
918 << ylo << yup << nyp << nlpts;
927 for (
int ii = 0; ii < nmodels; ii++ )
931 DbgLv(1) <<
"SGMO: orig_sols size" <<
orig_sols.size() <<
"nmodels" << nmodels;
940 DbgLv(1) <<
"2OMO: xlo xup ylo yup nyp nlp" << xlo << xup
941 << ylo << yup << nyp << nlpts;
950 for (
int ii = 0; ii < nmodels; ii++ )
954 DbgLv(1) <<
"2OMO: orig_sols size" <<
orig_sols.size() <<
"nmodels" << nmodels;
961 QStringList& modstats )
963 const char* ctp[] = {
"None",
965 "Increasing Sigmoid",
967 "Decreasing Sigmoid",
971 "Horizontal Line [ C(s) ]",
979 "Second-Order Power Law",
982 const int lenctp =
sizeof( ctp ) /
sizeof( ctp[ 0 ] );
986 nbmods = qMin(
nmtasks - 1, qMax( 3, nbmods ) );
988 int nblpts = mrecs[ 0 ].isolutes.size();
989 int soltype =
dsets[ 0 ]->solute_type;
990 double rmsdmin = 99999.0;
991 double rmsdmax = 0.0;
992 double rmsdavg = 0.0;
993 double brmsmin = 99999.0;
994 double brmsmax = 0.0;
995 double brmsavg = 0.0;
996 DbgLv(1) <<
"PC:MS: nmtasks mrssiz nbmods" <<
nmtasks << mrecs.size() << nbmods;
997 double rmsdmed = mrecs[
nmtasks / 2 ].rmsd;
998 double brmsmed = mrecs[ nbmods / 2 ].rmsd;
999 int nsolmin = 999999;
1002 int nbsomin = 999999;
1006 for (
int ii = 0; ii <
nmtasks; ii++ )
1008 double rmsd = mrecs[ ii ].rmsd;
1009 int nsols = mrecs[ ii ].csolutes.size();
1010 rmsdmin = qMin( rmsdmin, rmsd );
1011 rmsdmax = qMax( rmsdmax, rmsd );
1013 nsolmin = qMin( nsolmin, nsols );
1014 nsolmax = qMax( nsolmax, nsols );
1019 brmsmin = qMin( brmsmin, rmsd );
1020 brmsmax = qMax( brmsmax, rmsd );
1022 nbsomin = qMin( nbsomin, nsols );
1023 nbsomax = qMax( nbsomax, nsols );
1028 rmsdavg /= (double)nmtasks;
1029 nsolavg = ( nsolavg + nmtasks / 2 ) / nmtasks;
1030 brmsavg /= (double)nbmods;
1031 nbsoavg = ( nbsoavg + nbmods / 2 ) / nbmods;
1035 int curvtx = qMin(
curvtype, lenctp - 1 );
1036 modstats << tr(
"Curve Type:" )
1037 << QString( ctp[ curvtx ] );
1038 modstats << tr(
"Solute Type:" )
1040 modstats << tr(
"X Range:" )
1041 << QString().sprintf(
"%10.4f %10.4f",
xlolim,
xuplim );
1042 double str_y = mrecs[ 0 ].str_y;
1043 double end_y = mrecs[ 0 ].end_y;
1047 double slope = ( end_y - str_y ) / (
xuplim -
xlolim );
1049 modstats << tr(
"Y Range + delta:" )
1050 << QString().sprintf(
"%10.4f %10.4f %10.4f",
1052 modstats << tr(
"Best curve Y end points + slope:" )
1053 << QString().sprintf(
"%10.4f %10.4f %10.4f",
1054 str_y, end_y, slope );
1055 DbgLv(1) <<
"PC:MS: best str_y,end_y" << str_y << end_y;
1059 int p1ndx = mrecs[ 0 ].taskx /
nypts;
1060 int p2ndx = mrecs[ 0 ].taskx - ( p1ndx *
nypts );
1061 double krng = (double)(
nypts - 1 );
1062 double p1off = (double)p1ndx / krng;
1063 double par1 = exp( log( 0.001 )
1064 + ( log( 0.5 ) - log( 0.001 ) ) * p1off );
1065 double par2 = (double)p2ndx / krng;
1066 modstats << tr(
"Y Range:" )
1067 << QString().sprintf(
"%10.4f %10.4f",
ylolim,
yuplim );
1068 modstats << tr(
"Best curve par1 and par2:" )
1069 << QString().sprintf(
"%10.4f %10.4f", par1, par2 );
1070 modstats << tr(
"Best curve Y end points:" )
1071 << QString().sprintf(
"%10.4f %10.4f",
1072 mrecs[ 0 ].str_y, mrecs[ 0 ].end_y );
1076 modstats << tr(
"Y Range:" )
1077 << QString().sprintf(
"%10.4f %10.4f",
ylolim,
yuplim );
1078 modstats << tr(
"Best curve A, B, C:" )
1079 << QString().sprintf(
"%10.4f %10.4f %10.4f",
1080 mrecs[ 0 ].par1, mrecs[ 0 ].par2, mrecs[ 0 ].par3 );
1081 modstats << tr(
"Best curve Y end points:" )
1082 << QString().sprintf(
"%10.4f %10.4f",
1083 mrecs[ 0 ].str_y, mrecs[ 0 ].end_y );
1087 modstats << tr(
"Y Range:" )
1088 << QString().sprintf(
"%10.4f %10.4f",
ylolim,
yuplim );
1089 modstats << tr(
"Best curve par1 and par2:" )
1090 << QString().sprintf(
"%10.4f %10.4f",
1091 mrecs[ 0 ].par1, mrecs[ 0 ].par2 );
1092 modstats << tr(
"Best curve Y end points:" )
1093 << QString().sprintf(
"%10.4f %10.4f",
1094 mrecs[ 0 ].str_y, mrecs[ 0 ].end_y );
1096 modstats << tr(
"Number of models:" )
1097 << QString().sprintf(
"%5d", nmtasks );
1098 modstats << tr(
"Number of curve variations:" )
1099 << QString().sprintf(
"%5d",
nypts );
1100 modstats << tr(
"Solute points per curve:" )
1101 << QString().sprintf(
"%5d", nlpts );
1102 if ( nblpts != nlpts )
1103 modstats << tr(
"Best-curve points per curve:" )
1104 << QString().sprintf(
"%5d", nblpts );
1105 modstats << tr(
"Index of best model:" )
1106 << QString().sprintf(
"%5d", mrecs[ 0 ].taskx );
1107 modstats << tr(
"Best curve calculated solutes:" )
1108 << QString().sprintf(
"%5d", mrecs[ 0 ].csolutes.size() );
1109 modstats << tr(
"Minimum, Maximum calculated solutes:" )
1110 << QString().sprintf(
"%5d %5d", nsolmin, nsolmax );
1111 modstats << tr(
"Average calculated solutes:" )
1112 << QString().sprintf(
"%5d", nsolavg );
1113 modstats << tr(
"Minimum variance:" )
1114 << QString().sprintf(
"%12.6e",
varimin );
1115 modstats << tr(
"Minimum, Maximum rmsd:" )
1116 << QString().sprintf(
"%12.8f %12.8f", rmsdmin, rmsdmax );
1117 modstats << tr(
"Average, Median rmsd:" )
1118 << QString().sprintf(
"%12.8f %12.8f", rmsdavg, rmsdmed );
1119 modstats << tr(
"Number of \"better\" models:" )
1120 << QString().sprintf(
"%5d", nbmods );
1121 modstats << tr(
"%1 Best Min,Max calculated solutes:" ).arg( nbmods )
1122 << QString().sprintf(
"%5d %5d", nbsomin, nbsomax );
1123 modstats << tr(
"%1 Best Average calculated solutes:" ).arg( nbmods )
1124 << QString().sprintf(
"%5d", nbsoavg );
1125 modstats << tr(
"%1 Best Minimum, Maximum rmsd:" ).arg( nbmods )
1126 << QString().sprintf(
"%12.8f %12.8f", brmsmin, brmsmax );
1127 modstats << tr(
"%1 Best Average, Median rmsd:" ).arg( nbmods )
1128 << QString().sprintf(
"%12.8f %12.8f", brmsavg, brmsmed );
1129 modstats << tr(
"Tikhonov regularization parameter:" )
1130 << QString().sprintf(
"%12.3f",
alpha );
1131 DbgLv(1) <<
"PC:MS: RTN";
1138 static int ffcall=0;
1139 static double epar[ 20 ];
1140 static const int nepar =
sizeof( epar ) /
sizeof( epar[ 0 ] );
1155 QList< US_SolveSim::DataSet* >
dsets;
1156 void** iparP = (
void**)par;
1157 void** parP = (
void**)epar;
1158 double par1 = par[ 0 ];
1159 double par2 = par[ 1 ];
1160 int px = (
sizeof( double ) /
sizeof(
void* ) ) * 2;
1163 for (
int ii = 0; ii < nepar - 2; ii++ )
1164 epar[ ii ] = par[ ii + 2 ];
1165 parP[ 0 ] = iparP[ px ];
1170 int nlpts = (int)epar[ 1 ];
1171 double xmin = epar[ 2 ];
1172 double xmax = epar[ 3 ];
1173 double ylow = epar[ 6 ];
1174 double yhigh = epar[ 7 ];
1175 double p1lo = epar[ 8 ];
1176 double p1hi = epar[ 9 ];
1177 double p2lo = epar[ 10 ];
1178 double p2hi = epar[ 11 ];
1179 int noisfl = (int)epar[ 12 ];
1180 int dbg_lv = (int)epar[ 13 ];
1181 double alpha = epar[ 14 ];
1182 int attr_x = (int)epar[ 16 ];
1183 int attr_y = (int)epar[ 17 ];
1186 double ystart = par1;
1187 double yend = ystart + par2 * ( xmax - xmin );
1201 if ( par1 < p1lo || par2 < p2lo ||
1202 par1 > p1hi || par2 > p2hi ||
1203 ystart < ylow || yend < ylow ||
1204 ystart > yhigh || yend > yhigh )
1206 qDebug() <<
"ffSL: call" << ffcall <<
"par1 par2" << par1 << par2
1207 <<
"ys ye" << ystart << yend <<
"*OUT-OF-LIMITS*";
1212 double prange = (double)( nlpts - 1 );
1213 double xinc = ( xmax - xmin ) / prange;
1214 double yinc = ( yend - ystart ) / prange;
1215 double vbar20 = dsets[ 0 ]->vbar20;
1216 double xcurr = xmin;
1217 double ycurr = ystart;
1218 double zcurr = dsets[ 0 ]->zcoeffs[ 0 ];
1219 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
1220 qDebug() <<
"ffSL: zcurr vb" << zcurr << vbar20;
1237 for (
int ii = 0; ii < nlpts; ii++ )
1248 int ktimms = ftimer.elapsed();
1249 qDebug() <<
"ffSL: call" << ffcall <<
"par1 par2" << par1 << par2
1250 <<
"rmsd" << rmsd <<
"eval time" << ktimms <<
"ms.";
1252 qDebug() <<
"ffSL: epar0 epar1-9" << parP[0] << epar[1] << epar[2] << epar[3]
1253 << epar[4] << epar[5] << epar[6] << epar[7] << epar[8] << epar[9];
1256 qDebug() <<
"ffSL: ys ye yl yh" << ystart << yend << ylow << yhigh;
1264 static int ffcall=0;
1265 static double epar[ 18 ];
1266 static const int nepar =
sizeof( epar ) /
sizeof( epar[ 0 ] );
1281 QList< US_SolveSim::DataSet* >
dsets;
1282 void** iparP = (
void**)par;
1283 void** parP = (
void**)epar;
1284 double par1 = par[ 0 ];
1285 double par2 = par[ 1 ];
1286 int px = (
sizeof( double ) /
sizeof(
void* ) ) * 2;
1289 for (
int ii = 0; ii < nepar - 2; ii++ )
1290 epar[ ii ] = par[ ii + 2 ];
1291 parP[ 0 ] = iparP[ px ];
1296 int nlpts = (int)epar[ 1 ];
1297 double xmin = epar[ 2 ];
1298 double xmax = epar[ 3 ];
1299 double ymin = epar[ 4 ];
1300 double ymax = epar[ 5 ];
1301 double ylow = epar[ 6 ];
1302 double yhigh = epar[ 7 ];
1303 double p1lo = epar[ 8 ];
1304 double p1hi = epar[ 9 ];
1305 double p2lo = epar[ 10 ];
1306 double p2hi = epar[ 11 ];
1307 int noisfl = (int)epar[ 12 ];
1308 int dbg_lv = (int)epar[ 13 ];
1309 double alpha = epar[ 14 ];
1310 int attr_x = (int)epar[ 16 ];
1311 int attr_y = (int)epar[ 17 ];
1315 double ydif = ymax - ymin;
1316 double xrange = xmax - xmin;
1317 double p1fac = sqrt( 2.0 * qMax( par1, p1lo ) );
1318 double ystart = ystr + ydif * ( 0.5 * erf( ( 0.0 - par2 ) / p1fac ) + 0.5 );
1319 double yend = ystr + ydif * ( 0.5 * erf( ( 1.0 - par2 ) / p1fac ) + 0.5 );
1333 if ( par1 < p1lo || par2 < p2lo ||
1334 par1 > p1hi || par2 > p2hi ||
1335 ystart < ylow || yend < ylow ||
1336 ystart > yhigh || yend > yhigh )
1338 qDebug() <<
"ffIS: call" << ffcall <<
"par1 par2" << par1 << par2
1339 <<
"ys ye" << ystart << yend <<
"*OUT-OF-LIMITS*";
1344 double prange = (double)( nlpts - 1 );
1345 double xinc = 1.0 / prange;
1346 double vbar20 = dsets[ 0 ]->vbar20;
1347 double xcurr = xmin;
1348 double ycurr = ymin;
1349 double zcurr = dsets[ 0 ]->zcoeffs[ 0 ];
1350 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
1351 qDebug() <<
"ffIS: zcurr vb" << zcurr << vbar20;
1369 for (
int ii = 0; ii < nlpts; ii++ )
1371 double efac = 0.5 * erf( ( xoff - par2 ) / p1fac ) + 0.5;
1372 xcurr = xmin + xoff * xrange;
1373 ycurr = ymin + ydif * efac;
1382 int ktimms = ftimer.elapsed();
1383 qDebug() <<
"ffIS: call" << ffcall <<
"par1 par2" << par1 << par2
1384 <<
"rmsd" << rmsd <<
"eval time" << ktimms <<
"ms.";
1386 qDebug() <<
"ffIS: epar0 epar1-9" << parP[0] << epar[1] << epar[2] << epar[3]
1387 << epar[4] << epar[5] << epar[6] << epar[7] << epar[8] << epar[9];
1395 static int ffcall=0;
1396 static double epar[ 18 ];
1397 static const int nepar =
sizeof( epar ) /
sizeof( epar[ 0 ] );
1411 QList< US_SolveSim::DataSet* >
dsets;
1412 void** iparP = (
void**)par;
1413 void** parP = (
void**)epar;
1414 double par1 = par[ 0 ];
1415 double par2 = par[ 1 ];
1416 int px = (
sizeof( double ) /
sizeof(
void* ) ) * 2;
1419 for (
int ii = 0; ii < nepar - 2; ii++ )
1420 epar[ ii ] = par[ ii + 2 ];
1421 parP[ 0 ] = iparP[ px ];
1426 int nlpts = (int)epar[ 1 ];
1427 double xmin = epar[ 2 ];
1428 double xmax = epar[ 3 ];
1429 double ymin = epar[ 4 ];
1430 double ymax = epar[ 5 ];
1431 double ylow = epar[ 6 ];
1432 double yhigh = epar[ 7 ];
1433 double p1lo = epar[ 8 ];
1434 double p1hi = epar[ 9 ];
1435 double p2lo = epar[ 10 ];
1436 double p2hi = epar[ 11 ];
1437 int noisfl = (int)epar[ 12 ];
1438 int dbg_lv = (int)epar[ 13 ];
1439 double alpha = epar[ 14 ];
1440 int attr_x = (int)epar[ 16 ];
1441 int attr_y = (int)epar[ 17 ];
1445 double ydif = ymin - ymax;
1446 double xrange = xmax - xmin;
1447 double p1fac = sqrt( 2.0 * qMax( par1, p1lo ) );
1448 double ystart = ystr + ydif * ( 0.5 * erf( ( 0.0 - par2 ) / p1fac ) + 0.5 );
1449 double yend = ystr + ydif * ( 0.5 * erf( ( 1.0 - par2 ) / p1fac ) + 0.5 );
1463 if ( par1 < p1lo || par2 < p2lo ||
1464 par1 > p1hi || par2 > p2hi ||
1465 ystart < ylow || yend < ylow ||
1466 ystart > yhigh || yend > yhigh )
1468 qDebug() <<
"ffDS: call" << ffcall <<
"par1 par2" << par1 << par2
1469 <<
"ys ye" << ystart << yend <<
"*OUT-OF-LIMITS*";
1474 double prange = (double)( nlpts - 1 );
1475 double xoinc = 1.0 / prange;
1476 double vbar20 = dsets[ 0 ]->vbar20;
1477 double xcurr = xmin;
1478 double ycurr = ymin;
1479 double zcurr = dsets[ 0 ]->zcoeffs[ 0 ];
1480 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
1481 qDebug() <<
"ffDS: zcurr vb" << zcurr << vbar20;
1499 for (
int ii = 0; ii < nlpts; ii++ )
1501 double efac = 0.5 * erf( ( xoff - par2 ) / p1fac ) + 0.5;
1502 xcurr = xmin + xoff * xrange;
1503 ycurr = ystr + ydif * efac;
1512 int ktimms = ftimer.elapsed();
1513 qDebug() <<
"ffDS: call" << ffcall <<
"par1 par2" << par1 << par2
1514 <<
"rmsd" << rmsd <<
"eval time" << ktimms <<
"ms.";
1516 qDebug() <<
"ffDS: epar0 epar1-9" << parP[0] << epar[1] << epar[2] << epar[3]
1517 << epar[4] << epar[5] << epar[6] << epar[7] << epar[8] << epar[9];
1525 static int ffcall=0;
1526 static double epar[ 18 ];
1527 static const int nepar =
sizeof( epar ) /
sizeof( epar[ 0 ] );
1542 QList< US_SolveSim::DataSet* >
dsets;
1543 void** iparP = (
void**)par;
1544 void** parP = (
void**)epar;
1545 double par1 = par[ 0 ];
1546 double par2 = par[ 0 ];
1547 int px = (
sizeof( double ) /
sizeof(
void* ) ) * 2;
1550 for (
int ii = 0; ii < nepar - 2; ii++ )
1551 epar[ ii ] = par[ ii + 2 ];
1552 parP[ 0 ] = iparP[ px ];
1557 int nlpts = (int)epar[ 1 ];
1558 double xmin = epar[ 2 ];
1559 double xmax = epar[ 3 ];
1560 double ylow = epar[ 6 ];
1561 double yhigh = epar[ 7 ];
1562 double p1lo = epar[ 8 ];
1563 double p1hi = epar[ 9 ];
1564 int noisfl = (int)epar[ 12 ];
1565 int dbg_lv = (int)epar[ 13 ];
1566 double alpha = epar[ 14 ];
1567 int attr_x = (int)epar[ 16 ];
1568 int attr_y = (int)epar[ 17 ];
1583 if ( par1 < p1lo || par1 > p1hi ||
1584 yval < ylow || yval > yhigh )
1586 qDebug() <<
"ffHL: call" << ffcall <<
"par1" << par1 <<
"yv" << yval
1587 <<
"*OUT-OF-LIMITS*";
1592 double prange = (double)( nlpts - 1 );
1593 double xinc = ( xmax - xmin ) / prange;
1594 double vbar20 = dsets[ 0 ]->vbar20;
1595 double xcurr = xmin;
1596 double ycurr = yval;
1597 double zcurr = dsets[ 0 ]->zcoeffs[ 0 ];
1598 zcurr = ( zcurr == 0.0 ) ? vbar20 : zcurr;
1599 qDebug() <<
"ffHL: zcurr vb" << zcurr << vbar20;
1614 for (
int ii = 0; ii < nlpts; ii++ )
1624 int ktimms = ftimer.elapsed();
1625 qDebug() <<
"ffHL: call" << ffcall <<
"par1 par2" << par1 << par2
1626 <<
"rmsd" << rmsd <<
"eval time" << ktimms <<
"ms.";
1628 qDebug() <<
"ffHL: epar0 epar1-9" << parP[0] << epar[1] << epar[2] << epar[3]
1629 << epar[4] << epar[5] << epar[6] << epar[7] << epar[8] << epar[9];
1632 qDebug() <<
"ffHL: yv yl yh" << yval << ylow << yhigh;
1640 const int eslnc = 32;
1641 const int esigc = 44;
1648 static int n_par = 2;
1649 static int m_dat = 3;
1650 DbgLv(1) <<
"LMf: n_par m_dat" << n_par << m_dat;
1651 static double tarray[ 3 ] = { 0.0, 1.0, 2.0 };
1652 static double yarray[ 3 ] = { 0.0, 0.0, 0.0 };
1653 static double parray[ 20 ];
1659 double maxsl = -minsl;
1661 double minp1 = LnType ? minyv : 0.5;
1662 double maxp1 = LnType ? maxyv : 0.001;
1663 double minp2 = LnType ? minyv : 1.0;
1664 double maxp2 = LnType ? maxyv : 0.0;
1665 double minp3 = 9.99e+22;
1666 double maxp3 = -9.99e+22;
1678 lmtm_id = startTimer( stepms );
1679 mrecs[ 0 ].variance = 0.1;
1681 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
1683 "Levenberg-Marquardt fit ...\n" ),
true );
1690 minp1, maxp1, minp2, maxp2, minp3, maxp3 );
1693 const double par1lo=0.001;
1694 const double par1up=0.5;
1695 const double par2lo=0.0;
1696 const double par2up=1.0;
1699 minp1=(minp1+par1lo)*0.5;
1700 maxp1=(maxp1+par1up)*0.5;
1701 minp2=(minp2+par2lo)*0.5;
1702 maxp2=(maxp2+par2up)*0.5;
1705 double ibm_rmsd =
mrecs[ 0 ].rmsd;
1708 double *par = parray;
1709 void **ppar = (
void**)par;
1710 int px = (
sizeof( double ) /
sizeof(
void* ) ) * 2;
1711 double zbase =
dsets[ 0 ]->zcoeffs[ 0 ];
1712 par[ 0 ] =
mrecs[ 0 ].par1;
1713 par[ 1 ] =
mrecs[ 0 ].par2;
1714 DbgLv(0) <<
"LMf: par1 par2" << par[0] << par[1];
1716 ppar[ px ] = (
void*)
dsets[ 0 ];
1742 control.
ftol = 1.e-5;
1743 control.
xtol = 1.e-5;
1744 control.
gtol = 1.e-5;
1746 DbgLv(0) <<
"lmcurve_fit (SL) with par1,par2" << par[0] << par[1]
1747 <<
"ftol,epsl" << control.
ftol << control.
epsilon;
1753 DbgLv(0) <<
" lmcurve_fit (SL) return: par1,par2" << par[0] << par[1];
1754 DbgLv(0) <<
" lmcfit status: fnorm nfev info"
1761 int nsol =
dsets[0]->model.components.size();
1763 << rmsd <<
"ncsol" << nsol;
1769 control.
ftol = 1.0e-5;
1772 control.
epsilon = ibm_rmsd * 8.0e-5;
1774 DbgLv(0) <<
"lmcurve_fit (IS) with par1,par2" << par[0] << par[1]
1775 << QString().sprintf(
"%14.8e %14.8e", par[0], par[1] )
1776 <<
"ftol,epsl" << control.
ftol << control.
epsilon;
1781 DbgLv(0) <<
" lmcurve_fit (IS) return: par1,par2" << par[0] << par[1]
1782 << QString().sprintf(
"%14.8e %14.8e", par[0], par[1] );
1783 DbgLv(0) <<
" lmcfit status: fnorm nfev info"
1787 int nsol =
dsets[0]->model.components.size();
1788 DbgLv(0) <<
" lmcfit rmsd" << rmsd <<
"#solutes" << nsol;
1793 control.
ftol = 1.e-16;
1794 control.
xtol = 1.e-16;
1795 control.
gtol = 1.e-16;
1798 DbgLv(0) <<
"lmcurve_fit (DS) with par1,par2" << par[0] << par[1]
1799 << QString().sprintf(
"%14.8e %14.8e", par[0], par[1] )
1800 <<
"ftol,epsl" << control.
ftol << control.
epsilon;
1805 DbgLv(0) <<
" lmcurve_fit (DS) return: par1,par2" << par[0] << par[1]
1806 << QString().sprintf(
"%14.8e %14.8e", par[0], par[1] );
1807 DbgLv(0) <<
" lmcfit status: fnorm nfev info"
1810 int nsol =
dsets[0]->model.components.size();
1811 DbgLv(0) <<
" lmcfit rmsd" << rmsd <<
"#solutes" << nsol;
1816 control.
ftol = 1.e-5;
1817 control.
xtol = 1.e-5;
1818 control.
gtol = 1.e-5;
1820 DbgLv(0) <<
"lmcurve_fit (HL) with par1" << par[0]
1821 <<
"ftol,epsl" << control.
ftol << control.
epsilon;
1827 DbgLv(0) <<
" lmcurve_fit (HL) return: par1" << par[0];
1828 DbgLv(0) <<
" lmcfit status: fnorm nfev info"
1833 int nsol =
dsets[0]->model.components.size();
1835 << rmsd <<
"ncsol" << nsol;
1844 QApplication::restoreOverrideCursor();
1848 int nfev = status.
nfev;
1850 int ktimes = (
time_lm + 500 ) / 1000;
1851 int ktimeh = ktimes / 3600;
1852 int ktimem = ( ktimes - ktimeh * 3600 ) / 60;
1853 ktimes = ktimes - ktimeh * 3600 - ktimem * 60;
1854 DbgLv(0) <<
" lmcfit time: " << ktimeh <<
"h" << ktimem
1855 <<
"m" << ktimes <<
"s";
1856 DbgLv(0) <<
" lmcfit LM time(ms): estimated" <<
kctask
1858 QString fmsg = tr(
"The new best model has par1 %1, par2 %2,\n"
1859 " RMSD %3, %4 solutes, %5 LM iters. " )
1860 .arg( par[ 0 ] ).arg( par[ 1 ] ).arg( rmsd ).arg( nsol ).arg( nfev );
1862 fmsg = fmsg + tr(
"(%1 min., %2 sec.)" )
1863 .arg( ktimem ).arg( ktimes );
1865 fmsg = fmsg + tr(
"(%1 hr., %2 min., %3 sec.)" )
1866 .arg( ktimeh ).arg( ktimem ).arg( ktimes );
1868 fmsg = fmsg + tr(
"\nA Tikhonov regularization parameter of %1"
1879 mrec.
str_y = par[ 0 ];
1885 mrec.
str_y = par[ 0 ];
1886 mrec.
end_y = par[ 0 ];
1890 mrec.
par1 = par[ 0 ];
1891 mrec.
par2 = par[ 1 ];
1901 for (
int ii = 0; ii < mrec.
isolutes.size(); ii++ )
1912 for (
int ii = 0; ii < nsol; ii++ )
1924 DbgLv(1) <<
"LMf: ii" << ii <<
"x y c" << solute.
x << solute.
y << solute.
c;
1944 DbgLv(1) <<
"LMf:simparms: spts meni bott temp bpos"
1957 for (
int ii = 0; ii < nsol; ii++ )
1968 bool tino = ( (
noisflag & 1 ) != 0 );
1969 bool rino = ( (
noisflag & 2 ) != 0 );
1980 for (
int ii = 0; ii <
npoints; ii++ )
1992 for (
int ii = 0; ii <
nscans; ii++ )
2001 DbgLv(0) <<
"LMf:insert-new: old par1 par2" <<
mrecs[0].par1 <<
mrecs[0].par2
2002 <<
"new par1 par2" << mrec.
par1 << mrec.
par2 <<
"nmtasks mrec-size"
2004 DbgLv(0) <<
"LMf: old01 x,y" <<
mrecs[0].isolutes[0].x <<
mrecs[0].isolutes[0].y
2005 <<
mrecs[0].isolutes[1].x <<
mrecs[0].isolutes[1].y;
2008 mrecs.insert( 0, mrec );
2011 DbgLv(0) <<
"LMf: tino rino" << tino << rino;
2012 DbgLv(0) <<
"LMf: simdat nsc npt"
2014 DbgLv(1) <<
"LMf: resids nsc npt"
2016 DbgLv(1) <<
"LMf: rdata nsc npt"
2018 DbgLv(1) <<
"LMf: sdata nsc npt"
2024 for (
int ss = 0; ss <
nscans; ss++ )
2026 double rnois = rino ? mrec.
ri_noise[ ss ] : 0.0;
2028 for (
int rr = 0; rr <
npoints; rr++ )
2030 double tnois = tino ? mrec.
ti_noise[ rr ] : 0.0;
2032 -
sdata. value( ss, rr ) - tnois - rnois;
2033 rdata. setValue( ss, rr, resval );
2036 resids->
setValue( ss, rr, resval );
2037 if ((ss<3 && rr<3)||((ss+4)>nscans && (rr+4)>npoints)||(rr==(npoints/2)))
2038 DbgLv(1) <<
"LMf: ss rr" << ss << rr <<
"edat sdat resv"
2040 cvari +=
sq( resval );
2043 cvari /= (double)( nscans *
npoints );
2044 crmsd = sqrt( cvari );
2046 DbgLv(0) <<
"LMf: recomputed variance rmsd" << cvari << crmsd;
2051 double& minyv,
double& maxyv,
double& minp1,
double& maxp1,
2052 double& minp2,
double& maxp2 )
2054 const double efrac = 0.1;
2057 double m0p1 = mrecs[ 0 ].par1;
2058 double m0p2 = mrecs[ 0 ].par2;
2059 double m0p1l = m0p1;
2060 double m0p1h = m0p1;
2061 double m0p2l = m0p2;
2062 double m0p2h = m0p2;
2063 bool ln_type =
false;
2068 m0p1 = mrecs[ 0 ].str_y;
2069 m0p2 = mrecs[ 0 ].end_y;
2070 m0p1l = ( m0p1 >
ylolim ) ? m0p1 : ( m0p1 * 1.0001 );
2071 m0p1h = ( m0p1 <
yuplim ) ? m0p1 : ( m0p1 * 0.9991 );
2072 m0p2l = ( m0p2 >
ylolim ) ? m0p2 : ( m0p2 * 1.0001 );
2073 m0p2h = ( m0p2 <
yuplim ) ? m0p2 : ( m0p2 * 0.9991 );
2078 double dif1 = m0p1 - 0.001;
2079 double dif2 = m0p1 - 0.500;
2080 double dif3 = m0p2 - 0.000;
2081 double dif4 = m0p2 - 1.000;
2082 m0p1l = ( dif1 > 1.e-8 ) ? m0p1 : 0.002;
2083 m0p1h = ( dif2 < -1e-8 ) ? m0p1 : 0.499;
2084 m0p2l = ( dif3 > 1.e-8 ) ? m0p2 : 0.001;
2085 m0p2h = ( dif4 < -1e-8 ) ? m0p2 : 0.999;
2086 DbgLv(1) <<
" ElLim: ADJUST SIGM: m0p1 m0p1h" << m0p1 << m0p1h
2087 <<
"m0p1<0.500" << (m0p1<0.500) << 0.500 <<
"(m0p1-0.5)" << (m0p1-0.5);
2090 int nmr = mrecs.size();
2091 int nelite = qRound( efrac * nmr );
2092 int maxel = nmr / 2;
2093 int minel = qMin( maxel, 4 );
2094 nelite = qMin( nelite, maxel );
2095 nelite = qMax( nelite, minel );
2097 DbgLv(0) <<
" ElLim: nmr nelite nmtasks" << nmr << nelite <<
nmtasks;
2098 DbgLv(1) <<
" ElLim: in minyv maxyv" << minyv << maxyv;
2099 DbgLv(1) <<
" ElLim: in min/max p1/p2" << minp1 << maxp1 << minp2 << maxp2;
2100 DbgLv(1) <<
" ElLim: in m0p1 m0p2" << m0p1 << m0p2;
2101 DbgLv(1) <<
" ElLim: in m0p1l,m0p1h,m0p2l,m0p2h" << m0p1l << m0p1h
2104 for (
int ii = 0; ii < nmr; ii++ )
2106 double str_y = mrecs[ ii ].str_y;
2107 double end_y = mrecs[ ii ].end_y;
2108 double par1 = ln_type ? str_y : mrecs[ ii ].par1;
2109 double par2 = ln_type ? end_y : mrecs[ ii ].par2;
2110 if(ii<3||(ii+4)>nelite)
2111 DbgLv(1) <<
" ElLim: ii" << ii <<
"par1 par2" << par1 << par2
2112 <<
"str_y end_y" << str_y << end_y <<
"rmsd" << mrecs[ii].rmsd;
2113 minyv = qMin( minyv, str_y );
2114 maxyv = qMax( maxyv, str_y );
2115 minyv = qMin( minyv, end_y );
2116 maxyv = qMax( maxyv, end_y );
2117 minp1 = qMin( minp1, par1 );
2118 maxp1 = qMax( maxp1, par1 );
2119 minp2 = qMin( minp2, par2 );
2120 maxp2 = qMax( maxp2, par2 );
2127 DbgLv(1) <<
" ElLim: minp1 maxp1 m0p1" << minp1 << maxp1 << m0p1
2128 <<
"minp2 maxp2 m0p2" << minp2 << maxp2 << m0p2;
2130 minp1 < m0p1l && maxp1 > m0p1h &&
2131 minp2 < m0p2l && maxp2 > m0p2h )
2135 DbgLv(0) <<
" ElLim: out minyv maxyv" << minyv << maxyv;
2136 DbgLv(0) <<
" ElLim: out min/max p1/p2" << minp1 << maxp1 << minp2 << maxp2;
2148 for (
int ii = 0; ii < sim_vals.
zsolutes.size(); ii++ )
2162 int st_mask = dsets[ 0 ]->solute_type;
2164 for (
int ii = 0; ii < sim_vals.
zsolutes.size(); ii++ )
2182 int ntin = ( ( sim_vals.
noisflag & 1 ) == 0 ) ? 0
2184 int nrin = ( ( sim_vals.
noisflag & 2 ) == 0 ) ? 0
2187 for (
int ii = 0; ii < ntin; ii++ )
2190 for (
int ii = 0; ii < nrin; ii++ )
2195 double rmsd = sqrt( sim_vals.
variance );
2202 int tm_id =
event->timerId();
2206 QObject::timerEvent( event );
2238 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
2248 DbgLv(1) <<
"CFin: isolutes size" << sim_vals.
zsolutes.size();
2249 DbgLv(1) <<
"CFin: zsol0 x y z"
2261 int ktimsc = ( ftimer.elapsed() + 500 ) / 1000;
2262 DbgLv(1) <<
"CFin: nmsol nisol" << nmsol << nisol;
2265 "\nA final best model (RMSD=%1; %2-solute, %3 out; %4 sec.)\n"
2266 " used a Tikhonov regularization parameter of %5 .\n" )
2267 .arg( rmsd ).arg( nisol ).arg( nmsol ).arg( ktimsc ).arg(
alpha );
2277 for (
int ii = 0; ii < nmsol; ii++ )
2289 DbgLv(1) <<
"CFin: ii" << ii <<
"x y c" << solute.
x << solute.
y << solute.
c;
2311 QApplication::restoreOverrideCursor();
2312 DbgLv(0) <<
"CFin: recomputed variance rmsd" << mrec.
variance << rmsd;
2322 errMsg = tr(
"NO ERROR: start" );
2339 double elite_fact = 0.1;
2343 elite_fact = (double)qMax( 1, ( 4 -
fi_iter ) ) * 0.1;
2346 mrecs[ 0 ].variance = elite_fact;
2352 for (
int ii = 0; ii <
mrecs.size(); ii++ )
2357 <<
"nmodels" <<
mrecs.size();
2378 for (
int ktask = 0; ktask <
nmtasks; ktask++ )
2382 double stry =
orig_sols[ ktask ][ 0 ].y;
2383 double endy =
orig_sols[ ktask ][ mm ].y;
2398 for (
int ii = 0; ii <
nthreads; ii++ )
2405 DbgLv(1) <<
"PC:MEM: (5)PcAvail" << mempav;
2413 DbgLv(1) <<
"PC:MEM: (6)PcAvail" << mempav;
2416 tr(
"Starting fit iteration %1 computations of %2 models,\n"
2417 " using %3 threads" )
2418 .arg(
fi_iter ).arg( nmtasks ).arg( nthreads ),
false );
2425 DbgLv(1) <<
"PC:MEM: ClrMem IN rssnow" << memmb;
2433 DbgLv(1) <<
"PC:MEM: ClrMem OUT rssnow" << memmb;