Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
function [instancesTransformationKernel] = applyTransformation(allSeqsAsBags, clusterCentres, sig, debugLevel, debugMsgLocation)
% APPLYTRANSFORMATION
% Transforms the individual segments w.r.t. the cluster centres obtained by k-means
%
% INPUT PARAMS
% Param 'allSeqsAsBags' (Cell array)
% Collection of all segments per sequence
%
% Param 'clusterCentres' (matrix)
% A matrix where each cluster centre is represented coulnwise; dimensions: nClusters x FVlength
%
% Param 'sig'
% Gaussian bandwidth value
%
% Param 'debugLevel'
%
% Param 'debugMsgLocation'
%
% OUTPUT PARAMS
% Param 'instancesTransformationKernel'
% Transformation of the instances w.r.t. the cluster centres
%
% ADDITIONAL NOTES
%
% Author: snikumbh@mpi-inif.mpg.de
% We apply Gaussian tranformation
%
nBags = size(allSeqsAsBags, 2);
% transformationKernel = zeros(nBags, size(clusterCentres, 1)); % bag level information
nClusters = size(clusterCentres,1);
FVDim1 = size(clusterCentres, 2);
do_reshaped = 1; % by default, we use th reshaped version. This is tested to be the fastest is most experiments.
if ~issparse(allSeqsAsBags{1}) && do_reshaped == 1
logMessages(debugMsgLocation, sprintf('Doing reshaped version..\n'), debugLevel);
for i=1:nBags
% length of instancesTransformationKernel is nBags
% dimensions of each instancesTransformationKernel nInstances-by-nClusters
instancesTransformationKernel{i} = zeros(size(allSeqsAsBags{i},2), nClusters);
reshapedClusterCentres = reshape(clusterCentres', 1, size(clusterCentres,2), nClusters);
%dim are now nClusters-by-weightVectorDim-by-nClusters
temp = bsxfun(@minus, repmat(transpose(allSeqsAsBags{i}),1,1,nClusters), reshapedClusterCentres);
temp = sum(permute(temp,[2,1,3]).^2,1);
temp = exp(-0.5*temp./sig^2);
instancesTransformationKernel{i} = reshape(temp,[],nClusters);
end
elseif issparse(allSeqsAsBags{1}) && do_reshaped == 1
logMessages(debugMsgLocation, sprintf('Doing reshaped version for sparse vectors..\n'), debugLevel);
% Because N-D sparse arrays are not possible, hence, we opt to reshape/repmat
% the clusterCentres instead of the sparse FVs
for i=1:nBags
% length of instancesTransformationKernel is nBags
% dimensions of each instancesTransformationKernel nInstances-by-nClusters
numOfInstances = size(allSeqsAsBags{i},2);
instancesTransformationKernel{i} = zeros(numOfInstances, nClusters);
reshapedClusterCentres = reshape(repmat(clusterCentres, numOfInstances,1), FVDim1, numOfInstances, nClusters);
% dim are now nClusters-by-weightVectorDim-by-nClusters
temp = bsxfun(@minus, allSeqsAsBags{i}, reshapedClusterCentres);
temp = sum(temp.^2,1);
temp = exp(-0.5*temp./sig^2);
instancesTransformationKernel{i} = reshape(temp,[],nClusters);
end
else
for i=1:nBags
instancesTransformationKernelA{i} = zeros(size(allSeqsAsBags{i},2), size(clusterCentres,1));
for j=1:size(clusterCentres,1)
temp = bsxfun(@minus, transpose(allSeqsAsBags{i}), clusterCentres(j,:));
temp = sum(temp'.^2,1);
temp = exp(-0.5*temp./sig^2);
instancesTransformationKernelA{i}(:,j) = temp';
% transformationKernel(i,j) = sum(temp(:));
end
end
end
end % function ends