10#ifndef MULTINOMIAL_LPMF
11#define MULTINOMIAL_LPMF
14#include "../../common/fims_vector.hpp"
15#include "../../common/def.hpp"
17namespace fims_distributions {
21template <
typename Type>
23 Type
lpdf =
static_cast<Type
>(0.0);
48 Type
lpdf =
static_cast<Type
>(0.0);
52 std::fill(this->
lpdf_vec.begin(), this->lpdf_vec.end(), 0);
58 throw std::invalid_argument(
59 "MultinomialLPDF: Vector index out of bounds. The dimension of "
61 "number of rows times the number of columns is of size " +
63 " and the expected vector is of size " +
68 if (dims[0] *
dims[1] != this->
x.
size()) {
69 throw std::invalid_argument(
70 "MultinomialLPDF: Vector index out of bounds. The dimension of the "
71 "number of rows times the number of columns is of size " +
73 " and the observed vector is of size " +
74 fims::to_string(this->
x.size()));
76 if (this->
x.size() != this->expected_values.size()) {
77 throw std::invalid_argument(
78 "MultinomialLPDF: Vector index out of bounds. The dimension of the "
79 "observed vector of size " +
80 fims::to_string(this->
x.size()) +
81 " and the expected vector is of size " +
82 fims::to_string(this->expected_values.size()));
86 for (
size_t i = 0; i <
dims[0]; i++) {
93 bool containsNA =
false;
96 for (
size_t j = 0; j <
dims[1]; j++) {
101 static_cast<size_t>(j)) ==
107 size_t idx = (i *
dims[1]) + j;
114 size_t idx = (i *
dims[1]) + j;
122 dmultinom(x_vector.
to_tmb(), prob_vector.
to_tmb(),
true);
Definition fims_vector.hpp:27
void resize(size_t s)
Changes the number of elements stored.
Definition fims_vector.hpp:375
std::vector< Type > to_tmb() const
Convert fims::Vector to TMB vector type.
Definition fims_vector.hpp:468
size_type size() const
Returns the number of elements.
Definition fims_vector.hpp:273
Declares the DensityComponentBase class, which is the base class for all distribution functors.
Base class for all module_name functors.
Definition density_components_base.hpp:152
fims::Vector< Type > lpdf_vec
Definition density_components_base.hpp:160
fims::Vector< Type > report_lpdf_vec
Definition density_components_base.hpp:162
Type & get_observed(size_t i)
Definition density_components_base.hpp:55
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
std::string input_type
Definition density_components_base.hpp:28
fims::Vector< Type > x
Definition density_components_base.hpp:41
Type & get_expected(size_t i)
Definition density_components_base.hpp:98
Definition multinomial_lpmf.hpp:22
virtual const Type evaluate()
Evaluates the multinomial probability mass function.
Definition multinomial_lpmf.hpp:39
virtual ~MultinomialLPMF()
Destructor.
Definition multinomial_lpmf.hpp:34
fims::Vector< size_t > dims
Definition multinomial_lpmf.hpp:25
MultinomialLPMF()
Constructor.
Definition multinomial_lpmf.hpp:30
Type lpdf
Definition multinomial_lpmf.hpp:23