Skip to content

Commit

Permalink
style: run clang format
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristineStawitz-NOAA committed Feb 29, 2024
1 parent 895d728 commit 97281c2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion inst/include/common/data_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct DataObject : public fims_model_object::FIMSObject<Type> {
size_t jmax; /**< 2nd dimension of data object>*/
size_t kmax; /**< 3rd dimension of data object>*/
size_t lmax; /**< 4th dimension of data object>*/
Type na_value = -999; /**< specifying the NA value >*/
Type na_value = -999; /**< specifying the NA value >*/

/**
* Constructs a one-dimensional data object.
Expand Down
10 changes: 5 additions & 5 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ class PopulationInterface : public PopulationInterfaceBase {
Rcpp::NumericVector log_M; /**< log of the natural mortality of the stock*/
Rcpp::NumericVector log_init_naa; /**<log of the initial numbers at age*/
Rcpp::NumericVector ages; /**<vector of ages in the population; length nages*/
Rcpp::NumericVector proportion_female; /**<doule representing the proportion of female individuals */
bool estimate_M; /**<whether parameter should be estimated*/
bool estimate_initNAA; /**<whether parameter should be estimated*/
Rcpp::NumericVector proportion_female; /**<doule representing the proportion
of female individuals */
bool estimate_M; /**<whether parameter should be estimated*/
bool estimate_initNAA; /**<whether parameter should be estimated*/
bool estimate_prop_female; /**<whether proportion female should be estimated*/

PopulationInterface() : PopulationInterfaceBase() {}
Expand Down Expand Up @@ -148,12 +149,11 @@ class PopulationInterface : public PopulationInterfaceBase {
}
for (int i = 0; i < proportion_female.size(); i++) {
population->proportion_female[i] = this->proportion_female[i];
if(estimate_prop_female){
if (estimate_prop_female) {
info->RegisterParameter(population->proportion_female[i]);
}
}


// add to Information
info->populations[population->id] = population;

Expand Down
32 changes: 17 additions & 15 deletions inst/include/population_dynamics/fleet/fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,28 +168,30 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
observed_acomp.resize(this->nages);
expected_acomp.resize(this->nages);
Type sum = 0.0;
bool containsNA = false; /**< skips the entire year if any values are NA */
bool containsNA =
false; /**< skips the entire year if any values are NA */
for (size_t a = 0; a < this->nages; a++) {
if(this->observed_agecomp_data->at(y,a) != this->observed_agecomp_data->na_value){
if (this->observed_agecomp_data->at(y, a) !=
this->observed_agecomp_data->na_value) {
size_t i_age_year = y * this->nages + a;
sum += this->catch_numbers_at_age[i_age_year];
} else{
} else {
containsNA = true; /**< sets to true if any values are NA >*/
break;
}
}
if(!containsNA){
for (size_t a = 0; a < this->nages; a++) {
size_t i_age_year = y * this->nages + a;
expected_acomp[a] = this->catch_numbers_at_age[i_age_year] /
sum; // probabilities for ages
if (!containsNA) {
for (size_t a = 0; a < this->nages; a++) {
size_t i_age_year = y * this->nages + a;
expected_acomp[a] = this->catch_numbers_at_age[i_age_year] /
sum; // probabilities for ages

observed_acomp[a] = this->observed_agecomp_data->at(y, a);
observed_acomp[a] = this->observed_agecomp_data->at(y, a);

FLEET_LOG << " age " << a << " in year " << y
<< "has expected: " << expected_acomp[a]
<< " and observed: " << observed_acomp[a] << std::endl;
}
FLEET_LOG << " age " << a << " in year " << y
<< "has expected: " << expected_acomp[a]
<< " and observed: " << observed_acomp[a] << std::endl;
}
dmultinom.x = observed_acomp;
dmultinom.p = expected_acomp;
nll -= dmultinom.evaluate(true);
Expand All @@ -208,7 +210,8 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
#ifdef TMB_MODEL
fims_distributions::Dnorm<Type> dnorm;
for (size_t i = 0; i < this->expected_index.size(); i++) {
if(this->observed_index_data->at(i) != this->observed_index_data->na_value){
if (this->observed_index_data->at(i) !=
this->observed_index_data->na_value) {
dnorm.x = fims_math::log(this->observed_index_data->at(i));
dnorm.mean = fims_math::log(this->expected_index[i]);
dnorm.sd = fims_math::exp(this->log_obs_error[i]);
Expand All @@ -219,7 +222,6 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
<< this->observed_index_data->at(i)
<< " and expected is: " << this->expected_index[i] << std::endl;
FLEET_LOG << " log obs error is: " << this->log_obs_error[i] << std::endl;

}
FLEET_LOG << " sd is: " << dnorm.sd << std::endl;
FLEET_LOG << " index nll: " << nll << std::endl;
Expand Down
12 changes: 8 additions & 4 deletions inst/include/population_dynamics/population/population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct Population : public fims_model_object::FIMSObject<Type> {
fims::Vector<Type>
log_init_naa; /*!< estimated parameter: log numbers at age*/
fims::Vector<Type> log_M; /*!< estimated parameter: log Natural Mortality*/
fims::Vector<Type> proportion_female; /*!< estimated parameter: proportion female by age */
fims::Vector<Type>
proportion_female; /*!< estimated parameter: proportion female by age */

// Transformed values
fims::Vector<Type> M; /*!< transformed parameter: Natural Mortality*/
Expand Down Expand Up @@ -317,7 +318,8 @@ struct Population : public fims_model_object::FIMSObject<Type> {
this->spawning_biomass[year] +=
this->proportion_female[age] * this->numbers_at_age[i_age_year] *
this->proportion_mature_at_age[i_age_year] * this->weight_at_age[age];
POPULATION_LOG << " proportion female " << this->proportion_female[age] << " "
POPULATION_LOG << " proportion female " << this->proportion_female[age]
<< " "
<< " mature age " << age << " is "
<< this->proportion_mature_at_age[i_age_year] << " "
<< " numbers at age " << this->numbers_at_age[i_age_year]
Expand All @@ -339,7 +341,8 @@ struct Population : public fims_model_object::FIMSObject<Type> {
void CalculateUnfishedSpawningBiomass(size_t i_age_year, size_t year,
size_t age) {
this->unfished_spawning_biomass[year] +=
this->proportion_female[age] * this->unfished_numbers_at_age[i_age_year] *
this->proportion_female[age] *
this->unfished_numbers_at_age[i_age_year] *
this->proportion_mature_at_age[i_age_year] * this->weight_at_age[age];
}

Expand All @@ -364,7 +367,8 @@ struct Population : public fims_model_object::FIMSObject<Type> {
numbers_spr[this->nages - 1] =
(numbers_spr[nages - 2] * fims_math::exp(-this->M[nages - 2])) /
(1 - fims_math::exp(-this->M[this->nages - 1]));
phi_0 += numbers_spr[this->nages - 1] * this->proportion_female[this->nages - 1] *
phi_0 += numbers_spr[this->nages - 1] *
this->proportion_female[this->nages - 1] *
this->proportion_mature_at_age[this->nages - 1] *
this->growth->evaluate(ages[this->nages - 1]);
return phi_0;
Expand Down
10 changes: 5 additions & 5 deletions tests/gtest/test_population_test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class PopulationEvaluateTestFixture : public testing::Test {
population.log_init_naa[i] = log_naa_distribution(generator);
}

// prop_female
// prop_female
double prop_female_min = 0.1;
double prop_female_max = 0.9;
std::uniform_real_distribution<double> prop_female_distribution(prop_female_min,
prop_female_max);
std::uniform_real_distribution<double> prop_female_distribution(
prop_female_min, prop_female_max);
for (int i = 0; i < nages; i++) {
population.proportion_female[i] = prop_female_distribution(generator);
}
Expand Down Expand Up @@ -263,8 +263,8 @@ class PopulationPrepareTestFixture : public testing::Test {
// prop_female
double prop_female_min = 0.1;
double prop_female_max = 0.9;
std::uniform_real_distribution<double> prop_female_distribution(prop_female_min,
prop_female_max);
std::uniform_real_distribution<double> prop_female_distribution(
prop_female_min, prop_female_max);
for (int i = 0; i < nages; i++) {
population.proportion_female[i] = prop_female_distribution(generator);
}
Expand Down

0 comments on commit 97281c2

Please sign in to comment.