Skip to content

Commit

Permalink
Mods for 1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rklasky committed Feb 21, 2023
1 parent 3f657c9 commit 05e0816
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 63 deletions.
15 changes: 10 additions & 5 deletions MSSPM_GuiEstimation/nmfEstimationTab02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,8 @@ nmfEstimation_Tab2::saveFitWeights(const bool& verbose)
std::string tableName = nmfConstantsMSSPM::TableFitWeights;
std::string cmd;
std::string errorMsg = m_DatabasePtr->nmfUpdateDatabase(cmd);
QModelIndex indexBiomass,indexCatch;
std::string biomassStr = "";
std::string catchStr = "";
QStringList SpeciesList;
QStandardItemModel* smodel = qobject_cast<QStandardItemModel*>(Estimation_Tab2_WeightsFTCTV->model());

Expand Down Expand Up @@ -936,12 +937,16 @@ nmfEstimation_Tab2::saveFitWeights(const bool& verbose)

cmd = "INSERT INTO " + tableName + " (ProjectName,ModelName,SpeName,Biomass,Catch) VALUES ";
for (int i=0; i<smodel->rowCount(); ++i) { // Species
indexBiomass = smodel->index(i,0);
indexCatch = smodel->index(i,1);
biomassStr = smodel->index(i,0).data().toString().toStdString();
catchStr = smodel->index(i,1).data().toString().toStdString();
if (biomassStr.empty() || catchStr.empty()) {
biomassStr = "1.0";
catchStr = "0.0";
}
cmd += "('" + m_ProjectName + "','" + m_ModelName +
"','" + SpeciesList[i].toStdString() +
"', " + indexBiomass.data().toString().toStdString() +
", " + indexCatch.data().toString().toStdString() + "),";
"', " + biomassStr +
", " + catchStr + "),";
}

cmd = cmd.substr(0,cmd.size()-1);
Expand Down
7 changes: 4 additions & 3 deletions MSSPM_Main/nmfMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ void
nmfMainWindow::menu_about()
{
QString name = "Multi-Species Surplus Production Model";
QString version = "MSSPM v1.6.0 ";
QString version = "MSSPM v1.6.1 ";
QString specialAcknowledgement = "";
QString cppVersion = "C++??";
QString mysqlVersion = "?";
Expand Down Expand Up @@ -6170,7 +6170,8 @@ nmfMainWindow::updateOutputBiomassTable(std::string& ForecastName,
EstCarryingCapacities[species],
EstCarryingCapacityCovariateCoeffs[species],
CarryingCapacitiesCovariate(timeMinus1,species));
HarvestTerm = harvestFormPtr->evaluate(CovariateAlgorithmType,

HarvestTerm = harvestFormPtr->evaluate(CovariateAlgorithmType,
timeMinus1,species,
EstBiomassTMinus1,
Catch,Effort,Exploitation,
Expand Down Expand Up @@ -11062,7 +11063,7 @@ nmfMainWindow::callback_RunEstimation(bool showDiagnosticsChart)
QString multiRunSpeciesFilename;
QString multiRunModelFilename;
QString msg;
qDebug() <<"isAMultiOrMohnsRhoRun: " << isAMultiRun;

saveSettings();
loadAllWidgets();
readSettings();
Expand Down
49 changes: 35 additions & 14 deletions MSSPM_ParameterEstimationNLoptAlgorithm/NLopt_Estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,36 +160,45 @@ NLopt_Estimator::extractParameters(const nmfStructsQt::ModelDataStruct& NLoptDat
}
offset += NumSpeciesOrGuilds;

// Always extract growth rate covariates
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
growthRateCovariateCoeffs.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
}
offset += NumSpeciesOrGuilds;

// Extract growth rate shape parameters if is logistic
if (isLogistic) {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
growthRateShape.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
}
offset += NumSpeciesOrGuilds;
} else {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
growthRateShape.emplace_back(0);
}
}

// Always extract growth rate covariates
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
growthRateCovariateCoeffs.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
}
offset += NumSpeciesOrGuilds;

// Load the carrying capacity vector
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
if (isLogistic) {
// Load the carrying capacity vector if it's logistic
if (isLogistic) {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
carryingCapacity.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
} else {
}
offset += NumSpeciesOrGuilds;
} else {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
carryingCapacity.emplace_back(0);
}
}
offset += NumSpeciesOrGuilds;

if (isLogistic) {
// offset += NumSpeciesOrGuilds;
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
carryingCapacityCovariateCoeffs.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
}
offset += NumSpeciesOrGuilds;
} else {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
carryingCapacityCovariateCoeffs.emplace_back(0);
}
}

if (isCatchability) {
Expand All @@ -201,9 +210,13 @@ NLopt_Estimator::extractParameters(const nmfStructsQt::ModelDataStruct& NLoptDat
catchabilityCovariateCoeffs.emplace_back(QString::number(EstParameters[offset+i],'f',6).toDouble());
}
offset += NumSpeciesOrGuilds;
} else {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
catchability.emplace_back(0);
catchabilityCovariateCoeffs.emplace_back(0);
}
}


// Be sure to extract matrix data row by row which is for (row...) then for (col...)

if (isAlpha) {
Expand Down Expand Up @@ -274,6 +287,10 @@ NLopt_Estimator::extractParameters(const nmfStructsQt::ModelDataStruct& NLoptDat
exponent.emplace_back(EstParameters[offset+i]);
}
offset += NumSpeciesOrGuilds;
} else {
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
exponent.emplace_back(0);
}
}

// Survey Q
Expand All @@ -286,7 +303,7 @@ NLopt_Estimator::extractParameters(const nmfStructsQt::ModelDataStruct& NLoptDat
surveyQCovariateCoeffs.emplace_back(EstParameters[offset+i]);
}
offset += NumSpeciesOrGuilds;
//qDebug() << "Num Parameters Extracted: " << offset;
//qDebug() << "---> Num Parameters Extracted: " << offset;

// Calculate MSY, BMSY, and FMSY values
for (int i=0; i<NumSpeciesOrGuilds; ++i) {
Expand Down Expand Up @@ -1008,10 +1025,14 @@ NLopt_Estimator::setParameterBounds(nmfStructsQt::ModelDataStruct& NLoptStruct,
std::vector<double> lowerBounds(NumEstParameters);
std::vector<double> upperBounds(NumEstParameters);

//qDebug() << "---> Num Parameter Bounds: " << NumEstParameters;

// Set parameter bounds for all parameters
for (int i=0; i<NumEstParameters; ++i) {
lowerBounds[i] = ParameterRanges[i].first;
upperBounds[i] = ParameterRanges[i].second;
//qDebug() << "Setting parameter bounds: " << i << ", "
// << lowerBounds[i] << "," << upperBounds[i];
}
m_Optimizer.set_lower_bounds(lowerBounds);
m_Optimizer.set_upper_bounds(upperBounds);
Expand Down
78 changes: 37 additions & 41 deletions MSSPM_SimulatedData/nmfSimulatedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,47 +224,43 @@ nmfSimulatedData::createSimulatedBiomass(
getGuildCarryingCapacity(isAggProd,species,SpeciesK,GuildNum,
GuildSpecies,GuildCarryingCapacity);

GrowthTerm = SimGrowthForm.evaluate(
covariateAlgorithmType,
SimBiomassTMinus1,
GrowthRate[species],
GrowthRateShape[species],
GrowthRateCovariateCoeffs[species],
GrowthRateCovariate(timeMinus1,species),
SpeciesK[species],
SpeciesKCovariateCoeffs[species],
SpeciesKCovariate(timeMinus1,species));
HarvestTerm = SimHarvestForm.evaluate(
covariateAlgorithmType,
timeMinus1,species,SimBiomassTMinus1,
Catch,Effort,Exploitation,
Catchability[species],
CatchabilityCovariateCoeffs[species],
CatchabilityCovariate(timeMinus1,species));
CompetitionTerm = SimCompetitionForm.evaluate(
covariateAlgorithmType,
timeMinus1,species,SimBiomassTMinus1,
GrowthRate,
GrowthRateCovariate,
GuildCarryingCapacity,
SystemCarryingCapacity,
SimBiomassSpecies,
SimulatedBiomassGuild,
CompetitionAlpha,
CompetitionAlphaCovariate,
CompetitionBetaSpecies,
CompetitionBetaSpeciesCovariate,
CompetitionBetaGuild,
CompetitionBetaGuildSpeciesCovariate,
CompetitionBetaGuildGuild,
CompetitionBetaGuildGuildCovariate);
PredationTerm = SimPredationForm.evaluate(
covariateAlgorithmType,
timeMinus1, species,
SimBiomassSpecies,SimBiomassTMinus1,
PredationRho,PredationRhoCovariate,
PredationHandling,PredationHandlingCovariate,
PredationExponent,PredationExponentCovariate);
GrowthTerm = SimGrowthForm.evaluate(covariateAlgorithmType,
SimBiomassTMinus1,
GrowthRate[species],
GrowthRateShape[species],
GrowthRateCovariateCoeffs[species],
GrowthRateCovariate(timeMinus1,species),
SpeciesK[species],
SpeciesKCovariateCoeffs[species],
SpeciesKCovariate(timeMinus1,species));
HarvestTerm = SimHarvestForm.evaluate(covariateAlgorithmType,
timeMinus1,species,SimBiomassTMinus1,
Catch,Effort,Exploitation,
Catchability[species],
CatchabilityCovariateCoeffs[species],
CatchabilityCovariate(timeMinus1,species));
CompetitionTerm = SimCompetitionForm.evaluate(covariateAlgorithmType,
timeMinus1,species,SimBiomassTMinus1,
GrowthRate,
GrowthRateCovariate,
GuildCarryingCapacity,
SystemCarryingCapacity,
SimBiomassSpecies,
SimulatedBiomassGuild,
CompetitionAlpha,
CompetitionAlphaCovariate,
CompetitionBetaSpecies,
CompetitionBetaSpeciesCovariate,
CompetitionBetaGuild,
CompetitionBetaGuildSpeciesCovariate,
CompetitionBetaGuildGuild,
CompetitionBetaGuildGuildCovariate);
PredationTerm = SimPredationForm.evaluate(covariateAlgorithmType,
timeMinus1, species,
SimBiomassSpecies,SimBiomassTMinus1,
PredationRho,PredationRhoCovariate,
PredationHandling,PredationHandlingCovariate,
PredationExponent,PredationExponentCovariate);

SimBiomassTMinus1 += GrowthTerm - HarvestTerm - CompetitionTerm - PredationTerm;

Expand Down

0 comments on commit 05e0816

Please sign in to comment.