10 #include <qwt_double_interval.h>
11 #include <qwt_scale_widget.h>
12 #include <qwt_scale_draw.h>
22 DbgLv(1) <<
"TRP: RpScan IN";
24 setObjectName(
"US_RpScan" );
25 setAttribute( Qt::WA_DeleteOnClose,
false );
26 setWindowTitle( tr(
"Regularization Parameter (Alpha) Scan" ) );
29 QSize p1size( 560, 480 );
43 QLabel* lb_datctrls =
us_banner( tr(
"PCSA Model Parameters" ) );
44 QLabel* lb_mtype =
us_label( tr(
"Model Type:" ) );
45 QLabel* lb_npoints =
us_label( tr(
"Points per Line:" ) );
46 QLabel* lb_mdlpar1 =
us_label( tr(
"Best Model Par 1:" ) );
47 QLabel* lb_mdlpar2 =
us_label( tr(
"Best Model Par 2:" ) );
48 QLabel* lb_scnctrls =
us_banner( tr(
"Alpha Scan Parameters" ) );
49 QLabel* lb_stralpha =
us_label( tr(
"Starting Alpha:" ) );
50 QLabel* lb_endalpha =
us_label( tr(
"Ending Alpha:" ) );
51 QLabel* lb_incalpha =
us_label( tr(
"Alpha Increment:" ) );
52 QLabel* lb_selalpha =
us_label( tr(
"Selected Alpha:" ) );
53 QLabel* lb_status =
us_label( tr(
"Status:" ) );
61 DbgLv(1) <<
"TRP: nppln" << nppln;
81 lb_mtype ->adjustSize();
84 QFontMetrics fmet( font );
85 int fwidth = fmet.maxWidth();
86 int rheight = lb_mtype->height();
87 int cminw = fwidth * 9;
88 int csizw = cminw + fwidth;
95 DbgLv(1) <<
"TRP: csizw cminw" << csizw << cminw;
122 QString ctype = tr(
"Increasing Sigmoid" );
126 ? tr(
"Straight Line" )
127 : tr(
"Horizontal Line" );
130 ctype = tr(
"Decreasing Sigmoid" );
139 tr(
"Alpha Scan Points" ),
140 tr(
"Variance (x 1e-5)" ),
141 tr(
"Norm of X (solute concentrations)" ) );
145 data_plot1->enableAxis( QwtPlot::xBottom,
true );
146 data_plot1->enableAxis( QwtPlot::yLeft,
true );
149 pick->setRubberBand ( QwtPicker::CrossRubberBand );
150 pick->setMousePattern( QwtEventPattern::MouseSelect1,
164 connect( pb_scan, SIGNAL( clicked() ),
165 this, SLOT (
scan() ) );
166 connect( pb_help, SIGNAL( clicked() ),
167 this, SLOT (
help() ) );
168 connect( pb_cancel, SIGNAL( clicked() ),
170 connect( pb_accept, SIGNAL( clicked() ),
173 DbgLv(1) <<
"TRP: p1size" << p1size;
189 qApp->processEvents();
215 nalpha = qRound( ( ealpha - calpha ) / dalpha ) + 1;
225 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
226 le_stattext->setText( tr(
"Beginning Alpha Scan ..." ) );
228 qApp->processEvents();
230 for (
int ja = 0; ja <
nalpha; ja++ )
240 DbgLv(1) <<
"ASC: nalpha" << nalpha << kalpha <<
"nthr" <<
nthr;
244 QVector< double > csolutes;
247 int nscans =
dsets[ 0 ]->run_data.scanCount();
248 int npoints =
dsets[ 0 ]->run_data.pointCount();
250 le_stattext->setText( tr(
"Beginning Single-Thread Alpha Scan ..." ) );
252 for (
int ja = 0; ja <
nalpha; ja++ )
259 sim_vals.
alpha = calpha;
276 nscans, npoints, nisols, v_vari, v_xnsq );
285 varmx = qMax( varmx, v_vari );
286 xnomx = qMax( xnomx, v_xnsq );
287 QString astat = tr(
"Of %1 models, computed %2 (Alpha %3)" )
288 .arg( nalpha ).arg( kalf ).arg( calpha );
290 DbgLv(1) <<
"a v x" << calpha << v_vari << v_xnsq;
291 qApp->processEvents();
300 le_stattext->setText( tr(
"Beginning %1-Thread Alpha Scan ..." )
302 qApp->processEvents();
310 sim_vals.
alpha = calpha;
321 qDebug() <<
"A0: alpha" << calpha <<
"vari xnsq" << v_vari << v_xnsq
322 <<
"ncsols" << sim_vals.
zsolutes.size();;
329 tr(
"Of %1 models, %2 done (Alpha %3, thread %4)" )
330 .arg( nalpha ).arg(
nacomp ).arg(
alphas[ 0 ] ).arg( 0 );
334 for (
int jt = 0; jt <
nthr; jt++ )
337 calpha =
alphas[ jt + 1 ];
339 sim_vals.
alpha = calpha;
358 DbgLv(1) <<
"ASC: jt" << jt <<
"alpha" << calpha;
369 qApp->processEvents();
376 qApp->processEvents();
380 for (
int ja = 0; ja <
nalpha; ja++ )
382 varmx = qMax( varmx,
varias[ ja ] );
383 xnomx = qMax( xnomx,
xnorms[ ja ] );
387 for (
int jt = 0; jt <
nthr; jt++ )
394 lgv = 0 -(int)qFloor( log10( varmx ) );
395 lgx = -1 -(int)qFloor( log10( xnomx ) );
400 for (
int ja = 0; ja <
nalpha; ja++ )
407 QApplication::restoreOverrideCursor();
408 qApp->processEvents();
410 time_sc = timer.elapsed();
411 int ktimes = ( time_sc + 500 ) / 1000;
412 int ktimeh = ktimes / 3600;
413 int ktimem = ( ktimes - ktimeh * 3600 ) / 60;
414 ktimes = ktimes - ktimeh * 3600 - ktimem * 60;
417 QString astat = tr(
"%1 alphas evaluated in" ).arg( nalpha );
420 astat += tr(
" %1 hr., %2 min., %3 sec." )
421 .arg( ktimeh ).arg( ktimem ).arg( ktimes );
424 astat += tr(
" %1 min., %2 sec." ).arg( ktimem ).arg( ktimes );
426 astat += tr(
", in %1 threads" ).arg( nthr );
428 qApp->processEvents();
443 tr(
"Alpha Scan Points\nAlphas from %1 to %2 by %3" )
444 .arg( alphas[ 0 ] ).arg( alphas[ je ] ).arg( ainc ) );
448 data_plot1->setTitle( tr(
"Alpha Scan Points" ) );
452 tr(
"Variance (x 1e%1)" ).arg(
lgv ) ),
455 tr(
"Norm of X (solute concentrations)" ) :
456 tr(
"Norm of X (solute concentrations x 1e%1)" ).arg(
lgx ) );
460 QwtPlotCurve* curvln;
461 QwtPlotCurve* curvpt;
463 double* xx =
varias.data();
464 double* yy =
xnorms.data();
469 curvln->setPen( pen_plot );
470 curvln->setData( xx, yy,
nalpha );
475 sym.setStyle( QwtSymbol::Ellipse );
476 sym.setPen ( QPen( Qt::blue ) );
477 sym.setBrush( QBrush( Qt::white ) );
479 curvpt->setStyle( QwtPlotCurve::NoCurve );
480 curvpt->setSymbol( sym );
481 curvpt->setData( xx, yy,
nalpha );
490 double* xe = (
double*)xa;
491 double* ye = (
double*)ya;
492 QwtPlotCurve* curvh1;
493 QwtPlotCurve* curvh2;
494 QwtPlotCurve* curvh3;
495 double slope;
double slop2;
496 double intcp;
double intc2;
497 double sigma;
double corre;
498 double xl1p1;
double xl1p2;
double yl1p1;
double yl1p2;
499 double xl2p1;
double xl2p2;
double yl2p1;
double yl2p2;
500 double xl3p1;
double xl3p2;
double yl3p1;
double yl3p2;
501 QPen pen_red ( Qt::red, 0, Qt::DashLine );
502 QPen pen_cyan( Qt::cyan, 0, Qt::DashLine );
510 &sigma, &corre, nlp );
511 DbgLv(1) <<
"TRP:H1: avg" << avg <<
"nlp" << nlp;
512 DbgLv(1) <<
"TRP:H1: sl" << slope <<
"in" << intcp <<
"sg" << sigma
514 if ( slope < 1e99 && slope > (-1e99) )
520 DbgLv(1) <<
"TRP:H1: intcp slope" << intcp << slope;
522 xl1p1 = ( slope == 0.0 ) ? xx[ 0 ] : ( yl1p1 - intcp ) / slope;
524 xl1p2 = ( slope == 0.0 ) ? xl1p1 : ( yl1p2 - intcp ) / slope;
525 DbgLv(1) <<
"TRP:H1: l1: x1,y1,x2,y2" << xl1p1 << yl1p1 << xl1p2 << yl1p2;
529 for (
int jj = 0; jj < 5; jj++, je-- )
533 DbgLv(1) <<
"TRP:H2: jj x y" << jj << xe[jj] << ye[jj] <<
"je" << je;
536 DbgLv(1) <<
"TRP:H2: intcp slope" << intc2 << slop2;
538 yl2p1 = slop2 * xl2p1 + intc2;
540 yl2p2 = slop2 * xl2p2 + intc2;
541 DbgLv(1) <<
"TRP:H2: l2: x1,y1,x2,y2" << xl2p1 << yl2p1 << xl2p2 << yl2p2;
545 DbgLv(1) <<
"TRP:H3: l3: x1,y1" << xl3p1 << yl3p1;
555 double xcvp1 = xx[ 0 ];
556 double ycvp1 = yy[ 0 ];
557 double xcvp2 = xx[ je ];
558 double ycvp2 = yy[ je ];
559 bool do_plot = ( xl3p1 >= xcvp1 && yl3p1 <= ycvp1 &&
560 xl3p1 <= xcvp2 && yl3p1 >= ycvp2 );
561 DbgLv(1) <<
"TRP:T4: cv: x1,y1" << xcvp1 << ycvp1
562 <<
"x2,y2" << xcvp2 << ycvp2 <<
" do_plot" << do_plot;
568 curvh1->setPen( pen_red );
573 curvh1->setData( xh, yh, 2 );
576 curvh2->setPen( pen_red );
581 curvh2->setData( xh, yh, 2 );
584 curvh3->setPen( pen_cyan );
589 DbgLv(1) <<
"TRP:H3: x1,y1,x2,y2" << xl3p1 << yl3p1 << yl3p2 << yl3p2;
590 curvh3->setData( xh, yh, 2 );
600 connect(
pick, SIGNAL( cMouseUp(
const QwtDoublePoint& ) ),
601 this, SLOT (
mouse (
const QwtDoublePoint& ) ) );
617 xloc, yloc, &xcurv, &ycurv,
alphas.data(), &
alpha );
619 alpha = (double)qRound( alpha * 1000.0 ) / 1000.0;
620 QString salpha = QString().sprintf(
"%.3f", alpha );
627 data_plot1->detachItems( QwtPlotItem::Rtti_PlotMarker );
628 QwtPlotMarker* msymbo =
new QwtPlotMarker;
629 QBrush sbrush( Qt::cyan );
630 QPen spen ( sbrush, 2.0 );
631 msymbo->setValue( xcurv, ycurv );
633 QwtSymbol( QwtSymbol::Cross, sbrush, spen, QSize( 8, 8 ) ) );
635 QwtPlotMarker*
marker =
new QwtPlotMarker;
637 label.setText ( salpha );
638 label.setColor( Qt::cyan );
639 marker->setValue( xlabl, ylabl );
640 marker->setLabel( label );
641 marker->setLabelAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
649 DbgLv(1) <<
"SCPJ: IN";
654 int thrn = wresult.
thrn;
655 int taskx = wresult.
taskx;
656 DbgLv(1) <<
"SCPJ: thrn" << thrn <<
"taskx" << taskx;
659 DbgLv(1) <<
"SCPJ: a v x" <<
alphas[taskx] << variance << xnormsq;
660 varias[ taskx ] = variance;
661 xnorms[ taskx ] = xnormsq;
664 tr(
"Of %1 models, %2 done (Alpha %3, thread %4)" )
667 DbgLv(1) <<
"SCPJ: astat" << astat;
671 qApp->processEvents();
672 DbgLv(1) <<
"SCPJ: ALL-DONE";
696 DbgLv(1) <<
"SCPJ: new subm work defined sv_nnls_a" << wtask.
psv_nnls_b;
702 DbgLv(1) <<
"SCPJ: new subm tsk started" <<
nasubm;
704 qApp->processEvents();
708 QVector< double >* psv_nnls_b,
const int nscans,
const int npoints,
709 const int nisols,
double& variance,
double& xnormsq )
711 int ntotal = nscans * npoints;
712 int narows = ntotal + nisols;
716 QVector< double > nnls_a = *psv_nnls_a;
717 QVector< double > nnls_b = *psv_nnls_b;
718 QVector< double > nnls_x;
719 QVector< double > simdat;
720 nnls_x.fill( 0.0, nisols );
721 simdat.fill( 0.0, ntotal );
722 qDebug() <<
"AA: ns np ni na" << nscans << npoints << nisols << narows;
726 int dinc = ntotal + nisols + 1;
728 qDebug() <<
"AA: alf" << alpha <<
"dx dinc" << dx << dinc;
730 for (
int cc = 0; cc < nisols; cc++ )
732 nnls_a[ dx ] =
alpha;
738 nnls_b.data(), nnls_x.data() );
741 for (
int cc = 0; cc < nisols; cc++ )
743 double soluval = nnls_x[ cc ];
747 xnormsq +=
sq( soluval );
749 int aa = cc * narows;
751 for (
int kk = 0; kk < ntotal; kk++ )
753 simdat[ kk ] += ( soluval * (*psv_nnls_a)[ aa++ ] );
759 for (
int kk = 0; kk < ntotal; kk++ )
761 variance +=
sq( ( (*psv_nnls_b)[ kk ] - simdat[ kk ] ) );
763 qDebug() <<
"AA: ntotal" << ntotal <<
"varisum" << variance;
766 variance /= (double)ntotal;
767 qDebug() <<
"AA: alpha" << alpha <<
"vari xnsq" << variance << xnormsq
768 <<
"ncsols" << ncsols;
769 int mm = npoints / 2;
770 qDebug() <<
"AA: mm=" << mm <<
"a[m] b[m] s[m]" << (*psv_nnls_a)[mm]
771 << (*psv_nnls_b)[mm] << simdat[mm];