diff --git a/matlab/ols/getRhsToSubFromLhs.m b/matlab/ols/getRhsToSubFromLhs.m deleted file mode 100644 index f2ff2d84d..000000000 --- a/matlab/ols/getRhsToSubFromLhs.m +++ /dev/null @@ -1,76 +0,0 @@ -function lhssub = getRhsToSubFromLhs(ds, rhs, regex, splits, pnames) -%function lhssub = getRhsToSubFromLhs(ds, rhs, regex, splits, pnames) -% Helper function that identifies variables on RHS that need to be -% subtracted from LHS of OLS-style equation -% -% INPUTS -% ds [dseries] data -% rhs [string] RHS as a string -% regex [string] regex expressing valid list of variables -% splits [cell string] strings to split out of equation on RHS -% pnames [cell string] parameter names -% -% OUTPUTS -% lhssub [dseries] summed data to subtract from LHS -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2017-2018 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 . - -global M_ - -assert(isdseries(ds), 'The first argument must be a dseries'); -assert(ischar(rhs), 'The second argument must be a string'); -assert(ischar(regex), 'The third argument must be a string'); -assert(iscellstr(splits), 'The fourth argument must be a cell'); -assert(iscellstr(splits), 'The fourth argument must be a cell'); - -lhssub = dseries(); -rhs_ = strsplit(rhs, splits); -for j = 1:length(rhs_) - rhsj = rhs_{j}; - while ~isempty(rhsj) - minusstr = ''; - if strcmp(rhsj(1), '-') || strcmp(rhsj(1), '+') - if length(rhsj) == 1 - break - end - if strcmp(rhsj(1), '-') - minusstr = '-'; - end - rhsj = rhsj(2:end); - end - str = getStrMoveRight(rhsj); - if ~isempty(str) - try - lhssub = lhssub + eval(regexprep([minusstr str], regex, 'ds.$&')); - catch - if ~any(strcmp(M_.exo_names, str)) && ~any(strcmp(pnames, str)) - error(['getRhsToSubFromLhs: problem evaluating ' minusstr str]); - end - end - rhsj = rhsj(length(str)+1:end); - end - end -end -if ~isempty(lhssub) - assert(lhssub.vobs == 1, 'error in getRhsToSubFromLhs'); - lhssub.rename_(lhssub.name{:}, 'summed_rhs'); -end -end \ No newline at end of file diff --git a/matlab/ols/getStrMoveLeft.m b/matlab/ols/getStrMoveLeft.m deleted file mode 100644 index 44af892bb..000000000 --- a/matlab/ols/getStrMoveLeft.m +++ /dev/null @@ -1,75 +0,0 @@ -function retval = getStrMoveLeft(str) -%function retval = getStrMoveLeft(str) -% Helper function common to OLS routines. Given a string finds expr -% moving from right to left (potentially contained in parenthesis) until -% it gets to the + or -. e.g., given: str = -% 'res_9+DE_SIN*param+log(DE_SIN(-1))', returns 'log(DE_SIN)' -% -% INPUTS -% str [string] string -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2017 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 . - -if isempty(str) - retval = ''; - return -end - -mathidxs = regexp(str, '[\+\-]'); -closedidxs = strfind(str, ')'); -if isempty(closedidxs) ... - || (~isempty(mathidxs) ... - && max(mathidxs) > max(closedidxs)) - if isempty(mathidxs) - retval = str; - else - if str(max(mathidxs)) == '-' - retval = str(max(mathidxs):end); - else - retval = str(max(mathidxs)+1:end); - end - end -else - closedidxs = [(length(closedidxs):-1:1)' closedidxs']; - openidxs = strfind(str, '('); - openidxs = [(length(openidxs):-1:1)' openidxs']; - assert(rows(closedidxs) == rows(openidxs)); - for i = rows(openidxs):-1:1 - openparenidx = find(openidxs(i, 2) < closedidxs(:, 2), 1, 'first'); - if openidxs(i, 1) == closedidxs(openparenidx, 1) - break - end - end - retval = str(openidxs(openparenidx, 2):end); - if openidxs(openparenidx, 2) ~= 1 - if isempty(regexp(str(openidxs(openparenidx, 2) - 1), '[\+\-]', 'once')) - retval = [getStrMoveLeft(str(1:openidxs(openparenidx, 2) - 2)) ... - str(openidxs(openparenidx, 2) - 1) ... - retval]; - end - end - if strfind(str, ['-' retval]) - retval = ['-' retval]; - end -end diff --git a/matlab/ols/getStrMoveRight.m b/matlab/ols/getStrMoveRight.m deleted file mode 100644 index 9b65bd6f6..000000000 --- a/matlab/ols/getStrMoveRight.m +++ /dev/null @@ -1,69 +0,0 @@ -function retval = getStrMoveRight(str) -%function retval = getStrMoveRight(str) -% Helper function common to OLS routines. Given a string finds expr -% moving from left to right (potentially contained in parenthesis) until -% it gets to the + or -. e.g., given: str = -% '(log(DE_SIN(-1))-log(DE_SIN))+anotherparam1*log(DE_SIN)', returns -% '(log(DE_SIN(-1))-log(DE_SIN))' -% -% INPUTS -% str [string] string -% -% OUTPUTS -% none -% -% SPECIAL REQUIREMENTS -% none - -% Copyright (C) 2017 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 . - -if isempty(str) - retval = ''; - return -end - -mathidxs = regexp(str, '[\+\-]'); -openidxs = strfind(str, '('); -if isempty(openidxs) ... - || (~isempty(mathidxs) ... - && min(mathidxs) < min(openidxs)) - if isempty(mathidxs) - retval = str; - else - retval = str(1:min(mathidxs)-1); - end -else - openidxs = [(1:length(openidxs))' openidxs']; - closedidxs = strfind(str, ')'); - closedidxs = [(1:length(closedidxs))' closedidxs']; - assert(rows(openidxs) == rows(closedidxs)); - for i = 1:rows(closedidxs) - closedparenidx = sum(openidxs(:, 2) < closedidxs(i, 2)); - if openidxs(closedparenidx, 1) == closedidxs(i, 1) - break; - end - end - retval = str(1:closedidxs(closedparenidx, 2)); - if length(str) > closedidxs(closedparenidx, 2) + 1 - if any(strfind('*^/', str(closedidxs(closedparenidx, 2) + 1))) - retval = [retval ... - str(closedidxs(closedparenidx, 2) + 1) ... - getStrMoveRight(str(closedidxs(closedparenidx, 2) + 2:end))]; - end - end -end