diff --git a/MSSPM_GuiEstimation/nmfEstimationTab01.cpp b/MSSPM_GuiEstimation/nmfEstimationTab01.cpp index c5b6ccc..559b68b 100755 --- a/MSSPM_GuiEstimation/nmfEstimationTab01.cpp +++ b/MSSPM_GuiEstimation/nmfEstimationTab01.cpp @@ -471,17 +471,20 @@ nmfEstimation_Tab1::importSpeciesData(const QString& tableName, if (loadOK && updateSetup) { // Load signal with data to send to Species Setup tab QList SpeciesNames; + QList SpeciesMinimumBiomass; QList SpeciesInitBiomass; QList SpeciesGrowthRate; QList SpeciesK; for (int row=0; rowrowCount(); ++row) { SpeciesNames.push_back( m_SpeciesModel->item(row,m_ColumnMap["SpeName"])->text()); + SpeciesMinimumBiomass.push_back(m_SpeciesModel->item(row,m_ColumnMap["MinimumBiomass"])->text().remove(",")); SpeciesInitBiomass.push_back(m_SpeciesModel->item(row,m_ColumnMap["InitBiomass"])->text().remove(",")); SpeciesGrowthRate.push_back( m_SpeciesModel->item(row,m_ColumnMap["GrowthRate"])->text()); SpeciesK.push_back( m_SpeciesModel->item(row,m_ColumnMap["SpeciesK"])->text().remove(",")); } - emit UpdateSpeciesSetupData(SpeciesNames,SpeciesGuilds,SpeciesInitBiomass, + emit UpdateSpeciesSetupData(SpeciesNames,SpeciesGuilds, + SpeciesMinimumBiomass,SpeciesInitBiomass, SpeciesGrowthRate,SpeciesK); QMessageBox::information(Estimation_Tabs, "Data Updated", "\nSpecies/Guild table has been successfully updated.\n", @@ -600,6 +603,7 @@ nmfEstimation_Tab1::checkSpeciesDataPrimary(bool showPopup) { double WeightVal = 0; QString SpeName; + QString MinimumBiomass; QString InitBiomass; QString GrowthRate; QString SpeciesK; @@ -613,13 +617,15 @@ nmfEstimation_Tab1::checkSpeciesDataPrimary(bool showPopup) WeightVal = Weight.toDouble(); index = m_SpeciesModel->index(i,m_ColumnMap["SpeName"]); SpeName = index.data().toString().remove(","); + index = m_SpeciesModel->index(i,m_ColumnMap["MinimumBiomass"]); + MinimumBiomass = index.data().toString().remove(","); index = m_SpeciesModel->index(i,m_ColumnMap["InitBiomass"]); InitBiomass = index.data().toString().remove(","); index = m_SpeciesModel->index(i,m_ColumnMap["GrowthRate"]); GrowthRate = index.data().toString().remove(","); index = m_SpeciesModel->index(i,m_ColumnMap["SpeciesK"]); SpeciesK = index.data().toString().remove(","); - if (nmfUtilsQt::emptyField({Weight,SpeName,InitBiomass,GrowthRate,SpeciesK})) { + if (nmfUtilsQt::emptyField({Weight,SpeName,MinimumBiomass,InitBiomass,GrowthRate,SpeciesK})) { checkAndShowEmptyFieldError(showPopup,"checkSpeciesDataPrimary"); return false; } @@ -701,6 +707,7 @@ nmfEstimation_Tab1::showAllColumns(QTableView* tv) tv->setColumnHidden( i,false); } showCovariateColumns(tv,false); // Hide them for now as covariates are entered in their own tab (Tab 6) + showMinimumBiomassColumn(tv,false); } void @@ -720,6 +727,19 @@ nmfEstimation_Tab1::showCovariateColumns(QTableView* tv, const bool& show) } } +void +nmfEstimation_Tab1::showMinimumBiomassColumn(QTableView* tv, const bool& show) +{ + QString colName; + QStringList SpeciesSupp = {"MinimumBiomass"}; + + for (int i = 0; i < tv->model()->columnCount(); ++i) { + colName = tv->model()->headerData(i, Qt::Horizontal).toString(); + if (SpeciesSupp.contains(colName)) { + tv->setColumnHidden(i,!show); + } + } +} void nmfEstimation_Tab1::showPrimaryColumns(QTableView* tv) @@ -1561,7 +1581,8 @@ nmfEstimation_Tab1::callback_ExportPB() QList GuildGrowthRate; QList GuildK; QList SpeciesName; -// QList SpeciesGuild; +// QList SpeciesGuild; + QList SpeciesMinimumBiomass; QList SpeciesInitialBiomass; QList SpeciesGrowthRate; QList SpeciesK; @@ -1572,8 +1593,10 @@ nmfEstimation_Tab1::callback_ExportPB() saveGuildsCSVFile(tableNameStr,GuildName,GuildGrowthRate,GuildK); } else { emit LoadSpeciesGuild(); - callback_SaveSpeciesCSVFile(tableNameStr,SpeciesName,m_SpeciesGuild, - SpeciesInitialBiomass,SpeciesGrowthRate,SpeciesK); + callback_SaveSpeciesCSVFile( + tableNameStr,SpeciesName,m_SpeciesGuild, + SpeciesMinimumBiomass,SpeciesInitialBiomass, + SpeciesGrowthRate,SpeciesK); } } } @@ -1590,6 +1613,7 @@ nmfEstimation_Tab1::callback_QueryAndSaveSpeciesCSVFile( QString tableNameStr, QList SpeciesName, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitialBiomass, QList SpeciesGrowthRate, QList SpeciesK) @@ -1600,6 +1624,7 @@ nmfEstimation_Tab1::callback_QueryAndSaveSpeciesCSVFile( tableNameStr, SpeciesName, SpeciesGuild, + SpeciesMinimumBiomass, SpeciesInitialBiomass, SpeciesGrowthRate, SpeciesK); @@ -1611,6 +1636,7 @@ nmfEstimation_Tab1::callback_SaveSpeciesCSVFile( QString tableName, QList SpeciesName, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitialBiomass, QList SpeciesGrowthRate, QList SpeciesK) @@ -1626,7 +1652,8 @@ nmfEstimation_Tab1::callback_SaveSpeciesCSVFile( smodel, m_ColumnMap, inputDataPath,tableNameStr, - SpeciesName,SpeciesGuild,SpeciesInitialBiomass, + SpeciesName,SpeciesGuild, + SpeciesMinimumBiomass,SpeciesInitialBiomass, SpeciesGrowthRate,SpeciesK); QFileInfo fileInfo(tableNameStr); @@ -1969,13 +1996,13 @@ nmfEstimation_Tab1::loadSpecies() m_Logger->logMsg(nmfConstants::Normal,"nmfEstimation_Tab1::loadSpecies()"); // Load Population tableview - fields = {"Weight","SpeName","InitBiomass","InitBiomassMin","InitBiomassMax", + fields = {"Weight","SpeName","MinimumBiomass","InitBiomass","InitBiomassMin","InitBiomassMax", "GrowthRate","GrowthRateMin","GrowthRateMax", "GrowthRateShape","GrowthRateShapeMin","GrowthRateShapeMax", "SpeciesK","SpeciesKMin","SpeciesKMax", "SurveyQ","SurveyQMin","SurveyQMax","Catchability", "CatchabilityMin","CatchabilityMax"}; - queryStr = "SELECT Weight,SpeName,InitBiomass,InitBiomassMin,InitBiomassMax,"; + queryStr = "SELECT Weight,SpeName,MinimumBiomass,InitBiomass,InitBiomassMin,InitBiomassMax,"; queryStr += "GrowthRate,GrowthRateMin,GrowthRateMax,"; queryStr += "GrowthRateShape,GrowthRateShapeMin,GrowthRateShapeMax,"; queryStr += "SpeciesK,SpeciesKMin,SpeciesKMax,"; diff --git a/MSSPM_GuiEstimation/nmfEstimationTab01.h b/MSSPM_GuiEstimation/nmfEstimationTab01.h index de211cf..7c35fca 100755 --- a/MSSPM_GuiEstimation/nmfEstimationTab01.h +++ b/MSSPM_GuiEstimation/nmfEstimationTab01.h @@ -139,6 +139,7 @@ class nmfEstimation_Tab1: public QObject void setupHelpSpecies(); void setupHelpGuilds(); void showCovariateColumns(QTableView* tv, const bool& show); + void showMinimumBiomassColumn(QTableView* tv, const bool& show); void showNoColumns(QTableView* tv); void showAllColumns(QTableView* tv); void showPrimaryColumns(QTableView* tv); @@ -212,6 +213,7 @@ class nmfEstimation_Tab1: public QObject * @brief Signal sent so the Species Setup tab will be updated with the appropriate Species fields * @param SpeciesNames : list of species names * @param SpeciesGuilds : list of guilds that each species is in + * @param SpeciesMinimumBiomass : list of species minimum biomass values * @param SpeciesInitBiomass : list of species initial biomass values * @param SpeciesGrowthRate : list of species growth rates * @param SpeciesK : list of species carrying capacities @@ -219,6 +221,7 @@ class nmfEstimation_Tab1: public QObject void UpdateSpeciesSetupData( QList SpeciesNames, QList SpeciesGuilds, + QList SpeciesMinimumBiomass, QList SpeciesInitBiomass, QList SpeciesGrowthRate, QList SpeciesK); @@ -342,6 +345,7 @@ public Q_SLOTS: * @param TableName: name of table to save data from * @param SpeciesName : list of species names * @param SpeciesGuild : list of guilds that each species is a member of + * @param SpeciesMinimumBiomass : list of minimum biomass per species * @param SpeciesInitialBiomass : list of initial biomass per species * @param SpeciesGrowthRate : list of growth rate per species * @param SpeciesK : list of carrying capacities per species @@ -350,6 +354,7 @@ public Q_SLOTS: QString TableName, QList SpeciesName, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitialBiomass, QList SpeciesGrowthRate, QList SpeciesK); @@ -378,6 +383,7 @@ public Q_SLOTS: * @param TableName: name of table to save data from * @param SpeciesName : list of species names * @param SpeciesGuild : list of guilds that each species is a member of + * @param SpeciesMinimumBiomass : list of minimum biomass per species * @param SpeciesInitialBiomass : list of initial biomass per species * @param SpeciesGrowthRate : list of growth rate per species * @param SpeciesK : list of carrying capacities per species @@ -386,6 +392,7 @@ public Q_SLOTS: QString TableName, QList SpeciesName, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitialBiomass, QList SpeciesGrowthRate, QList SpeciesK); diff --git a/MSSPM_GuiEstimation/nmfEstimationTab06.cpp b/MSSPM_GuiEstimation/nmfEstimationTab06.cpp index 71d0b45..59601b1 100755 --- a/MSSPM_GuiEstimation/nmfEstimationTab06.cpp +++ b/MSSPM_GuiEstimation/nmfEstimationTab06.cpp @@ -667,6 +667,7 @@ nmfEstimation_Tab6::loadCovariateInitialValuesAndRangesTable() // QMessageBox::Ok); return false; } + int NumParameters = NumRecords/NumSpecies; int m = -1; int modelCol = 0; @@ -676,14 +677,14 @@ nmfEstimation_Tab6::loadCovariateInitialValuesAndRangesTable() ++m; modelCol += 3; coeffValue = dataMap["CoeffValue"][m]; - if (! QString::fromStdString(coeffValue).trimmed().isEmpty()) { - item = new QStandardItem(QString::fromStdString(coeffValue)); + if (! QString::fromStdString(coeffValue).trimmed().isEmpty()) { + item = nmfUtilsQt::itemFixedOrScientific(std::stod(coeffValue)); item->setTextAlignment(Qt::AlignCenter); smodelIR->setItem(species,modelCol+0,item); - item = new QStandardItem(QString::fromStdString(dataMap["CoeffMinValue"][m])); + item = nmfUtilsQt::itemFixedOrScientific(std::stod(dataMap["CoeffMinValue"][m])); item->setTextAlignment(Qt::AlignCenter); smodelIR->setItem(species,modelCol+1,item); - item = new QStandardItem(QString::fromStdString(dataMap["CoeffMaxValue"][m])); + item = nmfUtilsQt::itemFixedOrScientific(std::stod(dataMap["CoeffMaxValue"][m])); item->setTextAlignment(Qt::AlignCenter); smodelIR->setItem(species,modelCol+2,item); } else { @@ -1520,13 +1521,15 @@ nmfEstimation_Tab6::callback_SpeciesRangeSB(int pct) valueWithoutComma = initialIndex.data().toString().remove(","); if ((rangeType == "min/max") || (rangeType == "min only")) { newValue = valueWithoutComma.toDouble()*(1.0-pctVal); - minItem = new QStandardItem(QString::number(newValue,'f',6)); +// minItem = new QStandardItem(QString::number(newValue,'f',6)); + minItem = nmfUtilsQt::itemFixedOrScientific(newValue); minItem->setTextAlignment(Qt::AlignCenter); m_smodelIR->setItem(row,col+1,minItem); } if ((rangeType == "min/max") || (rangeType == "max only")) { newValue = valueWithoutComma.toDouble()*(1.0+pctVal); - maxItem = new QStandardItem(QString::number(newValue,'f',6)); +// maxItem = new QStandardItem(QString::number(newValue,'f',6)); + maxItem = nmfUtilsQt::itemFixedOrScientific(newValue); maxItem->setTextAlignment(Qt::AlignCenter); m_smodelIR->setItem(row,col+2,maxItem); } @@ -1545,7 +1548,8 @@ nmfEstimation_Tab6::callback_SpeciesRangeSB(int pct) valueWithoutComma = initialIndex.data().toString().remove(","); if ((rangeType == "min/max") || (rangeType == "min only")) { newValue = valueWithoutComma.toDouble()*(1.0-pctVal); - minItem = new QStandardItem(QString::number(newValue,'f',6)); +// minItem = new QStandardItem(QString::number(newValue,'f',6)); + minItem = nmfUtilsQt::itemFixedOrScientific(newValue); minItem->setTextAlignment(Qt::AlignCenter); m_smodelIR->setItem(row,col,minItem); } @@ -1555,7 +1559,8 @@ nmfEstimation_Tab6::callback_SpeciesRangeSB(int pct) valueWithoutComma = initialIndex.data().toString().remove(","); if ((rangeType == "min/max") || (rangeType == "max only")) { newValue = valueWithoutComma.toDouble()*(1.0+pctVal); - maxItem = new QStandardItem(QString::number(newValue,'f',6)); +// maxItem = new QStandardItem(QString::number(newValue,'f',6)); + maxItem = nmfUtilsQt::itemFixedOrScientific(newValue); maxItem->setTextAlignment(Qt::AlignCenter); m_smodelIR->setItem(row,col,maxItem); } diff --git a/MSSPM_GuiOutput/nmfOutputControls.cpp b/MSSPM_GuiOutput/nmfOutputControls.cpp index 8b81926..9e390e7 100644 --- a/MSSPM_GuiOutput/nmfOutputControls.cpp +++ b/MSSPM_GuiOutput/nmfOutputControls.cpp @@ -930,6 +930,11 @@ nmfOutputControls::getGuilds(int& NumGuilds, return true; } +void +nmfOutputControls::refreshBrightnessSlider() +{ + OutputLineBrightnessSL->setValue(OutputLineBrightnessSL->value()); +} void nmfOutputControls::callback_OutputLineBrightnessSL(int value) diff --git a/MSSPM_GuiOutput/nmfOutputControls.h b/MSSPM_GuiOutput/nmfOutputControls.h index 59e482d..da8e63f 100755 --- a/MSSPM_GuiOutput/nmfOutputControls.h +++ b/MSSPM_GuiOutput/nmfOutputControls.h @@ -380,6 +380,10 @@ class nmfOutputControls: public QObject * @brief Resets the Output Type widget as well as reloading the Scenario widget */ void refresh(); + /** + * @brief Refreshes the current chart by resetting the brightness slider + */ + void refreshBrightnessSlider(); /** * @brief Refreshes the current chart by flipping to another chart type and back to the current */ diff --git a/MSSPM_GuiSetup/nmfSetupTab02.cpp b/MSSPM_GuiSetup/nmfSetupTab02.cpp index 7e92430..26478e1 100755 --- a/MSSPM_GuiSetup/nmfSetupTab02.cpp +++ b/MSSPM_GuiSetup/nmfSetupTab02.cpp @@ -859,6 +859,7 @@ nmfSetup_Tab2::createTables(QString databaseName) cmd = "CREATE TABLE IF NOT EXISTS " + fullTableName; cmd += "(SpeName varchar(100) NOT NULL,"; cmd += " GuildName varchar(100) NULL,"; + cmd += " MinimumBiomass double NULL,"; cmd += " InitBiomass double NULL,"; cmd += " SurveyQ float NULL,"; cmd += " SpeciesK double NULL,"; diff --git a/MSSPM_GuiSetup/nmfSetupTab03.cpp b/MSSPM_GuiSetup/nmfSetupTab03.cpp index 65da44f..0a484f4 100644 --- a/MSSPM_GuiSetup/nmfSetupTab03.cpp +++ b/MSSPM_GuiSetup/nmfSetupTab03.cpp @@ -103,7 +103,8 @@ nmfSetup_Tab3::nmfSetup_Tab3(QTabWidget* tabs, Setup_Tab3_GuildsTW->setSelectionMode(QAbstractItemView::ContiguousSelection); Setup_Tab3_SpeciesTW->setSelectionMode(QAbstractItemView::ContiguousSelection); - m_colLabelsSpecies << "Name" << "Guild" << "Initial Absolute Biomass" << "Growth Rate" << "Species K" ; + m_colLabelsSpecies << "Name" << "Guild" << "Minimum Biomass" << "Initial Absolute Biomass" + << "Growth Rate" << "Species K" ; m_colLabelsGuilds << "GuildName" << "GrowthRate" << "GuildK"; } @@ -317,8 +318,8 @@ nmfSetup_Tab3::loadSpecies() clearSpeciesWidgets(); - fields = {"SpeName","GuildName","InitBiomass","GrowthRate","SpeciesK"}; - queryStr = "SELECT SpeName,GuildName,InitBiomass,GrowthRate,SpeciesK FROM " + nmfConstantsMSSPM::TableSpecies; + fields = {"SpeName","GuildName","MinimumBiomass","InitBiomass","GrowthRate","SpeciesK"}; + queryStr = "SELECT SpeName,GuildName,MinimumBiomass,InitBiomass,GrowthRate,SpeciesK FROM " + nmfConstantsMSSPM::TableSpecies; dataMap = m_databasePtr->nmfQueryDatabase(queryStr, fields); NumSpecies = dataMap["SpeName"].size(); if (NumSpecies == 0) { @@ -337,14 +338,17 @@ nmfSetup_Tab3::loadSpecies() // Populate text fields Setup_Tab3_SpeciesTW->item(i,0)->setText(QString::fromStdString(dataMap["SpeName"][i])); valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( - std::stod(dataMap["InitBiomass"][i]),m_NumSignificantDigits,6); + std::stod(dataMap["MinimumBiomass"][i]),m_NumSignificantDigits,3); Setup_Tab3_SpeciesTW->item(i,2)->setText(valueWithComma); valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( - std::stod(dataMap["GrowthRate"][i]),m_NumSignificantDigits,3); + std::stod(dataMap["InitBiomass"][i]),m_NumSignificantDigits,6); Setup_Tab3_SpeciesTW->item(i,3)->setText(valueWithComma); valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( - std::stod(dataMap["SpeciesK"][i]),m_NumSignificantDigits,6); + std::stod(dataMap["GrowthRate"][i]),m_NumSignificantDigits,3); Setup_Tab3_SpeciesTW->item(i,4)->setText(valueWithComma); + valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( + std::stod(dataMap["SpeciesK"][i]),m_NumSignificantDigits,6); + Setup_Tab3_SpeciesTW->item(i,5)->setText(valueWithComma); // Set Guild combo box guild = dataMap["GuildName"][i]; @@ -778,7 +782,7 @@ nmfSetup_Tab3::saveSpeciesData() std::string errorMsg; std::string GuildName; std::string SpeciesName; - std::string InitBiomass,SurveyQ,SpeciesK,GrowthRate; + std::string MinimumBiomass,InitBiomass,SurveyQ,SpeciesK,GrowthRate; std::string InitBiomassMin,InitBiomassMax,SurveyQMin,SurveyQMax,GrowthRateMin; std::string GrowthRateMax,SpeciesKMin,SpeciesKMax,Catchability,CatchabilityMin,CatchabilityMax,SpeDependence; std::map guildKMap; @@ -848,22 +852,25 @@ nmfSetup_Tab3::saveSpeciesData() SpeciesName = Setup_Tab3_SpeciesTW->item(i, 0)->text().toStdString(); GuildName = qobject_cast(Setup_Tab3_SpeciesTW->cellWidget(i,1))->currentText().toStdString(); valueWithoutComma = Setup_Tab3_SpeciesTW->item(i, 2)->text().remove(","); + MinimumBiomass = valueWithoutComma.toStdString(); + valueWithoutComma = Setup_Tab3_SpeciesTW->item(i, 3)->text().remove(","); InitBiomass = valueWithoutComma.toStdString(); - GrowthRate = Setup_Tab3_SpeciesTW->item(i, 3)->text().toStdString(); - valueWithoutComma = Setup_Tab3_SpeciesTW->item(i, 4)->text().remove(","); + GrowthRate = Setup_Tab3_SpeciesTW->item(i, 4)->text().toStdString(); + valueWithoutComma = Setup_Tab3_SpeciesTW->item(i, 5)->text().remove(","); SpeciesK = valueWithoutComma.toStdString(); guildKMap[GuildName] += std::stod(SpeciesK); systemK += std::stod(SpeciesK); cmd = "INSERT INTO " + nmfConstantsMSSPM::TableSpecies + " ("; - cmd += "SpeName,GuildName,InitBiomass,GrowthRate,SpeciesK) "; + cmd += "SpeName,GuildName,MinimumBiomass,InitBiomass,GrowthRate,SpeciesK) "; cmd += " VALUES ('" + SpeciesName + "', '" + GuildName + - "', "+ InitBiomass + ", " + GrowthRate + ", " + SpeciesK + ") "; + "', " + MinimumBiomass + ", " + InitBiomass + ", " + GrowthRate + ", " + SpeciesK + ") "; cmd += "ON DUPLICATE KEY UPDATE "; - cmd += "GuildName = '" + GuildName + "', "; - cmd += "InitBiomass = " + InitBiomass + ", "; - cmd += "GrowthRate = " + GrowthRate + ", "; - cmd += "SpeciesK = " + SpeciesK + ";"; + cmd += "GuildName = '" + GuildName + "', "; + cmd += "MinimumBiomass = " + MinimumBiomass + ", "; + cmd += "InitBiomass = " + InitBiomass + ", "; + cmd += "GrowthRate = " + GrowthRate + ", "; + cmd += "SpeciesK = " + SpeciesK + ";"; errorMsg = m_databasePtr->nmfUpdateDatabase(cmd); if (nmfUtilsQt::isAnError(errorMsg)) { m_logger->logMsg(nmfConstants::Error,"nmfSetup_Tab3 callback_Setup_Tab3_SavePB (Species): Write table error: " + errorMsg); @@ -920,9 +927,10 @@ nmfSetup_Tab3::setupHelp() // set Tool tips here for column headings Setup_Tab3_SpeciesTW->horizontalHeaderItem(0)->setToolTip("Species Name"); Setup_Tab3_SpeciesTW->horizontalHeaderItem(1)->setToolTip("Guild Name"); - Setup_Tab3_SpeciesTW->horizontalHeaderItem(2)->setToolTip("Species Initial Absolute Biomass"); - Setup_Tab3_SpeciesTW->horizontalHeaderItem(3)->setToolTip("Species Growth Rate"); - Setup_Tab3_SpeciesTW->horizontalHeaderItem(4)->setToolTip("Species Carrying Capacity"); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(2)->setToolTip("Species Minimum Biomass"); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(3)->setToolTip("Species Initial Absolute Biomass"); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(4)->setToolTip("Species Growth Rate"); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(5)->setToolTip("Species Carrying Capacity"); msg = "
Species Name

"; msg += "The Species name entered must be unique."; @@ -930,16 +938,19 @@ nmfSetup_Tab3::setupHelp() msg = "
Guild Name

"; msg += "The user must create Guilds prior to being able to select one here."; Setup_Tab3_SpeciesTW->horizontalHeaderItem(1)->setWhatsThis(prefix+msg+suffix); + msg = "
Minimum Biomass

"; + msg += "The minimum biomass that a species may have in units of metric tons."; + Setup_Tab3_SpeciesTW->horizontalHeaderItem(2)->setWhatsThis(prefix+msg+suffix); msg = "
Initial Absolute Biomass

"; msg += "The initial species absolute biomass is in units of metric tons."; - Setup_Tab3_SpeciesTW->horizontalHeaderItem(2)->setWhatsThis(prefix+msg+suffix); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(3)->setWhatsThis(prefix+msg+suffix); msg = "
Growth Rate

"; msg += "The Species growth rate (r) is a unit-less value typically between 0.0 and 1.0."; - Setup_Tab3_SpeciesTW->horizontalHeaderItem(3)->setWhatsThis(prefix+msg+suffix); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(4)->setWhatsThis(prefix+msg+suffix); msg = "
Species K

"; msg += "The Species carrying capacity (K) is the number of individuals
"; msg += "in a population that can be supported by the habitat's resources."; - Setup_Tab3_SpeciesTW->horizontalHeaderItem(4)->setWhatsThis(prefix+msg+suffix); + Setup_Tab3_SpeciesTW->horizontalHeaderItem(5)->setWhatsThis(prefix+msg+suffix); } @@ -1108,6 +1119,7 @@ nmfSetup_Tab3::callback_ExportPB() QList GuildK; QList SpeciesName; QList SpeciesGuild; + QList SpeciesMinimumBiomass; QList SpeciesInitialBiomass; QList SpeciesGrowthRate; QList SpeciesK; @@ -1138,6 +1150,9 @@ nmfSetup_Tab3::callback_ExportPB() } else if (col == m_ColumnMap["Guild"]) { cbox = qobject_cast(Setup_Tab3_SpeciesTW->cellWidget(row,col)); SpeciesGuild.push_back(cbox->currentText()); + } else if (col == m_ColumnMap["Minimum Biomass"]) { + valueWithoutComma = Setup_Tab3_SpeciesTW->item(row,col)->text().remove(","); + SpeciesMinimumBiomass.push_back(valueWithoutComma); } else if (col == m_ColumnMap["Initial Absolute Biomass"]) { valueWithoutComma = Setup_Tab3_SpeciesTW->item(row,col)->text().remove(","); SpeciesInitialBiomass.push_back(valueWithoutComma); @@ -1152,6 +1167,7 @@ nmfSetup_Tab3::callback_ExportPB() emit SaveSpeciesSupplemental(tableName, SpeciesName, SpeciesGuild, + SpeciesMinimumBiomass, SpeciesInitialBiomass, SpeciesGrowthRate, SpeciesK); @@ -1426,6 +1442,7 @@ nmfSetup_Tab3::callback_UpdateSpeciesPB() void nmfSetup_Tab3::callback_UpdateSpeciesTable(QList SpeciesNames, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitBiomass, QList SpeciesGrowthRate, QList SpeciesK) @@ -1441,10 +1458,12 @@ nmfSetup_Tab3::callback_UpdateSpeciesTable(QList SpeciesNames, QList columns = {m_ColumnMap["Name"], m_ColumnMap["Guild"], + m_ColumnMap["Minimum Biomass"], m_ColumnMap["Initial Absolute Biomass"], m_ColumnMap["Growth Rate"], m_ColumnMap["Species K"]}; - for (QList list : {SpeciesNames,SpeciesGuild,SpeciesInitBiomass,SpeciesGrowthRate,SpeciesK}) { + for (QList list : {SpeciesNames,SpeciesGuild,SpeciesMinimumBiomass, + SpeciesInitBiomass,SpeciesGrowthRate,SpeciesK}) { col = columns[index++]; for (int row=0; row SpeciesNames, valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( list[row].toDouble(),m_NumSignificantDigits,6); item->setText(valueWithComma); - + } else if (col == m_ColumnMap["Minimum Biomass"]) { + valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( + list[row].toDouble(),m_NumSignificantDigits,1); + item->setText(valueWithComma); } else if (col == m_ColumnMap["Growth Rate"]) { valueWithComma = nmfUtilsQt::checkAndCalculateWithSignificantDigits( list[row].toDouble(),m_NumSignificantDigits,3); diff --git a/MSSPM_GuiSetup/nmfSetupTab03.h b/MSSPM_GuiSetup/nmfSetupTab03.h index 6d5675b..44cd0db 100644 --- a/MSSPM_GuiSetup/nmfSetupTab03.h +++ b/MSSPM_GuiSetup/nmfSetupTab03.h @@ -221,6 +221,7 @@ class nmfSetup_Tab3: public QObject * file. * @param SpeciesName : list of species names * @param SpeciesGuild : list of species guilds + * @param SpeciesMinimumBiomass : list of minimum biomasses per species * @param SpeciesInitialBiomass : list of initial biomasses per species * @param SpeciesGrowthRate : list of growth rates per species * @param SpeciesK : list of carrying capacities per species @@ -228,6 +229,7 @@ class nmfSetup_Tab3: public QObject void SaveSpeciesSupplemental(QString, QList SpeciesName, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitialBiomass, QList SpeciesGrowthRate, QList SpeciesK); @@ -342,12 +344,14 @@ public Q_SLOTS: * Species Setup data must also be updated * @param SpeciesNames : names of Species * @param SpeciesGuild : list of Species Guild groups + * @param SpeciesMinimumBiomass : values of all Species minimum biomasses * @param SpeciesInitBiomass : values of all Species initial biomasses * @param SpeciesGrowthRate : values of all Species growth rates * @param SpeciesK : values of all Species carrying capacities */ void callback_UpdateSpeciesTable(QList SpeciesNames, QList SpeciesGuild, + QList SpeciesMinimumBiomass, QList SpeciesInitBiomass, QList SpeciesGrowthRate, QList SpeciesK); diff --git a/MSSPM_GuiSetup/nmfSetupTab04.cpp b/MSSPM_GuiSetup/nmfSetupTab04.cpp index 11491bb..b64136c 100755 --- a/MSSPM_GuiSetup/nmfSetupTab04.cpp +++ b/MSSPM_GuiSetup/nmfSetupTab04.cpp @@ -392,7 +392,7 @@ nmfSetup_Tab4::loadModel() "' AND ModelName = '" + m_ModelName + "'"; dataMap = m_databasePtr->nmfQueryDatabase(queryStr, fields); if (dataMap["ModelName"].size() == 0) { - m_logger->logMsg(nmfConstants::Error,"nmfSetupTab3::callback_Setup_Tab4_LoadPB: No data found in Models table"); + m_logger->logMsg(nmfConstants::Error,"nmfSetupTab4::callback_Setup_Tab4_LoadPB: No data found in Models table"); m_logger->logMsg(nmfConstants::Error,queryStr); return; } @@ -462,7 +462,7 @@ nmfSetup_Tab4::loadModel() "' AND ModelName = '" + m_ModelName + "'"; errorMsg = m_databasePtr->nmfUpdateDatabase(cmd); if (nmfUtilsQt::isAnError(errorMsg)) { - m_logger->logMsg(nmfConstants::Error,"nmfSetupTab3 callback_Setup_Tab4_LoadPB: Write table error: " + errorMsg); + m_logger->logMsg(nmfConstants::Error,"nmfSetupTab4 callback_Setup_Tab4_LoadPB: Write table error: " + errorMsg); m_logger->logMsg(nmfConstants::Error,"cmd: " + cmd); return; } diff --git a/MSSPM_Main/forms/Estimation/Estimation_Tab07.ui b/MSSPM_Main/forms/Estimation/Estimation_Tab07.ui index 6911ef4..315ed78 100644 --- a/MSSPM_Main/forms/Estimation/Estimation_Tab07.ui +++ b/MSSPM_Main/forms/Estimation/Estimation_Tab07.ui @@ -7,7 +7,7 @@ 0 0 787 - 771 + 965 @@ -45,9 +45,9 @@ 0 - -172 + 0 731 - 843 + 886 @@ -585,10 +585,10 @@ <html><head/><body><p align="center"><span style=" font-weight:600;">Seed Value</span></p><p>This is the seed value for the current stochastic algorithm. If a multi-run is chosen then this will be the beginning seed value for all of the runs.</p></body></html> - 0 + 1 - 0 + 1 @@ -2440,6 +2440,201 @@ with the non-assigned bees being assigned to random positions. + + + + + 50 + false + + + + Parameter Range Controls: + + + + + + + + The type of initial parameter value + + + The type of initial parameter value + + + <html><head/><body><p align="center"><span style=" font-weight:600;">Initial Parameter Value Type</span></p><p>This combobox allows the user to select if the initial parameter value type should be given by the value defined by the user (Fixed), a randomized value (Random), or a randomized value that will give the same value every time a multirun is run (Random Repeatable).</p></body></html> + + + Initial Parameter Value Type: + + + + + + + The type of initial parameter value + + + The type of initial parameter value + + + <html><head/><body><p align="center"><span style=" font-weight:600;">Initial Parameter Value Type</span></p><p>This combobox allows the user to select if the initial parameter value type should be given by the value defined by the user (Fixed) or a randomized value (Random).</p></body></html> + + + + Fixed + + + + + Random + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + The amount of randomness added to the parameter ranges + + + The amount of randomness added to the parameter ranges + + + <html><head/><body><p align="center"><span style=" font-weight:600;">Parameter Value Range Jitter</span></p><p>This value adds a <span style=" font-family:'Google Sans','Roboto','arial','sans-serif'; font-size:14px; color:#202124; background-color:#ffffff;">± percent jitter value to the minimum and maximum parameter range values. This initial parameter value is checked, and if need be, clamped to these values in the event it falls outside of the jittered range.</span></p></body></html> + + + Range Jitter (%): + + + + + + + The amount of randomness added to the parameter ranges + + + The amount of randomness added to the parameter ranges + + + <html><head/><body><p align="center"><span style=" font-weight:600;">Parameter Value Range Jitter</span></p><p>This value adds a ± percent jitter value to the minimum and maximum parameter range values. This initial parameter value is checked, and if need be, clamped to these values in the event it falls outside of the jittered range.</p></body></html> + + + 0.010000000000000 + + + 1.000000000000000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + 0 + 0 + + + + + 5 + 0 + + + + + 5 + 16777215 + + + + } + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Makes any random initial parameter or range jitter % repeatable + + + Makes any random initial parameter or range jitter % repeatable + + + <html><head/><body><p align="center"><span style=" font-weight:600;">Jitter Repeatable Checkbox</span></p><p>If checked, this box allows the user to specify that any random initial parameter value and and any randomized parameter range jitter value be repeatable. That is, the user will get the same randomized values every time the multirun is run.</p></body></html> + + + Repeatable + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + @@ -3093,186 +3288,6 @@ with the non-assigned bees being assigned to random positions. - - - - - - The type of initial parameter value - - - The type of initial parameter value - - - <html><head/><body><p align="center"><span style=" font-weight:600;">Initial Parameter Value Type</span></p><p>This combobox allows the user to select if the initial parameter value type should be given by the value defined by the user (Fixed), a randomized value (Random), or a randomized value that will give the same value every time a multirun is run (Random Repeatable).</p></body></html> - - - Initial Parameter Value Type: - - - - - - - The type of initial parameter value - - - The type of initial parameter value - - - <html><head/><body><p align="center"><span style=" font-weight:600;">Initial Parameter Value Type</span></p><p>This combobox allows the user to select if the initial parameter value type should be given by the value defined by the user (Fixed) or a randomized value (Random).</p></body></html> - - - - Fixed - - - - - Random - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - The amount of randomness added to the parameter ranges - - - The amount of randomness added to the parameter ranges - - - <html><head/><body><p align="center"><span style=" font-weight:600;">Parameter Value Range Jitter</span></p><p>This value adds a <span style=" font-family:'Google Sans','Roboto','arial','sans-serif'; font-size:14px; color:#202124; background-color:#ffffff;">± percent jitter value to the minimum and maximum parameter range values. This initial parameter value is checked, and if need be, clamped to these values in the event it falls outside of the jittered range.</span></p></body></html> - - - Range Jitter (%): - - - - - - - The amount of randomness added to the parameter ranges - - - The amount of randomness added to the parameter ranges - - - <html><head/><body><p align="center"><span style=" font-weight:600;">Parameter Value Range Jitter</span></p><p>This value adds a ± percent jitter value to the minimum and maximum parameter range values. This initial parameter value is checked, and if need be, clamped to these values in the event it falls outside of the jittered range.</p></body></html> - - - 0.010000000000000 - - - 1.000000000000000 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - - 0 - 0 - - - - - 5 - 0 - - - - - 5 - 16777215 - - - - } - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 5 - 20 - - - - - - - - Makes any random initial parameter or range jitter % repeatable - - - Makes any random initial parameter or range jitter % repeatable - - - <html><head/><body><p align="center"><span style=" font-weight:600;">Jitter Repeatable Checkbox</span></p><p>If checked, this box allows the user to specify that any random initial parameter value and and any randomized parameter range jitter value be repeatable. That is, the user will get the same randomized values every time the multirun is run.</p></body></html> - - - Repeatable - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - diff --git a/MSSPM_Main/nmfMainWindow.cpp b/MSSPM_Main/nmfMainWindow.cpp index fd08c26..44ce77b 100755 --- a/MSSPM_Main/nmfMainWindow.cpp +++ b/MSSPM_Main/nmfMainWindow.cpp @@ -18,7 +18,6 @@ nmfMainWindow::nmfMainWindow(QWidget *parent) : QMainWindow(parent), m_UI(new Ui::nmfMainWindow) { - m_UI->setupUi(this); // QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -1530,6 +1529,7 @@ nmfMainWindow::menu_exportHPCFiles() QString outputFile; QString hpcDir = QDir(QString::fromStdString(m_ProjectDir)).filePath(QString::fromStdString(nmfConstantsMSSPM::OutputDataHPCDir)); hpcDir = QDir(hpcDir).filePath(QString::fromStdString(m_ModelName)); + QString useCovariateData = (Estimation_Tab6_ptr->isCovariateData()) ? "1" : "0"; m_DatabasePtr->getAlgorithmIdentifiers( this,m_Logger,m_ProjectName,m_ModelName, @@ -1564,40 +1564,42 @@ nmfMainWindow::menu_exportHPCFiles() QTextStream stream(&file); // Line 1 - stream << "\n# Project Name, Model Name\n"; + stream << "\n# 1. Project Name, Model Name\n"; stream << QString::fromStdString(m_ProjectName) << ", "; stream << QString::fromStdString(m_ModelName) << "\n"; // Line 2 - stream << "\n# Growth Form, Harvest Form, Competition Form, Predation Form\n"; + stream << "\n# 2. Growth Form, Harvest Form, Competition Form, Predation Form\n"; stream << growthForm << ", "; stream << harvestForm << ", "; stream << competitionForm << ", "; stream << predationForm << "\n"; - // Line 3...RSK add boolean (0/1) for using covariate data + // Line 3 + stream << "\n# 3. Use covariate data? (0 = no, 1 = yes)\n"; + stream << useCovariateData << "\n"; // Line 3 - stream << "\n# Algorithm Family, Minimizer, Objective Criterion, Scaling\n"; + stream << "\n# 4. Algorithm Family, Minimizer, Objective Criterion, Scaling\n"; stream << QString::fromStdString(Algorithm) << ", "; stream << QString::fromStdString(Minimizer) << ", "; stream << QString::fromStdString(ObjectiveCriterion) << ", "; stream << QString::fromStdString(Scaling) << "\n"; // Line 4 - stream << "\n# Initial Parameter Value type, Range Jitter Value (%), Range Jitter Repeatable boolean\n"; + stream << "\n# 5. Initial Parameter Value type, Range Jitter Value (%), Range Jitter Repeatable boolean\n"; stream << Estimation_Tab7_ptr->getEnsembleRandInitParamValue() << ", "; stream << Estimation_Tab7_ptr->getEnsembleRangeJitterValue() << ", "; stream << Estimation_Tab7_ptr->isEnsembleRangeJitterRepeatable() << "\n"; // Line 5 - stream << "\n# Number of Total Runs, Stop Tolerance, Stop Time (sec)\n"; + stream << "\n# 6. Number of Total Runs, Stop Tolerance, Stop Time (sec)\n"; stream << QString::number(Estimation_Tab7_ptr->getEnsembleNumberOfTotalRuns()) << ", "; stream << QString::number(Estimation_Tab7_ptr->getCurrentToleranceStopValue()) << ", "; stream << QString::number(Estimation_Tab7_ptr->getCurrentStopAfterTime()) << "\n"; // Line 6 - stream << "\n# Parameter Name, Enabled, Checked, ...\n"; + stream << "\n# 7. Parameter Name, Enabled, Checked, ...\n"; std::vector estimatedRunBoxes = Estimation_Tab7_ptr->getEstimateRunBoxes(); for (unsigned i=0; iclearOutputTE(); + clearOutputTables(); + + // Read hpc meta file and extract project and model name + QString fullPath = QDir(hpcDir).filePath(QString::fromStdString(nmfConstantsMSSPM::FilenameHPCMetaData)); + QFile file(fullPath); + if (! file.open(QIODevice::ReadOnly)) { + QMessageBox::information(0, "Error", file.errorString()); + return; + } + QString line; + QTextStream in(&file); + bool foundModelName = false; + while (!in.atEnd() && !foundModelName) { + line = in.readLine(); + if ((! line.isEmpty()) && (line.trimmed()[0] != '#')) { // project name and model name are first data items in meta file + QStringList parts = line.split(","); + if (parts.count() == 2) { + hpcProjectName = parts[0].trimmed().toStdString(); + hpcModelName = parts[1].trimmed().toStdString(); + m_Logger->logMsg(nmfConstants::Normal,"Setting project,model: " + hpcProjectName + ", " + hpcModelName); + } else { + m_Logger->logMsg(nmfConstants::Error,"Problem parsing HPC Meta file. Read project/model name line: " + line.toStdString()); + } + foundModelName = true; + } + } + file.close(); + + // Load model name from hpc meta file + Setup_Tab4_ptr->setModelName(QString::fromStdString(hpcModelName)); + Setup_Tab4_ptr->loadModel(); + callback_ModelSaved(); +} + +bool +nmfMainWindow::checkForMissingHPCFiles(const int& numHPCFiles) +{ + int numFiles; + int NumHPCParameterGroups = (int)nmfConstantsMSSPM::HPCFilePrefixes.size(); + QString hpcDir = QDir(QString::fromStdString(m_ProjectDir)).filePath(QString::fromStdString(nmfConstantsMSSPM::InputDataHPCDir)); + QDir source(hpcDir); + QStringList files; + std::string errorMsg; + QString filename; + + for (int i=0; ilogMsg(nmfConstants::Error,"[Error 1] checkForMissingHPCFiles: " + errorMsg); + QMessageBox::warning(this, "Warning", + QString::fromStdString("\nChecking completeness of HPC files...\n\n"+errorMsg+"\n\nImport cancelled.\n"), QMessageBox::Ok); + return false; + } + } + + return true; +} + void nmfMainWindow::menu_importHPCFiles() { std::string Algorithm,Minimizer,ObjectiveCriterion,Scaling; std::string CompetitionForm; std::string multiRunModelFilename; + std::string hpcProjectName,hpcModelName; std::string Label = ""; // Temporarily keep blank until find a use for this field std::vector fitnessVec; QString hpcDir = QDir(QString::fromStdString(m_ProjectDir)).filePath(QString::fromStdString(nmfConstantsMSSPM::InputDataHPCDir)); @@ -1723,8 +1799,14 @@ nmfMainWindow::menu_importHPCFiles() return; } + // Load model from HPCMetaData.csv file in the inputData/hpc directory + loadModelFromHPCMetaFile(hpcProjectName,hpcModelName); + + QString msg = "\nThis will import HPC .csv files from the project's inputData/hpc directory."; - msg += "\n\nNumber of HPC runs to import: " + QString::number(numHPCFiles); + msg += "\n\nSetting Project Name to: " + QString::fromStdString(hpcProjectName); + msg += "\nSetting Model Name to load: " + QString::fromStdString(hpcModelName); + msg += "\nNumber of HPC runs to import: " + QString::number(numHPCFiles); msg += "\n\nOK to continue?\n"; reply = QMessageBox::question(this, tr("HPC Import"), tr(msg.toLatin1()), QMessageBox::No|QMessageBox::Yes, @@ -1732,6 +1814,13 @@ nmfMainWindow::menu_importHPCFiles() if (reply == QMessageBox::No) { return; } + m_ProjectName = hpcProjectName; + m_ModelName = hpcModelName; + + // Check to make sure there are the correct number of each parameter's estimated biomass files. + if (! checkForMissingHPCFiles(numHPCFiles)) { + return; + } bool loadOK = loadParameters(m_DataStruct,nmfConstantsMSSPM::VerboseOn); if (! loadOK) { @@ -2512,7 +2601,7 @@ void nmfMainWindow::menu_about() { QString name = "Multi-Species Surplus Production Model"; - QString version = "MSSPM v1.7.4 "; + QString version = "MSSPM v1.7.5 "; QString specialAcknowledgement = ""; QString cppVersion = "C++??"; QString mysqlVersion = "?"; @@ -2818,6 +2907,7 @@ nmfMainWindow::menu_troubleshooting() // Step 1. Add topic in appropriate group, creating a group if need be estimationTopics << "Estimation doesn't run"; + estimationTopics << "Multi-run never converges, just increments seed"; estimationTopics << "Poor fit when estimating parameters"; estimationTopics << "Still getting poor fit after adjusting ranges"; estimationTopics << "Tail of estimation curve is too high"; @@ -2840,6 +2930,7 @@ nmfMainWindow::menu_troubleshooting() // Step 3. Add the topic solutions here estimationSolutions << "If estimation doesn't produce any plots it could be a permission issue. If on Windows, exit the application and re-run as Administrator."; + estimationSolutions << "If a multi-run continually selects a new seed and never converges, it may be because there are no ranges around any of the input parameters."; estimationSolutions << QString("Try one or more of the following:
    ") + QString("
  • Adjust parameter ranges and/or initial values
  • ") + QString("
  • Adjust model algorithm and/or algorithm parameters
  • ") + @@ -4146,8 +4237,8 @@ nmfMainWindow::initConnections() this, SLOT(callback_ReloadWidgets(bool))); connect(Estimation_Tab1_ptr, SIGNAL(ReloadSetupWidgets()), this, SLOT(callback_ReloadSetupWidgets())); - connect(Setup_Tab3_ptr, SIGNAL(SaveSpeciesSupplemental(QString,QList,QList,QList,QList,QList)), - Estimation_Tab1_ptr, SLOT(callback_QueryAndSaveSpeciesCSVFile(QString,QList,QList,QList,QList,QList))); + connect(Setup_Tab3_ptr, SIGNAL(SaveSpeciesSupplemental(QString,QList,QList,QList,QList,QList,QList)), + Estimation_Tab1_ptr, SLOT(callback_QueryAndSaveSpeciesCSVFile(QString,QList,QList,QList,QList,QList,QList))); connect(Setup_Tab3_ptr, SIGNAL(SaveGuildSupplemental(QList,QList,QList)), Estimation_Tab1_ptr, SLOT(callback_SaveGuildsCSVFile(QList,QList,QList))); connect(Setup_Tab4_ptr, SIGNAL(SaveMainSettings()), @@ -4204,8 +4295,8 @@ nmfMainWindow::initConnections() this, SLOT(callback_RestoreOutputSpecies())); connect(Estimation_Tab1_ptr, SIGNAL(LoadSpeciesGuild()), this, SLOT(callback_LoadSpeciesGuild())); - connect(Estimation_Tab1_ptr, SIGNAL(UpdateSpeciesSetupData(QList, QList, QList, QList, QList)), - Setup_Tab3_ptr, SLOT(callback_UpdateSpeciesTable(QList, QList, QList, QList, QList))); + connect(Estimation_Tab1_ptr, SIGNAL(UpdateSpeciesSetupData(QList, QList, QList, QList, QList, QList)), + Setup_Tab3_ptr, SLOT(callback_UpdateSpeciesTable(QList, QList, QList, QList, QList, QList))); connect(Estimation_Tab1_ptr, SIGNAL(UpdateGuildSetupData(QList, QList, QList)), Setup_Tab3_ptr, SLOT(callback_UpdateGuildTable(QList, QList, QList))); connect(Setup_Tab3_ptr, SIGNAL(LoadSpeciesSupplemental(bool,bool,QString)), @@ -7118,7 +7209,7 @@ nmfMainWindow::updateOutputBiomassTable(std::string& ForecastName, EstBiomassTMinus1 += GrowthTerm - HarvestTerm - CompetitionTerm - PredationTerm; if ( std::isnan(std::fabs(EstBiomassTMinus1)) || (EstBiomassTMinus1 < 0) ) { - EstBiomassTMinus1 = 0; + EstBiomassTMinus1 = m_DataStruct.MinimumBiomass[species]; } EstBiomassSpecies(time,species) = EstBiomassTMinus1; @@ -12474,6 +12565,7 @@ nmfMainWindow::callback_RunForecast(std::string ForecastName, int currOutputSpecies = Output_Controls_ptr->getOutputSpeciesIndex(); Output_Controls_ptr->setOutputType("Forecast"); Output_Controls_ptr->setOutputSpeciesIndex(currOutputSpecies); + Output_Controls_ptr->refreshBrightnessSlider(); // Assure Output tab is set to Chart setCurrentOutputTab("Chart"); @@ -13352,7 +13444,7 @@ nmfMainWindow::calculateSubRunBiomass(std::vector& EstInitBiomass, if ( std::isnan(std::fabs(EstBiomassVal)) || (EstBiomassVal < 0) ) { - EstBiomassVal = 0; + EstBiomassVal = m_DataStruct.MinimumBiomass[species]; } EstBiomassSpecies(time,species) = EstBiomassVal; @@ -13435,6 +13527,7 @@ nmfMainWindow::getEstimatedParameters( if (m_UsingHPCFiles) { QString hpcDir = QDir(QString::fromStdString(m_ProjectDir)).filePath(QString::fromStdString(nmfConstantsMSSPM::InputDataHPCDir)); QString hpcFile = QDir(hpcDir).filePath(QString::fromStdString("InitBiomass_"+std::to_string(run)+".csv")); + nmfUtilsQt::loadFromHPCFile(hpcFile,EstInitBiomass); hpcFile = QDir(hpcDir).filePath(QString::fromStdString("GrowthRate_"+std::to_string(run)+".csv")); nmfUtilsQt::loadFromHPCFile(hpcFile,EstGrowthRates); @@ -13721,7 +13814,6 @@ nmfMainWindow::callback_SubRunCompleted(int run, } - // Update Progress Chart m_ProgressWidget->setRunBoxes(1,run+1,numRuns); @@ -15378,6 +15470,7 @@ nmfMainWindow::loadParameters(nmfStructsQt::ModelDataStruct& dataStruct, dataStruct.GrowthRateShape.clear(); dataStruct.GrowthRateShapeMin.clear(); dataStruct.GrowthRateShapeMax.clear(); + dataStruct.MinimumBiomass.clear(); dataStruct.InitBiomass.clear(); dataStruct.InitBiomassMin.clear(); dataStruct.InitBiomassMax.clear(); @@ -15426,17 +15519,17 @@ nmfMainWindow::loadParameters(nmfStructsQt::ModelDataStruct& dataStruct, dataStruct.SurveyQCovariateCoeff = surveyQCovariateRanges; dataStruct.useApplicationFixedSeedBees = Estimation_Tab7_ptr->isSetToDeterministicBees(); - dataStruct.EstimationAlgorithm = Estimation_Tab7_ptr->getCurrentAlgorithm(); - dataStruct.ObjectiveCriterion = Estimation_Tab7_ptr->getCurrentObjectiveCriterion(); - dataStruct.MinimizerAlgorithm = Estimation_Tab7_ptr->getCurrentMinimizer(); - dataStruct.ScalingAlgorithm = Estimation_Tab7_ptr->getCurrentScaling(); + dataStruct.EstimationAlgorithm = Estimation_Tab7_ptr->getCurrentAlgorithm(); + dataStruct.ObjectiveCriterion = Estimation_Tab7_ptr->getCurrentObjectiveCriterion(); + dataStruct.MinimizerAlgorithm = Estimation_Tab7_ptr->getCurrentMinimizer(); + dataStruct.ScalingAlgorithm = Estimation_Tab7_ptr->getCurrentScaling(); dataStruct.CovariateAlgorithmType = m_DatabasePtr->getCovariateAlgorithmType(m_Logger,m_ProjectName,m_ModelName); - dataStruct.ParameterLogScale = Estimation_Tab7_ptr->getLogScale(); - dataStruct.allowConvergedOnly = Estimation_Tab7_ptr->isAllowConvergedOnly(); + dataStruct.ParameterLogScale = Estimation_Tab7_ptr->getLogScale(); + dataStruct.allowConvergedOnly = Estimation_Tab7_ptr->isAllowConvergedOnly(); dataStruct.useRandomInitialParameters = Estimation_Tab7_ptr->isEnsembleRandInitParam(); - dataStruct.rangeJitter = Estimation_Tab7_ptr->getEnsembleRangeJitterValue(); - dataStruct.isRangeJitterRepeatable = Estimation_Tab7_ptr->isEnsembleRangeJitterRepeatable(); + dataStruct.rangeJitter = Estimation_Tab7_ptr->getEnsembleRangeJitterValue(); + dataStruct.isRangeJitterRepeatable = Estimation_Tab7_ptr->isEnsembleRangeJitterRepeatable(); m_DatabasePtr->createUnitsMap(m_ProjectName,m_ModelName,previousUnits); dataStruct.PreviousUnits = previousUnits; @@ -15610,8 +15703,8 @@ std::cout << "Error: Implement loading for init values of parameter and for Surv dataStruct.GuildSpecies[GuildNum].push_back(guild); dataStruct.GuildNum.push_back(GuildNum); } - fields = {"SpeName","GuildName","InitBiomass","InitBiomassMin","InitBiomassMax"}; - queryStr = "SELECT SpeName,GuildName,InitBiomass,InitBiomassMin,InitBiomassMax from " + + fields = {"SpeName","GuildName","MinimumBiomass","InitBiomass","InitBiomassMin","InitBiomassMax"}; + queryStr = "SELECT SpeName,GuildName,MinimumBiomass,InitBiomass,InitBiomassMin,InitBiomassMax from " + nmfConstantsMSSPM::TableSpecies + " ORDER BY SpeName"; dataMap = m_DatabasePtr->nmfQueryDatabase(queryStr, fields); @@ -15622,15 +15715,16 @@ std::cout << "Error: Implement loading for init values of parameter and for Surv initialGuildBiomass[guildName] += std::stod(dataMap["InitBiomass"][species]); initialGuildBiomassMin[guildName] += std::stod(dataMap["InitBiomassMin"][species]); initialGuildBiomassMax[guildName] += std::stod(dataMap["InitBiomassMax"][species]); + } dataStruct.NumSpecies = NumSpecies; checkGuildRanges(NumGuilds,dataStruct); } else { - fields = {"Weight","SpeName","GuildName","InitBiomass","InitBiomassMin","InitBiomassMax", + fields = {"Weight","SpeName","GuildName","MinimumBiomass","InitBiomass","InitBiomassMin","InitBiomassMax", "GrowthRate","GrowthRateMin","GrowthRateMax","GrowthRateShape","GrowthRateShapeMin","GrowthRateShapeMax", "SpeciesK","SpeciesKMin","SpeciesKMax","Catchability","CatchabilityMin","CatchabilityMax", "SurveyQ","SurveyQMin","SurveyQMax"}; - queryStr = "SELECT Weight,SpeName,GuildName,InitBiomass,InitBiomassMin,InitBiomassMax,"; + queryStr = "SELECT Weight,SpeName,GuildName,MinimumBiomass,InitBiomass,InitBiomassMin,InitBiomassMax,"; queryStr += "GrowthRate,GrowthRateMin,GrowthRateMax,GrowthRateShape,GrowthRateShapeMin,GrowthRateShapeMax,"; queryStr += "SpeciesK,SpeciesKMin,SpeciesKMax,Catchability,CatchabilityMin,CatchabilityMax,SurveyQ,SurveyQMin,SurveyQMax from " + nmfConstantsMSSPM::TableSpecies + @@ -15639,6 +15733,7 @@ std::cout << "Error: Implement loading for init values of parameter and for Surv NumSpecies = dataMap["SpeName"].size(); dataStruct.NumSpecies = NumSpecies; nmfUtils::initialize(dataStruct.SpeciesWeights, NumSpecies); + nmfUtils::initialize(dataStruct.MinimumBiomass, NumSpecies); nmfUtils::initialize(dataStruct.InitBiomass, NumSpecies); nmfUtils::initialize(dataStruct.InitBiomassMin, NumSpecies); nmfUtils::initialize(dataStruct.InitBiomassMax, NumSpecies); @@ -15659,6 +15754,7 @@ std::cout << "Error: Implement loading for init values of parameter and for Surv nmfUtils::initialize(dataStruct.SurveyQMax, NumSpecies); for (int species=0; species& Exploitation); + void loadModelFromHPCMetaFile(std::string& hpcProjectName, + std::string& hpcModelName); bool loadInteraction(int &NumSpecies, std::string InteractionType, std::string InitTable, diff --git a/MSSPM_ParameterEstimationNLoptAlgorithm/NLopt_Estimator.cpp b/MSSPM_ParameterEstimationNLoptAlgorithm/NLopt_Estimator.cpp index 3dd3285..60f0f86 100755 --- a/MSSPM_ParameterEstimationNLoptAlgorithm/NLopt_Estimator.cpp +++ b/MSSPM_ParameterEstimationNLoptAlgorithm/NLopt_Estimator.cpp @@ -159,7 +159,7 @@ NLopt_Estimator::extractParameters(const nmfStructsQt::ModelDataStruct& NLoptDat // Always extract growth rate for (int i=0; i= 25) && (species == 9)) { -// std::cout << time << ": " << EstBiomassTMinus1 << ":: " << growthRate[species] << ", " << growthRateShape[species] << ", " << -// growthRateCovariateCoeffs[species] << ", " << growthRateCovariate(timeMinus1,species) << ", " << -// carryingCapacity[species] << ", " << carryingCapacityCovariateCoeffs[species] << ", " << -// carryingCapacityCovariate(timeMinus1,species) << std::endl; -// if (time == 4) std::cout << std::endl; +// if ((species == 5) && (time == 1)) { +// std::cout << time << ": " << EstBiomassTMinus1 << ":: " << +// growthRate[species] << ", " << +// growthRateShape[species] << ", " << +// growthRateCovariateCoeffs[species] << ", " << +// growthRateCovariate(timeMinus1,species) << ", " << +// carryingCapacity[species] << ", " << +// carryingCapacityCovariateCoeffs[species] << ", " << +// carryingCapacityCovariate(timeMinus1,species) << std::endl; +// // if (time == NumYears-1) std::cout << std::endl; //} HarvestTerm = NLoptHarvestForm->evaluate(covariateAlgorithmType, timeMinus1,species,EstBiomassTMinus1, @@ -745,7 +749,7 @@ NLopt_Estimator::objectiveFunction(unsigned nUnused, //CompetitionTerm = nmfUtils::round(CompetitionTerm,precision); //PredationTerm = nmfUtils::round(PredationTerm, precision); -//if ((time >= 25) && (species == 9)) { +//if ((time >= 1) && (species == 5)) { // std::cout << "Time: [" << time << "] " << EstBiomassTMinus1 << ": " // << GrowthTerm << ", " << HarvestTerm // << ", " << CompetitionTerm << ", " << PredationTerm << std::endl; @@ -759,13 +763,16 @@ NLopt_Estimator::objectiveFunction(unsigned nUnused, //if (species == 1) { //std::cout << "(" << time << "," << species << "): " << EstBiomassTMinus1 << " "; +//} +//if ((species == 5) && (time == 1)) { +// std::cout << EstBiomassTMinus1 << " += "; //} EstBiomassTMinus1 += GrowthTerm - HarvestTerm - CompetitionTerm - PredationTerm; -//if (species == 1) { -//std::cout << GrowthTerm << " - " << HarvestTerm << " - " << CompetitionTerm << " - " << PredationTerm << std::endl; +//if ((species == 6) && (time == 25)) { +// std::cout << GrowthTerm << " - " << HarvestTerm << " - " << CompetitionTerm << " - " << PredationTerm << std::endl; //} - EstBiomassTMinus1 = (EstBiomassTMinus1 < 0) ? 0 : EstBiomassTMinus1; + EstBiomassTMinus1 = (EstBiomassTMinus1 < 0) ? NLoptDataStruct.MinimumBiomass[species] : EstBiomassTMinus1; if ((EstBiomassTMinus1 < 0) || (std::isnan(std::fabs(EstBiomassTMinus1)))) { incrementObjectiveFunctionCounter(MSSPMName,(double)DefaultFitness,NLoptDataStruct); return DefaultFitness; @@ -808,10 +815,11 @@ NLopt_Estimator::objectiveFunction(unsigned nUnused, nmfUtils::rescaleMatrixLog10(EstBiomassSpecies, EstBiomassRescaled); nmfUtils::rescaleMatrixLog10(ObsBiomassBySpeciesOrGuilds, ObsBiomassBySpeciesOrGuildsRescaled); } +//nmfUtils::printMatrix("ObsCatch",ObsCatch,10,10); //nmfUtils::printMatrix("ObsCatchRescaled",ObsCatchRescaled,10,10); +//nmfUtils::printMatrix("ObsBiomassBySpeciesOrGuildsRescaled",ObsBiomassBySpeciesOrGuildsRescaled,10,10); //nmfUtils::printMatrix("EstCatchRescaled",EstCatchRescaled,10,10); //nmfUtils::printMatrix("EstBiomassRescaled",EstBiomassRescaled,14,10); -//nmfUtils::printMatrix("ObsBiomassBySpeciesOrGuildsRescaled",ObsBiomassBySpeciesOrGuildsRescaled,10,10); // Remove first row from all matrices because we don't want to include // the initial biomass in the fitness calculations. @@ -862,10 +870,14 @@ NLopt_Estimator::objectiveFunction(unsigned nUnused, } incrementObjectiveFunctionCounter(MSSPMName,fitness,NLoptDataStruct); +//nmfUtils::printMatrix("ObsCatchRescaled", ObsCatchRescaled, 16,10); +//nmfUtils::printMatrix("ObsBiomassBySpeciesOrGuildsRescaled",ObsBiomassBySpeciesOrGuildsRescaled,16,10); +//nmfUtils::printMatrix("EstCatchRescaled", EstCatchRescaled, 16,10); +//nmfUtils::printMatrix("EstBiomassRescaled",EstBiomassRescaled,16,10); //qDebug() << "tolerance: " << m_Optimizer.get_ftol_abs(); //std::cout << "fitness: " << fitness << std::endl; - +//exit(0); if (m_ForceStop) { m_Optimizer.force_stop(); fitness = USER_STOPPED_VALUE; @@ -1055,7 +1067,7 @@ NLopt_Estimator::setSeed(const bool& isSetToDeterministic, const bool& incrementFixedSeed) { if (useUserFixedSeed && incrementFixedSeed) { - nlopt::srand(m_FixedSeed++); + nlopt::srand((unsigned long)m_FixedSeed++); std::cout << "[Info 0] Using seed value: " << m_FixedSeed-1 << std::endl; } else if (useUserFixedSeed) { nlopt::srand(userFixedSeedVal); @@ -1066,7 +1078,7 @@ std::cout << "[Info 2] Using seed value: 1" << std::endl; } else { if (isSetToDeterministic) { nlopt::srand(++m_Seed); -std::cout << "[Info 3] Using seed value: " << m_Seed-1 << std::endl; +std::cout << "[Info 3] Using seed value: " << m_Seed << std::endl; } else { nlopt::srand_time(); std::cout << "[Info 4] Using seed value of srand_time " << std::endl; @@ -1090,10 +1102,15 @@ NLopt_Estimator::setParameterBounds(int runNum, m_RandomizeSeed = (m_isRangeJitterRepeatable) ? m_RandomizeSeed+3 : -3; + // set seed for c++ rand() function if (m_isRangeJitterRepeatable) { +//double seedFactor = 1.0e6; srand(runNum); +//std::cout << "s1 - Setting c++ random seed to: " << runNum << std::endl; } else { - srand((unsigned)time(NULL)+runNum); + unsigned seedVal = (unsigned)time(NULL)+runNum; + srand(seedVal); +//std::cout << "s2 - Setting c++ random seed to: " << seedVal << std::endl; } //qDebug() << "---> Num Parameter Bounds: " << NumEstParameters; @@ -1101,7 +1118,7 @@ NLopt_Estimator::setParameterBounds(int runNum, // Set parameter bounds for all parameters rangeJitterPct = NLoptStruct.rangeJitter/100.0; for (int i=0; i& MultiRunLines, int& TotalIndividualRuns) { + bool errorFound = false; bool isAMultiRun = bools.first; bool isSetToDeterministic = bools.second; bool foundOneNLoptRun = false; @@ -1282,6 +1300,7 @@ NLopt_Estimator::estimateParameters(nmfStructsQt::ModelDataStruct &NLoptStruct, // std::cout << val << std::endl; // } // + returnCode = m_Optimizer.optimize(m_Parameters, fitness); // theReturnCodeStr = returnCodeStr(returnCode);