diff --git a/inst/include/common/fims_vector.hpp b/inst/include/common/fims_vector.hpp index c557ebdb..0892846d 100644 --- a/inst/include/common/fims_vector.hpp +++ b/inst/include/common/fims_vector.hpp @@ -3,421 +3,366 @@ #include "../interface/interface.hpp" -namespace fims { - +namespace fims { /** - * Wrapper class for std::vector types. If this file is compiled with -DTMB_MODEL, - * conversion operators are defined for TMB vector types. - * - * All std::vector functions are copied over from the std library. While some of these may - * not be called explicitly in FIMS, they may be required to run other std library functions. - * + * Wrapper class for std::vector types. If this file is compiled with + * -DTMB_MODEL, conversion operators are defined for TMB vector types. + * + * All std::vector functions are copied over from the std library. While some of + * these may not be called explicitly in FIMS, they may be required to run other + * std library functions. + * */ -template -class Vector{ - std::vector vec_m; - - /** - * @brief friend comparison operator. Allows the operartor to see private - * members of fims::Vector. - */ - template - friend bool operator==( const fims::Vector& lhs, - const fims::Vector& rhs ); -public: - //Member Types - - typedef typename std::vector::value_type value_type; /*!*/ - typedef typename std::vector::allocator_type allocator_type; /*!*/ - typedef typename std::vector::size_type size_type; /*!*/ - typedef typename std::vector::difference_type difference_type; /*!*/ - typedef typename std::vector::reference reference;/*!*/ - typedef typename std::vector::const_reference const_reference; /*!*/ - typedef typename std::vector::pointer pointer; /*!*/ - typedef typename std::vector::const_pointer const_pointer; /*!*/ - typedef typename std::vector::iterator iterator; /*!*/ - typedef typename std::vector::const_iterator const_iterator;/*!*/ - typedef typename std::vector::reverse_iterator reverse_iterator;/*!*/ - typedef typename std::vector::const_reverse_iterator const_reverse_iterator; /*!*/ - - //Constructors - /** - * Default constructor. - */ - Vector(){ - } - - /** - * @brief Constructs a Vector of length "size" and sets the elements with the value from input "value". - */ - Vector(size_t size, const Type& value = Type()){ - this->vec_m.resize(size, value); - } - - /** - * @brief Copy constructor. - */ - Vector(const Vector& other){ - this->vec_m.resize(other.size()); - for(size_t i =0; i < this->vec_m.size(); i++){ - this->vec_m[i] = other[i]; - } - } - - /** - * @brief Initialization constructor from std::vector type. - */ - Vector(const std::vector& other){ - this->vec_m = other; - } +template +class Vector { + std::vector vec_m; + + /** + * @brief friend comparison operator. Allows the operartor to see private + * members of fims::Vector. + */ + template + friend bool operator==(const fims::Vector& lhs, + const fims::Vector& rhs); + + public: + // Member Types - //TMB specific constructor + typedef + typename std::vector::value_type value_type; /*!*/ + typedef typename std::vector::allocator_type + allocator_type; /*!*/ + typedef typename std::vector::size_type size_type; /*!*/ + typedef typename std::vector::difference_type + difference_type; /*!*/ + typedef typename std::vector::reference + reference; /*!*/ + typedef typename std::vector::const_reference + const_reference; /*!*/ + typedef typename std::vector::pointer pointer; /*!*/ + typedef typename std::vector::const_pointer + const_pointer; /*!*/ + typedef typename std::vector::iterator iterator; /*!*/ + typedef typename std::vector::const_iterator + const_iterator; /*!*/ + typedef typename std::vector::reverse_iterator + reverse_iterator; /*!*/ + typedef typename std::vector::const_reverse_iterator + const_reverse_iterator; /*!*/ + + // Constructors + /** + * Default constructor. + */ + Vector() {} + + /** + * @brief Constructs a Vector of length "size" and sets the elements with the + * value from input "value". + */ + Vector(size_t size, const Type& value = Type()) { + this->vec_m.resize(size, value); + } + + /** + * @brief Copy constructor. + */ + Vector(const Vector& other) { + this->vec_m.resize(other.size()); + for (size_t i = 0; i < this->vec_m.size(); i++) { + this->vec_m[i] = other[i]; + } + } + + /** + * @brief Initialization constructor from std::vector type. + */ + Vector(const std::vector& other) { this->vec_m = other; } + + // TMB specific constructor #ifdef TMB_MODEL - - /** - * @brief Initialization constructor from tmbutils::vector type. - */ - Vector(const tmbutils::vector& other){ - this->vec_m.resize(other.size()); - for(size_t i =0; i < this->vec_m.size(); i++){ - this->vec_m[i] = other[i]; - } - } - - + + /** + * @brief Initialization constructor from tmbutils::vector type. + */ + Vector(const tmbutils::vector& other) { + this->vec_m.resize(other.size()); + for (size_t i = 0; i < this->vec_m.size(); i++) { + this->vec_m[i] = other[i]; + } + } + #endif - - /** - * The following are std::vector functions copied over from the standard library. While some of these may - * not be called explicitly in FIMS, they may be required to run other std library functions. - */ - - /** - * @brief Returns a reference to the element at specified location pos. No bounds checking is performed. - */ - inline Type& operator[](size_t pos){ - return this->vec_m[pos]; - } - - /** - * @brief Returns a constant reference to the element at specified location pos. No bounds checking is performed. - */ - inline const Type& operator[](size_t n) const{ - return this->vec_m[n]; - } - - - /** - * @brief Returns a reference to the element at specified location pos. Bounds checking is performed. - */ - inline Type& at(size_t n) { - return this->vec_m.at(n); - } - - /** - * @brief Returns a constant reference to the element at specified location pos. Bounds checking is performed. - */ - inline const Type& at(size_t n) const{ - return this->vec_m.at(n); - } - - /** - * @brief Returns a reference to the first element in the container. - */ - inline reference front() { - return this->vec_m.front(); - } - - /** - * @brief Returns a constant reference to the first element in the container. - */ - inline const_reference front() const { - return this->vec_m.front(); - } - - /** - * @brief Returns a reference to the last element in the container. - */ - inline reference back() { - return this->vec_m.back(); - } - - - /** - * @brief Returns a constant reference to the last element in the container. - */ - inline const_reference back() const { - return this->vec_m.back(); - } - - - /** - * @brief Returns a pointer to the underlying data array. - */ - inline pointer data() { - return this->vec_m.data(); - } - - - /** - * @brief Returns a constant pointer to the underlying data array. - */ - inline const_pointer data() const { - return this->vec_m.data(); - } - - //iterators - - - /** - * @brief Returns an iterator to the first element of the vector. - */ - inline iterator begin() { - return this->vec_m.begin(); - } - - /** - * @brief Returns an iterator to the element following the last element of the vector. - */ - inline iterator end() { - return this->vec_m.end(); - } - - /** - * @brief Returns a reverse iterator to the first element of the reversed vector. It corresponds to the last element of the non-reversed vector. - */ - inline reverse_iterator rbegin() { - return this->vec_m.rbegin(); - } - - /** - * @brief Returns a reverse iterator to the element following the last element of the reversed vector. It corresponds to the element preceding the first element of the non-reversed vector. - */ - inline reverse_iterator rend() { - return this->vec_m.rend(); - } - - - /** - * @brief Returns a constant reverse iterator to the first element of the reversed vector. It corresponds to the last element of the non-reversed vector. - */ - inline const_reverse_iterator rbegin() const { - return this->vec_m.rbegin(); - } - - - /** - * @brief Returns a constant reverse iterator to the element following the last element of the reversed vector. It corresponds to the element preceding the first element of the non-reversed vector. - */ - inline const_reverse_iterator rend() const { - return this->vec_m.rend(); - } - - //capacity - - - /** - * @brief Checks whether the container is empty. - */ - inline bool empty() { - return this->vec_m.empty(); - } - - /** - * @brief Returns the number of elements. - */ - inline size_type size() const { - return this->vec_m.size(); - } - - /** - * @brief Returns the maximum possible number of elements. - */ - inline size_type max_size() const { - return this->vec_m.max_size(); - } - - /** - * @brief Reserves storage. - */ - inline void reserve(size_type cap) { - this->vec_m.reserve(cap); - } - - - /** - * @brief Returns the number of elements that can be held in currently allocated storage. - */ - inline size_type capacity() { - return this->vec_m.capacity(); - } - - /** - * @brief Reduces memory usage by freeing unused memory. - */ - inline void shrink_to_fit() { - this->vec_m.shrink_to_fit(); - } - - //modifiers - - /** - * @brief Clears the contents. - */ - inline void clear() { - this->vec_m.clear(); - } - - - /** - * @brief Inserts value before pos. - */ - inline iterator insert(const_iterator pos, const Type& value) { - return this->vec_m.insert(pos, value); - } - - /** - * @brief Inserts count copies of the value before pos. - */ - inline iterator insert(const_iterator pos, size_type count, const Type& value) { - return this->vec_m.insert(pos, count, value); - } - - /** - * @brief Inserts elements from range [first, last) before pos. - */ - template< class InputIt > - iterator insert(const_iterator pos, InputIt first, InputIt last) { - return this->vec_m.insert(pos, first, last); - } - - /** - * @brief Inserts elements from initializer list ilist before pos. - */ - - iterator insert(const_iterator pos, std::initializer_list ilist) { - return this->vec_m.insert(pos, ilist); - } - - - /** - * @brief Constructs element in-place. - */ - template< class... Args > - iterator emplace(const_iterator pos, Args&&... args) { - return this->vec_m.emplace(pos, std::forward(args)...); - } - - - /** - * @brief Removes the element at pos. - */ - inline iterator erase(iterator pos) { - return this->vec_m.erase(pos); - } - - /** - * @brief Removes the elements in the range [first, last). - */ - inline iterator erase(iterator first, iterator last) { - return this->vec_m.erase(first, last); - } - - - /** - * @brief Adds an element to the end. - */ - inline void push_back(const Type&& value) { - this->vec_m.push_back(value); - } - - /** - * @brief Constructs an element in-place at the end. - */ - template< class... Args > - void emplace_back(Args&&... args) { - this->vec_m.emplace_back(std::forward(args)...); - } - - /** - * @brief Removes the last element. - */ - inline void pop_back() { - this->vec_m.pop_back(); - } - - - /** - * @brief Changes the number of elements stored. - */ - inline void resize(size_t s) { - this->vec_m.resize(s); - } - - /** - * @brief Swaps the contents. - */ - inline void swap( Vector& other ){ - this->vec_m.swap(other.vec_m); - } - - // end std::vector functions - - /** - * Conversion operators - */ - - /** - * @brief Converts fims::Vector to std::vector - */ - inline operator std::vector(){ - return this->vec_m; - } - -#ifdef TMB_MODEL - /** - * @brief Converts fims::Vector to tmbutils::vectorconst - */ - operator tmbutils::vector()const{ - tmbutils::vector ret; - ret.resize(this->vec_m.size()); - for(size_t i =0; i < this->vec_m.size(); i++){ - ret[i] = this->vec_m[i]; - } - return ret; - } - - - /** - * @brief Converts fims::Vector to tmbutils::vector - */ - operator tmbutils::vector(){ - tmbutils::vector ret; - ret.resize(this->vec_m.size()); - for(size_t i =0; i < this->vec_m.size(); i++){ - ret[i] = this->vec_m[i]; - } - return ret; - } - - + + /** + * The following are std::vector functions copied over from the standard + * library. While some of these may not be called explicitly in FIMS, they may + * be required to run other std library functions. + */ + + /** + * @brief Returns a reference to the element at specified location pos. No + * bounds checking is performed. + */ + inline Type& operator[](size_t pos) { return this->vec_m[pos]; } + + /** + * @brief Returns a constant reference to the element at specified location + * pos. No bounds checking is performed. + */ + inline const Type& operator[](size_t n) const { return this->vec_m[n]; } + + /** + * @brief Returns a reference to the element at specified location pos. Bounds + * checking is performed. + */ + inline Type& at(size_t n) { return this->vec_m.at(n); } + + /** + * @brief Returns a constant reference to the element at specified location + * pos. Bounds checking is performed. + */ + inline const Type& at(size_t n) const { return this->vec_m.at(n); } + + /** + * @brief Returns a reference to the first element in the container. + */ + inline reference front() { return this->vec_m.front(); } + + /** + * @brief Returns a constant reference to the first element in the container. + */ + inline const_reference front() const { return this->vec_m.front(); } + + /** + * @brief Returns a reference to the last element in the container. + */ + inline reference back() { return this->vec_m.back(); } + + /** + * @brief Returns a constant reference to the last element in the container. + */ + inline const_reference back() const { return this->vec_m.back(); } + + /** + * @brief Returns a pointer to the underlying data array. + */ + inline pointer data() { return this->vec_m.data(); } + + /** + * @brief Returns a constant pointer to the underlying data array. + */ + inline const_pointer data() const { return this->vec_m.data(); } + + // iterators + + /** + * @brief Returns an iterator to the first element of the vector. + */ + inline iterator begin() { return this->vec_m.begin(); } + + /** + * @brief Returns an iterator to the element following the last element of the + * vector. + */ + inline iterator end() { return this->vec_m.end(); } + + /** + * @brief Returns a reverse iterator to the first element of the reversed + * vector. It corresponds to the last element of the non-reversed vector. + */ + inline reverse_iterator rbegin() { return this->vec_m.rbegin(); } + + /** + * @brief Returns a reverse iterator to the element following the last element + * of the reversed vector. It corresponds to the element preceding the first + * element of the non-reversed vector. + */ + inline reverse_iterator rend() { return this->vec_m.rend(); } + + /** + * @brief Returns a constant reverse iterator to the first element of the + * reversed vector. It corresponds to the last element of the non-reversed + * vector. + */ + inline const_reverse_iterator rbegin() const { return this->vec_m.rbegin(); } + + /** + * @brief Returns a constant reverse iterator to the element following the + * last element of the reversed vector. It corresponds to the element + * preceding the first element of the non-reversed vector. + */ + inline const_reverse_iterator rend() const { return this->vec_m.rend(); } + + // capacity + + /** + * @brief Checks whether the container is empty. + */ + inline bool empty() { return this->vec_m.empty(); } + + /** + * @brief Returns the number of elements. + */ + inline size_type size() const { return this->vec_m.size(); } + + /** + * @brief Returns the maximum possible number of elements. + */ + inline size_type max_size() const { return this->vec_m.max_size(); } + + /** + * @brief Reserves storage. + */ + inline void reserve(size_type cap) { this->vec_m.reserve(cap); } + + /** + * @brief Returns the number of elements that can be held in currently + * allocated storage. + */ + inline size_type capacity() { return this->vec_m.capacity(); } + + /** + * @brief Reduces memory usage by freeing unused memory. + */ + inline void shrink_to_fit() { this->vec_m.shrink_to_fit(); } + + // modifiers + + /** + * @brief Clears the contents. + */ + inline void clear() { this->vec_m.clear(); } + + /** + * @brief Inserts value before pos. + */ + inline iterator insert(const_iterator pos, const Type& value) { + return this->vec_m.insert(pos, value); + } + + /** + * @brief Inserts count copies of the value before pos. + */ + inline iterator insert(const_iterator pos, size_type count, + const Type& value) { + return this->vec_m.insert(pos, count, value); + } + + /** + * @brief Inserts elements from range [first, last) before pos. + */ + template + iterator insert(const_iterator pos, InputIt first, InputIt last) { + return this->vec_m.insert(pos, first, last); + } + + /** + * @brief Inserts elements from initializer list ilist before pos. + */ + + iterator insert(const_iterator pos, std::initializer_list ilist) { + return this->vec_m.insert(pos, ilist); + } + + /** + * @brief Constructs element in-place. + */ + template + iterator emplace(const_iterator pos, Args&&... args) { + return this->vec_m.emplace(pos, std::forward(args)...); + } + + /** + * @brief Removes the element at pos. + */ + inline iterator erase(iterator pos) { return this->vec_m.erase(pos); } + + /** + * @brief Removes the elements in the range [first, last). + */ + inline iterator erase(iterator first, iterator last) { + return this->vec_m.erase(first, last); + } + + /** + * @brief Adds an element to the end. + */ + inline void push_back(const Type&& value) { this->vec_m.push_back(value); } + + /** + * @brief Constructs an element in-place at the end. + */ + template + void emplace_back(Args&&... args) { + this->vec_m.emplace_back(std::forward(args)...); + } + + /** + * @brief Removes the last element. + */ + inline void pop_back() { this->vec_m.pop_back(); } + + /** + * @brief Changes the number of elements stored. + */ + inline void resize(size_t s) { this->vec_m.resize(s); } + + /** + * @brief Swaps the contents. + */ + inline void swap(Vector& other) { this->vec_m.swap(other.vec_m); } + + // end std::vector functions + + /** + * Conversion operators + */ + + /** + * @brief Converts fims::Vector to std::vector + */ + inline operator std::vector() { return this->vec_m; } + +#ifdef TMB_MODEL + /** + * @brief Converts fims::Vector to tmbutils::vectorconst + */ + operator tmbutils::vector() const { + tmbutils::vector ret; + ret.resize(this->vec_m.size()); + for (size_t i = 0; i < this->vec_m.size(); i++) { + ret[i] = this->vec_m[i]; + } + return ret; + } + + /** + * @brief Converts fims::Vector to tmbutils::vector + */ + operator tmbutils::vector() { + tmbutils::vector ret; + ret.resize(this->vec_m.size()); + for (size_t i = 0; i < this->vec_m.size(); i++) { + ret[i] = this->vec_m[i]; + } + return ret; + } + #endif - -private: - -};// end fims::Vector class + + private: +}; // end fims::Vector class /** * @brief Comparison operator. */ -template< class T> -bool operator==( const fims::Vector& lhs, - const fims::Vector& rhs ){ - return lhs.vec_m == rhs.vec_m; +template +bool operator==(const fims::Vector& lhs, const fims::Vector& rhs) { + return lhs.vec_m == rhs.vec_m; } - -} //end fims namespace +} // namespace fims #endif diff --git a/inst/include/common/information.hpp b/inst/include/common/information.hpp index 508ae9bf..a54e2347 100644 --- a/inst/include/common/information.hpp +++ b/inst/include/common/information.hpp @@ -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 { diff --git a/inst/include/common/model.hpp b/inst/include/common/model.hpp index 5ade1380..402eebe3 100644 --- a/inst/include/common/model.hpp +++ b/inst/include/common/model.hpp @@ -74,11 +74,11 @@ class Model { // may need singleton // vector< vector > creates a nested vector structure where // each vector can be a different dimension. Does not work with ADREPORT // fleets - vector > exp_index(n_fleets); - vector > exp_catch(n_fleets); - vector > cnaa(n_fleets); - vector > cwaa(n_fleets); - vector > F_mort(n_fleets); + vector > exp_index(n_fleets); + vector > exp_catch(n_fleets); + vector > cnaa(n_fleets); + vector > cwaa(n_fleets); + vector > F_mort(n_fleets); // populations vector > naa(n_pops); vector > ssb(n_pops); @@ -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; } @@ -215,7 +215,6 @@ class Model { // may need singleton return jnll; } - }; // Create singleton instance of Model class diff --git a/inst/include/distributions/functors/tmb_distributions.hpp b/inst/include/distributions/functors/tmb_distributions.hpp index 33e467ca..17427351 100644 --- a/inst/include/distributions/functors/tmb_distributions.hpp +++ b/inst/include/distributions/functors/tmb_distributions.hpp @@ -11,8 +11,8 @@ #ifdef TMB_MODEL -#include "distributions_base.hpp" #include "../../common/fims_vector.hpp" +#include "distributions_base.hpp" namespace fims_distributions { @@ -48,8 +48,8 @@ struct Dnorm : public DistributionsBase { template struct Dmultinom : public DistributionsBase { fims::Vector x; /*!< Vector of length K of integers */ - fims::Vector p; /*!< Vector of length K, specifying the probability for the K - classes (note, unlike in R these must sum to 1). */ + fims::Vector p; /*!< Vector of length K, specifying the probability for + the K classes (note, unlike in R these must sum to 1). */ Dmultinom() : DistributionsBase() {} diff --git a/inst/include/interface/interface.hpp b/inst/include/interface/interface.hpp index 17edbb50..a6c07ed5 100644 --- a/inst/include/interface/interface.hpp +++ b/inst/include/interface/interface.hpp @@ -20,6 +20,7 @@ // use isnan macro in math.h instead of TMB's isnan for fixing the r-cmd-check // issue #include + #include // define REPORT, ADREPORT, and SIMULATE diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp index c266e76d..227e9fb3 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_fleet.hpp @@ -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() {} diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp index 91c855fd..ee21ef82 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_recruitment.hpp @@ -30,7 +30,8 @@ class RecruitmentInterfaceBase : public FIMSRcppInterfaceBase { // static std::vector 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++; @@ -69,12 +70,12 @@ std::map */ 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() {} diff --git a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp index f22775bd..9c21eed0 100644 --- a/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp +++ b/inst/include/interface/rcpp/rcpp_objects/rcpp_tmb_distribution.hpp @@ -240,7 +240,6 @@ class DmultinomDistributionsInterface : public DistributionsInterfaceBase { template bool add_to_fims_tmb_internal() { - std::shared_ptr> info = fims_info::Information::GetInstance(); diff --git a/inst/include/population_dynamics/fleet/fleet.hpp b/inst/include/population_dynamics/fleet/fleet.hpp index 32f36f79..1463758a 100644 --- a/inst/include/population_dynamics/fleet/fleet.hpp +++ b/inst/include/population_dynamics/fleet/fleet.hpp @@ -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 { @@ -24,62 +24,63 @@ namespace fims_popdy { */ template struct Fleet : public fims_model_object::FIMSObject { - 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; /*!> - 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> - agecomp_likelihood; /*!< agecomp likelihood component*/ - - // selectivity - int fleet_selectivity_id_m = -999; /*!< id of selectivity component*/ - std::shared_ptr> - selectivity; /*!< selectivity component*/ - - int fleet_observed_index_data_id_m = -999; /*!< id of index data */ - std::shared_ptr> - observed_index_data; /*!< observed index data*/ - - int fleet_observed_agecomp_data_id_m = -999; /*!< id of age comp data */ - std::shared_ptr> - observed_agecomp_data; /*!< observed agecomp data*/ - - // Mortality and catchability - fims::Vector log_Fmort; /*!< estimated parameter: log Fishing mortality*/ - Type log_q; /*!< estimated parameter: catchability of the fleet */ - - fims::Vector log_obs_error; /*!< estimated parameters: observation error associated - with index */ - fims::Vector Fmort; /*!< transformed parameter: Fishing mortality*/ - Type q; /*!< transofrmed parameter: the catchability of the fleet */ - - // derived quantities - fims::Vector catch_at_age; /*! catch_index; /*! age_composition; /*! expected_catch; /*! expected_index; /*! catch_numbers_at_age; /*! catch_weight_at_age; /*!> + 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> + agecomp_likelihood; /*!< agecomp likelihood component*/ + + // selectivity + int fleet_selectivity_id_m = -999; /*!< id of selectivity component*/ + std::shared_ptr> + selectivity; /*!< selectivity component*/ + + int fleet_observed_index_data_id_m = -999; /*!< id of index data */ + std::shared_ptr> + observed_index_data; /*!< observed index data*/ + + int fleet_observed_agecomp_data_id_m = -999; /*!< id of age comp data */ + std::shared_ptr> + observed_agecomp_data; /*!< observed agecomp data*/ + + // Mortality and catchability + fims::Vector + log_Fmort; /*!< estimated parameter: log Fishing mortality*/ + Type log_q; /*!< estimated parameter: catchability of the fleet */ + + fims::Vector log_obs_error; /*!< estimated parameters: observation error + associated with index */ + fims::Vector Fmort; /*!< transformed parameter: Fishing mortality*/ + Type q; /*!< transofrmed parameter: the catchability of the fleet */ + + // derived quantities + fims::Vector catch_at_age; /*! catch_index; /*! age_composition; /*! expected_catch; /*! expected_index; /*! catch_numbers_at_age; /*! catch_weight_at_age; /*! *of; + ::objective_function *of; #endif /** @@ -108,7 +109,7 @@ struct Fleet : public fims_model_object::FIMSObject { 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); @@ -141,7 +142,8 @@ struct Fleet : public fims_model_object::FIMSObject { 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]); } } @@ -160,7 +162,6 @@ struct Fleet : public fims_model_object::FIMSObject { } else { for (size_t y = 0; y < this->nyears; y++) { - fims::Vector observed_acomp; fims::Vector expected_acomp; @@ -191,31 +192,31 @@ struct Fleet : public fims_model_object::FIMSObject { 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 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 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 diff --git a/inst/include/population_dynamics/population/population.hpp b/inst/include/population_dynamics/population/population.hpp index fc6b48ff..67ced183 100644 --- a/inst/include/population_dynamics/population/population.hpp +++ b/inst/include/population_dynamics/population/population.hpp @@ -24,8 +24,8 @@ namespace fims_popdy { /*TODO: - Review, add functions to evaluate, push vectors back to fleet (or point to fleet - directly?) + Review, add functions to evaluate, push vectors back to fleet (or point to + fleet directly?) */ /** @@ -34,210 +34,211 @@ namespace fims_popdy { */ template struct Population : public fims_model_object::FIMSObject { - static uint32_t id_g; /*!< reference id for population object*/ - size_t nyears; /*!< total number of years in the fishery*/ - size_t nseasons; /*!< total number of seasons in the fishery*/ - size_t nages; /*!< total number of ages in the population*/ - size_t nfleets; /*!< total number of fleets in the fishery*/ - - // constants - const Type proportion_female = - 0.5; /*!< Sex proportion fixed at 50/50 for M1*/ - - // parameters are estimated; after initialize in create_model, push_back to - // parameter list - in information.hpp (same for initial F in fleet) - fims::Vector log_init_naa; /*!< estimated parameter: log numbers at age*/ - fims::Vector log_M; /*!< estimated parameter: log Natural Mortality*/ - - // Transformed values - fims::Vector M; /*!< transformed parameter: Natural Mortality*/ - - fims::Vector ages; /*!< vector of the ages for referencing*/ - fims::Vector years; /*!< vector of years for referencing*/ - fims::Vector mortality_F; /*!< vector of fishing mortality summed across - fleet by year and age*/ - fims::Vector - mortality_Z; /*!< vector of total mortality by year and age*/ - - // derived quantities - fims::Vector - weight_at_age; /*!< Derived quantity: expected weight at age */ - // fecundity removed because we don't need it yet - fims::Vector numbers_at_age; /*!< Derived quantity: population expected - numbers at age in each year*/ - fims::Vector - unfished_numbers_at_age; /*!< Derived quantity: population expected - unfished numbers at age in each year*/ - fims::Vector - biomass; /*!< Derived quantity: total population biomass in each year*/ - fims::Vector spawning_biomass; /*!< Derived quantity: Spawning_biomass*/ - fims::Vector unfished_biomass; /*!< Derived quanity - biomass assuming unfished*/ - fims::Vector unfished_spawning_biomass; /*!< Derived quanity Spawning - biomass assuming unfished*/ - fims::Vector proportion_mature_at_age; /*!< Derived quantity: Proportion - matura at age */ - fims::Vector expected_numbers_at_age; /*!< Expected values: Numbers at - age (thousands?? millions??) */ - fims::Vector expected_catch; /*!< Expected values: Catch*/ - fims::Vector expected_recruitment; /*!< Expected recruitment */ - /// recruitment - int recruitment_id = -999; /*!< id of recruitment model object*/ - std::shared_ptr> - recruitment; /*!< shared pointer to recruitment module */ - - // growth - int growth_id = -999; /*!< id of growth model object*/ - std::shared_ptr> - growth; /*!< shared pointer to growth module */ - - // maturity - int maturity_id = -999; /*!< id of maturity model object*/ - std::shared_ptr> - maturity; /*!< shared pointer to maturity module */ - - // fleet - int fleet_id = -999; /*!< id of fleet model object*/ - std::vector>> - fleets; /*!< shared pointer to fleet module */ - - // Define objective function object to be able to REPORT and ADREPORT + static uint32_t id_g; /*!< reference id for population object*/ + size_t nyears; /*!< total number of years in the fishery*/ + size_t nseasons; /*!< total number of seasons in the fishery*/ + size_t nages; /*!< total number of ages in the population*/ + size_t nfleets; /*!< total number of fleets in the fishery*/ + + // constants + const Type proportion_female = + 0.5; /*!< Sex proportion fixed at 50/50 for M1*/ + + // parameters are estimated; after initialize in create_model, push_back to + // parameter list - in information.hpp (same for initial F in fleet) + fims::Vector + log_init_naa; /*!< estimated parameter: log numbers at age*/ + fims::Vector log_M; /*!< estimated parameter: log Natural Mortality*/ + + // Transformed values + fims::Vector M; /*!< transformed parameter: Natural Mortality*/ + + fims::Vector ages; /*!< vector of the ages for referencing*/ + fims::Vector years; /*!< vector of years for referencing*/ + fims::Vector mortality_F; /*!< vector of fishing mortality summed across + fleet by year and age*/ + fims::Vector + mortality_Z; /*!< vector of total mortality by year and age*/ + + // derived quantities + fims::Vector + weight_at_age; /*!< Derived quantity: expected weight at age */ + // fecundity removed because we don't need it yet + fims::Vector numbers_at_age; /*!< Derived quantity: population expected + numbers at age in each year*/ + fims::Vector + unfished_numbers_at_age; /*!< Derived quantity: population expected + unfished numbers at age in each year*/ + fims::Vector + biomass; /*!< Derived quantity: total population biomass in each year*/ + fims::Vector spawning_biomass; /*!< Derived quantity: Spawning_biomass*/ + fims::Vector unfished_biomass; /*!< Derived quanity + biomass assuming unfished*/ + fims::Vector unfished_spawning_biomass; /*!< Derived quanity Spawning + biomass assuming unfished*/ + fims::Vector proportion_mature_at_age; /*!< Derived quantity: Proportion + matura at age */ + fims::Vector expected_numbers_at_age; /*!< Expected values: Numbers at + age (thousands?? millions??) */ + fims::Vector expected_catch; /*!< Expected values: Catch*/ + fims::Vector expected_recruitment; /*!< Expected recruitment */ + /// recruitment + int recruitment_id = -999; /*!< id of recruitment model object*/ + std::shared_ptr> + recruitment; /*!< shared pointer to recruitment module */ + + // growth + int growth_id = -999; /*!< id of growth model object*/ + std::shared_ptr> + growth; /*!< shared pointer to growth module */ + + // maturity + int maturity_id = -999; /*!< id of maturity model object*/ + std::shared_ptr> + maturity; /*!< shared pointer to maturity module */ + + // fleet + int fleet_id = -999; /*!< id of fleet model object*/ + std::vector>> + fleets; /*!< shared pointer to fleet module */ + + // Define objective function object to be able to REPORT and ADREPORT #ifdef TMB_MODEL ::objective_function *of; // :: references global namespace, defined in src/FIMS.cpp, // available anywhere in the R package #endif - - // this -> means you're referring to a class member (member of self) - - Population() { this->id = Population::id_g++; } - - /** - * @brief Initialize values. Called once at the start of model run. - * - * @param nyears number of years in the population - * @param nseasons number of seasons in the population - * @param nages number of ages in the population - */ - void Initialize(int nyears, int nseasons, int nages) { - this->nyears = nyears; - this->nseasons = nseasons; - this->nages = nages; - - // size all the vectors to length of nages - nfleets = fleets.size(); - expected_catch.resize(nyears * nfleets); - years.resize(nyears); - mortality_F.resize(nyears * nages); - mortality_Z.resize(nyears * nages); - proportion_mature_at_age.resize((nyears + 1) * nages); - weight_at_age.resize(nages); - unfished_numbers_at_age.resize((nyears + 1) * nages); - numbers_at_age.resize((nyears + 1) * nages); - biomass.resize((nyears + 1)); - unfished_biomass.resize((nyears + 1)); - unfished_spawning_biomass.resize((nyears + 1)); - spawning_biomass.resize((nyears + 1)); - expected_recruitment.resize((nyears + 1)); - M.resize(nyears * nages); - ages.resize(nages); - log_init_naa.resize(nages); - log_M.resize(nyears * nages); + + // this -> means you're referring to a class member (member of self) + + Population() { this->id = Population::id_g++; } + + /** + * @brief Initialize values. Called once at the start of model run. + * + * @param nyears number of years in the population + * @param nseasons number of seasons in the population + * @param nages number of ages in the population + */ + void Initialize(int nyears, int nseasons, int nages) { + this->nyears = nyears; + this->nseasons = nseasons; + this->nages = nages; + + // size all the vectors to length of nages + nfleets = fleets.size(); + expected_catch.resize(nyears * nfleets); + years.resize(nyears); + mortality_F.resize(nyears * nages); + mortality_Z.resize(nyears * nages); + proportion_mature_at_age.resize((nyears + 1) * nages); + weight_at_age.resize(nages); + unfished_numbers_at_age.resize((nyears + 1) * nages); + numbers_at_age.resize((nyears + 1) * nages); + biomass.resize((nyears + 1)); + unfished_biomass.resize((nyears + 1)); + unfished_spawning_biomass.resize((nyears + 1)); + spawning_biomass.resize((nyears + 1)); + expected_recruitment.resize((nyears + 1)); + M.resize(nyears * nages); + ages.resize(nages); + log_init_naa.resize(nages); + log_M.resize(nyears * nages); + } + + /** + * @brief Prepare to run the population loop. Called at each model iteration, + * and used to zero out derived quantities, values that were summed, etc. + * + */ + void Prepare() { + POPULATION_LOG << " population prepare " << this->nages << std::endl; + POPULATION_LOG << "nfleets: " << this->nfleets << std::endl; + POPULATION_LOG << "nseasons: " << this->nseasons << std::endl; + POPULATION_LOG << "nyears: " << this->nyears << std::endl; + + for (size_t fleet = 0; fleet < this->nfleets; fleet++) { + this->fleets[fleet]->Prepare(); } - - /** - * @brief Prepare to run the population loop. Called at each model iteration, - * and used to zero out derived quantities, values that were summed, etc. - * - */ - void Prepare() { - POPULATION_LOG << " population prepare " << this->nages << std::endl; - POPULATION_LOG << "nfleets: " << this->nfleets << std::endl; - POPULATION_LOG << "nseasons: " << this->nseasons << std::endl; - POPULATION_LOG << "nyears: " << this->nyears << std::endl; - - for (size_t fleet = 0; fleet < this->nfleets; fleet++) { - this->fleets[fleet]->Prepare(); - } - - std::fill(biomass.begin(), biomass.end(), 0.0); - std::fill(unfished_spawning_biomass.begin(), - unfished_spawning_biomass.end(), 0.0); - std::fill(spawning_biomass.begin(), spawning_biomass.end(), 0.0); - std::fill(expected_catch.begin(), expected_catch.end(), 0.0); - std::fill(expected_recruitment.begin(), expected_recruitment.end(), 0.0); - std::fill(proportion_mature_at_age.begin(), proportion_mature_at_age.end(), - 0.0); - std::fill(mortality_Z.begin(), mortality_Z.end(), 0.0); - - // Transformation Section - for (size_t age = 0; age < this->nages; age++) { + + std::fill(biomass.begin(), biomass.end(), 0.0); + std::fill(unfished_spawning_biomass.begin(), + unfished_spawning_biomass.end(), 0.0); + std::fill(spawning_biomass.begin(), spawning_biomass.end(), 0.0); + std::fill(expected_catch.begin(), expected_catch.end(), 0.0); + std::fill(expected_recruitment.begin(), expected_recruitment.end(), 0.0); + std::fill(proportion_mature_at_age.begin(), proportion_mature_at_age.end(), + 0.0); + std::fill(mortality_Z.begin(), mortality_Z.end(), 0.0); + + // Transformation Section + for (size_t age = 0; age < this->nages; age++) { this->weight_at_age[age] = growth->evaluate(ages[age]); - for (size_t year = 0; year < this->nyears; year++) { - size_t i_age_year = age * this->nyears + year; - this->M[i_age_year] = fims_math::exp(this->log_M[i_age_year]); - // mortality_F is a fims::Vector and therefore needs to be filled - // within a loop - this->mortality_F[i_age_year] = 0.0; - } - } - } - - /** - * life history calculations - */ - - /** - * @brief Calculates initial numbers at age for index and age - * - * @param i_age_year dimension folded index for age and year - * @param a age index - */ - inline void CalculateInitialNumbersAA( - size_t i_age_year, size_t a) { // inline all function unless complicated - this->numbers_at_age[i_age_year] = fims_math::exp(this->log_init_naa[a]); + for (size_t year = 0; year < this->nyears; year++) { + size_t i_age_year = age * this->nyears + year; + this->M[i_age_year] = fims_math::exp(this->log_M[i_age_year]); + // mortality_F is a fims::Vector and therefore needs to be filled + // within a loop + this->mortality_F[i_age_year] = 0.0; + } } - - /** - * @brief Calculates total mortality at an index, year, and age - * - * @param i_age_year dimension folded index for age and year - * @param year year index - * @param age age index - */ - void CalculateMortality(size_t i_age_year, size_t year, size_t age) { - for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) { - if (this->fleets[fleet_]->is_survey == false) { - this->mortality_F[i_age_year] += - this->fleets[fleet_]->Fmort[year] * + } + + /** + * life history calculations + */ + + /** + * @brief Calculates initial numbers at age for index and age + * + * @param i_age_year dimension folded index for age and year + * @param a age index + */ + inline void CalculateInitialNumbersAA( + size_t i_age_year, size_t a) { // inline all function unless complicated + this->numbers_at_age[i_age_year] = fims_math::exp(this->log_init_naa[a]); + } + + /** + * @brief Calculates total mortality at an index, year, and age + * + * @param i_age_year dimension folded index for age and year + * @param year year index + * @param age age index + */ + void CalculateMortality(size_t i_age_year, size_t year, size_t age) { + for (size_t fleet_ = 0; fleet_ < this->nfleets; fleet_++) { + if (this->fleets[fleet_]->is_survey == false) { + this->mortality_F[i_age_year] += + this->fleets[fleet_]->Fmort[year] * // evaluate is a member function of the selectivity class - this->fleets[fleet_]->selectivity->evaluate(ages[age]); - POPULATION_LOG << " selectivity at age " << ages[age] << " for fleet " + this->fleets[fleet_]->selectivity->evaluate(ages[age]); + POPULATION_LOG << " selectivity at age " << ages[age] << " for fleet " << fleet_ << " is " - << this->fleets[fleet_]->selectivity->evaluate(ages[age]) - << " apical fishing mortality F for the fleet in year " - << year << " is " << this->fleets[fleet_]->Fmort[year] + << this->fleets[fleet_]->selectivity->evaluate(ages[age]) + << " apical fishing mortality F for the fleet in year " + << year << " is " << this->fleets[fleet_]->Fmort[year] << std::endl; - } - } - POPULATION_LOG << "M in calculate mortality is " << this->M[i_age_year] - << std::endl; - this->mortality_Z[i_age_year] = - this->M[i_age_year] + this->mortality_F[i_age_year]; + } } - - /** - * @brief Calculates numbers at age at year and age specific indices - * - * @param i_age_year dimension folded index for age and year - * @param i_agem1_yearm1 dimension folded index for age-1 and year-1 - * @param age age index - */ - inline void CalculateNumbersAA(size_t i_age_year, size_t i_agem1_yearm1, - size_t age) { - // using Z from previous age/year - this->numbers_at_age[i_age_year] = + POPULATION_LOG << "M in calculate mortality is " << this->M[i_age_year] + << std::endl; + this->mortality_Z[i_age_year] = + this->M[i_age_year] + this->mortality_F[i_age_year]; + } + + /** + * @brief Calculates numbers at age at year and age specific indices + * + * @param i_age_year dimension folded index for age and year + * @param i_agem1_yearm1 dimension folded index for age-1 and year-1 + * @param age age index + */ + inline void CalculateNumbersAA(size_t i_age_year, size_t i_agem1_yearm1, + size_t age) { + // using Z from previous age/year + this->numbers_at_age[i_age_year] = this->numbers_at_age[i_agem1_yearm1] * (fims_math::exp(-this->mortality_Z[i_agem1_yearm1])); @@ -391,22 +392,22 @@ struct Population : public fims_model_object::FIMSObject { << this->recruitment->evaluate( this->spawning_biomass[year - 1], phi0) << std::endl; - if(i_dev==this->nyears){ - this->numbers_at_age[i_age_year] = - this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0); - /*the final year of the time series has no data to inform recruitment devs, - so this value is set to the mean recruitment.*/ - } else{ - this->numbers_at_age[i_age_year] = - this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0) * - /*the log_recruit_dev vector does not include a value for year == 0 - and is of length nyears - 1 where the first position of the vector - corresponds to the second year of the time series.*/ - fims_math::exp(this->recruitment->log_recruit_devs[i_dev-1]); - this->expected_recruitment[year] = this->numbers_at_age[i_age_year]; + if (i_dev == this->nyears) { + this->numbers_at_age[i_age_year] = + this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0); + /*the final year of the time series has no data to inform recruitment + devs, so this value is set to the mean recruitment.*/ + } else { + this->numbers_at_age[i_age_year] = + this->recruitment->evaluate(this->spawning_biomass[year - 1], phi0) * + /*the log_recruit_dev vector does not include a value for year == 0 + and is of length nyears - 1 where the first position of the vector + corresponds to the second year of the time series.*/ + fims_math::exp(this->recruitment->log_recruit_devs[i_dev - 1]); + this->expected_recruitment[year] = this->numbers_at_age[i_age_year]; } - POPULATION_LOG << " numbers at age at index i_age_year " << i_age_year << " is " - << this->numbers_at_age[i_age_year] << std::endl; + POPULATION_LOG << " numbers at age at index i_age_year " << i_age_year + << " is " << this->numbers_at_age[i_age_year] << std::endl; } /** diff --git a/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp b/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp index 0728b1eb..bbec7f93 100644 --- a/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp +++ b/inst/include/population_dynamics/recruitment/functors/recruitment_base.hpp @@ -17,9 +17,9 @@ #include // for using std::pow and M_PI #include "../../../common/fims_math.hpp" // for using fims_math::log() +#include "../../../common/fims_vector.hpp" #include "../../../common/model_object.hpp" #include "../../../distributions/distributions.hpp" -#include "../../../common/fims_vector.hpp" namespace fims_popdy { @@ -33,7 +33,7 @@ struct RecruitmentBase : public fims_model_object::FIMSObject { static uint32_t id_g; /**< reference id for recruitment object*/ fims::Vector - log_recruit_devs; /*!< A vector of log recruitment deviations */ + log_recruit_devs; /*!< A vector of log recruitment deviations */ bool constrain_deviations = false; /*!< A flag to indicate if recruitment deviations are summing to zero or not */ @@ -41,9 +41,8 @@ struct RecruitmentBase : public fims_model_object::FIMSObject { deviations */ Type log_rzero; /**< Log of unexploited recruitment.*/ - bool estimate_log_recruit_devs = - true; /*!< A flag to indicate if recruitment deviations are estimated or - not */ + bool estimate_log_recruit_devs = true; /*!< A flag to indicate if recruitment + deviations are estimated or not */ /** @brief Constructor. */ @@ -51,7 +50,6 @@ struct RecruitmentBase : public fims_model_object::FIMSObject { virtual ~RecruitmentBase() {} - /** * @brief Prepares the recruitment deviations vector. * diff --git a/inst/include/utilities/fims_json.hpp b/inst/include/utilities/fims_json.hpp index c3718928..8537cbab 100644 --- a/inst/include/utilities/fims_json.hpp +++ b/inst/include/utilities/fims_json.hpp @@ -1,4 +1,4 @@ -/** +/** * @file fims_json.hpp * @brief A simple JSON parsing and generation library. * @details This library provides classes and functions for parsing JSON @@ -13,29 +13,29 @@ class JsonValue; -/** +/** * Alias for a JSON object, mapping strings to JSON values. */ using JsonObject = std::map; -/** +/** * Alias for a JSON array, containing a sequence of JSON values. */ using JsonArray = std::vector; -/** +/** * Represents different types of JSON values. */ enum JsonValueType { - Null = 0, /**< Null JSON value. */ - Number, /**< Numeric JSON value. */ - String, /**< String JSON value. */ - Bool, /**< Boolean JSON value. */ - Object, /**< JSON object. */ - Array /**< JSON array. */ + Null = 0, /**< Null JSON value. */ + Number, /**< Numeric JSON value. */ + String, /**< String JSON value. */ + Bool, /**< Boolean JSON value. */ + Object, /**< JSON object. */ + Array /**< JSON array. */ }; -/** +/** * Represents a JSON value. */ class JsonValue { @@ -83,15 +83,15 @@ class JsonValue { JsonArray& GetArray() { return array; } private: - JsonValueType type; /**< Type of the JSON value. */ - double number; /**< Numeric value. */ - std::string str; /**< String value. */ - bool boolean; /**< Boolean value. */ - JsonObject object; /**< JSON object. */ - JsonArray array; /**< JSON array. */ + JsonValueType type; /**< Type of the JSON value. */ + double number; /**< Numeric value. */ + std::string str; /**< String value. */ + bool boolean; /**< Boolean value. */ + JsonObject object; /**< JSON object. */ + JsonArray array; /**< JSON array. */ }; -/** +/** * Parses JSON strings and generates JSON values. */ class JsonParser { @@ -129,11 +129,11 @@ class JsonParser { /** Indentation helper for printing JSON values in an output stream. */ void Indent(std::ofstream& outputFile, int level); - std::string data; /**< Input JSON data. */ - size_t position; /**< Current position in the data. */ + std::string data; /**< Input JSON data. */ + size_t position; /**< Current position in the data. */ }; -/** +/** * Parse a JSON string and return the corresponding JSON value. * @param json The JSON string to parse. * @return The parsed JSON value. @@ -150,7 +150,7 @@ void JsonParser::SkipWhitespace() { } } -/** +/** * Parse a JSON value. * @return The parsed JSON value. */ @@ -173,7 +173,7 @@ JsonValue JsonParser::ParseValue() { } } -/** +/** * Parse a numeric JSON value. * @return The parsed JSON value. */ @@ -204,7 +204,7 @@ JsonValue JsonParser::ParseNumber() { } } -/** +/** * Parse a string JSON value. * @return The parsed JSON value. */ diff --git a/tests/gtest/test_population_test_fixture.hpp b/tests/gtest/test_population_test_fixture.hpp index 9c3963cb..a365708a 100644 --- a/tests/gtest/test_population_test_fixture.hpp +++ b/tests/gtest/test_population_test_fixture.hpp @@ -144,24 +144,22 @@ class PopulationEvaluateTestFixture : public testing::Test { population.growth = growth; population.Prepare(); - auto maturity = std::make_shared>(); maturity->inflection_point = 6; maturity->slope = 0.15; population.maturity = maturity; - - auto recruitment = std::make_shared>(); - recruitment->logit_steep = fims_math::logit(0.2, 1.0, 0.75); - recruitment->log_rzero = fims_math::log(1000000.0); - /*the log_recruit_dev vector does not include a value for year == 0 - and is of length nyears - 1 where the first position of the vector - corresponds to the second year of the time series.*/ - recruitment->log_recruit_devs.resize(nyears-1); - for (int i = 0; i < recruitment->log_recruit_devs.size(); i++) { - recruitment->log_recruit_devs[i] = 0.0; - } - population.recruitment = recruitment; + auto recruitment = std::make_shared>(); + recruitment->logit_steep = fims_math::logit(0.2, 1.0, 0.75); + recruitment->log_rzero = fims_math::log(1000000.0); + /*the log_recruit_dev vector does not include a value for year == 0 + and is of length nyears - 1 where the first position of the vector + corresponds to the second year of the time series.*/ + recruitment->log_recruit_devs.resize(nyears - 1); + for (int i = 0; i < recruitment->log_recruit_devs.size(); i++) { + recruitment->log_recruit_devs[i] = 0.0; + } + population.recruitment = recruitment; int year = 4; int age = 6;