From 60b5a4ea88173e0c888d229484c662be4b2d4ddb Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Thu, 26 Sep 2024 09:55:20 -0500 Subject: [PATCH 1/4] Added diff in fit params table but may refactor to a single table --- src/mvc/FittingDialog.cpp | 26 ++++++++++++++++++++++++-- src/mvc/FittingDialog.h | 4 ++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/mvc/FittingDialog.cpp b/src/mvc/FittingDialog.cpp index f137d4d..97e0cba 100644 --- a/src/mvc/FittingDialog.cpp +++ b/src/mvc/FittingDialog.cpp @@ -67,6 +67,9 @@ void FittingDialog::_createLayout() _new_fit_params_table_model = new FitParamsTableModel(); _new_fit_params_table_model->setEditable(false); + _diff_fit_params_table_model = new FitParamsTableModel(); + _diff_fit_params_table_model->setEditable(false); + _fit_params_table = new QTableView(); _fit_params_table->setModel(_fit_params_table_model); _fit_params_table->sortByColumn(0, Qt::AscendingOrder); @@ -77,7 +80,7 @@ void FittingDialog::_createLayout() _fit_params_table->setItemDelegateForColumn(5, npDelegate); _fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); _fit_params_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); - _fit_params_table->horizontalHeader()->setSectionResizeMode(2, QHeaderView::ResizeToContents); + _fit_params_table->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents); _new_fit_params_table = new QTableView(); _new_fit_params_table->setModel(_new_fit_params_table_model); @@ -86,7 +89,16 @@ void FittingDialog::_createLayout() _new_fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); _new_fit_params_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + _diff_fit_params_table = new QTableView(); + _diff_fit_params_table->setModel(_diff_fit_params_table_model); + _diff_fit_params_table->sortByColumn(0, Qt::AscendingOrder); + _diff_fit_params_table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive); + _diff_fit_params_table->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); + + connect(_new_fit_params_table->verticalScrollBar(), &QAbstractSlider::valueChanged, _fit_params_table->verticalScrollBar(), &QAbstractSlider::setValue); + connect(_new_fit_params_table->verticalScrollBar(), &QAbstractSlider::valueChanged, _diff_fit_params_table->verticalScrollBar(), &QAbstractSlider::setValue); + _btn_run = new QPushButton("Run"); connect(_btn_run, &QPushButton::released, this, &FittingDialog::runProcessing); @@ -116,7 +128,7 @@ void FittingDialog::_createLayout() QHBoxLayout* hbox_tables = new QHBoxLayout(); hbox_tables->addWidget(_fit_params_table); hbox_tables->addWidget(_new_fit_params_table); - + hbox_tables->addWidget(_diff_fit_params_table); hbox_btn_update->addStretch(); hbox_btn_update->addWidget(_btn_update_fitp); @@ -456,6 +468,16 @@ void FittingDialog::runProcessing() if (false == _canceled) { + data_struct::Fit_Parameters diff_out_fit_params; + for(auto &itr :_out_fit_params) + { + double dif_val = _new_out_fit_params.at(itr.first).value - itr.second.value; + diff_out_fit_params.add_parameter(data_struct::Fit_Param(itr.first, dif_val)); + } + + _diff_fit_params_table_model->setFitParams(diff_out_fit_params); + _diff_fit_params_table_model->only_keep_these_keys(_out_fit_params); + _new_fit_params_table_model->setFitParams(_new_out_fit_params); //don't want to display element counts, so removing them diff --git a/src/mvc/FittingDialog.h b/src/mvc/FittingDialog.h index cb42af9..9caeb54 100644 --- a/src/mvc/FittingDialog.h +++ b/src/mvc/FittingDialog.h @@ -111,10 +111,14 @@ public slots: QTableView* _new_fit_params_table; + QTableView* _diff_fit_params_table; + FitParamsTableModel* _fit_params_table_model; FitParamsTableModel* _new_fit_params_table_model; + FitParamsTableModel* _diff_fit_params_table_model; + SpectraWidget* _spectra_widget; fitting::models::Range _energy_range; From 90f564243b08e94c1583880e0bfa4cf3dafbc93a Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Tue, 1 Oct 2024 10:12:22 -0500 Subject: [PATCH 2/4] Replaced lmfit with nlopt --- CMakeLists.txt | 11 +++-- src/mvc/BatchRoiFitWidget.cpp | 18 +++---- src/mvc/BlueskyComm.h | 2 +- src/mvc/FitSpectraWidget.cpp | 76 ++---------------------------- src/mvc/FitSpectraWidget.h | 2 +- src/mvc/FittingDialog.cpp | 11 ++--- src/mvc/FittingDialog.h | 4 +- src/mvc/NetStreamWorker.h | 2 +- src/mvc/OptimizerOptionsWidget.cpp | 7 ++- src/mvc/OptimizerOptionsWidget.h | 6 +-- 10 files changed, 40 insertions(+), 99 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bcd64b4..fee9f45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,10 +82,11 @@ find_package(Threads) find_package(hdf5 CONFIG REQUIRED) find_package(netCDF CONFIG REQUIRED) find_package(yaml-cpp CONFIG REQUIRED) -find_package(ZeroMQ CONFIG REQUIRED) +find_package(cppzmq CONFIG REQUIRED) find_package(TIFF REQUIRED) find_package(XRF_Maps CONFIG REQUIRED COMPONENTS libxrf_io libxrf_fit) find_package(OpenCV CONFIG REQUIRED) +find_package(NLopt CONFIG REQUIRED) if (libxrf_fit_FOUND) message("Found libxrf_fit") @@ -210,7 +211,7 @@ endforeach() #qt_use_modules(uProbeX Core Widgets Gui) IF (MSVC) set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "/D_WINSOCKAPI_") - set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS_RELEASE "/O3 /Qvec-report:2 /GL /MP /bigobj /Qansi-alias") + set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS_RELEASE "/O2 /Qvec-report:2 /GL /MP /bigobj /Qansi-alias") set_target_properties(uProbeX PROPERTIES LINK_FLAGS "/LTCG") target_link_libraries (uProbeX PRIVATE yaml-cpp::yaml-cpp @@ -228,6 +229,8 @@ IF (MSVC) opencv_flann netCDF::netcdf hdf5::hdf5-shared + cppzmq cppzmq-static + NLopt::nlopt libxrf_fit libxrf_io ${CMAKE_THREAD_LIBS_INIT} @@ -236,7 +239,7 @@ ELSEIF (UNIX) #IF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # set_target_properties(uProbeX PROPERTIES MACOSX_BUNDLE TRUE) #ENDIF() - set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "-O3") + set_target_properties(uProbeX PROPERTIES COMPILE_FLAGS "-O2") target_link_libraries (uProbeX PRIVATE libzmq @@ -250,6 +253,8 @@ ELSEIF (UNIX) opencv_dnn opencv_flann netCDF::netcdf + cppzmq cppzmq-static + NLopt::nlopt libxrf_fit libxrf_io ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/src/mvc/BatchRoiFitWidget.cpp b/src/mvc/BatchRoiFitWidget.cpp index 8797a92..7efcbf8 100644 --- a/src/mvc/BatchRoiFitWidget.cpp +++ b/src/mvc/BatchRoiFitWidget.cpp @@ -53,9 +53,9 @@ void BatchRoiFitWidget::createLayout() _le_detectors = new QLineEdit("0,1,2,3,4,5,6"); _cb_opt_method = new QComboBox(); - _cb_opt_method->addItem(STR_MP_FIT); + _cb_opt_method->addItem(STR_NL_FIT); _cb_opt_method->addItem(STR_HYBRID_MP_FIT); - _cb_opt_method->addItem(STR_LM_FIT); + _cb_opt_method->addItem(STR_MP_FIT); connect(_cb_opt_method, &QComboBox::currentTextChanged, this, &BatchRoiFitWidget::optimizer_changed); _file_list_model = new QStandardItemModel(); @@ -80,8 +80,8 @@ void BatchRoiFitWidget::createLayout() detector_hbox->addWidget(_le_detectors); _optimizer_widget = new OptimizerOptionsWidget(); - fitting::optimizers::LMFit_Optimizer lmfit_optimizer; - _optimizer_widget->setOptimizer(STR_LM_FIT, lmfit_optimizer); + fitting::optimizers::NLOPT_Optimizer optimizer; + _optimizer_widget->setOptimizer(STR_NL_FIT, optimizer); QVBoxLayout* layout = new QVBoxLayout(); layout->addItem(detector_hbox); @@ -99,10 +99,10 @@ void BatchRoiFitWidget::createLayout() void BatchRoiFitWidget::optimizer_changed(QString val) { - if (val == STR_LM_FIT) + if (val == STR_NL_FIT) { - fitting::optimizers::LMFit_Optimizer lmfit_optimizer; - _optimizer_widget->setOptimizer(val, lmfit_optimizer); + fitting::optimizers::NLOPT_Optimizer optimizer; + _optimizer_widget->setOptimizer(val, optimizer); } else if (val == STR_MP_FIT || val == STR_HYBRID_MP_FIT) { @@ -197,7 +197,7 @@ void BatchRoiFitWidget::runProcessing() analysis_job.dataset_directory = _directory; if (_cb_opt_method->currentText() == STR_HYBRID_MP_FIT) { - analysis_job.set_optimizer("mpfit"); + analysis_job.set_optimizer("nlopt"); analysis_job.optimize_fit_routine = OPTIMIZE_FIT_ROUTINE::HYBRID; } else @@ -208,7 +208,7 @@ void BatchRoiFitWidget::runProcessing() } else { - analysis_job.set_optimizer("lmfit"); + analysis_job.set_optimizer("nlopt"); } } diff --git a/src/mvc/BlueskyComm.h b/src/mvc/BlueskyComm.h index d94fc9a..c5cb42c 100644 --- a/src/mvc/BlueskyComm.h +++ b/src/mvc/BlueskyComm.h @@ -12,7 +12,7 @@ #include #include #include -#include "support/zmq/zmq.hpp" +#include #include "mvc/BlueskyPlan.h" #include //--------------------------------------------------------------------------- diff --git a/src/mvc/FitSpectraWidget.cpp b/src/mvc/FitSpectraWidget.cpp index 9d9ba8f..134a92a 100644 --- a/src/mvc/FitSpectraWidget.cpp +++ b/src/mvc/FitSpectraWidget.cpp @@ -21,7 +21,6 @@ #include "data_struct/element_info.h" #include "io/file/hl_file_io.h" -#include "fitting//optimizers/lmfit_optimizer.h" #include #include #include "io/file/aps/aps_roi.h" @@ -250,10 +249,10 @@ void FitSpectraWidget::createLayout() _cb_opttimizer = new QComboBox(); - _cb_opttimizer->addItem(STR_MP_FIT); + _cb_opttimizer->addItem(STR_NL_FIT); _cb_opttimizer->addItem(STR_HYBRID_MP_FIT); - _cb_opttimizer->addItem(STR_LM_FIT); - connect(_cb_opttimizer, &QComboBox::currentTextChanged, this, &FitSpectraWidget::optimizer_changed); + _cb_opttimizer->addItem(STR_MP_FIT); +// connect(_cb_opttimizer, &QComboBox::currentTextChanged, this, &FitSpectraWidget::optimizer_changed); _chk_auto_model = new QCheckBox("Auto Update Model"); _chk_auto_model->setChecked(false); @@ -315,7 +314,8 @@ void FitSpectraWidget::createLayout() _cb_fitting_preset->setCurrentIndex(3); //optimizer_preset_changed(3); // batch with tails - optimizer_changed(STR_MP_FIT); + + _cb_opttimizer->setCurrentText(STR_NL_FIT); QLayout* layout = new QVBoxLayout(); // layout->addWidget(splitter); @@ -892,13 +892,6 @@ void FitSpectraWidget::Fit_Spectra_Click() if(_elements_to_fit != nullptr && _int_spec != nullptr) { - ////std::lock_guard lock(_mutex); - - //fitting::optimizers::LMFit_Optimizer lmfit_optimizer; - //fitting::optimizers::MPFit_Optimizer mpfit_optimizer; - //fitting::models::Gaussian_Model model; - - data_struct::Fit_Parameters out_fit_params = _fit_params_table_model->getFitParams(); data_struct::Fit_Parameters element_fit_params = _fit_elements_table_model->getAsFitParams(); @@ -921,51 +914,6 @@ void FitSpectraWidget::Fit_Spectra_Click() _spectra_widget->getDisplayHeightMax()); _fitting_dialog->exec(); - //Range of energy in spectra to fit - //fitting::models::Range energy_range; - //energy_range.min = 0; - //energy_range.max = _int_spec->rows() -1; - - //data_struct::Spectra s1 = _integrated_spectra.sub_spectra(energy_range); - - //Fitting routines - //fitting::routines::Param_Optimized_Fit_Routine fit_routine; - //fit_routine.set_update_coherent_amplitude_on_fit(false); - - //if(_cb_opttimizer->currentText() == STR_LM_FIT) - //{ - // fit_routine.set_optimizer(&lmfit_optimizer); - //} - //else if(_cb_opttimizer->currentText() == STR_MP_FIT) - //{ - // fit_routine.set_optimizer(&mpfit_optimizer); - //} - - //reset model fit parameters to defaults - //model.reset_to_default_fit_params(); - //Update fit parameters by override values - //model.update_fit_params_values(&out_fit_params); - //model.update_and_add_fit_params_values_gt_zero(&element_fit_params); - - //model.set_fit_params_preset(fitting::models::Fit_Params_Preset::BATCH_FIT_WITH_TAILS); - - //Initialize the fit routine - //fit_routine.initialize(&model, _elements_to_fit, energy_range); - - //Fit the spectra saving the element counts in element_fit_count_dict - // single threaded - //out_fit_params = fit_routine.fit_spectra_parameters(&model, int_spectra, _elements_to_fit); - // use background thread to not freeze up the gui - //std::future ret = global_threadpool.enqueue(&fitting::routines::Param_Optimized_Fit_Routine::fit_spectra_parameters, fit_routine, &model, (Spectra*)_int_spec, _elements_to_fit); - - //while (ret._Is_ready() == false) - //{ - // QCoreApplication::processEvents(); - //} - //out_fit_params = ret.get(); - - //out_fit_params = fit_routine.fit_spectra_parameters(&model, &s1, _elements_to_fit); - if (_fitting_dialog->accepted_fit()) { @@ -1362,20 +1310,6 @@ void FitSpectraWidget::optimizer_preset_changed(int val) //--------------------------------------------------------------------------- - -void FitSpectraWidget::optimizer_changed(QString val) -{ - if(val == STR_LM_FIT) - _fit_params_table_model->setOptimizerSupportsMinMax(false); - else if(val == STR_MP_FIT || val == STR_HYBRID_MP_FIT) - _fit_params_table_model->setOptimizerSupportsMinMax(true); - - _fit_params_table->resizeColumnToContents(0); - -} - -//--------------------------------------------------------------------------- - void FitSpectraWidget::setIntegratedSpectra(ArrayDr* int_spec) { { diff --git a/src/mvc/FitSpectraWidget.h b/src/mvc/FitSpectraWidget.h index 7ee7e12..fc6a327 100644 --- a/src/mvc/FitSpectraWidget.h +++ b/src/mvc/FitSpectraWidget.h @@ -108,7 +108,7 @@ public slots: void check_auto_model(int state); - void optimizer_changed(QString val); + //void optimizer_changed(QString val); void optimizer_preset_changed(int idx); diff --git a/src/mvc/FittingDialog.cpp b/src/mvc/FittingDialog.cpp index 97e0cba..c00ffee 100644 --- a/src/mvc/FittingDialog.cpp +++ b/src/mvc/FittingDialog.cpp @@ -63,6 +63,7 @@ void FittingDialog::_createLayout() NumericPrecDelegate* npDelegate = new NumericPrecDelegate(); _fit_params_table_model = new FitParamsTableModel(); + _fit_params_table_model->setOptimizerSupportsMinMax(true); _new_fit_params_table_model = new FitParamsTableModel(); _new_fit_params_table_model->setEditable(false); @@ -214,26 +215,22 @@ void FittingDialog::updateFitParams(data_struct::Fit_Parameters out_fit_ void FittingDialog::setOptimizer(QString opt) { - if (opt == STR_LM_FIT) + if (opt == STR_NL_FIT) { - _optimizer = &_lmfit_optimizer; + _optimizer = &_nlfit_optimizer; _param_fit_routine.set_optimizer(_optimizer); - _is_hybrid_fit = false; - _fit_params_table_model->setOptimizerSupportsMinMax(false); } else if (opt == STR_MP_FIT) { _optimizer = &_mpfit_optimizer; _param_fit_routine.set_optimizer(_optimizer); _is_hybrid_fit = false; - _fit_params_table_model->setOptimizerSupportsMinMax(true); } else if (opt == STR_HYBRID_MP_FIT) { - _optimizer = &_mpfit_optimizer; + _optimizer = &_nlfit_optimizer; _is_hybrid_fit = true; _hybrid_fit_routine.set_optimizer(_optimizer); - _fit_params_table_model->setOptimizerSupportsMinMax(true); } _optimizer_widget->setOptimizer(opt, *_optimizer); } diff --git a/src/mvc/FittingDialog.h b/src/mvc/FittingDialog.h index 9caeb54..a4b3294 100644 --- a/src/mvc/FittingDialog.h +++ b/src/mvc/FittingDialog.h @@ -32,7 +32,7 @@ #include "mvc/ComboBoxDelegate.h" #include "mvc/FitParamsTableModel.h" #include "mvc/SpectraWidget.h" -#include "fitting//optimizers/lmfit_optimizer.h" +#include "fitting//optimizers/nlopt_optimizer.h" #include "fitting//optimizers/mpfit_optimizer.h" #include "fitting/routines/param_optimized_fit_routine.h" #include "fitting/routines/hybrid_param_nnls_fit_routine.h" @@ -151,7 +151,7 @@ public slots: OptimizerOptionsWidget* _optimizer_widget; - fitting::optimizers::LMFit_Optimizer _lmfit_optimizer; + fitting::optimizers::NLOPT_Optimizer _nlfit_optimizer; fitting::optimizers::MPFit_Optimizer _mpfit_optimizer; diff --git a/src/mvc/NetStreamWorker.h b/src/mvc/NetStreamWorker.h index 5a8f26f..8bfe1fb 100644 --- a/src/mvc/NetStreamWorker.h +++ b/src/mvc/NetStreamWorker.h @@ -9,7 +9,7 @@ //--------------------------------------------------------------------------- #include -#include "support/zmq/zmq.hpp" +#include #include "io/net/basic_serializer.h" #include //--------------------------------------------------------------------------- diff --git a/src/mvc/OptimizerOptionsWidget.cpp b/src/mvc/OptimizerOptionsWidget.cpp index aeac8e3..c780c85 100644 --- a/src/mvc/OptimizerOptionsWidget.cpp +++ b/src/mvc/OptimizerOptionsWidget.cpp @@ -160,7 +160,11 @@ void OptimizerOptionsWidget::_createLayout() void OptimizerOptionsWidget::setOptimizer(QString opt, fitting::optimizers::Optimizer& optimizer) { - if (opt == STR_LM_FIT) + + _mp_fit_ctrl_grp->setVisible(false); + _lm_fit_ctrl_grp->setVisible(false); + /* + if (opt == STR_NL_FIT) { _mp_fit_ctrl_grp->setVisible(false); _lm_fit_ctrl_grp->setVisible(true); @@ -175,6 +179,7 @@ void OptimizerOptionsWidget::setOptimizer(QString opt, fitting::optimizers::Opti _lm_fit_ctrl_grp->setVisible(false); _mp_fit_ctrl_grp->setVisible(true); } + */ updateGUIOptimizerOptions(optimizer); } diff --git a/src/mvc/OptimizerOptionsWidget.h b/src/mvc/OptimizerOptionsWidget.h index b0a1d7e..df8846c 100644 --- a/src/mvc/OptimizerOptionsWidget.h +++ b/src/mvc/OptimizerOptionsWidget.h @@ -18,16 +18,16 @@ #include #include #include "mvc/ComboBoxDelegate.h" -#include "fitting//optimizers/lmfit_optimizer.h" +#include "fitting//optimizers/nlopt_optimizer.h" #include "fitting//optimizers/mpfit_optimizer.h" #include "fitting/routines/param_optimized_fit_routine.h" #include "fitting/routines/hybrid_param_nnls_fit_routine.h" //--------------------------------------------------------------------------- -const static QString STR_LM_FIT = "Levenberg-Marquardt Fit"; +const static QString STR_NL_FIT = "NL Opt"; const static QString STR_MP_FIT = "MP Fit"; -const static QString STR_HYBRID_MP_FIT = "Hybrid MP Fit"; +const static QString STR_HYBRID_MP_FIT = "Hybrid NL Opt"; //--------------------------------------------------------------------------- From 8e766fa3f3606281c56cc084366819dc73c1f34b Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Wed, 2 Oct 2024 07:51:16 -0500 Subject: [PATCH 3/4] Set fit params to show min max by default. Change red warning background to be < instead of <= --- src/mvc/FitParamsTableModel.cpp | 4 ++-- src/mvc/FitSpectraWidget.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mvc/FitParamsTableModel.cpp b/src/mvc/FitParamsTableModel.cpp index 94dbdb6..6fa70ad 100644 --- a/src/mvc/FitParamsTableModel.cpp +++ b/src/mvc/FitParamsTableModel.cpp @@ -189,7 +189,7 @@ QVariant FitParamsTableModel::data(const QModelIndex &index, int role) const { if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI) { - if (fitp.value <= fitp.min_val) + if (fitp.value < fitp.min_val) { return QColor(Qt::red); } @@ -199,7 +199,7 @@ QVariant FitParamsTableModel::data(const QModelIndex &index, int role) const { if (fitp.bound_type == data_struct::E_Bound_Type::LIMITED_HI || fitp.bound_type == data_struct::E_Bound_Type::LIMITED_LO_HI) { - if (fitp.value >= fitp.max_val) + if (fitp.value > fitp.max_val) { return QColor(Qt::red); } diff --git a/src/mvc/FitSpectraWidget.cpp b/src/mvc/FitSpectraWidget.cpp index 134a92a..02a8c9d 100644 --- a/src/mvc/FitSpectraWidget.cpp +++ b/src/mvc/FitSpectraWidget.cpp @@ -137,6 +137,7 @@ void FitSpectraWidget::createLayout() _fit_params_table_model = new FitParamsTableModel(); _fit_params_table_model->setFitParams(g_model.fit_parameters()); + _fit_params_table_model->setOptimizerSupportsMinMax(true); connect(_fit_params_table_model, &FitParamsTableModel::onEnergyChange, this, &FitSpectraWidget::replot_integrated_spectra_with_background); ComboBoxDelegate *cbDelegate = new ComboBoxDelegate(bound_types); NumericPrecDelegate* npDelegate = new NumericPrecDelegate(); @@ -160,6 +161,7 @@ void FitSpectraWidget::createLayout() SLOT(fit_params_customMenuRequested(QPoint))); _fit_elements_table_model = new FitElementsTableModel(_detector_element); + //_fit_elements_table_model->setDisplayHeaderMinMax(true); connect(_spectra_widget, SIGNAL(y_axis_changed(bool)), _fit_elements_table_model, SLOT(update_counts_log10(bool))); connect(_fit_elements_table_model, &FitElementsTableModel::braching_ratio_changed, this, &FitSpectraWidget::on_braching_ratio_update); From 15cd7d58573e81fe71417278afb90b3023cbfb79 Mon Sep 17 00:00:00 2001 From: Arthur Glowacki Date: Thu, 3 Oct 2024 10:48:19 -0500 Subject: [PATCH 4/4] Removed mpfit, replaced with nlopt --- src/mvc/BatchRoiFitWidget.cpp | 39 +------- src/mvc/BatchRoiFitWidget.h | 4 - src/mvc/FitElementsTableModel.h | 2 +- src/mvc/FitSpectraWidget.cpp | 15 +-- src/mvc/FitSpectraWidget.h | 4 - src/mvc/FittingDialog.cpp | 52 ++++------ src/mvc/FittingDialog.h | 11 +- src/mvc/MapsH5Model.h | 1 - src/mvc/OptimizerOptionsWidget.cpp | 156 ++++++++++++++++------------- src/mvc/OptimizerOptionsWidget.h | 31 +++--- src/mvc/RawH5Model.h | 1 - 11 files changed, 134 insertions(+), 182 deletions(-) diff --git a/src/mvc/BatchRoiFitWidget.cpp b/src/mvc/BatchRoiFitWidget.cpp index 7efcbf8..921e1ab 100644 --- a/src/mvc/BatchRoiFitWidget.cpp +++ b/src/mvc/BatchRoiFitWidget.cpp @@ -51,12 +51,6 @@ void BatchRoiFitWidget::createLayout() connect(_btn_cancel, &QPushButton::released, this, &BatchRoiFitWidget::onClose); _le_detectors = new QLineEdit("0,1,2,3,4,5,6"); - - _cb_opt_method = new QComboBox(); - _cb_opt_method->addItem(STR_NL_FIT); - _cb_opt_method->addItem(STR_HYBRID_MP_FIT); - _cb_opt_method->addItem(STR_MP_FIT); - connect(_cb_opt_method, &QComboBox::currentTextChanged, this, &BatchRoiFitWidget::optimizer_changed); _file_list_model = new QStandardItemModel(); _file_list_view = new QListView(); @@ -81,11 +75,10 @@ void BatchRoiFitWidget::createLayout() _optimizer_widget = new OptimizerOptionsWidget(); fitting::optimizers::NLOPT_Optimizer optimizer; - _optimizer_widget->setOptimizer(STR_NL_FIT, optimizer); + _optimizer_widget->setOptimizer(optimizer); QVBoxLayout* layout = new QVBoxLayout(); layout->addItem(detector_hbox); - layout->addWidget(_cb_opt_method); layout->addWidget(_optimizer_widget); layout->addWidget(_file_list_view); layout->addItem(buttonlayout); @@ -97,20 +90,6 @@ void BatchRoiFitWidget::createLayout() //--------------------------------------------------------------------------- -void BatchRoiFitWidget::optimizer_changed(QString val) -{ - if (val == STR_NL_FIT) - { - fitting::optimizers::NLOPT_Optimizer optimizer; - _optimizer_widget->setOptimizer(val, optimizer); - } - else if (val == STR_MP_FIT || val == STR_HYBRID_MP_FIT) - { - fitting::optimizers::MPFit_Optimizer mpfit_optimizer; - _optimizer_widget->setOptimizer(val, mpfit_optimizer); - } -} - void BatchRoiFitWidget::onClose() { _canceled = true; @@ -189,27 +168,17 @@ void BatchRoiFitWidget::runProcessing() QCoreApplication::processEvents(); data_struct::Analysis_Job analysis_job; - QString val = _cb_opt_method->currentText(); - analysis_job.set_optimizer(val.toStdString()); - + //analysis_job.set_optimizer_algorithm(); //run in thread analysis_job.dataset_directory = _directory; - if (_cb_opt_method->currentText() == STR_HYBRID_MP_FIT) + if (_optimizer_widget->isHybrid()) { - analysis_job.set_optimizer("nlopt"); analysis_job.optimize_fit_routine = OPTIMIZE_FIT_ROUTINE::HYBRID; } else { - if (_cb_opt_method->currentText() == STR_MP_FIT) - { - analysis_job.set_optimizer("mpfit"); - } - else - { - analysis_job.set_optimizer("nlopt"); - } + analysis_job.optimize_fit_routine = OPTIMIZE_FIT_ROUTINE::ALL_PARAMS; } _optimizer_widget->updateOptimizerOptions(*(analysis_job.optimizer())); diff --git a/src/mvc/BatchRoiFitWidget.h b/src/mvc/BatchRoiFitWidget.h index f80d01a..9cdc1bb 100644 --- a/src/mvc/BatchRoiFitWidget.h +++ b/src/mvc/BatchRoiFitWidget.h @@ -56,8 +56,6 @@ class BatchRoiFitWidget : public QWidget public slots: void runProcessing(); - - void optimizer_changed(QString val); void onClose(); @@ -86,8 +84,6 @@ public slots: QLineEdit* _le_detectors; - QComboBox* _cb_opt_method; - std::unordered_map _roi_map; size_t _total_itr; diff --git a/src/mvc/FitElementsTableModel.h b/src/mvc/FitElementsTableModel.h index 6e26bf1..3f4b995 100644 --- a/src/mvc/FitElementsTableModel.h +++ b/src/mvc/FitElementsTableModel.h @@ -46,7 +46,7 @@ class FitElementsTableModel ~FitElementsTableModel(); - void setDisplayHeaderMinMax(bool val); + //void setDisplayHeaderMinMax(bool val); data_struct::Fit_Element_Map_Dict getElementsToFit(); diff --git a/src/mvc/FitSpectraWidget.cpp b/src/mvc/FitSpectraWidget.cpp index 02a8c9d..b2e9b22 100644 --- a/src/mvc/FitSpectraWidget.cpp +++ b/src/mvc/FitSpectraWidget.cpp @@ -249,13 +249,6 @@ void FitSpectraWidget::createLayout() _cb_fitting_preset->addItem("Fit No Tails Energy Quadratic"); connect(_cb_fitting_preset, &QComboBox::currentIndexChanged, this, &FitSpectraWidget::optimizer_preset_changed); - - _cb_opttimizer = new QComboBox(); - _cb_opttimizer->addItem(STR_NL_FIT); - _cb_opttimizer->addItem(STR_HYBRID_MP_FIT); - _cb_opttimizer->addItem(STR_MP_FIT); -// connect(_cb_opttimizer, &QComboBox::currentTextChanged, this, &FitSpectraWidget::optimizer_changed); - _chk_auto_model = new QCheckBox("Auto Update Model"); _chk_auto_model->setChecked(false); connect(_chk_auto_model, @@ -272,7 +265,6 @@ void FitSpectraWidget::createLayout() orient_layout = new QHBoxLayout(); //splitter->setOrientation(Qt::Horizontal); grid_layout->addWidget(_cb_fitting_preset, 0, 0); - grid_layout->addWidget(_cb_opttimizer, 0, 1); grid_layout->addWidget(_btn_fit_spectra, 1, 0); grid_layout->addWidget(_btn_fit_roi_spectra, 1, 1); @@ -288,7 +280,6 @@ void FitSpectraWidget::createLayout() orient_layout = new QVBoxLayout(); //splitter->setOrientation(Qt::Vertical); grid_layout->addWidget(_cb_fitting_preset, 0, 0); - grid_layout->addWidget(_cb_opttimizer, 0, 1); grid_layout->addWidget(_chk_auto_model, 0, 2); grid_layout->addWidget(_btn_export_csv, 0, 3); @@ -317,8 +308,6 @@ void FitSpectraWidget::createLayout() _cb_fitting_preset->setCurrentIndex(3); //optimizer_preset_changed(3); // batch with tails - _cb_opttimizer->setCurrentText(STR_NL_FIT); - QLayout* layout = new QVBoxLayout(); // layout->addWidget(splitter); layout->addItem(orient_layout); @@ -903,7 +892,7 @@ void FitSpectraWidget::Fit_Spectra_Click() _fitting_dialog = new FittingDialog(); } _fitting_dialog->updateFitParams(out_fit_params, element_fit_params); - _fitting_dialog->setOptimizer(_cb_opttimizer->currentText()); + // _fitting_dialog->setOptimizer(_cb_opttimizer->currentText()); _fitting_dialog->setSpectra((Spectra*)_int_spec, _ev); _fitting_dialog->setElementsToFit(_elements_to_fit); if (_fit_spec.size() > 0) @@ -1054,7 +1043,7 @@ void FitSpectraWidget::Fit_ROI_Spectra_Click() _fitting_dialog = new FittingDialog(); } _fitting_dialog->updateFitParams(out_fit_params, element_fit_params); - _fitting_dialog->setOptimizer(_cb_opttimizer->currentText()); + //_fitting_dialog->setOptimizer(_cb_opttimizer->currentText()); _fitting_dialog->setSpectra((Spectra*)roi_spec, _ev); _fitting_dialog->setElementsToFit(_elements_to_fit); if (_fit_spec.size() > 0) diff --git a/src/mvc/FitSpectraWidget.h b/src/mvc/FitSpectraWidget.h index fc6a327..a102e28 100644 --- a/src/mvc/FitSpectraWidget.h +++ b/src/mvc/FitSpectraWidget.h @@ -108,8 +108,6 @@ public slots: void check_auto_model(int state); - //void optimizer_changed(QString val); - void optimizer_preset_changed(int idx); // void element_clicked(QModelIndex index); @@ -193,8 +191,6 @@ private slots: QCheckBox *_chk_auto_model; - QComboBox *_cb_opttimizer; - QComboBox *_cb_fitting_preset; QTabWidget *_fit_params_tab_widget; diff --git a/src/mvc/FittingDialog.cpp b/src/mvc/FittingDialog.cpp index c00ffee..4f52771 100644 --- a/src/mvc/FittingDialog.cpp +++ b/src/mvc/FittingDialog.cpp @@ -25,10 +25,25 @@ FittingDialog::FittingDialog(QWidget *parent) : QDialog(parent) _accepted = false; _canceled = false; _running = false; - _is_hybrid_fit = false; _elements_to_fit = nullptr; _param_fit_routine.set_update_coherent_amplitude_on_fit(false); + _param_fit_routine.set_optimizer(&_nlopt_optimizer); _hybrid_fit_routine.set_update_coherent_amplitude_on_fit(false); + _hybrid_fit_routine.set_optimizer(&_nlopt_optimizer); + +/* +void FittingDialog::setOptimizer(QString opt) +{ + _param_fit_routine.set_optimizer(_optimizer); + + _is_hybrid_fit = true; + _hybrid_fit_routine.set_optimizer(_optimizer); + } + _optimizer_widget->setOptimizer(opt, _nlopt_optimizer); +} + +*/ + ////_model.set_num_threads(std::thread::hardware_concurrency()); _createLayout(); } @@ -143,6 +158,7 @@ void FittingDialog::_createLayout() hbox_progresss_blocks->addWidget(_progressBarBlocks); _optimizer_widget = new OptimizerOptionsWidget(); + _optimizer_widget->setOptimizer(_nlopt_optimizer); QVBoxLayout* layout = new QVBoxLayout(); @@ -211,31 +227,6 @@ void FittingDialog::updateFitParams(data_struct::Fit_Parameters out_fit_ _btn_accept->setEnabled(false); } -//--------------------------------------------------------------------------- - -void FittingDialog::setOptimizer(QString opt) -{ - if (opt == STR_NL_FIT) - { - _optimizer = &_nlfit_optimizer; - _param_fit_routine.set_optimizer(_optimizer); - } - else if (opt == STR_MP_FIT) - { - _optimizer = &_mpfit_optimizer; - _param_fit_routine.set_optimizer(_optimizer); - _is_hybrid_fit = false; - } - else if (opt == STR_HYBRID_MP_FIT) - { - _optimizer = &_nlfit_optimizer; - _is_hybrid_fit = true; - _hybrid_fit_routine.set_optimizer(_optimizer); - } - _optimizer_widget->setOptimizer(opt, *_optimizer); -} - - //--------------------------------------------------------------------------- void FittingDialog::setSpectra(data_struct::Spectra* spectra, ArrayDr energy) @@ -366,8 +357,7 @@ void FittingDialog::runProcessing() bool use_weights = _optimizer_widget->useWeights(); - _optimizer_widget->updateOptimizerOptions(*_optimizer); - + _optimizer_widget->updateOptimizerOptions(_nlopt_optimizer); //data_struct::Spectra s1 = _integrated_spectra.sub_spectra(energy_range); //Fitting routines @@ -384,7 +374,7 @@ void FittingDialog::runProcessing() //_model.set_fit_params_preset(fitting::models::Fit_Params_Preset::BATCH_FIT_WITH_TAILS); //Initialize the fit routine - if (_is_hybrid_fit) + if (_optimizer_widget->isHybrid()) { _hybrid_fit_routine.initialize(&_model, _elements_to_fit, _energy_range); } @@ -400,7 +390,7 @@ void FittingDialog::runProcessing() Callback_Func_Status_Def cb_func = std::bind(&FittingDialog::status_callback, this, std::placeholders::_1, std::placeholders::_2); try { - if (_is_hybrid_fit) + if (_optimizer_widget->isHybrid()) { _outcome = _hybrid_fit_routine.fit_spectra_parameters(&_model, &_int_spec, _elements_to_fit, use_weights, _new_out_fit_params, &cb_func); } @@ -412,7 +402,7 @@ void FittingDialog::runProcessing() std::string out_str = optimizer_outcome_to_str(_outcome); _le_outcome->setText(QString(out_str.c_str())); - std::string det_out = _optimizer->get_last_detailed_outcome(); + std::string det_out = _nlopt_optimizer.get_last_detailed_outcome(); _le_detailed_outcome->setText(QString(det_out.c_str())); if (_new_out_fit_params.contains(STR_RESIDUAL)) diff --git a/src/mvc/FittingDialog.h b/src/mvc/FittingDialog.h index a4b3294..27cadeb 100644 --- a/src/mvc/FittingDialog.h +++ b/src/mvc/FittingDialog.h @@ -33,7 +33,6 @@ #include "mvc/FitParamsTableModel.h" #include "mvc/SpectraWidget.h" #include "fitting//optimizers/nlopt_optimizer.h" -#include "fitting//optimizers/mpfit_optimizer.h" #include "fitting/routines/param_optimized_fit_routine.h" #include "fitting/routines/hybrid_param_nnls_fit_routine.h" #include "fitting/models/gaussian_model.h" @@ -65,8 +64,6 @@ class FittingDialog : public QDialog void status_callback(size_t cur_block, size_t total_blocks); - void setOptimizer(QString opt); - bool accepted_fit() { return _accepted; } void setSpectra(data_struct::Spectra* spectra, ArrayDr energy); @@ -151,11 +148,7 @@ public slots: OptimizerOptionsWidget* _optimizer_widget; - fitting::optimizers::NLOPT_Optimizer _nlfit_optimizer; - - fitting::optimizers::MPFit_Optimizer _mpfit_optimizer; - - fitting::optimizers::Optimizer*_optimizer; + fitting::optimizers::NLOPT_Optimizer _nlopt_optimizer; std::unordered_map _labeled_spectras; @@ -185,8 +178,6 @@ public slots: ArrayDr _spectra_background; - bool _is_hybrid_fit; - // energy vector ArrayDr _ev; diff --git a/src/mvc/MapsH5Model.h b/src/mvc/MapsH5Model.h index 70b6f47..a499bff 100644 --- a/src/mvc/MapsH5Model.h +++ b/src/mvc/MapsH5Model.h @@ -19,7 +19,6 @@ #include "core/defines.h" #include "io/file/hdf5_io.h" #include "fitting/routines/param_optimized_fit_routine.h" -#include "fitting/optimizers/mpfit_optimizer.h" #include "fitting/models/gaussian_model.h" #include "data_struct/stream_block.h" diff --git a/src/mvc/OptimizerOptionsWidget.cpp b/src/mvc/OptimizerOptionsWidget.cpp index c780c85..af261fb 100644 --- a/src/mvc/OptimizerOptionsWidget.cpp +++ b/src/mvc/OptimizerOptionsWidget.cpp @@ -12,16 +12,17 @@ //--------------------------------------------------------------------------- -const QString tip_ftol = "Relative error desired in the sum of squares. Termination occurs when both the actual and predicted relative reductions in the sum of squares are at most ftol."; +//const QString tip_ftol = "Relative error desired in the sum of squares. Termination occurs when both the actual and predicted relative reductions in the sum of squares are at most ftol."; const QString tip_xtol = "Relative error between last two approximations. Termination occurs when the relative error between two consecutive iterates is at most xtol."; -const QString tip_gtol = "Orthogonality desired between fvec and its derivs. Termination occurs when the cosine of the angle between fvec and any column of the Jacobian is at most gtol in absolute value."; -const QString tip_epsilon = "Step used to calculate the Jacobian, should be slightly larger than the relative error in the user-supplied functions."; -const QString tip_step = "Used in determining the initial step bound. This bound is set to the product of stepbound and the Euclidean norm of diag*x if nonzero, or else to stepbound itself. In most cases stepbound should lie in the interval (0.1,100.0). Generally, the value 100.0 is recommended."; +//const QString tip_gtol = "Orthogonality desired between fvec and its derivs. Termination occurs when the cosine of the angle between fvec and any column of the Jacobian is at most gtol in absolute value."; +//const QString tip_epsilon = "Step used to calculate the Jacobian, should be slightly larger than the relative error in the user-supplied functions."; +//const QString tip_step = "Used in determining the initial step bound. This bound is set to the product of stepbound and the Euclidean norm of diag*x if nonzero, or else to stepbound itself. In most cases stepbound should lie in the interval (0.1,100.0). Generally, the value 100.0 is recommended."; const QString tip_maxitr = "Used to set the maximum number of function evaluations to maxiter*(number_of_parameters+1)."; -const QString tip_scale = "If 1, the variables will be rescaled internally. Recommended value is 1."; -const QString tip_covtol = "Range tolerance for covariance calculation Default: 1e-14"; -const QString tip_verbose = "OR'ed: 1: print some messages; 2: print Jacobian."; +//const QString tip_scale = "If 1, the variables will be rescaled internally. Recommended value is 1."; +//const QString tip_covtol = "Range tolerance for covariance calculation Default: 1e-14"; +//const QString tip_verbose = "OR'ed: 1: print some messages; 2: print Jacobian."; +const QString tip_general = "General passes fit parameters and element amplitudes to optimzier, Hybrid passes only fit parameters to optimizer and calls NNLS for element amplitudes."; //--------------------------------------------------------------------------- @@ -44,16 +45,28 @@ void OptimizerOptionsWidget::_createLayout() QGridLayout* optimizerLayout = new QGridLayout(); + _cb_optimization_type = new QComboBox(); + _cb_optimization_type->addItem(STR_GENERAL_FIT); + _cb_optimization_type->addItem(STR_HYBRID_FIT); + _cb_optimization_type->setCurrentIndex(0); + QLabel* lbl_opt_type = new QLabel("Optimization Type: "); + lbl_opt_type->setToolTip(tip_general); + + + _cb_algorithm = new QComboBox(); + QLabel* lbl_algo = new QLabel("Algorithm: "); + //lbl_algo->setToolTip(tip_xtol); +/* _opt_ftol = new QLineEdit(); _opt_ftol->setToolTip(tip_ftol); QLabel* lbl_ftol = new QLabel("FTol: "); lbl_ftol->setToolTip(tip_ftol); - + */ _opt_xtol = new QLineEdit(); _opt_xtol->setToolTip(tip_xtol); QLabel* lbl_xtol = new QLabel("XTol: "); lbl_xtol->setToolTip(tip_xtol); - +/* _opt_gtol = new QLineEdit(); _opt_gtol->setToolTip(tip_gtol); QLabel* lbl_gtol = new QLabel("GTol: "); @@ -71,15 +84,14 @@ void OptimizerOptionsWidget::_createLayout() _opt_stepbound->setSingleStep(0.1); QLabel* lbl_step = new QLabel("Step Bound: "); lbl_step->setToolTip(tip_step); - +*/ _opt_maxiter = new QSpinBox(); _opt_maxiter->setToolTip(tip_maxitr); - //_opt_maxiter->setDecimals(1); - _opt_maxiter->setRange(0, 100000); + _opt_maxiter->setRange(0, 1000000); _opt_maxiter->setSingleStep(100.0); QLabel* lbl_maxitr = new QLabel("MaxIter: "); lbl_maxitr->setToolTip(tip_maxitr); - +/* _opt_lm_scale_diag = new QSpinBox(); _opt_lm_scale_diag->setToolTip(tip_scale); _opt_lm_scale_diag->setRange(0, 1); @@ -99,41 +111,47 @@ void OptimizerOptionsWidget::_createLayout() QLabel* lbl_covtol = new QLabel("CovTol: "); lbl_covtol->setToolTip(tip_covtol); - +*/ _ck_use_weights = new QCheckBox("Use Weights"); _ck_use_weights->setChecked(true); - optimizerLayout->addWidget(lbl_ftol, 0, 0, Qt::AlignRight); - optimizerLayout->addWidget(_opt_ftol, 0, 1, Qt::AlignLeft); + //optimizerLayout->addWidget(lbl_ftol, 0, 0, Qt::AlignRight); + //optimizerLayout->addWidget(_opt_ftol, 0, 1, Qt::AlignLeft); + optimizerLayout->addWidget(lbl_opt_type, 0, 0, Qt::AlignRight); + optimizerLayout->addWidget(_cb_optimization_type, 0, 1, Qt::AlignLeft); + optimizerLayout->addWidget(lbl_xtol, 0, 2, Qt::AlignRight); optimizerLayout->addWidget(_opt_xtol, 0, 3, Qt::AlignLeft); - optimizerLayout->addWidget(lbl_gtol, 0, 4, Qt::AlignRight); - optimizerLayout->addWidget(_opt_gtol, 0, 5, Qt::AlignLeft); + //optimizerLayout->addWidget(lbl_gtol, 0, 4, Qt::AlignRight); + //optimizerLayout->addWidget(_opt_gtol, 0, 5, Qt::AlignLeft); + + optimizerLayout->addWidget(lbl_algo, 1, 0, Qt::AlignRight); + optimizerLayout->addWidget(_cb_algorithm, 1, 1, Qt::AlignLeft); - optimizerLayout->addWidget(lbl_epsilon, 1, 0, Qt::AlignRight); - optimizerLayout->addWidget(_opt_epsilon, 1, 1, Qt::AlignLeft); - optimizerLayout->addWidget(lbl_step, 1, 2, Qt::AlignRight); - optimizerLayout->addWidget(_opt_stepbound, 1, 3, Qt::AlignLeft); - optimizerLayout->addWidget(lbl_maxitr, 1, 4, Qt::AlignRight); - optimizerLayout->addWidget(_opt_maxiter, 1, 5, Qt::AlignLeft); + //optimizerLayout->addWidget(lbl_epsilon, 1, 0, Qt::AlignRight); + //optimizerLayout->addWidget(_opt_epsilon, 1, 1, Qt::AlignLeft); + //optimizerLayout->addWidget(lbl_step, 1, 2, Qt::AlignRight); + //optimizerLayout->addWidget(_opt_stepbound, 1, 3, Qt::AlignLeft); + optimizerLayout->addWidget(lbl_maxitr, 0, 4, Qt::AlignRight); + optimizerLayout->addWidget(_opt_maxiter, 0, 5, Qt::AlignLeft); optimizerLayout->addWidget(_ck_use_weights, 0, 6, Qt::AlignLeft); - QHBoxLayout* hbox_lm = new QHBoxLayout(); - hbox_lm->addWidget(lbl_scale); - hbox_lm->addWidget(_opt_lm_scale_diag); - hbox_lm->addWidget(lbl_verbose); - hbox_lm->addWidget(_opt_lm_verbose); - _lm_fit_ctrl_grp = new QGroupBox(); - _lm_fit_ctrl_grp->setLayout(hbox_lm); - optimizerLayout->addWidget(_lm_fit_ctrl_grp, 0, 7, Qt::AlignLeft); - - QHBoxLayout* hbox_mp = new QHBoxLayout(); - hbox_mp->addWidget(lbl_covtol); - hbox_mp->addWidget(_opt_mp_covtol); - _mp_fit_ctrl_grp = new QGroupBox(); - _mp_fit_ctrl_grp->setLayout(hbox_mp); - optimizerLayout->addWidget(_mp_fit_ctrl_grp, 1, 7, Qt::AlignLeft); + //QHBoxLayout* hbox_lm = new QHBoxLayout(); + //hbox_lm->addWidget(lbl_scale); + //hbox_lm->addWidget(_opt_lm_scale_diag); + //hbox_lm->addWidget(lbl_verbose); + //hbox_lm->addWidget(_opt_lm_verbose); + //_lm_fit_ctrl_grp = new QGroupBox(); + //_lm_fit_ctrl_grp->setLayout(hbox_lm); + //optimizerLayout->addWidget(_lm_fit_ctrl_grp, 0, 7, Qt::AlignLeft); + + //QHBoxLayout* hbox_mp = new QHBoxLayout(); + //hbox_mp->addWidget(lbl_covtol); + //hbox_mp->addWidget(_opt_mp_covtol); + //_mp_fit_ctrl_grp = new QGroupBox(); + //_mp_fit_ctrl_grp->setLayout(hbox_mp); + //optimizerLayout->addWidget(_mp_fit_ctrl_grp, 1, 7, Qt::AlignLeft); QVBoxLayout* layout = new QVBoxLayout(); @@ -153,34 +171,24 @@ void OptimizerOptionsWidget::_createLayout() setLayout(l); - } //--------------------------------------------------------------------------- -void OptimizerOptionsWidget::setOptimizer(QString opt, fitting::optimizers::Optimizer& optimizer) +void OptimizerOptionsWidget::setOptimizer(fitting::optimizers::Optimizer& optimizer) { + updateGUIOptimizerOptions(optimizer); +} - _mp_fit_ctrl_grp->setVisible(false); - _lm_fit_ctrl_grp->setVisible(false); - /* - if (opt == STR_NL_FIT) - { - _mp_fit_ctrl_grp->setVisible(false); - _lm_fit_ctrl_grp->setVisible(true); - } - else if (opt == STR_MP_FIT) - { - _lm_fit_ctrl_grp->setVisible(false); - _mp_fit_ctrl_grp->setVisible(true); - } - else if (opt == STR_HYBRID_MP_FIT) +//--------------------------------------------------------------------------- + +bool OptimizerOptionsWidget::isHybrid() +{ + if(_cb_optimization_type->currentText() == STR_GENERAL_FIT) { - _lm_fit_ctrl_grp->setVisible(false); - _mp_fit_ctrl_grp->setVisible(true); + return false; } - */ - updateGUIOptimizerOptions(optimizer); + return true; } //--------------------------------------------------------------------------- @@ -188,15 +196,25 @@ void OptimizerOptionsWidget::setOptimizer(QString opt, fitting::optimizers::Opti void OptimizerOptionsWidget::updateGUIOptimizerOptions(fitting::optimizers::Optimizer& optimizer) { + _cb_algorithm->clear(); + for(auto itr : optimizer.get_algorithm_list()) + { + _cb_algorithm->addItem(QString(itr.c_str())); + } + _cb_algorithm->setCurrentText("LN_SBPLX"); + std::unordered_map opt = optimizer.get_options(); + /* if (opt.count(STR_OPT_FTOL) > 0) { _opt_ftol->setText(QString::number(opt.at(STR_OPT_FTOL), 'e', 0)); } + */ if (opt.count(STR_OPT_XTOL) > 0) { _opt_xtol->setText(QString::number(opt.at(STR_OPT_XTOL), 'e', 0)); } + /* if (opt.count(STR_OPT_GTOL) > 0) { _opt_gtol->setText(QString::number(opt.at(STR_OPT_GTOL), 'e', 0)); @@ -209,10 +227,12 @@ void OptimizerOptionsWidget::updateGUIOptimizerOptions(fitting::optimizers::Opt { _opt_stepbound->setValue(opt.at(STR_OPT_STEP)); } + */ if (opt.count(STR_OPT_MAXITER) > 0) { _opt_maxiter->setValue(opt.at(STR_OPT_MAXITER)); } + /* if (opt.count(STR_OPT_SCALE_DIAG) > 0) { _opt_lm_scale_diag->setValue((int)opt.at(STR_OPT_SCALE_DIAG)); @@ -225,23 +245,25 @@ void OptimizerOptionsWidget::updateGUIOptimizerOptions(fitting::optimizers::Opt { _opt_lm_verbose->setValue(opt.at(STR_OPT_VERBOSE_LEVEL)); } - + */ } //--------------------------------------------------------------------------- void OptimizerOptionsWidget::updateOptimizerOptions(fitting::optimizers::Optimizer& optimizer) { + optimizer.set_algorithm( _cb_algorithm->currentText().toStdString()); + std::unordered_map opt; - opt[STR_OPT_FTOL] = _opt_ftol->text().toDouble(); + //opt[STR_OPT_FTOL] = _opt_ftol->text().toDouble(); opt[STR_OPT_XTOL] = _opt_xtol->text().toDouble(); - opt[STR_OPT_GTOL] = _opt_gtol->text().toDouble(); - opt[STR_OPT_EPSILON] = _opt_epsilon->text().toDouble(); - opt[STR_OPT_STEP] = _opt_stepbound->value(); + //opt[STR_OPT_GTOL] = _opt_gtol->text().toDouble(); + //opt[STR_OPT_EPSILON] = _opt_epsilon->text().toDouble(); + //opt[STR_OPT_STEP] = _opt_stepbound->value(); opt[STR_OPT_MAXITER] = _opt_maxiter->value(); - opt[STR_OPT_SCALE_DIAG] = _opt_lm_scale_diag->value(); - opt[STR_OPT_COVTOL] = _opt_mp_covtol->text().toDouble(); - opt[STR_OPT_VERBOSE_LEVEL] = _opt_lm_verbose->value(); + //opt[STR_OPT_SCALE_DIAG] = _opt_lm_scale_diag->value(); + //opt[STR_OPT_COVTOL] = _opt_mp_covtol->text().toDouble(); + //opt[STR_OPT_VERBOSE_LEVEL] = _opt_lm_verbose->value(); optimizer.set_options(opt); } diff --git a/src/mvc/OptimizerOptionsWidget.h b/src/mvc/OptimizerOptionsWidget.h index df8846c..e5d7d17 100644 --- a/src/mvc/OptimizerOptionsWidget.h +++ b/src/mvc/OptimizerOptionsWidget.h @@ -16,18 +16,17 @@ #include #include #include +#include #include #include "mvc/ComboBoxDelegate.h" -#include "fitting//optimizers/nlopt_optimizer.h" -#include "fitting//optimizers/mpfit_optimizer.h" +#include "fitting//optimizers/optimizer.h" #include "fitting/routines/param_optimized_fit_routine.h" #include "fitting/routines/hybrid_param_nnls_fit_routine.h" //--------------------------------------------------------------------------- -const static QString STR_NL_FIT = "NL Opt"; -const static QString STR_MP_FIT = "MP Fit"; -const static QString STR_HYBRID_MP_FIT = "Hybrid NL Opt"; +const static QString STR_GENERAL_FIT = "General"; +const static QString STR_HYBRID_FIT = "Hybrid"; //--------------------------------------------------------------------------- @@ -48,7 +47,7 @@ class OptimizerOptionsWidget : public QWidget */ ~OptimizerOptionsWidget(); - void setOptimizer(QString opt, fitting::optimizers::Optimizer& optimizer); + void setOptimizer(fitting::optimizers::Optimizer& optimizer); void updateOptimizerOptions(fitting::optimizers::Optimizer& optimizer); // get gui settings and send to optimizer @@ -56,6 +55,8 @@ class OptimizerOptionsWidget : public QWidget bool useWeights() { return _ck_use_weights->isChecked(); } + bool isHybrid(); + protected: /** @@ -65,29 +66,29 @@ class OptimizerOptionsWidget : public QWidget QTextEdit *_textEdit; - QGroupBox* _lm_fit_ctrl_grp; + QComboBox *_cb_optimization_type; - QGroupBox* _mp_fit_ctrl_grp; + QComboBox *_cb_algorithm; QCheckBox* _ck_use_weights; - QLineEdit* _opt_ftol; + //QLineEdit* _opt_ftol; QLineEdit* _opt_xtol; - QLineEdit* _opt_gtol; + //QLineEdit* _opt_gtol; - QLineEdit* _opt_epsilon; + //QLineEdit* _opt_epsilon; - QDoubleSpinBox* _opt_stepbound; + //QDoubleSpinBox* _opt_stepbound; QSpinBox* _opt_maxiter; - QSpinBox* _opt_lm_scale_diag; + //QSpinBox* _opt_lm_scale_diag; - QSpinBox* _opt_lm_verbose; + //QSpinBox* _opt_lm_verbose; - QLineEdit* _opt_mp_covtol; + //QLineEdit* _opt_mp_covtol; }; diff --git a/src/mvc/RawH5Model.h b/src/mvc/RawH5Model.h index 0df7047..7ed2540 100644 --- a/src/mvc/RawH5Model.h +++ b/src/mvc/RawH5Model.h @@ -15,7 +15,6 @@ #include #include "io/file/hdf5_io.h" #include "fitting/routines/param_optimized_fit_routine.h" -#include "fitting/optimizers/mpfit_optimizer.h" #include "fitting/models/gaussian_model.h" #include "data_struct/stream_block.h"