create ols directory to hold common OLS code

time-shift
Houtan Bastani 2017-11-02 15:10:30 +01:00
parent e0b051314b
commit 4da12aac5e
6 changed files with 116 additions and 99 deletions

View File

@ -64,6 +64,7 @@ p = {'/distributions/' ; ...
'/cli/' ; ...
'/lmmcp/' ; ...
'/optimization/' ; ...
'/ols/'; ...
'/modules/dates/src/' ; ...
'/modules/dseries/src/' ; ...
'/utilities/doc/' ; ...

View File

@ -191,50 +191,3 @@ for i = 1:length(lhs)
[oo_.ols.(tagv).beta oo_.ols.(tagv).tstat oo_.ols.(tagv).stderr]);
end
end
function retval = getStrMoveLeft(str)
mathops = '[\+\*\^\-\/]';
if str(end) ~= ')'
retval = str(max(regexp(str, mathops))+1:end);
else
closedidxs = strfind(str, ')');
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(max(regexp(str(1:openidxs(openparenidx,2)), mathops))+1:closedidxs(end));
end
end
function retval = getStrMoveRight(str)
mathops = '[\+\*\^\-\/]';
mathidxs = regexp(str, mathops);
openidxs = strfind(str, '(');
if isempty(openidxs) ...
|| (~isempty(mathidxs) ...
&& min(mathidxs) < min(openidxs))
if isempty(mathidxs)
retval = str;
else
retval = str(1:min(regexp(str, mathops))-1);
end
else
openidxs = [(1:length(openidxs))' openidxs'];
closedidxs = strfind(str, ')');
closedidxs = [(1:length(closedidxs))' closedidxs'];
assert(length(openidxs) == length(closedidxs));
for i = 1:length(closedidxs)
closedparenidx = sum(openidxs(:, 2) < closedidxs(i, 2));
if openidxs(closedparenidx, 1) == closedidxs(i, 1)
break;
end
end
retval = str(1:closedidxs(closedparenidx, 2));
end
end

View File

@ -0,0 +1,56 @@
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 <http://www.gnu.org/licenses/>.
mathops = '[\+\*\^\-\/]';
if str(end) ~= ')'
mathidxs = regexp(str, mathops);
if isempty(mathidxs)
retval = str;
else
retval = str(max(mathidxs)+1:end);
end
else
closedidxs = strfind(str, ')');
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(max(regexp(str(1:openidxs(openparenidx,2)), mathops))+1:closedidxs(end));
end

View File

@ -0,0 +1,59 @@
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 <http://www.gnu.org/licenses/>.
mathops = '[\+\*\^\-\/]';
mathidxs = regexp(str, mathops);
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(length(openidxs) == length(closedidxs));
for i = 1:length(closedidxs)
closedparenidx = sum(openidxs(:, 2) < closedidxs(i, 2));
if openidxs(closedparenidx, 1) == closedidxs(i, 1)
break;
end
end
retval = str(1:closedidxs(closedparenidx, 2));
end

View File

@ -178,55 +178,3 @@ for i = 1:length(idxs)
M_.params(strcmp(param_names_trim, names{i})) = values(i);
end
end
function retval = getStrMoveLeft(str)
mathops = '[\+\*\^\-\/]';
if str(end) ~= ')'
mathidxs = regexp(str, mathops);
if isempty(mathidxs)
retval = str;
else
retval = str(max(mathidxs)+1:end);
end
else
closedidxs = strfind(str, ')');
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(max(regexp(str(1:openidxs(openparenidx,2)), mathops))+1:closedidxs(end));
end
end
function retval = getStrMoveRight(str)
mathops = '[\+\*\^\-\/]';
mathidxs = regexp(str, mathops);
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(length(openidxs) == length(closedidxs));
for i = 1:length(closedidxs)
closedparenidx = sum(openidxs(:, 2) < closedidxs(i, 2));
if openidxs(closedparenidx, 1) == closedidxs(i, 1)
break;
end
end
retval = str(1:closedidxs(closedparenidx, 2));
end
end