How to MATLAB function using parallel Pooling

1 次查看(过去 30 天)
I have a MATLAB function and a dataset that I would like to run in parallel on the CPU. Specifically, I would like to compare the performance of running the function with and without parallelization
I also attached my Dataset below
Please help me with this, I know parfor is used but i am unable to used that
load('Dataset.mat')
clusternumber = 6;
function [Score] = Scorefunction(Dataset,clusternumber)
dataset_len = size(Dataset,1);
Score = zeros(1,clusternumber);
for j=1:clusternumber
[cluster_assignments,centroids] = kmeans(Dataset,j);
distance_within=zeros(dataset_len,1);
distance_between=Inf(dataset_len,j);
for i=1:dataset_len
for jj=1:j
boo=cluster_assignments==cluster_assignments(i);
Xsamecluster=Dataset(boo,:);
if size(Xsamecluster,1)>1
distance_within(i)=sum(sum((Dataset(i,:)-Xsamecluster).^2,2))/(size(Xsamecluster,1)-1);
end
boo1= cluster_assignments~=cluster_assignments(i);
Xdifferentcluster=Dataset(boo1 & cluster_assignments ==jj,:);
if ~isempty(Xdifferentcluster)
distance_between(i,jj)=mean(sum((Dataset(i,:)-Xdifferentcluster).^2,2));
end
end
end
minavgDBetween = min(distance_between, [], 2);
silh = (minavgDBetween - distance_within) ./ max(distance_within,minavgDBetween);
Score(j) =mean(silh);
end
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by