Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea-Havron-NOAA committed May 31, 2024
1 parent d19224d commit 251d6e3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ struct DensityComponentBase : public fims_model_object::FIMSObject<Type> {
std::string nll_type; //prior, re, data
bool osa_flag = false;
bool simulate_flag = false;
#ifdef TMB_MODEL
::objective_function<Type> *of;
#endif

/** @brief Constructor.
*/
Expand Down
5 changes: 4 additions & 1 deletion inst/include/distributions/functors/lognormal_lpdf.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef LOGNORMALl_LPDF
#ifndef LOGNORMAL_LPDF
#define LOGNORMAL_LPDF

#include "density_components_base.hpp"
Expand Down Expand Up @@ -55,8 +55,10 @@ namespace fims_distributions
for (size_t i = 0; i < this->observed_values.size(); i++)
{
if(!is_na[i]){
#ifdef TMB_MODEL
// this->nll_vec[i] = this->keep[i] * -dnorm(this->observed_values[i], mu[i], sd[i], do_log);
this->nll_vec[i] = -dnorm(log(this->observed_values[i]), mu[i], sd[i], do_log) - log(this->observed_values[i]);

nll += this->nll_vec[i];
if (this->simulate_flag)
{
Expand All @@ -66,6 +68,7 @@ namespace fims_distributions
this->observed_values[i] = exp(rnorm(mu[i], sd[i]));
}
}
#endif

/* osa not working yet
if(osa_flag){//data observation type implements osa residuals
Expand Down
6 changes: 5 additions & 1 deletion inst/include/distributions/functors/multinomial_lpmf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ namespace fims_distributions
Type nll = 0.0;
fims::Vector<size_t> dims;
std::vector<bool> is_na;
#ifdef TMB_MODEL
::objective_function<Type> *of;
#endif
// data_indicator<tmbutils::vector<Type> , Type> keep;

MultinomialLPMF() : DensityComponentBase<Type>()
Expand All @@ -42,7 +45,7 @@ namespace fims_distributions
}
#ifdef TMB_model
this->nll_vec[i] = -dmultinom((vector<Type>)observed_vector, (vector<Type>)expected_vector, do_log);
#endif

nll += this->nll_vec[i];
/*
if (this->simulate_flag)
Expand All @@ -61,6 +64,7 @@ namespace fims_distributions
}
}
*/
#endif
}
}
#ifdef TMB_MODEL
Expand Down
6 changes: 6 additions & 0 deletions inst/include/distributions/functors/normal_lpdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct NormalLPDF : public DensityComponentBase<Type> {
fims::Vector<Type> sd;
Type nll = 0.0;
std::vector<bool> is_na;
#ifdef TMB_MODEL
::objective_function<Type> *of;
#endif
//data_indicator<tmbutils::vector<Type> , Type> keep;

NormalLPDF() : DensityComponentBase<Type>() {
Expand Down Expand Up @@ -43,13 +46,16 @@ struct NormalLPDF : public DensityComponentBase<Type> {
for(size_t i=0; i<this->observed_values.size(); i++){
if(!is_na[i]){
// this->nll_vec[i] = this->keep[i] * -dnorm(this->observed_values[i], mu[i], sd[i], do_log);
#ifdef TMB_MODEL
this->nll_vec[i] = -dnorm(this->observed_values[i], mu[i], sd[i], do_log);

nll += this->nll_vec[i];
if(this->simulate_flag){
FIMS_SIMULATE_F(this->of){
this->observed_values[i] = rnorm(mu[i], sd[i]);
}
}
#endif
/* osa not working yet
if(osa_flag){//data observation type implements osa residuals
//code for osa cdf method
Expand Down

0 comments on commit 251d6e3

Please sign in to comment.