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 authored Dec 13, 2023
1 parent b58aaee commit 77c807c
Show file tree
Hide file tree
Showing 13 changed files with 704 additions and 762 deletions.
751 changes: 348 additions & 403 deletions inst/include/common/fims_vector.hpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions inst/include/common/information.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
#include "../population_dynamics/recruitment/recruitment.hpp"
#include "../population_dynamics/selectivity/selectivity.hpp"
#include "def.hpp"
#include "model_object.hpp"
#include "fims_vector.hpp"

#include "model_object.hpp"

namespace fims_info {

Expand Down
21 changes: 10 additions & 11 deletions inst/include/common/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class Model { // may need singleton
// vector< vector<Type> > creates a nested vector structure where
// each vector can be a different dimension. Does not work with ADREPORT
// fleets
vector<vector<Type> > exp_index(n_fleets);
vector<vector<Type> > exp_catch(n_fleets);
vector<vector<Type> > cnaa(n_fleets);
vector<vector<Type> > cwaa(n_fleets);
vector<vector<Type> > F_mort(n_fleets);
vector<vector<Type> > exp_index(n_fleets);
vector<vector<Type> > exp_catch(n_fleets);
vector<vector<Type> > cnaa(n_fleets);
vector<vector<Type> > cwaa(n_fleets);
vector<vector<Type> > F_mort(n_fleets);
// populations
vector<vector<Type> > naa(n_pops);
vector<vector<Type> > ssb(n_pops);
Expand Down Expand Up @@ -163,11 +163,11 @@ class Model { // may need singleton
for (jt = this->fims_information->fleets.begin();
jt != this->fims_information->fleets.end(); ++jt) {
#ifdef TMB_MODEL
exp_index(fleet_idx) = (*jt).second->expected_index;
exp_catch(fleet_idx) = (*jt).second->expected_catch;
F_mort(fleet_idx) = (*jt).second->Fmort;
cnaa(fleet_idx) = (*jt).second->catch_numbers_at_age;
cwaa(fleet_idx) = (*jt).second->catch_weight_at_age;
exp_index(fleet_idx) = (*jt).second->expected_index;
exp_catch(fleet_idx) = (*jt).second->expected_catch;
F_mort(fleet_idx) = (*jt).second->Fmort;
cnaa(fleet_idx) = (*jt).second->catch_numbers_at_age;
cwaa(fleet_idx) = (*jt).second->catch_weight_at_age;
#endif
fleet_idx += 1;
}
Expand Down Expand Up @@ -215,7 +215,6 @@ class Model { // may need singleton

return jnll;
}

};

// Create singleton instance of Model class
Expand Down
6 changes: 3 additions & 3 deletions inst/include/distributions/functors/tmb_distributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

#ifdef TMB_MODEL

#include "distributions_base.hpp"
#include "../../common/fims_vector.hpp"
#include "distributions_base.hpp"

namespace fims_distributions {

Expand Down Expand Up @@ -48,8 +48,8 @@ struct Dnorm : public DistributionsBase<Type> {
template <typename Type>
struct Dmultinom : public DistributionsBase<Type> {
fims::Vector<Type> x; /*!< Vector of length K of integers */
fims::Vector<Type> p; /*!< Vector of length K, specifying the probability for the K
classes (note, unlike in R these must sum to 1). */
fims::Vector<Type> p; /*!< Vector of length K, specifying the probability for
the K classes (note, unlike in R these must sum to 1). */

Dmultinom() : DistributionsBase<Type>() {}

Expand Down
1 change: 1 addition & 0 deletions inst/include/interface/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// use isnan macro in math.h instead of TMB's isnan for fixing the r-cmd-check
// issue
#include <math.h>

#include <TMB.hpp>

// define REPORT, ADREPORT, and SIMULATE
Expand Down
8 changes: 4 additions & 4 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class FleetInterface : public FleetInterfaceBase {
log_Fmort; /**< log of fishing mortality rate for the fleet*/
bool estimate_F = false; /**< whether the parameter F should be estimated*/
bool estimate_q = false; /**< whether the parameter q should be estimated*/
bool estimate_obs_error = false; /**< whether the parameter log_obs_error
should be estimated*/
bool random_q = false; /**< whether q should be a random effect*/
bool random_F = false; /**< whether F should be a random effect*/
bool estimate_obs_error = false; /**< whether the parameter log_obs_error
should be estimated*/
bool random_q = false; /**< whether q should be a random effect*/
bool random_F = false; /**< whether F should be a random effect*/
Rcpp::NumericVector log_obs_error; /**< the log of the observation error */

FleetInterface() : FleetInterfaceBase() {}
Expand Down
15 changes: 8 additions & 7 deletions inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class RecruitmentInterfaceBase : public FIMSRcppInterfaceBase {

// static std::vector<double> log_recruit_devs; /**< vector of log recruitment
// deviations*/
// static bool constrain_deviations; /**< whether or not the rec devs are constrained*/
// static bool constrain_deviations; /**< whether or not the rec devs are
// constrained*/

RecruitmentInterfaceBase() {
this->id = RecruitmentInterfaceBase::id_g++;
Expand Down Expand Up @@ -69,12 +70,12 @@ std::map<uint32_t, RecruitmentInterfaceBase*>
*/
class BevertonHoltRecruitmentInterface : public RecruitmentInterfaceBase {
public:
Parameter logit_steep; /**< steepness or the productivity of the stock*/
Parameter log_rzero; /**< recruitment at unfished biomass */
Parameter log_sigma_recruit; /**< the log of the stock recruit standard deviation */
Rcpp::NumericVector log_devs; /**< log recruitment deviations*/
bool estimate_log_devs =
false; /**< boolean describing whether to estimate */
Parameter logit_steep; /**< steepness or the productivity of the stock*/
Parameter log_rzero; /**< recruitment at unfished biomass */
Parameter
log_sigma_recruit; /**< the log of the stock recruit standard deviation */
Rcpp::NumericVector log_devs; /**< log recruitment deviations*/
bool estimate_log_devs = false; /**< boolean describing whether to estimate */

BevertonHoltRecruitmentInterface() : RecruitmentInterfaceBase() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase {

template <typename Type>
bool add_to_fims_tmb_internal() {

std::shared_ptr<fims_info::Information<Type>> info =
fims_info::Information<Type>::GetInstance();

Expand Down
161 changes: 81 additions & 80 deletions inst/include/population_dynamics/fleet/fleet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#define FIMS_POPULATION_DYNAMICS_FLEET_HPP

#include "../../common/data_object.hpp"
#include "../../common/fims_vector.hpp"
#include "../../common/model_object.hpp"
#include "../../distributions/distributions.hpp"
#include "../selectivity/selectivity.hpp"
#include "../../common/fims_vector.hpp"

namespace fims_popdy {

Expand All @@ -24,62 +24,63 @@ namespace fims_popdy {
*/
template <class Type>
struct Fleet : public fims_model_object::FIMSObject<Type> {
static uint32_t id_g; /*!< reference id for fleet object*/
size_t nyears; /*!< the number of years in the model*/
size_t nages; /*!< the number of ages in the model*/

// This likelihood index is not currently being used as only one likelihood
// distribution is available. These are for a future update M2+.
int fleet_index_likelihood_id_m =
-999; /*!<id of index likelihood component. The "fleet_" prefix indicates
it belongs to the Fleet struct, and the "_m" postfix signifies
that it's a member variable.*/
std::shared_ptr<fims_distributions::DistributionsBase<Type>>
index_likelihood; /*!< index likelihood component*/

// This likelihood index is not currently being used as only one likelihood
// distribution is available. These are for a future update M2+.
int fleet_agecomp_likelihood_id_m =
-999; /*!< id of agecomp likelihood component*/
std::shared_ptr<fims_distributions::DistributionsBase<Type>>
agecomp_likelihood; /*!< agecomp likelihood component*/

// selectivity
int fleet_selectivity_id_m = -999; /*!< id of selectivity component*/
std::shared_ptr<SelectivityBase<Type>>
selectivity; /*!< selectivity component*/

int fleet_observed_index_data_id_m = -999; /*!< id of index data */
std::shared_ptr<fims_data_object::DataObject<Type>>
observed_index_data; /*!< observed index data*/

int fleet_observed_agecomp_data_id_m = -999; /*!< id of age comp data */
std::shared_ptr<fims_data_object::DataObject<Type>>
observed_agecomp_data; /*!< observed agecomp data*/

// Mortality and catchability
fims::Vector<Type> log_Fmort; /*!< estimated parameter: log Fishing mortality*/
Type log_q; /*!< estimated parameter: catchability of the fleet */

fims::Vector<Type> log_obs_error; /*!< estimated parameters: observation error associated
with index */
fims::Vector<Type> Fmort; /*!< transformed parameter: Fishing mortality*/
Type q; /*!< transofrmed parameter: the catchability of the fleet */

// derived quantities
fims::Vector<Type> catch_at_age; /*!<derived quantity catch at age*/
fims::Vector<Type> catch_index; /*!<derived quantity catch index*/
fims::Vector<Type> age_composition; /*!<derived quantity age composition*/

// derived quantities
fims::Vector<Type> expected_catch; /*!<model expected total catch*/
fims::Vector<Type> expected_index; /*!<model expected index of abundance*/
fims::Vector<Type> catch_numbers_at_age; /*!<model expected catch at age*/
fims::Vector<Type> catch_weight_at_age; /*!<model expected weight at age*/
bool is_survey = false; /*!< is this fleet object a survey*/

static uint32_t id_g; /*!< reference id for fleet object*/
size_t nyears; /*!< the number of years in the model*/
size_t nages; /*!< the number of ages in the model*/

// This likelihood index is not currently being used as only one likelihood
// distribution is available. These are for a future update M2+.
int fleet_index_likelihood_id_m =
-999; /*!<id of index likelihood component. The "fleet_" prefix indicates
it belongs to the Fleet struct, and the "_m" postfix signifies
that it's a member variable.*/
std::shared_ptr<fims_distributions::DistributionsBase<Type>>
index_likelihood; /*!< index likelihood component*/

// This likelihood index is not currently being used as only one likelihood
// distribution is available. These are for a future update M2+.
int fleet_agecomp_likelihood_id_m =
-999; /*!< id of agecomp likelihood component*/
std::shared_ptr<fims_distributions::DistributionsBase<Type>>
agecomp_likelihood; /*!< agecomp likelihood component*/

// selectivity
int fleet_selectivity_id_m = -999; /*!< id of selectivity component*/
std::shared_ptr<SelectivityBase<Type>>
selectivity; /*!< selectivity component*/

int fleet_observed_index_data_id_m = -999; /*!< id of index data */
std::shared_ptr<fims_data_object::DataObject<Type>>
observed_index_data; /*!< observed index data*/

int fleet_observed_agecomp_data_id_m = -999; /*!< id of age comp data */
std::shared_ptr<fims_data_object::DataObject<Type>>
observed_agecomp_data; /*!< observed agecomp data*/

// Mortality and catchability
fims::Vector<Type>
log_Fmort; /*!< estimated parameter: log Fishing mortality*/
Type log_q; /*!< estimated parameter: catchability of the fleet */

fims::Vector<Type> log_obs_error; /*!< estimated parameters: observation error
associated with index */
fims::Vector<Type> Fmort; /*!< transformed parameter: Fishing mortality*/
Type q; /*!< transofrmed parameter: the catchability of the fleet */

// derived quantities
fims::Vector<Type> catch_at_age; /*!<derived quantity catch at age*/
fims::Vector<Type> catch_index; /*!<derived quantity catch index*/
fims::Vector<Type> age_composition; /*!<derived quantity age composition*/

// derived quantities
fims::Vector<Type> expected_catch; /*!<model expected total catch*/
fims::Vector<Type> expected_index; /*!<model expected index of abundance*/
fims::Vector<Type> catch_numbers_at_age; /*!<model expected catch at age*/
fims::Vector<Type> catch_weight_at_age; /*!<model expected weight at age*/
bool is_survey = false; /*!< is this fleet object a survey*/

#ifdef TMB_MODEL
::objective_function<Type> *of;
::objective_function<Type> *of;
#endif

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
expected_catch.resize(nyears);
expected_index.resize(nyears); // assume index is for all ages.
catch_numbers_at_age.resize(nyears * nages);

log_obs_error.resize(nyears);
log_Fmort.resize(nyears);
Fmort.resize(nyears);
Expand Down Expand Up @@ -141,7 +142,8 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
for (size_t year = 0; year < this->nyears; year++) {
FLEET_LOG << "input F mort " << this->log_Fmort[year] << std::endl;
FLEET_LOG << "input q " << this->log_q << std::endl;
FLEET_LOG << "input log_obs_error " << this->log_obs_error[year] << std::endl;
FLEET_LOG << "input log_obs_error " << this->log_obs_error[year]
<< std::endl;
this->Fmort[year] = fims_math::exp(this->log_Fmort[year]);
}
}
Expand All @@ -160,7 +162,6 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {

} else {
for (size_t y = 0; y < this->nyears; y++) {

fims::Vector<Type> observed_acomp;
fims::Vector<Type> expected_acomp;

Expand Down Expand Up @@ -191,31 +192,31 @@ struct Fleet : public fims_model_object::FIMSObject<Type> {
FLEET_LOG << "Age comp negative log-likelihood for fleet," << this->id
<< nll << std::endl;
#endif
return nll;
}
virtual const Type evaluate_index_nll() {
Type nll = 0.0; /*!< The negative log likelihood value */
return nll;
}

virtual const Type evaluate_index_nll() {
Type nll = 0.0; /*!< The negative log likelihood value */

#ifdef TMB_MODEL
fims_distributions::Dnorm<Type> dnorm;
for (size_t i = 0; i < this->expected_index.size(); i++) {
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]);
nll -= dnorm.evaluate(true);
FLEET_LOG << "observed index data: " << i << " is "
<< 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;
fims_distributions::Dnorm<Type> dnorm;
for (size_t i = 0; i < this->expected_index.size(); i++) {
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]);
nll -= dnorm.evaluate(true);

FLEET_LOG << "observed index data: " << i << " is "
<< 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;

#endif
return nll;
}
return nll;
}
};

// default id of the singleton fleet class
Expand Down
Loading

0 comments on commit 77c807c

Please sign in to comment.