Skip to content
Snippets Groups Projects
Verified Commit 0d9857e7 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

k_order_welfare MEX: drop ObjectiveAC abstract class, it has a single subclass

parent adc42bb4
Branches
Tags
No related merge requests found
/* /*
* Copyright © 2021-2023 Dynare Team * Copyright © 2021-2024 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -18,13 +18,12 @@ ...@@ -18,13 +18,12 @@
*/ */
#include "k_ord_objective.hh" #include "k_ord_objective.hh"
#include "objective_abstract_class.hh"
#include <cassert> #include <cassert>
#include <utility> #include <utility>
KordwDynare::KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams, KordwDynare::KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
std::unique_ptr<ObjectiveAC> objectiveFile_arg, std::unique_ptr<ObjectiveMFile> objectiveFile_arg,
const std::vector<int>& dr_order) : const std::vector<int>& dr_order) :
model {m}, model {m},
NNZD {NNZD_arg}, NNZD {NNZD_arg},
......
/* /*
* Copyright © 2021-2023 Dynare Team * Copyright © 2021-2024 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define K_ORD_OBJECTIVE_HH #define K_ORD_OBJECTIVE_HH
#include "k_ord_dynare.hh" #include "k_ord_dynare.hh"
#include "objective_abstract_class.hh" #include "objective_m.hh"
class KordwDynare; class KordwDynare;
...@@ -38,11 +38,11 @@ private: ...@@ -38,11 +38,11 @@ private:
TensorContainer<FSSparseTensor> ud; // planner's objective derivatives, in Dynare++ form TensorContainer<FSSparseTensor> ud; // planner's objective derivatives, in Dynare++ form
std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones
std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones
std::unique_ptr<ObjectiveAC> objectiveFile; std::unique_ptr<ObjectiveMFile> objectiveFile;
public: public:
KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams, KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int>& varOrder); std::unique_ptr<ObjectiveMFile> objectiveFile_arg, const std::vector<int>& varOrder);
void calcDerivativesAtSteady(); void calcDerivativesAtSteady();
void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord); void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord);
[[nodiscard]] const TensorContainer<FSSparseTensor>& [[nodiscard]] const TensorContainer<FSSparseTensor>&
......
/* /*
* Copyright © 2021-2022 Dynare Team * Copyright © 2021-2024 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -87,8 +87,8 @@ The routine proceeds in several steps: ...@@ -87,8 +87,8 @@ The routine proceeds in several steps:
to the approxAtSteady method in the ApproximationWelfare class carries out the necessary to the approxAtSteady method in the ApproximationWelfare class carries out the necessary
operation operation
- Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of - Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of
the KordwDynare class. It relies on the Matlab-generated files, which are handled by the the KordwDynare class. It relies on the MATLAB-generated files, which are handled by the
ObjectiveAC and ObjectiveMFile classes ObjectiveMFile class
- Pinpointing the derivatives of the felicity and welfare functions. The performStep method of - Pinpointing the derivatives of the felicity and welfare functions. The performStep method of
the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its
methods to get the needed intermediary results. methods to get the needed intermediary results.
...@@ -301,7 +301,7 @@ extern "C" ...@@ -301,7 +301,7 @@ extern "C"
mxGetPr(objective_tmp_nbr_mx) + kOrder + 1, 0); mxGetPr(objective_tmp_nbr_mx) + kOrder + 1, 0);
// Getting derivatives of the planner's objective function // Getting derivatives of the planner's objective function
std::unique_ptr<ObjectiveAC> objectiveFile; std::unique_ptr<ObjectiveMFile> objectiveFile;
objectiveFile = std::make_unique<ObjectiveMFile>(fname, ntt_objective); objectiveFile = std::make_unique<ObjectiveMFile>(fname, ntt_objective);
// make KordwDynare object // make KordwDynare object
......
/*
* Copyright © 2021-2023 Dynare Team
*
* This file is part of Dynare.
*
* Dynare 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 3 of the License, or
* (at your option) any later version.
*
* Dynare 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.
*
* You should have received a copy of the GNU General Public License
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef OBJECTIVE_ABSTRACT_CLASS_HH
#define OBJECTIVE_ABSTRACT_CLASS_HH
#include <vector>
#include "twod_matrix.hh"
class ObjectiveAC
{
protected:
int ntt; // Size of vector of temporary terms
public:
ObjectiveAC(int ntt_arg) : ntt {ntt_arg} {};
virtual ~ObjectiveAC() = default;
virtual void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
std::vector<TwoDMatrix>& md)
= 0;
};
#endif
/* /*
* Copyright © 2021-2023 Dynare Team * Copyright © 2021-2024 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "objective_m.hh" #include "objective_m.hh"
ObjectiveMFile::ObjectiveMFile(const std::string& modName, int ntt_arg) : ObjectiveMFile::ObjectiveMFile(const std::string& modName, int ntt_arg) :
ObjectiveAC(ntt_arg), ObjectiveMFilename {modName + ".objective.static"} ntt {ntt_arg}, ObjectiveMFilename {modName + ".objective.static"}
{ {
} }
......
/* /*
* Copyright © 2021-2023 Dynare Team * Copyright © 2021-2024 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -20,24 +20,23 @@ ...@@ -20,24 +20,23 @@
#ifndef OBJECTIVE_M_HH #ifndef OBJECTIVE_M_HH
#define OBJECTIVE_M_HH #define OBJECTIVE_M_HH
#include "objective_abstract_class.hh" #include <vector>
#include "mex.h"
#include <dynmex.h> #include <dynmex.h>
/** #include "twod_matrix.hh"
* handles calls to <model>/+objective/static.m
* // Handles calls to <model>/+objective/static.m
**/ class ObjectiveMFile
class ObjectiveMFile : public ObjectiveAC
{ {
private: private:
int ntt; // Size of vector of temporary terms
const std::string ObjectiveMFilename; const std::string ObjectiveMFilename;
static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm); static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm);
public: public:
explicit ObjectiveMFile(const std::string& modName, int ntt_arg); explicit ObjectiveMFile(const std::string& modName, int ntt_arg);
void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual, void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
std::vector<TwoDMatrix>& md) override; std::vector<TwoDMatrix>& md);
}; };
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment