Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • python-codegen
  • 6.x protected
  • llvm-15
  • julia-6.4.0
  • julia
  • julia-meson
  • 5.x protected
  • julia-6.3.0
  • 4.6 protected
  • uop
  • rework_pac
  • aux_vars_fix
  • julia-6.2.0
  • created_preprocessor_repo
15 results

SymbolTable.cc

Blame
    • Sébastien Villemot's avatar
      0169240f
      Ramsey: write derivatives of static model w.r.t. Lagrange multipliers in a new file · 0169240f
      Sébastien Villemot authored
      The computing of the Ramsey steady state relies on the fact that Lagrange
      multipliers appear linearly in the system to be solved. Instead of directly
      solving for the Lagrange multipliers along with the other variables,
      dyn_ramsey_static.m reduces the size of the problem by always computing the
      value of the multipliers that minimizes the residuals, given the other
      variables (using a minimum norm solution, easy to compute because of the
      linearity property). That function thus needs the derivatives of the optimality
      FOCs with respect to the multipliers. The problem is that, when multipliers
      appear in an auxiliary variable related to a lead/lag, then those derivatives
      need to be retrieved by a chain rule derivation, which cannot be easily done
      with the regular static file.
      
      This commit implements the creation of a new file,
      ramsey_multipliers_static_g1.{m,mex}, that provides exactly the needed
      derivatives w.r.t. Lagrange multipliers through chain rule derivation.
      
      Ref. dynare#633, dynare#1119, dynare#1133
      0169240f
      History
      Ramsey: write derivatives of static model w.r.t. Lagrange multipliers in a new file
      Sébastien Villemot authored
      The computing of the Ramsey steady state relies on the fact that Lagrange
      multipliers appear linearly in the system to be solved. Instead of directly
      solving for the Lagrange multipliers along with the other variables,
      dyn_ramsey_static.m reduces the size of the problem by always computing the
      value of the multipliers that minimizes the residuals, given the other
      variables (using a minimum norm solution, easy to compute because of the
      linearity property). That function thus needs the derivatives of the optimality
      FOCs with respect to the multipliers. The problem is that, when multipliers
      appear in an auxiliary variable related to a lead/lag, then those derivatives
      need to be retrieved by a chain rule derivation, which cannot be easily done
      with the regular static file.
      
      This commit implements the creation of a new file,
      ramsey_multipliers_static_g1.{m,mex}, that provides exactly the needed
      derivatives w.r.t. Lagrange multipliers through chain rule derivation.
      
      Ref. dynare#633, dynare#1119, dynare#1133
    SymbolTable.cc 31.65 KiB
    /*
     * Copyright © 2003-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/>.
     */
    
    #include <algorithm>
    #include <sstream>
    #include <iostream>
    #include <cassert>
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wold-style-cast"
    #include <boost/algorithm/string/replace.hpp>
    #pragma GCC diagnostic pop
    #include <utility>
    
    #include "SymbolTable.hh"
    
    int
    SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string, string>> &partition_value) noexcept(false)
    {
      if (frozen)
        throw FrozenException();
    
      if (exists(name))
        {
          if (type_table[getID(name)] == type)
            throw AlreadyDeclaredException(name, true);
          else
            throw AlreadyDeclaredException(name, false);
        }
    
      string final_tex_name = tex_name;
      if (final_tex_name.empty())
        {
          final_tex_name = name;
          size_t pos = 0;
          while ((pos = final_tex_name.find('_', pos)) != string::npos)
            {
              final_tex_name.insert(pos, R"(\)");
              pos += 2;
            }
        }
    
      string final_long_name = name;
      bool non_long_name_partition_exists = false;
      for (const auto &it : partition_value)
        if (it.first == "long_name")
          final_long_name = it.second;
        else
          non_long_name_partition_exists = true;
    
      int id = symbol_table.size();
    
      symbol_table[name] = id;
      type_table.push_back(type);
      name_table.push_back(name);