fix bug in ols common parsing routines causing ordering of regressor columns to change

time-shift
Houtan Bastani 2019-01-22 15:25:17 +01:00
parent 9d413e2f8f
commit 078e1ab99e
No known key found for this signature in database
GPG Key ID: 000094FB955BE169
1 changed files with 10 additions and 8 deletions

View File

@ -117,15 +117,16 @@ while ~isempty(plus_node) || ~isempty(last_node_to_parse)
% Handle constraits
% Look through Xtmp names for constant
% if found, subtract from LHS
for j = length(Xtmp.name):-1:1
if ~isnan(str2double(Xtmp.name{j}))
lhssub = lhssub + str2double(Xtmp.name{j}) * Xtmp{j};
Xtmp = Xtmp.remove(Xtmp.name{j});
names = Xtmp.name;
for j = length(names):-1:1
if ~isnan(str2double(names{j}))
lhssub = lhssub + str2double(names{j}) * Xtmp.(names{j});
Xtmp = Xtmp.remove(names{j});
else
% Multiply by -1 now so that it can be added together below
% Otherwise, it would matter which was encountered first,
% a parameter on its own or a linear constraint
Xtmp.(Xtmp.name{j}) = -1 * Xtmp{j};
Xtmp.(names{j}) = -1 * Xtmp.(names{j});
end
end
end
@ -133,12 +134,13 @@ while ~isempty(plus_node) || ~isempty(last_node_to_parse)
parsing_error('didn''t expect to arrive here', line);
end
for j = length(Xtmp.name):-1:1
names = Xtmp.name;
for j = length(names):-1:1
% Handle constraits
idx = find(strcmp(X.name, Xtmp.name{j}));
idx = find(strcmp(X.name, names{j}));
if ~isempty(idx)
X.(X.name{idx}) = X{idx} + Xtmp{j};
Xtmp = Xtmp.remove(Xtmp.name{j});
Xtmp = Xtmp.remove(names{j});
end
end
X = [X Xtmp];