%
% Calculation of the exploration sequence matrix W
% (based on singular value decomposition)
%
% INPUT: Td (2n x 2n matrix), map parameters a1,a2, singular values of W
% (rk(Td) x 1 vector), dimension n of the the optimization problem 
%
%
function [W,U,V,Sigma] = getExplorationSequence_W(Td,a1,a2,sigma,n)
%
% two cases for exploration sequence calculations
%
if abs(2*a2-(a1+a2)^2) > 10^-4
    [U,gamma,delta,rk] = reorderEigen_normal(Td);
    [w_,~,Perm] = calc_w_normal(gamma,delta,rk,a1,a2);
    [m,P_] = calc_m(rk,w_,a1,a2);
    Sigma = calc_Sigma(sigma,n,m,rk);
    [V,~] = calc_V_normal(w_,P_,m,rk,Perm);
else
    [U,delta,rk] = reorderEigen_skew(Td);
    [w_,Perm,~] = calc_w_skew(sigma,rk,delta,a1,a2);
    [m,P_] = calc_m(rk,w_,a1,a2);
    Sigma = calc_Sigma(sigma,n,m,rk);
    [V,~] = calc_V_skew(w_,P_,m,rk,Perm);
end
W = U*Sigma*V';
W= W*(a1+a2); %scaling due to wired MATLAB calculations
end