function [vWeights,vMetric] = GetWeights_IsotropicGaussian( cPoints, cPointsIdxs,cCenter, cExtraParam, FixedMetric )

%
% function [vWeights,vMetric] = GetWeights_IsotropicGaussian( cPoints, cPointsIdxs,cCenter, cExtraParam )
%
% IN:
%   cPoints     : M points in N dimensions in a M by N matrix (typically the whole dataset)
%   cPointsIdxs : K indices (into cPoints) of the points involved in the weights computation
%   cCenter     : Row vector representing the point from which to compute the weights to the cPoints(cPointsIdxs,:)
%   cExtraParam : contains the fields:
%                   Delta : width of the gaussian.
%                   Distances : row vector of distances, i-th entry being the distance between cPoints(cPointsIdxs(i),:) and cCenter,
%                                if cDistances==[] then they get computed here
%  FixedMetric  : (default) empty array; if not empty, the metric is fixed and given by N-by-N matrix 
%                   
%
% OUT:
%   vWeights    : K row vector, i-th entry being the weight from cCenter to cPoints(cPointsIdxs(lk),:)
%   vMetric     : []   
%
% USES:
%   nothing
%

vMetric=[];
lNumberOfPoints = length(cPointsIdxs);

% Check if metric is preset (Added, AL 4/24/04)  % NEW!
if isempty(FixedMetric)
    % Check if distances are passed
    if isfield(cExtraParam,'Distances')
        lDistances = cExtraParam.Distances;
    else
        lDistances = [];
    end;
    % If no distances provided, compute them
    if isempty(lDistances)
        lDistances = zeros(1,size(cPointsIdxs));
        %for lk = 1:size(cPointsIdxs)
        %    lDistances(lk) = norm(cCenter-cPoints(cPointsIdxs,:));
        %end;
        lDistances=sqrt((ones(lNumberOfPoints,1)*cCenter-cPoints(cPointsIdxs,:)).^2);
    end;
    
else  % Fixed metric % NEW!
    for lk = 1:lNumberOfPoints
        lCenteredPoint = cPoints(lk,:)-cCenter;
        lDistances(lk) = sqrt(lCenteredPoint*FixedMetric*lCenteredPoint');
    end;
end

% Compute the weights from the distances
vWeights = exp(-(lDistances/cExtraParam.Delta).^2);
% No diffusion outside the ellipsoid of radius cExtraParam.Epsilon
vWeights(find(lDistances>cExtraParam.Epsilon))=0;
return;