From 0e4ce16143d828847375da5ff3149835908fb52c Mon Sep 17 00:00:00 2001 From: Ron Date: Fri, 16 Sep 2022 18:32:04 -0400 Subject: [PATCH] Mods for 1.3.1 --- MSSPM_Main/SimulatedBiomassDialog.cpp | 61 +++++++++++++----------- MSSPM_Main/nmfMainWindow.cpp | 2 +- MSSPM_SimulatedData/nmfSimulatedData.cpp | 17 +++---- MSSPM_SimulatedData/nmfSimulatedData.h | 8 ++-- 4 files changed, 48 insertions(+), 40 deletions(-) diff --git a/MSSPM_Main/SimulatedBiomassDialog.cpp b/MSSPM_Main/SimulatedBiomassDialog.cpp index 72475d8..7dceb16 100755 --- a/MSSPM_Main/SimulatedBiomassDialog.cpp +++ b/MSSPM_Main/SimulatedBiomassDialog.cpp @@ -20,6 +20,8 @@ SimulatedBiomassDialog::SimulatedBiomassDialog(QWidget *parent, std::string CompetitionForm; std::string PredationForm; QString msg; + QString uniformTooltip; + QString lognormalTooltip; m_ProjectDir = projectDir; m_ProjectName = projectName; @@ -51,8 +53,8 @@ SimulatedBiomassDialog::SimulatedBiomassDialog(QWidget *parent, ErrorGB = new QGroupBox("Data Noise:"); NoneRB = new QRadioButton("No noise"); UniformSB = new QDoubleSpinBox(); - UniformRB = new QRadioButton("Uniform:"); - NormalRB = new QRadioButton("Normal:"); + UniformRB = new QRadioButton(nmfConstantsMSSPM::DistributionUniform +":"); + NormalRB = new QRadioButton(nmfConstantsMSSPM::DistributionLognormal+":"); NormalSB = new QDoubleSpinBox(); UniformLB = new QLabel("% error"); NormalLB = new QLabel("% CV"); @@ -68,17 +70,17 @@ SimulatedBiomassDialog::SimulatedBiomassDialog(QWidget *parent, UniformSB->setMaximum(99.9); UniformSB->setValue(1.0); NormalSB->setMinimum(0.1); - NormalSB->setMaximum(99.9); + NormalSB->setMaximum(50.0); NormalSB->setValue(1.0); NormalSB->setEnabled(false); NormalLB->setEnabled(false); UniformSB->setEnabled(false); UniformLB->setEnabled(false); NoneRB->setChecked(true); - UniformRB->setMinimumWidth(80); - UniformRB->setMinimumWidth(80); - NormalRB->setMinimumWidth(80); - NormalRB->setMinimumWidth(80); + UniformRB->setMinimumWidth(90); + UniformRB->setMinimumWidth(90); + NormalRB->setMinimumWidth(90); + NormalRB->setMinimumWidth(90); // Create error group box NoneLT->addWidget(NoneRB); @@ -100,23 +102,26 @@ SimulatedBiomassDialog::SimulatedBiomassDialog(QWidget *parent, msg += "(and not the range data) will be used to generate the simulated data."; InfoLBL->setText(msg); - SavePB->setToolTip("Continue with Simulated Biomass calculations and Save"); + uniformTooltip = "A uniformly randomized ±% error applied to the Simulated Biomass"; + // lognormalTooltip = "The stddev value used to generate the lognormal (i.e., Gaussian) error on the Simulated Biomass"; + lognormalTooltip = "A Coefficient of Variation (CV) percentage used for the lognormal (i.e., Gaussian) error on the Simulated Biomass"; + SavePB->setToolTip( "Continue with Simulated Biomass calculations and Save"); SavePB->setStatusTip("Continue with Simulated Biomass calculations and Save"); - NoneRB->setToolTip("No error will be applied to the data"); + NoneRB->setToolTip( "No error will be applied to the data"); NoneRB->setStatusTip("No error will be applied to the data"); - UniformLB->setToolTip("A randomized ±% error applied to the Simulated Biomass"); - UniformLB->setStatusTip("A randomized ±% error applied to the Simulated Biomass"); - UniformRB->setToolTip("A randomized ±% error applied to the Simulated Biomass"); - UniformRB->setStatusTip("A randomized ±% error applied to the Simulated Biomass"); - UniformSB->setToolTip("A randomized ±% error applied to the Simulated Biomass"); - UniformSB->setStatusTip("A randomized ±% error applied to the Simulated Biomass"); - NormalLB->setToolTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - NormalLB->setStatusTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - NormalRB->setToolTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - NormalRB->setStatusTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - NormalSB->setToolTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - NormalSB->setStatusTip("A Coefficient of Variation (CV) percentage used for the normal (i.e., Gaussian) error on the Simulated Biomass"); - ErrorLE->setToolTip("The name of the Simulated Biomass file"); + UniformLB->setToolTip( uniformTooltip); + UniformLB->setStatusTip(uniformTooltip); + UniformRB->setToolTip( uniformTooltip); + UniformRB->setStatusTip(uniformTooltip); + UniformSB->setToolTip( uniformTooltip); + UniformSB->setStatusTip(uniformTooltip); + NormalLB->setToolTip( lognormalTooltip); + NormalLB->setStatusTip(lognormalTooltip); + NormalRB->setToolTip( lognormalTooltip); + NormalRB->setStatusTip(lognormalTooltip); + NormalSB->setToolTip( lognormalTooltip); + NormalSB->setStatusTip(lognormalTooltip); + ErrorLE->setToolTip( "The name of the Simulated Biomass file"); ErrorLE->setStatusTip("The name of the Simulated Biomass file"); ErrorLT1->addWidget(ErrorLBL1); @@ -158,9 +163,11 @@ SimulatedBiomassDialog::setFileName(double value) QString defaultName = ""; if (UniformRB->isChecked()) { - suffix = "_uniform_" + QString::number(value,'f',1) + "_pct"; + suffix = "_" + nmfConstantsMSSPM::DistributionUniform.toLower() + + "_" + QStringLiteral("%1").arg(value,4,'f',1,QChar('0')) + "_pct"; } else if (NormalRB->isChecked()) { - suffix = "_normal_" + QString::number(value,'f',1) + "_cv"; + suffix = "_" + nmfConstantsMSSPM::DistributionLognormal.toLower() + + "_" + QStringLiteral("%1").arg(value,4,'f',1,QChar('0')) + "_cv"; } defaultName = ( m_IsBiomassAbsolute ? @@ -179,14 +186,14 @@ SimulatedBiomassDialog::getFilename() void SimulatedBiomassDialog::getError(QString& errorType, double& errorValue) { - errorType = "None"; + errorType = nmfConstantsMSSPM::DistributionNone; errorValue = 0; if (NormalRB->isChecked()) { - errorType = "Normal"; + errorType = nmfConstantsMSSPM::DistributionLognormal; errorValue = NormalSB->value(); } else if (UniformRB->isChecked()) { - errorType = "Uniform"; + errorType = nmfConstantsMSSPM::DistributionUniform; errorValue = (double)UniformSB->value(); } } diff --git a/MSSPM_Main/nmfMainWindow.cpp b/MSSPM_Main/nmfMainWindow.cpp index 3aa3ca3..5125b79 100755 --- a/MSSPM_Main/nmfMainWindow.cpp +++ b/MSSPM_Main/nmfMainWindow.cpp @@ -2062,7 +2062,7 @@ void nmfMainWindow::menu_about() { QString name = "Multi-Species Surplus Production Model"; - QString version = "MSSPM v1.3.0 "; + QString version = "MSSPM v1.3.1 "; QString specialAcknowledgement = ""; QString cppVersion = "C++??"; QString mysqlVersion = "?"; diff --git a/MSSPM_SimulatedData/nmfSimulatedData.cpp b/MSSPM_SimulatedData/nmfSimulatedData.cpp index c35e62a..d763b4a 100644 --- a/MSSPM_SimulatedData/nmfSimulatedData.cpp +++ b/MSSPM_SimulatedData/nmfSimulatedData.cpp @@ -266,9 +266,9 @@ nmfSimulatedData::createSimulatedBiomass( SimBiomassTMinus1 += GrowthTerm - HarvestTerm - CompetitionTerm - PredationTerm; - if (errorType == "Normal") { - addNormalError(errorValue,SimBiomassTMinus1); - } else if (errorType == "Uniform") { + if (errorType == nmfConstantsMSSPM::DistributionLognormal) { + addLognormalError(errorValue,SimBiomassTMinus1); + } else if (errorType == nmfConstantsMSSPM::DistributionUniform) { addUniformError(errorValue,SimBiomassTMinus1); } @@ -338,15 +338,16 @@ nmfSimulatedData::addUniformError(const double& errorPct, } void -nmfSimulatedData::addNormalError(const double& cv, - double& value) +nmfSimulatedData::addLognormalError(const double& cv, + double& value) { - double mu = value; +// double mu = value; std::random_device rd{}; std::mt19937 gen{rd()}; - std::normal_distribution<> normalDist(mu,(cv/100.0)*mu); // sigma = cv*mu + std::lognormal_distribution<> logNormalDist(0, cv/100.0); // stddev = cv*mu - value = std::fabs(normalDist(gen)); + value *= logNormalDist(gen); + value = (value < 0) ? 0 : value; } void diff --git a/MSSPM_SimulatedData/nmfSimulatedData.h b/MSSPM_SimulatedData/nmfSimulatedData.h index c01a71d..1c194f9 100644 --- a/MSSPM_SimulatedData/nmfSimulatedData.h +++ b/MSSPM_SimulatedData/nmfSimulatedData.h @@ -63,12 +63,12 @@ class nmfSimulatedData nmfStructsQt::ModelDataStruct m_DataStruct; /** - * @brief Adds a normal (i.e., Gaussian) error to the passed value + * @brief Adds a lognormal (i.e., Gaussian) error to the passed value * @param cv : coefficient of variation percentage - * @param value : the value which receives the normal error + * @param value : the value which receives the lognormal error */ - void addNormalError(const double& cv, - double& value); + void addLognormalError(const double& cv, + double& value); /** * @brief Adds a uniform percent error to the passed value * @param errorPct : percent error to add to value