function [distance, R] = sampleTreeParameters(adjmat, dist, m)



% Assign parameters randomly to a tree and generate N samples.



M = size(adjmat,1);



switch dist

    case 'gaussian'

%         J = -rand(M,M).*adjmat;
% 
%         J = (J + J')/2;
% 
%         mineig = 0.1+0.8*rand(1)
% 
%         %mineig = 0.001;
% 
%         J = J + (mineig - min(eig(J)))*eye(M);
% 
%         Sigma = inv(J);
% 
%         D = diag(1./sqrt(diag(Sigma)));
% 
%         rho_matrix = D*Sigma*D;

        edge_distance = -(log(0.2+0.6*rand(M,M))).*adjmat;
        edge_distance = (edge_distance + edge_distance')/2;
        %edge_distance = -log(abs(rho_matrix));
        distance = treeDistance(edge_distance);
        rho_matrix = exp(-distance);

        %distance = -log(abs(rho_matrix));
        %distance = distance(1:m,1:m);

        R = chol(rho_matrix(1:m,1:m));     

end



