Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor parameter constructor #455

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions inst/include/interface/rcpp/rcpp_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ RCPP_MODULE(fims) {
.constructor()
.constructor<double>()
.constructor<Parameter>()
.field("value", &Parameter::value)
.field("min", &Parameter::min)
.field("max", &Parameter::max)
.field("is_random_effect", &Parameter::is_random_effect)
.field("estimated", &Parameter::estimated);
.field("value", &Parameter::value_m)
.field("min", &Parameter::min_m)
.field("max", &Parameter::max_m)
.field("is_random_effect", &Parameter::is_random_effect_m)
.field("estimated", &Parameter::estimated_m);

Rcpp::class_<BevertonHoltRecruitmentInterface>("BevertonHoltRecruitment")
.constructor()
Expand Down
16 changes: 8 additions & 8 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class FleetInterface : public FIMSRcppInterfaceBase {
f0->observed_index_data_id = this->observed_index_data_id;
f0->selectivity_id = this->selectivity_id;

f0->log_obs_error = this->log_obs_error.value;
if (this->log_obs_error.estimated) {
f0->log_obs_error = this->log_obs_error.value_m;
if (this->log_obs_error.estimated_m) {
d0->RegisterParameter(f0->log_obs_error);
}
f0->log_q = this->log_q;
Expand Down Expand Up @@ -158,8 +158,8 @@ class FleetInterface : public FIMSRcppInterfaceBase {
f1->index_likelihood_id = this->index_likelihood_id;
f1->observed_agecomp_data_id = this->observed_agecomp_data_id;
f1->observed_index_data_id = this->observed_index_data_id;
f1->log_obs_error = this->log_obs_error.value;
if (this->log_obs_error.estimated) {
f1->log_obs_error = this->log_obs_error.value_m;
if (this->log_obs_error.estimated_m) {
d1->RegisterParameter(f1->log_obs_error);
}
f1->selectivity_id = this->selectivity_id;
Expand Down Expand Up @@ -203,8 +203,8 @@ class FleetInterface : public FIMSRcppInterfaceBase {
f2->index_likelihood_id = this->index_likelihood_id;
f2->observed_agecomp_data_id = this->observed_agecomp_data_id;
f2->observed_index_data_id = this->observed_index_data_id;
f2->log_obs_error = this->log_obs_error.value;
if (this->log_obs_error.estimated) {
f2->log_obs_error = this->log_obs_error.value_m;
if (this->log_obs_error.estimated_m) {
d2->RegisterParameter(f2->log_obs_error);
}
f2->selectivity_id = this->selectivity_id;
Expand Down Expand Up @@ -248,8 +248,8 @@ class FleetInterface : public FIMSRcppInterfaceBase {
f3->observed_agecomp_data_id = this->observed_agecomp_data_id;
f3->observed_index_data_id = this->observed_index_data_id;
f3->selectivity_id = this->selectivity_id;
f3->log_obs_error = this->log_obs_error.value;
if (this->log_obs_error.estimated) {
f3->log_obs_error = this->log_obs_error.value_m;
if (this->log_obs_error.estimated_m) {
d3->RegisterParameter(f3->log_obs_error);
}
f3->log_q = this->log_q;
Expand Down
16 changes: 8 additions & 8 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_interface_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@
*/
class Parameter {
public:
double value; /**< initial value of the parameter*/
double min =
double value_m; /**< initial value of the parameter*/
double min_m =
std::numeric_limits<double>::min(); /**< min value of the parameter*/
double max =
double max_m =
std::numeric_limits<double>::max(); /**< max value of the parameter*/
bool is_random_effect = false; /**< Is the parameter a random effect
bool is_random_effect_m = false; /**< Is the parameter a random effect
parameter? Default value is false.*/
bool estimated =
bool estimated_m =
false; /**< Is the parameter estimated? Default value is false.*/

/**
* @brief Constructor for initializing Parameter.
* @details Inputs include value, min, max, estimated.
*/
Parameter(double value, double min, double max, bool estimated)
: value(value), min(min), max(max), estimated(estimated) {}
: value_m(value), min_m(min), max_m(max), estimated_m(estimated) {}

/**
* @brief Constructor for initializing Parameter.
* @details Inputs include value.
*/
Parameter(double value) { this->value = value; }
Parameter(double value) { value_m = value; }

/**
* @brief Constructor for initializing Parameter.
* @details Set value to 0 when there is no input value.
*/
Parameter() { this->value = 0; }
Parameter() { value_m = 0; }
};

/**
Expand Down
52 changes: 26 additions & 26 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_maturity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {
virtual double evaluate(double x) {
fims::LogisticMaturity<double> LogisticMat;

LogisticMat.median = this->median.value;
LogisticMat.slope = this->slope.value;
LogisticMat.median = this->median.value_m;
LogisticMat.slope = this->slope.value_m;
return LogisticMat.evaluate(x);
}

Expand All @@ -90,17 +90,17 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {

// set relative info
lm0->id = this->id;
lm0->median = this->median.value;
if (this->median.estimated) {
if (this->median.is_random_effect) {
lm0->median = this->median.value_m;
if (this->median.estimated_m) {
if (this->median.is_random_effect_m) {
d0->RegisterRandomEffect(lm0->median);
} else {
d0->RegisterParameter(lm0->median);
}
}
lm0->slope = this->slope.value;
if (this->slope.estimated) {
if (this->slope.is_random_effect) {
lm0->slope = this->slope.value_m;
if (this->slope.estimated_m) {
if (this->slope.is_random_effect_m) {
d0->RegisterRandomEffect(lm0->slope);
} else {
d0->RegisterParameter(lm0->slope);
Expand All @@ -118,17 +118,17 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {

// set relative info
lm1->id = this->id;
lm1->median = this->median.value;
if (this->median.estimated) {
if (this->median.is_random_effect) {
lm1->median = this->median.value_m;
if (this->median.estimated_m) {
if (this->median.is_random_effect_m) {
d1->RegisterRandomEffect(lm1->median);
} else {
d1->RegisterParameter(lm1->median);
}
}
lm1->slope = this->slope.value;
if (this->slope.estimated) {
if (this->slope.is_random_effect) {
lm1->slope = this->slope.value_m;
if (this->slope.estimated_m) {
if (this->slope.is_random_effect_m) {
d1->RegisterRandomEffect(lm1->slope);
} else {
d1->RegisterParameter(lm1->slope);
Expand All @@ -146,17 +146,17 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {

// set relative info
lm2->id = this->id;
lm2->median = this->median.value;
if (this->median.estimated) {
if (this->median.is_random_effect) {
lm2->median = this->median.value_m;
if (this->median.estimated_m) {
if (this->median.is_random_effect_m) {
d2->RegisterRandomEffect(lm2->median);
} else {
d2->RegisterParameter(lm2->median);
}
}
lm2->slope = this->slope.value;
if (this->slope.estimated) {
if (this->slope.is_random_effect) {
lm2->slope = this->slope.value_m;
if (this->slope.estimated_m) {
if (this->slope.is_random_effect_m) {
d2->RegisterRandomEffect(lm2->slope);
} else {
d2->RegisterParameter(lm2->slope);
Expand All @@ -174,17 +174,17 @@ class LogisticMaturityInterface : public MaturityInterfaceBase {

// set relative info
lm3->id = this->id;
lm3->median = this->median.value;
if (this->median.estimated) {
if (this->median.is_random_effect) {
lm3->median = this->median.value_m;
if (this->median.estimated_m) {
if (this->median.is_random_effect_m) {
d3->RegisterRandomEffect(lm3->median);
} else {
d3->RegisterParameter(lm3->median);
}
}
lm3->slope = this->slope.value;
if (this->slope.estimated) {
if (this->slope.is_random_effect) {
lm3->slope = this->slope.value_m;
if (this->slope.estimated_m) {
if (this->slope.is_random_effect_m) {
d3->RegisterRandomEffect(lm3->slope);
} else {
d3->RegisterParameter(lm3->slope);
Expand Down
80 changes: 40 additions & 40 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {
virtual double evaluate(double spawners, double ssbzero) {
fims::SRBevertonHolt<double> BevHolt;

BevHolt.logit_steep = this->logit_steep.value;
if (this->logit_steep.value == 1.0) {
BevHolt.logit_steep = this->logit_steep.value_m;
if (this->logit_steep.value_m == 1.0) {
warning(
"Steepness is subject to a logit transformation, so its value is "
"0.7848469. Fixing it at 1.0 is not currently possible.");
}

BevHolt.log_rzero = this->log_rzero.value;
BevHolt.log_rzero = this->log_rzero.value_m;

return BevHolt.evaluate(spawners, ssbzero);
}

virtual double evaluate_nll() {
fims::SRBevertonHolt<double> NLL;

NLL.log_sigma_recruit = this->log_sigma_recruit.value;
NLL.log_sigma_recruit = this->log_sigma_recruit.value_m;
NLL.recruit_deviations.resize(deviations.size()); // Vector from TMB
for (int i = 0; i < deviations.size(); i++) {
NLL.recruit_deviations[i] = deviations[i];
Expand All @@ -121,25 +121,25 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {

// set relative info
b0->id = this->id;
b0->logit_steep = this->logit_steep.value;
if (this->logit_steep.estimated) {
if (this->logit_steep.is_random_effect) {
b0->logit_steep = this->logit_steep.value_m;
if (this->logit_steep.estimated_m) {
if (this->logit_steep.is_random_effect_m) {
d0->RegisterRandomEffect(b0->logit_steep);
} else {
d0->RegisterParameter(b0->logit_steep);
}
}
b0->log_rzero = this->log_rzero.value;
if (this->log_rzero.estimated) {
if (this->log_rzero.is_random_effect) {
b0->log_rzero = this->log_rzero.value_m;
if (this->log_rzero.estimated_m) {
if (this->log_rzero.is_random_effect_m) {
d0->RegisterRandomEffect(b0->log_rzero);
} else {
d0->RegisterParameter(b0->log_rzero);
}
}
b0->log_sigma_recruit = this->log_sigma_recruit.value;
if (this->log_sigma_recruit.estimated) {
if (this->log_sigma_recruit.is_random_effect) {
b0->log_sigma_recruit = this->log_sigma_recruit.value_m;
if (this->log_sigma_recruit.estimated_m) {
if (this->log_sigma_recruit.is_random_effect_m) {
d0->RegisterRandomEffect(b0->log_sigma_recruit);
} else {
d0->RegisterParameter(b0->log_sigma_recruit);
Expand Down Expand Up @@ -170,25 +170,25 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {

// set relative info
b1->id = this->id;
b1->logit_steep = this->logit_steep.value;
if (this->logit_steep.estimated) {
if (this->logit_steep.is_random_effect) {
b1->logit_steep = this->logit_steep.value_m;
if (this->logit_steep.estimated_m) {
if (this->logit_steep.is_random_effect_m) {
d1->RegisterRandomEffect(b1->logit_steep);
} else {
d1->RegisterParameter(b1->logit_steep);
}
}
b1->log_rzero = this->log_rzero.value;
if (this->log_rzero.estimated) {
if (this->log_rzero.is_random_effect) {
b1->log_rzero = this->log_rzero.value_m;
if (this->log_rzero.estimated_m) {
if (this->log_rzero.is_random_effect_m) {
d1->RegisterRandomEffect(b1->log_rzero);
} else {
d1->RegisterParameter(b1->log_rzero);
}
}
b1->log_sigma_recruit = this->log_sigma_recruit.value;
if (this->log_sigma_recruit.estimated) {
if (this->log_sigma_recruit.is_random_effect) {
b1->log_sigma_recruit = this->log_sigma_recruit.value_m;
if (this->log_sigma_recruit.estimated_m) {
if (this->log_sigma_recruit.is_random_effect_m) {
d1->RegisterRandomEffect(b1->log_sigma_recruit);
} else {
d1->RegisterParameter(b1->log_sigma_recruit);
Expand Down Expand Up @@ -219,25 +219,25 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {

// set relative info
b2->id = this->id;
b2->logit_steep = this->logit_steep.value;
if (this->logit_steep.estimated) {
if (this->logit_steep.is_random_effect) {
b2->logit_steep = this->logit_steep.value_m;
if (this->logit_steep.estimated_m) {
if (this->logit_steep.is_random_effect_m) {
d2->RegisterRandomEffect(b2->logit_steep);
} else {
d2->RegisterParameter(b2->logit_steep);
}
}
b2->log_rzero = this->log_rzero.value;
if (this->log_rzero.estimated) {
if (this->log_rzero.is_random_effect) {
b2->log_rzero = this->log_rzero.value_m;
if (this->log_rzero.estimated_m) {
if (this->log_rzero.is_random_effect_m) {
d2->RegisterRandomEffect(b2->log_rzero);
} else {
d2->RegisterParameter(b2->log_rzero);
}
}
b2->log_sigma_recruit = this->log_sigma_recruit.value;
if (this->log_sigma_recruit.estimated) {
if (this->log_sigma_recruit.is_random_effect) {
b2->log_sigma_recruit = this->log_sigma_recruit.value_m;
if (this->log_sigma_recruit.estimated_m) {
if (this->log_sigma_recruit.is_random_effect_m) {
d2->RegisterRandomEffect(b2->log_sigma_recruit);
} else {
d2->RegisterParameter(b2->log_sigma_recruit);
Expand Down Expand Up @@ -268,25 +268,25 @@ class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {

// set relative info
b3->id = this->id;
b3->logit_steep = this->logit_steep.value;
if (this->logit_steep.estimated) {
if (this->logit_steep.is_random_effect) {
b3->logit_steep = this->logit_steep.value_m;
if (this->logit_steep.estimated_m) {
if (this->logit_steep.is_random_effect_m) {
d3->RegisterRandomEffect(b3->logit_steep);
} else {
d3->RegisterParameter(b3->logit_steep);
}
}
b3->log_rzero = this->log_rzero.value;
if (this->log_rzero.estimated) {
if (this->log_rzero.is_random_effect) {
b3->log_rzero = this->log_rzero.value_m;
if (this->log_rzero.estimated_m) {
if (this->log_rzero.is_random_effect_m) {
d3->RegisterRandomEffect(b3->log_rzero);
} else {
d3->RegisterParameter(b3->log_rzero);
}
}
b3->log_sigma_recruit = this->log_sigma_recruit.value;
if (this->log_sigma_recruit.estimated) {
if (this->log_sigma_recruit.is_random_effect) {
b3->log_sigma_recruit = this->log_sigma_recruit.value_m;
if (this->log_sigma_recruit.estimated_m) {
if (this->log_sigma_recruit.is_random_effect_m) {
d3->RegisterRandomEffect(b3->log_sigma_recruit);
} else {
d3->RegisterParameter(b3->log_sigma_recruit);
Expand Down
Loading