Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kthohr committed Sep 20, 2017
1 parent c55997d commit 49a918c
Show file tree
Hide file tree
Showing 126 changed files with 859 additions and 772 deletions.
4 changes: 4 additions & 0 deletions src/bmlib/include/dsge/dsge_class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class dsge
arma::vec lower_bounds;
arma::vec upper_bounds;

// choice of filtering method

int filter_choice = 1; // 1 for Kalman, 2 for Chandrasekhar

// data used for estimation

arma::mat estim_data;
Expand Down
19 changes: 17 additions & 2 deletions src/bmlib/include/dsge/dsge_class.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,22 @@ const

// run filter

const double log_likelihood_val = kalman_filter(estim_data, kalman_mat_F,kalman_mat_Q, kalman_mat_C,kalman_mat_H,kalman_mat_R);
double log_likelihood_val = 0.0;

switch (filter_choice) {
case 1:
log_likelihood_val = kalman_filter(estim_data, kalman_mat_F,kalman_mat_Q, kalman_mat_C,kalman_mat_H,kalman_mat_R);
break;

case 2:
log_likelihood_val = chand_recur(estim_data, kalman_mat_F,kalman_mat_Q, kalman_mat_C,kalman_mat_H,kalman_mat_R);
break;

default:
printf("error: unknown choice for filter\n");
break;

}

// compute the prior

Expand Down Expand Up @@ -345,7 +360,7 @@ const
dsge_obj_copy.solve_to_state_space(dsge_draws.row(j).t());

arma::mat G_state;
dsge_obj_copy.state_space(kalman_mat_F,G_state);
dsge_obj_copy.state_space(dsge_obj_copy.kalman_mat_F,G_state);

//

Expand Down
6 changes: 0 additions & 6 deletions src/bmlib/include/stats/dens/dbern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the univariate Bernoulli distribution
*
* Keith O'Hara
* 01/03/2016
*
* This version:
* 07/06/2017
*/

#ifndef _statslib_dbern_HPP
Expand Down
10 changes: 4 additions & 6 deletions src/bmlib/include/stats/dens/dbern.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the univariate Bernoulli distribution
*
* Keith O'Hara
* 01/03/2016
*
* This version:
* 07/06/2017
*/

//
Expand Down Expand Up @@ -74,12 +68,16 @@ arma::mat
dbern_int(const arma::mat& x, const double* prob_par_inp, const bool log_form)
{
const double prob_par = (prob_par_inp) ? *prob_par_inp : 0.5;

//

arma::mat ret(x.n_rows,x.n_cols);

(log_form) ? ret.fill(std::log(1.0 - prob_par)) : ret.fill(1.0 - prob_par);
(log_form) ? ret.elem(arma::find(x)).fill(std::log(prob_par)) : ret.elem(arma::find(x)).fill(prob_par);

//

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/bmlib/include/stats/dens/dbeta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the beta distribution
*
* Keith O'Hara
* 01/02/16
*
* This version:
* 07/06/2017
*/

#ifndef _statslib_dbeta_HPP
Expand Down
14 changes: 6 additions & 8 deletions src/bmlib/include/stats/dens/dbeta.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the beta distribution
*
* Keith O'Hara
* 01/02/16
*
* This version:
* 07/02/2017
*/

//
Expand Down Expand Up @@ -73,16 +67,20 @@ inline
arma::mat
dbeta_int(const arma::mat& x, const double* a_par_inp, const double* b_par_inp, const bool log_form)
{
const double a_par = (a_par_inp) ? *a_par_inp : 2; // shape parameter 'alpha'
const double b_par = (b_par_inp) ? *b_par_inp : 2; // scale parameter 'beta'
const double a_par = (a_par_inp) ? *a_par_inp : 2.0; // shape parameter 'alpha'
const double b_par = (b_par_inp) ? *b_par_inp : 2.0; // scale parameter 'beta'

//

const double lbeta_term = std::lgamma(a_par + b_par) - std::lgamma(a_par) - std::lgamma(b_par); // log beta function
arma::mat ret = lbeta_term + (a_par - 1.0)*arma::log(x) + (b_par - 1.0)*arma::log(1.0 - x);

if (!log_form) {
ret = arma::exp(ret);
}

//

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/bmlib/include/stats/dens/dbinom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the univariate Binomial distribution
*
* Keith O'Hara
* 06/23/2017
*
* This version:
* 07/06/2017
*/

#ifndef _statslib_dbinom_HPP
Expand Down
10 changes: 4 additions & 6 deletions src/bmlib/include/stats/dens/dbinom.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the univariate Binomial distribution
*
* Keith O'Hara
* 06/23/2017
*
* This version:
* 07/06/2017
*/

//
Expand Down Expand Up @@ -81,14 +75,18 @@ dbinom_int(const arma::mat& x, const int* n_trials_par_inp, const double* prob_p
const int n = x.n_rows;
const int k = x.n_cols;

//

arma::mat ret(n,k);

for (int j=0; j < k; j++) {
for (int i=0; i < n; i++) {
ret(i,j) = dbinom((int)x(i,j),n_trials_par,prob_par,log_form);
}
}

//

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/bmlib/include/stats/dens/dcauchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the Cauchy distribution
*
* Keith O'Hara
* 07/01/2017
*
* This version:
* 07/07/2017
*/

#ifndef _statslib_dcauchy_HPP
Expand Down
14 changes: 6 additions & 8 deletions src/bmlib/include/stats/dens/dcauchy.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the Cauchy distribution
*
* Keith O'Hara
* 07/01/2017
*
* This version:
* 07/07/2017
*/

//
Expand Down Expand Up @@ -73,17 +67,21 @@ inline
arma::mat
dcauchy_int(const arma::mat& x, const double* mu_par_inp, const double* sigma_par_inp, const bool log_form)
{
const double mu_par = (mu_par_inp) ? *mu_par_inp : 0;
const double sigma_par = (sigma_par_inp) ? *sigma_par_inp : 1;
const double mu_par = (mu_par_inp) ? *mu_par_inp : 0.0;
const double sigma_par = (sigma_par_inp) ? *sigma_par_inp : 1.0;

//

const arma::mat z = (x - mu_par) / sigma_par;

arma::mat ret = 1.0 / ( sigma_par*GCEM_PI*(1.0 + z%z) );

if (log_form) {
ret = arma::log(ret);
}

//

return ret;
}

Expand Down
6 changes: 0 additions & 6 deletions src/bmlib/include/stats/dens/dchisq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the chi-squared distribution
*
* Keith O'Hara
* 04/12/2017
*
* This version:
* 07/07/2017
*/

#ifndef _statslib_dchisq_HPP
Expand Down
10 changes: 4 additions & 6 deletions src/bmlib/include/stats/dens/dchisq.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

/*
* pdf of the chi-squared distribution
*
* Keith O'Hara
* 04/12/2017
*
* This version:
* 07/07/2017
*/

//
Expand Down Expand Up @@ -74,15 +68,19 @@ arma::mat
dchisq_int(const arma::mat& x, const double* dof_par_inp, const bool log_form)
{
const double dof_2 = (dof_par_inp) ? *dof_par_inp / 2.0 : 0.5; // dof / 2

//

const double norm_term = - std::lgamma(dof_2) - dof_2*GCEM_LOG_2;

arma::mat ret = norm_term + (dof_2 - 1) * arma::log(x) - x / 2.0;

if (!log_form) {
ret = arma::exp(ret);
}

//

return ret;
}

Expand Down
1 change: 1 addition & 0 deletions src/bmlib/include/stats/dens/dens.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "dbeta.hpp"
#include "dcauchy.hpp"
#include "dchisq.hpp"
#include "dexp.hpp"
#include "dgamma.hpp"
#include "dinvgamma.hpp"
#include "dinvwish.hpp"
Expand Down
44 changes: 44 additions & 0 deletions src/bmlib/include/stats/dens/dexp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*################################################################################
##
## Copyright (C) 2011-2017 Keith O'Hara
##
## This file is part of the StatsLib C++ library.
##
## StatsLib is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 2 of the License, or
## (at your option) any later version.
##
## StatsLib is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
################################################################################*/

/*
* pdf of the exponential distribution
*/

#ifndef _statslib_dexp_HPP
#define _statslib_dexp_HPP

// single input
template<typename T>
statslib_constexpr T dexp(const T x, const T dof_par, const bool log_form);

statslib_constexpr double dexp(const double x);
statslib_constexpr double dexp(const double x, const bool log_form);
statslib_constexpr double dexp(const double x, const double dof_par);

// matrix/vector input
arma::mat dexp_int(const arma::mat& x, const double* dof_par_inp, const bool log_form);

arma::mat dexp(const arma::mat& x);
arma::mat dexp(const arma::mat& x, const bool log_form);
arma::mat dexp(const arma::mat& x, const double dof_par);
arma::mat dexp(const arma::mat& x, const double dof_par, const bool log_form);

#include "dexp.ipp"

#endif
Loading

0 comments on commit 49a918c

Please sign in to comment.