Vote count:
0
I have 3 sets of data (AA,B1 and C1) with different lenght and size. The purpose of my code is to be able to count for the similarity score between the data for example the similarity score between AA and B1, AA and C1, B1 and C1. So below is my code that should be able to calculate the similarity score but there is a bit of problem in looping. Only the highest value is select for each pair of data of different length. The output should be AA-B1: 0.2226, AA-C1: 0.2037 and B1-C1: 0.1111 that represent similarity score for each pair.
In reality the output for my code especially max_val{i} is supposed according to the size of pairs. For example pairs with size 1 x 2 should have one value in max_val output instead of three. Thanks.
A1={[4,3,4,3,3]};
A2={[3,1,2,4]};
A3={[1,2,4]};
AA=[A1,A2,A3];
B1={[2,2,4,4]};
C1={[4,4,4,3,2,2]};
set={[AA],[B1],[C1]};
comb_set=nchoosek(set,2); %combinations of two sets
for h=1:size(comb_set,1)
comb_pair=comb_set(h,:)';
sets=comb_pair;
cat=horzcat(sets{:});
c=reshape(repmat(sets{1},numel(sets{2}),1),numel(sets{1})*numel(sets{2}),1);
d=repmat(sets{2}(:),length(sets{1}),1);
pairs=[c d];
ind=cellfun(@numel,pairs(:,1)) > cellfun(@numel,pairs(:,2));
pairs(ind,[1 2]) = pairs(ind,[2 1]) %possible pairs of the row of subset
p=cell(size(pairs,1),1);
for i=1:size(pairs,1)
%the two vectors
[a,b]=deal(pairs{i,:});
%sliding window indices, and compute the sum
idx=hankel(1:numel(a),numel(a):numel(b));
count_minus{i}=bsxfun(@minus,b(idx.'),a); %count minus between pairs
count_total{i}=numel(a)+numel(b); %count total
count_intersect{i}=sum(count_minus{i}'==0)'; %count no. of intersection
union{i}=count_total{i}-count_intersect{i}; %union
subset{i}=count_intersect{i}./union{i}; %subset each pair similarity score
max_val{i}=max(subset{i}) %maximum similarity score
bsum=cellfun(@(x) sum(x),max_val);
total{i}=sum(bsum~=0);
average=sum(bsum) / total{i}
end
end
asked 22 secs ago
Matlab Looping Issue for counting similarity score
Aucun commentaire:
Enregistrer un commentaire