source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/@sdpvar/recovermonoms.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.1 KB
Line 
1function monom = recovermonoms(newton_m,x)
2%RECOVERMONOMS Internal function used in SOS programs
3
4% Author Johan Löfberg
5% $Id: recovermonoms.m,v 1.14 2006/07/26 20:17:58 joloef Exp $
6
7if size(newton_m,1)==1 & nnz(newton_m)==0
8    monom = 1;
9    return
10end
11
12[mt,oldvariabletype,mt_hash,hash] = yalmip('monomtable');
13
14origSize = size(mt,1);
15vars = x.lmi_variables;
16
17newton_m_extended = spalloc(size(newton_m,1),size(mt,2),nnz(newton_m));
18newton_m_extended(:,vars) = newton_m;
19newton_m_extended_hash = newton_m_extended*hash;
20
21newton_m = newton_m';
22newton_m_extended = newton_m_extended';
23mt = mt';
24
25monom = x;
26%monom.n = size(newton_m,1);
27monom.dim(1) = size(newton_m,2);
28monom.dim(2) = 1;
29monom.lmi_variables = [];
30%variable_here = ones(1,size(newton_m,1));
31%variable_here = ones(1,size(newton_m,2));
32mt_hash = full(mt_hash);
33nvar = size(mt,2);
34new_mt_hash = [];
35new_mt = [];
36variable_here = any(newton_m,1);
37for i = find(variable_here)%1:size(newton_m,2)
38    %if nnz(newton_m(:,i))==0
39    %    variable_here(i) = 0;
40    %else
41        if isempty(mt_hash)%MESSY DUE TO BEHAVIOUR IN LINUX 6.1
42           previous_variable = [];
43        else
44            previous_variable = find(mt_hash == newton_m_extended_hash(i));           
45        end
46        if isempty(previous_variable) 
47            if isempty(new_mt_hash)
48                previous_variable = [];
49            else
50                previous_variable = find(new_mt_hash == newton_m_extended_hash(i));
51            end
52            if isempty(previous_variable)
53                nvar = nvar + 1;
54          %      mt = [mt newton_m_extended(:,i)];
55          %      mt_hash = [mt_hash ; newton_m_extended(:,i)'*hash];
56                new_mt = [new_mt newton_m_extended(:,i)];
57                new_mt_hash = [new_mt_hash ; newton_m_extended(:,i)'*hash];
58         
59                monom.lmi_variables = [monom.lmi_variables nvar];
60            else
61                monom.lmi_variables = [monom.lmi_variables size(mt,2)+previous_variable];
62            end
63        else
64%            try
65                 monom.lmi_variables = [monom.lmi_variables previous_variable];
66 %           catch
67  %              error
68   %         end
69        end
70  %  end
71end
72mt = [mt new_mt]';
73mt_hash = [mt_hash;new_mt_hash];
74%mt = mt';
75
76% if append_one   
77%     monom.basis = [[1;spalloc(monom.dim(1),1,0)] [spalloc(1,monom.dim(1),0);speye(monom.dim(1))]];
78%     monom.dim(1) = monom.dim(1) + 1;
79% else
80% monom.basis = [spalloc(monom.dim(1),1,0) spalloc(monom.dim(1),length(find(variable_here)),0)];
81% monom.basis = [spalloc(monom.dim(1),1+length(find(variable_here)),1+length(find(variable_here)))];
82% monom.basis(find(variable_here),2:end) = speye(length(find(variable_here)));
83% monom.basis(find(variable_here==0),1)=1;
84
85nz = find(variable_here);
86zv = find(variable_here==0);
87i = [zv(:);nz(:)];
88j = [ones(length(zv),1);(2:(length(nz)+1))'];
89k = ones(length(variable_here),1);
90monom.basis = sparse(i,j,k,monom.dim(1),1+length(find(variable_here)));
91
92%end
93
94% Fucked up order
95if any(diff(monom.lmi_variables)<0)
96    [i,j]=sort(monom.lmi_variables);
97    monom.lmi_variables = monom.lmi_variables(j);
98    monom.basis(:,2:end) = monom.basis(:,j+1);
99end
100
101un_monom_vars = uniquestripped(monom.lmi_variables);
102if length(un_monom_vars)<length(monom.lmi_variables)
103    [un_monom_vars,hh,jj] = unique(monom.lmi_variables);
104    if length(monom.lmi_variables) ~=length(un_monom_vars)
105        newmonombase = monom.basis*sparse([1 1+jj],[1 1+(1:length(jj))],ones(1,1+length(jj)))';
106        monom.basis = newmonombase;
107        monom.lmi_variables = un_monom_vars;
108    end
109end
110
111if size(mt,1) > origSize
112    newmt = mt(origSize+1:end,:);
113    newvariabletype = spalloc(size(newmt,1),1,0)';
114    nonlinear = ~(sum(newmt,2)==1 & sum(newmt~=0,2)==1);
115    if ~isempty(nonlinear)
116        %mt = internal_sdpvarstate.monomtable;
117        newvariabletype(nonlinear) = 3;
118        quadratic = sum(newmt,2)==2;
119        newvariabletype(quadratic) = 2;
120        bilinear = max(newmt,[],2)<=1;
121        newvariabletype(bilinear & quadratic) = 1;
122        sigmonial = any(0>newmt,2) | any(newmt-fix(newmt),2);
123        newvariabletype(sigmonial) = 4;
124    end
125    yalmip('setmonomtable',mt,[oldvariabletype newvariabletype]);
126end
127
128
Note: See TracBrowser for help on using the repository browser.