forked from gregkaplan/phact
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_G0_sparse.m
More file actions
30 lines (26 loc) · 853 Bytes
/
clean_G0_sparse.m
File metadata and controls
30 lines (26 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function [state_red,inv_state_red,g0,g1,c,pi,psi] = clean_G0_sparse(g0,g1,c,pi,psi)
% Solves out static constraints of the linear model by solving out last n_p
% variables with 0 rows in g0.
%
% Input/Output/Rerences: It will be faster to read the codes below
%
% by SeHyoun, June 2106
%
% [state_red,inv_state_red,g0,g1,c,pi,psi] = clean_G0_sparse(g0,g1,c,pi,psi)
n = size(g0,1);
tmp = (max(abs(g0),[],2)==0);
redundant = find(tmp);
%n_red = length(redundant);
keep=find(1-tmp);
n_keep = length(keep);
inv_state_red = sparse(n,n_keep);
inv_state_red(keep,:) = speye(n_keep);
inv_state_red(redundant,:) = -g1(redundant,redundant)\g1(redundant,keep);
state_red = sparse(n_keep,n);
state_red(:,keep)=speye(n_keep);
g0=state_red*g0*inv_state_red;
g1=state_red*g1*inv_state_red;
g1=g0\g1;
psi=g0\state_red*psi;
pi=g0\state_red*pi;
c=g0\state_red*c;