Skip to content

Commit

Permalink
Mods for 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rklasky committed Sep 16, 2022
1 parent add04c4 commit 0e4ce16
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 40 deletions.
61 changes: 34 additions & 27 deletions MSSPM_Main/SimulatedBiomassDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 ?
Expand All @@ -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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion MSSPM_Main/nmfMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "?";
Expand Down
17 changes: 9 additions & 8 deletions MSSPM_SimulatedData/nmfSimulatedData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions MSSPM_SimulatedData/nmfSimulatedData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0e4ce16

Please sign in to comment.