我有一个mapreduce函数,它的输出应该反馈给另一个mapreduce函数,代码如下
function clustering = parallel_clustering_kmeans(data)
%% find first clustering from all chunks
result = mapreduce(data,@k_means_Mapper,@k_means_Reducer);
result = readall(result);
index = result{:,1};
index = cell2mat(cellfun(@str2num,strrep(index,',',' '),'un',0));
clustering = mapreduce(data,@k_means_Mapper_second,@k_means_Reducer);
end
第一个函数很好地工作result=mapreduce(data,@k_means_mapper,@k_means_reducer); 但是,我想将索引作为k\u means\u mapper\u second的参数传递
代码必须如下
function k_means_Mapper_second(data,index,intermidiateValuesOut)
distance = zeros(size(data,1),size(index,1));
parfor i = 1:size(data,1)
for j = 1:size(index,1)
distance(i,j) = sum((data(i,:)-index(j,:)).^2).^0.5;
end
end
for i = 1:size(distance,1)
x = distance(i,:);
[~,ind] = min(x);
key = combine_values(data(i,:));
addmulti(intermidiateValuesOut,key,ind);
end
end
我的问题是如何将索引作为参数传递给最后一行中的k\u means\u mapper\u second函数
clustering = mapreduce(data,@k_means_Mapper_second,@k_means_Reducer);
提前谢谢
1条答案
按热度按时间iqxoj9l91#
您需要将您的函数 Package 在一个匿名函数中,该匿名函数接受
mapreduce
然后调用函数,只传递相关的值。对于您的情况,它看起来像: