FIMS  v0.8.0
Loading...
Searching...
No Matches
density_components_base.hpp
Go to the documentation of this file.
1
12#ifndef DENSITY_COMPONENT_BASE_HPP
13#define DENSITY_COMPONENT_BASE_HPP
14
15#include "../../common/data_object.hpp"
16#include "../../common/model_object.hpp"
17#include "../../interface/interface.hpp"
18#include "../../common/fims_vector.hpp"
19#include "../../common/fims_math.hpp"
20
21namespace fims_distributions {
22
26template <typename Type>
28 std::string input_type;
31 std::shared_ptr<fims_data_object::DataObject<Type>>
37 NULL;
39 std::vector<fims::Vector<Type>*>
45 std::string use_mean = fims::to_string("no");
47 // std::shared_ptr<DistributionElementObject<Type>> expected; /**< expected
48 // value of distribution function */
49
55 inline Type& get_observed(size_t i) {
56 if (this->input_type == "data") {
57 return observed_values->at(i);
58 }
59 if (this->input_type == "random_effects") {
60 return (*re)[i];
61 }
62 if (this->input_type == "prior") {
63 if (priors.size() == 0) {
64 throw std::runtime_error("No priors defined for this distribution.");
65 } else if (priors.size() == 1) {
66 return (*(priors[0]))[i];
67 } else if (priors.size() > 1) {
68 return (*(priors[i]))[0];
69 }
70 }
71 return x[i];
72 }
73
80 inline Type& get_observed(size_t i, size_t j) {
81 if (this->input_type == "data") {
82 return observed_values->at(i, j);
83 }
84 if (this->input_type == "random_effects") {
85 return (*re)[i, j];
86 }
87 if (this->input_type == "prior") {
88 return (*(priors[i, j]))[0];
89 }
90 return x[i];
91 }
92
98 inline Type& get_expected(size_t i) {
99 if (this->input_type == "data") {
100 return (*data_expected_values)[i];
101 } else if (this->use_mean == "yes") {
102 return this->expected_mean.get_force_scalar(i);
103 } else if (this->input_type == "random_effects") {
104 return (*re_expected_values)[i];
105 } else {
106 return this->expected_values.get_force_scalar(i);
107 }
108 }
109
114 inline size_t get_n_x() {
115 if (this->input_type == "data") {
116 return this->observed_values->data.size();
117 }
118 if (this->input_type == "random_effects") {
119 return (*re).size();
120 }
121 if (this->input_type == "prior") {
122 return this->expected_values.size();
123 }
124 return x.size();
125 }
126
131 inline size_t get_n_expected() {
132 if (this->input_type == "data") {
133 return (*data_expected_values).size();
134 }
135 if (this->input_type == "random_effects") {
136 return (*re_expected_values).size();
137 }
138 if (this->input_type == "prior") {
139 return this->expected_values.size();
140 }
141 return x.size();
142 }
143};
144
150template <typename Type>
152 public DistributionElementObject<Type> {
153 // id_g is the ID of the instance of the DensityComponentBase class.
154 // this is like a memory tracker.
155 // Assigning each one its own ID is a way to keep track of
156 // all the instances of the DensityComponentBase class.
157 static uint32_t
164 bool osa_flag = false;
166 false;
167 std::vector<uint32_t>
170#ifdef TMB_MODEL
171 ::objective_function<Type>* of;
172#endif
173
177 // initialize the priors vector with a size of 1 and set the first element
178 // to NULL
179 this->priors.resize(1);
180 this->priors[0] = NULL;
181 this->id = DensityComponentBase::id_g++;
182 }
183
184 virtual ~DensityComponentBase() {}
189 virtual const Type evaluate() = 0;
190};
191
194template <typename Type>
196
197} // namespace fims_distributions
198
199#endif /* DENSITY_COMPONENT_BASE_HPP */
Definition fims_vector.hpp:27
Type & get_force_scalar(size_t pos)
If this vector is size 1 and pos is greater than zero, the first index is returned....
Definition fims_vector.hpp:182
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:273
Base class for all module_name functors.
Definition density_components_base.hpp:152
std::vector< uint32_t > key
Definition density_components_base.hpp:168
fims::Vector< Type > lpdf_vec
Definition density_components_base.hpp:160
bool simulate_flag
Definition density_components_base.hpp:165
bool osa_flag
Definition density_components_base.hpp:164
fims::Vector< Type > report_lpdf_vec
Definition density_components_base.hpp:162
DensityComponentBase()
Constructor.
Definition density_components_base.hpp:176
virtual const Type evaluate()=0
Generic probability density function. Calculates the pdf at the independent variable value.
static uint32_t id_g
Default id of the singleton distribution class.
Definition density_components_base.hpp:158
int observed_data_id_m
Definition density_components_base.hpp:159
Definition density_components_base.hpp:27
size_t get_n_x()
Definition density_components_base.hpp:114
Type & get_observed(size_t i)
Definition density_components_base.hpp:55
std::vector< fims::Vector< Type > * > priors
Definition density_components_base.hpp:40
size_t get_n_expected()
Definition density_components_base.hpp:131
Type & get_observed(size_t i, size_t j)
Definition density_components_base.hpp:80
fims::Vector< Type > * data_expected_values
Definition density_components_base.hpp:38
std::shared_ptr< fims_data_object::DataObject< Type > > observed_values
Definition density_components_base.hpp:32
fims::Vector< Type > * re
Definition density_components_base.hpp:35
fims::Vector< Type > * re_expected_values
Definition density_components_base.hpp:36
std::string input_type
Definition density_components_base.hpp:28
fims::Vector< Type > x
Definition density_components_base.hpp:41
std::string use_mean
Definition density_components_base.hpp:45
fims::Vector< Type > expected_values
Definition density_components_base.hpp:34
Type & get_expected(size_t i)
Definition density_components_base.hpp:98
fims::Vector< Type > expected_mean
Definition density_components_base.hpp:43
FIMSObject struct that defines member types and returns the unique id.
Definition model_object.hpp:25