9#ifndef FIMS_COMMON_MODEL_HPP
10#define FIMS_COMMON_MODEL_HPP
22template <
typename Type>
25 static std::shared_ptr<Model<Type>>
27 std::shared_ptr<fims_info::Information<Type>>
47 ::objective_function<Type> *of =
nullptr;
55 static std::shared_ptr<Model<Type>> GetInstance() {
56 if (Model<Type>::fims_model ==
nullptr) {
57 Model<Type>::fims_model = std::make_shared<fims_model::Model<Type>>();
58 Model<Type>::fims_model->fims_information =
61 return Model<Type>::fims_model;
67 const Type Evaluate() {
69 Type jnll =
static_cast<Type
>(0.0);
72 if (this->fims_information ==
nullptr) {
74 "Model: fims_information is not set. Please set fims_information "
76 "calling Evaluate().");
81 fims::Vector<Type> nll_vec(
82 this->fims_information->density_components.size(), 0.0);
84 for (m_it = this->fims_information->models_map.begin();
85 m_it != this->fims_information->models_map.end(); ++m_it) {
87 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> m = (*m_it).second;
95 for (d_it = this->fims_information->density_components.begin();
96 d_it != this->fims_information->density_components.end(); ++d_it) {
97 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
102 if (d->input_type ==
"prior") {
103 nll_vec[nll_vec_idx] = -d->evaluate();
104 jnll += nll_vec[nll_vec_idx];
111 "Model: Finished evaluating prior distributions. The jnll after "
113 fims::to_string(n_priors) +
" priors is: " + fims::to_string(jnll));
117 size_t n_random_effects = 0;
118 for (d_it = this->fims_information->density_components.begin();
119 d_it != this->fims_information->density_components.end(); ++d_it) {
120 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
125 if (d->input_type ==
"random_effects") {
126 nll_vec[nll_vec_idx] = -d->evaluate();
127 jnll += nll_vec[nll_vec_idx];
128 n_random_effects += 1;
134 "Model: Finished evaluating random effect distributions. The jnll "
135 "after evaluating priors and " +
136 fims::to_string(n_random_effects) +
137 " random_effects is: " + fims::to_string(jnll));
141 for (d_it = this->fims_information->density_components.begin();
142 d_it != this->fims_information->density_components.end(); ++d_it) {
143 std::shared_ptr<fims_distributions::DensityComponentBase<Type>> d =
149 if (d->input_type ==
"data") {
150 nll_vec[nll_vec_idx] = -d->evaluate();
151 jnll += nll_vec[nll_vec_idx];
158 "Model: Finished evaluating data likelihoods. The jnll after "
159 "evaluating priors, random effects, and " +
160 fims::to_string(n_data) +
161 " data likelihoods is: " + fims::to_string(jnll));
167 vector<Type> nll_components = nll_vec.to_tmb();
174 for (m_it = this->fims_information->models_map.begin();
175 m_it != this->fims_information->models_map.end(); ++m_it) {
177 std::shared_ptr<fims_popdy::FisheryModelBase<Type>> m = (*m_it).second;
189template <
typename Type>
190std::shared_ptr<Model<Type>> Model<Type>::fims_model =
#define FIMS_INFO_LOG(MESSAGE)
Record an info-log entry with metadata.
Definition def.hpp:648
#define FIMS_ERROR_LOG(MESSAGE)
Definition def.hpp:664
#define FIMS_REPORT_F(name, F)
TMB macro that reports variables.
Definition interface.hpp:79