Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.72 KB | None | 0 0
  1. function W_ind = upoclust_newdist2(eps)
  2. %UPOCLUST Summary of this function goes here
  3. %   Inputs: eps - Connectivity threshold.
  4.  
  5. load('ks22f90h25t120_sortedupos.mat'); %Load UPO data.
  6. %distfunction=sprintf('upo_%s',funHandle);
  7. %paramfile=sprintf('param_%s.mat',funHandle);
  8. %load(paramfile); %Load parameters, such as Fourier Modes, how many points to interpolate, etc.
  9.  
  10. %%%%%TEMP PARAMS%%%%
  11. nph=120; %Interpolate 120 phase points between -L/2 and L/2.
  12. phase=gpuArray(complex(exp((-2i*pi/nph).*(1:nph))));
  13. ExtraPoints=5; %Interpolate 5 points between each trajectory point.
  14. %%%%%%%%%%%%%%%%%%%%
  15. nupo=length(upo);
  16.  
  17. %eval(sprintf('W=%s(upo(1).a,upo(1).T,A1,A2,ExtraPoints,L,h);',interpfunction));
  18. [~,aa]=ksfmetd2(upo(1).a, L, h, upo(1).T, 1);
  19. W_t=upo_pchip(aa,ExtraPoints);
  20. W=gpuArray(complex(W_t(1:2:end,:)+1i*W_t(2:2:end,:))); %Combine real and imaginary parts.
  21. clear W_t;
  22.  
  23. W_ind=1;
  24. dW=size(W,1);
  25. sW=size(W,2);
  26.  
  27. for i=2:20
  28.     [~,aa]=ksfmetd2(upo(i).a, L, h, upo(i).T, 1);
  29.     W_t=upo_pchip(aa,ExtraPoints);
  30.     W_t=gpuArray(complex(W_t(1:2:end,:)+1i*W_t(2:2:end,:))); %After interpolating in all dimensions, combine real and imaginary parts.
  31.     sWt=size(W_t,2);
  32.    
  33.     for nWt=1:sWt %For all points in period of W_t.
  34.        
  35.         minD=gpuArray(Inf);
  36.         Wt=W_t(:,nWt);
  37.         normWi=sqrt(sum(abs(W).^2));
  38.        
  39.         dotWiWt=sum(bsxfun(@times,conj(Wt),W),1); %Dot product along every element of W, with Wt.
  40.         ph_ang=abs(acos(bsxfun(@rdivide,bsxfun(@times,dotWiWt,phase'),normWi)));
  41.         [minColVal,minRowIdx]=min(ph_ang); %minColIdx(minRowIdx) gives which point in W.
  42.         [~,minColIdx]=min(minColVal);
  43.        
  44.         Wi=W(:,minColIdx);
  45.         Wtt=Wt.*phase(minRowIdx(minColIdx));
  46.         minVal=norm(Wi-Wtt);
  47.  
  48.         rdotWiWt=sum(bsxfun(@times,-Wt,W),1); %Just -Wt in here, because -conj(conj(Wt))=-Wt.
  49.         rph_ang=abs(acos(bsxfun(@rdivide,bsxfun(@times,rdotWiWt,phase'),normWi)));
  50.         [minColVal,minRowIdx]=min(rph_ang); %minColIdx(minRowIdx) gives which point in W.
  51.         [~,minColIdx]=min(minColVal);
  52.        
  53.         rminVal=norm(W(:,minColIdx)+conj(Wt).*exp(-2i*pi*minRowIdx(minColIdx)/nph));
  54.        
  55.         minD=min(minD,min(minVal,rminVal));
  56.        
  57.         minD;
  58.        
  59.         if minD>eps;
  60.             W=[W, W_t];
  61.             W_ind=[W_ind, i];
  62.             sW=sW+sWt;
  63.             break; %If any min of nWt are larger than eps, then break and move onto next orbit.
  64.         end
  65.         %If you get to the end of this loop without breaking out,
  66.         %then it means that the orbit can be represented by a combination of other orbits in the set.
  67.        
  68.     end
  69.    
  70.    
  71.    
  72.    
  73.     %%%%%
  74.    
  75. end
  76.  
  77. %save('W_new.mat','eps','funHandle','W_ind')
  78.  
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement