Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [Saver] = create_xi_cluster(X, Arg_Saver)
- % Date: 22.11.2010
- % Author: sz
- % TODO: the next function deletes multiple entries
- % in Saver and the entries of order 1
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Introduction
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % interpret terms as points in lN^n space
- % x^3*y^2*z => (3,2,1) in lN^3
- % X is the set of all points, which we write like in
- % this example: (1,3) , (3,3), (1,2) are points of the set
- % Then X = [ 1,3 ; 3,3 ; 1,2 ]
- % Saver is global
- % global
- Saver_in = Arg_Saver;
- bigger2 = false;
- X2 = []; % initialize to prevent cases where X2 is empty
- % hence the program does not know where it came from
- % in these cases
- % a fancy way to find out:
- % does any point in X have a distance bigger than 2 to the (0,...0) ?
- STX = sum(transpose(X));
- u = 1; % a counter (pretty technical stuff)
- for i = 1:length(STX)
- if STX(i) > 2
- bigger2 = true; % bigger2 is dominant
- X2(u,:) = X(i,:) % create a new Matrix X2 (that way you filter
- u = u+1; % counter
- % out the others without having to delete it
- % [the ladder wouldnt work..]
- end
- end
- X = X2 % assign back
- % if only one term is in X, you use the Halbieren-method
- % FYI: if you dont consider this case you will get an
- % error evaluating T = clusterdata(X,0.9), since that is only allowed
- % for X with 2 elements or more...
- if size(X,1) > 1
- % step 2 in the PDF
- % given the X, we create clusters
- T = clusterdata(X,2)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % if all "Clusters disjunct", that means, every cluster contains only 1 element
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if max(T) == size(X,1)
- display('entering disjunct');
- M = []; % initialize
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % HALBIEREN - METHODE
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % loop over Zeilen (Zeilenweise)
- for i = 1:size(X,1)
- display('check if only 1s and 0s');
- if sum(transpose(X(i,:))) <= size(X(i,:),2)
- % if there are only 1s and 0s in the X
- % new strategy, cut off only a vector of distance 1
- % in every process, namely the first 1 appearing
- for m = 1:size(X,2)
- if X(1,m) == 1
- X(1,m) = 0 ; % make it 0
- break; % we only want to make one entry 0
- end
- end
- else % check the Zeile for even / odd
- display('entering even/odd');
- even = false; % initialize it
- % loop over Spalten
- for j = 1:size(X,2)
- if mod(X(i,j),2)== 0 % coord. is even
- even = true;
- end
- end
- if even % every coord. is even
- M = [M; X(i,:)/2]; % add the half
- else % there are uneven coordinates
- % loop over Zeile
- for e = 1:size(X,1)
- % loop over Spalte
- for f = 1:size(X,2)
- if mod(X(e,f),2) == 1 % coord in (e,f) is odd
- Y(e,f) = X(e,f) - 1; % new Vector Y
- end
- end
- M = [M; Y(e,:)];
- % and add the difference
- M = [M; X(e,:)-Y(e,:)];
- end
- end
- end
- end
- Saver = [Saver_in; M] % SAVE
- % now Recursion
- create_xi_cluster(M, Saver);
- %%%%%%%%%%%%%%%%%%%%%
- % not all disjunct and >= 2
- %%%%%%%%%%%%%%%%%%%%%
- elseif bigger2
- display('bigger2');
- % map the elements in X to cluster sets M(i) of number i
- % note to self: Faktorzerlegung von X zu Mengen M(i)
- number_of_clusters = max(T);
- for i = 1:length(T)
- Set.(['A',num2str(i)]) = []; % initializing
- for j = 1:length(T)
- if T(j)==i
- Set.(['A',num2str(i)])=[Set.(['A',num2str(i)]); X(j,:)]
- % set displayed as matrix (better to work with)
- end
- end
- end
- % now we have i sets Set.(['A',num2str(i)])
- % now, for every cluster, determine the "Stuetzstelle x_i*"
- % with the "method of the minimal projection" (see documentation PDF)
- % since Set.(['A',num2str(i)]) is a matrix, we can easily access
- % the entrys of Set.(['A',num2str(i)])
- % step 3
- % for all clusters Set.(['A',num2str(i)])
- for o = 1 : number_of_clusters
- % and for all number of columns of Set.Ao
- for p = 1:size(Set.(['A',num2str(o)]),2)
- x(o,p)=min(Set.(['A',num2str(o)])(:,p)) % x(o,:) is the "Stuetzpunkt" of Cluster o
- end
- end
- % step 4
- % for all t=length(Set.(['A',num2str(s)])) elements in Cluster Set.(['A',num2str(s)]),
- % calculate the differences
- b = 1;
- % for all clusters
- for a = 1:number_of_clusters
- for e = 1:size(Set.(['A',num2str(a)]),1)
- % the differences
- t(b,:)= Set.(['A',num2str(a)])(e,:) - x(a,:)
- b = b+1;
- end
- end
- % union the sets to one set (to one matrix M)
- display('union x and t to M');
- M = [x ; t]
- Saver = [Saver_in; M]
- create_xi_cluster(M, Saver);
- end
- elseif isempty(X)
- display('done');
- else %HALBIEREN DES EINZIGEN TERMS
- display('only 1 term');
- % sum of the only Zeile
- if sum(transpose(X)) <= size(X,2)
- % if there are only 1s and 0s in the X
- % new strategy, cut off only a vector of distance 1
- % in every process, namely the first 1 appearing
- for m = 1:size(X,2)
- if X(1,m) == 1
- X(1,m) = 0 ; % make it 0
- break; % we only want to make one entry 0
- end
- end
- M = X;
- Saver = [Saver_in; M] % SAVE
- create_xi_cluster(M, Saver); % Recursion
- else
- even = true; % initialize : uneven is dominant
- % loop over Spalten
- for j = 1:size(X,2)
- % there is only 1 Zeile, hence 1 in X(1,j)
- if mod(X(1,j),2)== 1 % coord. is uneven
- even = false
- end
- end
- if even % every coord. is even
- M = X(1,:)/2; % add the half
- else % there are uneven coordinates
- % loop over Spalte
- for f = 1:size(X,2)
- if mod(X(1,f),2) == 1 % coord in (e,f) is odd
- Y(1,f) = X(1,f) - 1 % new Vector Y
- else Y(1,f) = X(1,f); % else add the even coord.
- end
- end
- M = [Y(1,:)]
- % and add the difference
- M = [M; X(1,:)-Y(1,:)]
- end
- Saver = [Saver_in; M] % SAVE
- create_xi_cluster(M, Saver); % Recursion
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement