Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XPP 7.87 KB | None | 0 0
  1. function [Saver] = create_xi_cluster(X, Arg_Saver)
  2.     % Date: 22.11.2010
  3.     % Author: sz
  4.    
  5.     % TODO: the next function deletes multiple entries
  6.     % in Saver and the entries of order 1
  7.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8.  
  9.     % Introduction
  10.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  11.     % interpret terms as points in lN^n space
  12.     % x^3*y^2*z => (3,2,1) in lN^3
  13.  
  14.     % X is the set of all points, which we write like in
  15.     % this example: (1,3) , (3,3), (1,2) are points of the set
  16.     % Then X = [ 1,3 ; 3,3 ; 1,2 ]
  17.  
  18.     % Saver is global
  19.     % global
  20.     Saver_in = Arg_Saver;
  21.    
  22.     bigger2 = false;
  23.    
  24.     X2 = []; % initialize to prevent cases where X2 is empty
  25.              % hence the program does not know where it came from
  26.              % in these cases
  27.    
  28. % a fancy way to find out:
  29. % does any point in X have a distance bigger than 2 to the (0,...0) ?
  30. STX = sum(transpose(X));
  31.         u = 1; % a counter (pretty technical stuff)
  32. for i = 1:length(STX)
  33.     if STX(i) > 2
  34.         bigger2 = true; % bigger2 is dominant
  35.         X2(u,:) = X(i,:) % create a new Matrix X2 (that way you filter
  36.         u = u+1; % counter
  37.         % out the others without having to delete it
  38.         % [the ladder wouldnt work..]
  39.     end
  40. end
  41.  
  42.  
  43. X = X2 % assign back
  44.  
  45. % if only one term is in X, you use the Halbieren-method
  46. % FYI: if you dont consider this case you will get an
  47. % error evaluating T = clusterdata(X,0.9), since that is only allowed
  48. % for X with 2 elements or more...
  49.  
  50.  
  51. if size(X,1) > 1
  52.    
  53.    
  54.     % step 2 in the PDF
  55.     % given the X, we create clusters
  56.     T = clusterdata(X,2)
  57.  
  58.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  59.     % if all "Clusters disjunct", that means, every cluster contains only 1 element
  60.     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61.     if max(T) == size(X,1)
  62.       display('entering disjunct');
  63.       M = []; % initialize
  64.  
  65.       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  66.       % HALBIEREN - METHODE
  67.       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68.  
  69.         % loop over Zeilen (Zeilenweise)
  70.         for i = 1:size(X,1)
  71.            
  72.                 display('check if only 1s and 0s');
  73.                
  74.                 if sum(transpose(X(i,:))) <= size(X(i,:),2)
  75.                
  76.                 % if there are only 1s and 0s in the X
  77.        
  78.                 % new strategy, cut off only a vector of distance 1
  79.                 % in every process, namely the first 1 appearing
  80.                
  81.                 for m = 1:size(X,2)
  82.                     if X(1,m) == 1
  83.                        X(1,m) = 0 ; % make it 0
  84.                        break; % we only want to make one entry 0
  85.                     end
  86.                 end
  87.        
  88.                
  89.                 else % check the Zeile for even / odd  
  90.                     display('entering even/odd');
  91.                    
  92.                     even = false; % initialize it
  93.                     % loop over Spalten
  94.                     for j = 1:size(X,2)
  95.                         if mod(X(i,j),2)== 0 % coord. is even
  96.                             even = true;
  97.                         end
  98.                     end
  99.  
  100.                     if even % every coord. is even
  101.                         M = [M; X(i,:)/2]; % add the half
  102.  
  103.                     else % there are uneven coordinates
  104.                         % loop over Zeile
  105.                         for e = 1:size(X,1)
  106.                             % loop over Spalte
  107.                             for f = 1:size(X,2)
  108.                                 if mod(X(e,f),2) == 1 % coord in (e,f) is odd
  109.                                     Y(e,f) = X(e,f) - 1; % new Vector Y
  110.                                 end
  111.                             end
  112.                             M = [M; Y(e,:)];
  113.                             % and add the difference
  114.                             M = [M; X(e,:)-Y(e,:)];
  115.                         end
  116.                     end                  
  117.                 end
  118.         end
  119.        
  120.       Saver = [Saver_in; M] % SAVE
  121.  
  122.       % now Recursion
  123.       create_xi_cluster(M, Saver);
  124.  
  125.     %%%%%%%%%%%%%%%%%%%%%
  126.     % not all disjunct and >= 2
  127.     %%%%%%%%%%%%%%%%%%%%%
  128.     elseif bigger2
  129.     display('bigger2');
  130.  
  131.         % map the elements in X to cluster sets M(i) of number i
  132.         % note to self: Faktorzerlegung von X zu Mengen M(i)
  133.  
  134.         number_of_clusters = max(T);
  135.  
  136.         for i = 1:length(T)
  137.            Set.(['A',num2str(i)]) = []; % initializing
  138.            for j = 1:length(T)
  139.                if T(j)==i
  140.                    Set.(['A',num2str(i)])=[Set.(['A',num2str(i)]); X(j,:)]
  141.                    % set displayed as matrix (better to work with)
  142.                end
  143.            end
  144.         end
  145.  
  146.         % now we have i sets Set.(['A',num2str(i)])
  147.  
  148.         % now, for every cluster, determine the "Stuetzstelle x_i*"
  149.         % with the "method of the minimal projection" (see documentation PDF)
  150.  
  151.         % since Set.(['A',num2str(i)]) is a matrix, we can easily access
  152.         % the entrys of Set.(['A',num2str(i)])
  153.  
  154.  
  155.         % step 3
  156.         % for all clusters Set.(['A',num2str(i)])
  157.         for o = 1 : number_of_clusters
  158.             % and for all number of columns of Set.Ao
  159.             for p = 1:size(Set.(['A',num2str(o)]),2)                        
  160.                 x(o,p)=min(Set.(['A',num2str(o)])(:,p))  % x(o,:) is the "Stuetzpunkt" of Cluster o
  161.             end
  162.         end
  163.  
  164.         % step 4
  165.         % for all t=length(Set.(['A',num2str(s)])) elements in Cluster Set.(['A',num2str(s)]),
  166.         % calculate the differences
  167.  
  168.            b = 1;
  169.         % for all clusters
  170.         for a = 1:number_of_clusters
  171.  
  172.             for e = 1:size(Set.(['A',num2str(a)]),1)              
  173.                % the differences              
  174.                t(b,:)= Set.(['A',num2str(a)])(e,:) - x(a,:)
  175.                b = b+1;
  176.            end
  177.         end
  178.  
  179.         % union the sets to one set (to one matrix M)
  180.         display('union x and t to M');
  181.         M = [x ; t]
  182.  
  183.         Saver = [Saver_in; M]
  184.  
  185.         create_xi_cluster(M, Saver);
  186.     end    
  187.  
  188. elseif isempty(X)
  189.     display('done');
  190.    
  191. else %HALBIEREN DES EINZIGEN TERMS
  192.         display('only 1 term');
  193.        
  194.         % sum of the only Zeile
  195.        
  196.         if sum(transpose(X)) <= size(X,2)
  197.         % if there are only 1s and 0s in the X
  198.        
  199.             % new strategy, cut off only a vector of distance 1
  200.             % in every process, namely the first 1 appearing
  201.            
  202.             for m = 1:size(X,2)
  203.                 if X(1,m) == 1
  204.                    X(1,m) = 0 ; % make it 0
  205.                    break; % we only want to make one entry 0
  206.                 end
  207.             end
  208.        
  209.             M = X;
  210.            
  211.             Saver = [Saver_in; M] % SAVE
  212.             create_xi_cluster(M, Saver); % Recursion  
  213.            
  214.         else
  215.            
  216.             even = true; % initialize : uneven is dominant
  217.  
  218.             % loop over Spalten
  219.             for j = 1:size(X,2)
  220.  
  221.                 % there is only 1 Zeile, hence 1 in X(1,j)
  222.                 if mod(X(1,j),2)== 1 % coord. is uneven
  223.                     even = false
  224.                 end
  225.             end
  226.  
  227.             if even % every coord. is even
  228.                 M = X(1,:)/2; % add the half
  229.  
  230.             else % there are uneven coordinates
  231.                 % loop over Spalte
  232.                 for f = 1:size(X,2)
  233.                     if mod(X(1,f),2) == 1 % coord in (e,f) is odd
  234.                         Y(1,f) = X(1,f) - 1 % new Vector Y
  235.                     else Y(1,f) = X(1,f); % else add the even coord.
  236.                     end
  237.                 end
  238.                 M = [Y(1,:)]
  239.                 % and add the difference
  240.                 M = [M; X(1,:)-Y(1,:)]
  241.  
  242.             end
  243.  
  244.             Saver = [Saver_in; M] % SAVE
  245.  
  246.             create_xi_cluster(M, Saver); % Recursion        
  247.                
  248.         end
  249.        
  250.            
  251. end
  252.        
  253. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement