From 1e41458826ee166e7f3f20bcbaf3ef28d1d712b9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Thu, 10 Jun 2010 18:27:03 +0200
Subject: [PATCH] Estimation DLL: bugfixes in LogLikelihoodMain

---
 .../estimation/EstimatedParametersDescription.cc      | 11 +++++++++++
 .../estimation/EstimatedParametersDescription.hh      |  1 +
 mex/sources/estimation/EstimationSubsample.hh         |  2 +-
 mex/sources/estimation/LogLikelihoodMain.cc           |  5 ++---
 4 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/mex/sources/estimation/EstimatedParametersDescription.cc b/mex/sources/estimation/EstimatedParametersDescription.cc
index 6141f6b46..69d302f82 100644
--- a/mex/sources/estimation/EstimatedParametersDescription.cc
+++ b/mex/sources/estimation/EstimatedParametersDescription.cc
@@ -34,3 +34,14 @@ EstimatedParametersDescription::EstimatedParametersDescription(std::vector<Estim
 {
 }
 
+size_t
+EstimatedParametersDescription::getNumberOfPeriods() const
+{
+  size_t r = 0;
+  for (size_t i = 0; i < estSubsamples.size(); i++)
+    {
+      size_t r2 = estSubsamples[i].endPeriod + 1;
+      if (r2 > r)
+        r = r2;
+    }
+}
diff --git a/mex/sources/estimation/EstimatedParametersDescription.hh b/mex/sources/estimation/EstimatedParametersDescription.hh
index 8d6aaf009..0e4a14fac 100644
--- a/mex/sources/estimation/EstimatedParametersDescription.hh
+++ b/mex/sources/estimation/EstimatedParametersDescription.hh
@@ -49,6 +49,7 @@ public:
   EstimatedParametersDescription(std::vector<EstimationSubsample> &estSubsamples, std::vector<EstimatedParameter> &estParams);
   std::vector<EstimationSubsample> estSubsamples;
   std::vector<EstimatedParameter> estParams;
+  size_t getNumberOfPeriods() const;
 };
 
 #endif // !defined(E8F2C096_A301_42e8_80FF_A643291BF995__INCLUDED_)
diff --git a/mex/sources/estimation/EstimationSubsample.hh b/mex/sources/estimation/EstimationSubsample.hh
index 41e560098..ab3ed3c7a 100644
--- a/mex/sources/estimation/EstimationSubsample.hh
+++ b/mex/sources/estimation/EstimationSubsample.hh
@@ -53,7 +53,7 @@
  * class LogPosteriorDensity on as needed basis and updates all parameters (inc. H
  * and Q) when time slot xparam1 is supplied.
  *
- *
+ * Time indices follow C convention: first period has index 0.
  */
 class EstimationSubsample {
 public:
diff --git a/mex/sources/estimation/LogLikelihoodMain.cc b/mex/sources/estimation/LogLikelihoodMain.cc
index 272030078..29ce8c077 100644
--- a/mex/sources/estimation/LogLikelihoodMain.cc
+++ b/mex/sources/estimation/LogLikelihoodMain.cc
@@ -34,8 +34,7 @@ LogLikelihoodMain::LogLikelihoodMain( //const Matrix &data_arg, Vector &deepPara
   : estSubsamples(estiParDesc.estSubsamples),
   logLikelihoodSubSample(dynamicDllFile, estiParDesc, n_endo, n_exo, zeta_fwrd_arg, zeta_back_arg, zeta_mixed_arg, zeta_static_arg, qz_criterium,
                          varobs, riccati_tol, lyapunov_tol, info_arg),
-  //deepParams(deepParams_arg),
-  vll(estSubsamples[estSubsamples.size()-1].endPeriod) // time dimension size of data
+    vll(estiParDesc.getNumberOfPeriods()) // time dimension size of data
 
 {
 
@@ -49,7 +48,7 @@ LogLikelihoodMain::~LogLikelihoodMain()
 double
 LogLikelihoodMain::compute(Matrix &steadyState, const Vector &estParams, Vector &deepParams, const MatrixConstView &data, Matrix &Q, Matrix &H, size_t start, int &info)
 {
-  for (size_t i = 1; i <= (size_t) estSubsamples.size(); ++i)
+  for (size_t i = 0; i < estSubsamples.size(); ++i)
     {
       VectorView vSteadyState = mat::get_col(steadyState, i);
 
-- 
GitLab