Skip to main content
. 2024 Oct 1;10:e2322. doi: 10.7717/peerj-cs.2322

Algorithm 1. Calculate similarity.

Input: Support set S={s1,s2,,sn}, Query sample xq
Output: Similarity score Score
1: n size of S                             ⊳ Get the size of support set S
2: W0                                     ⊳ Initialize total weight W
3: θ0.008                                     ⊳ Set hyperparameter θ
4: Xproto0                          ⊳ Initialize prototype vector Xproto
5: if n>1 then              ⊳ If support set contains more than one sample
6:   for i1 to n do             ⊳ Loop over each sample in the support set
7:     Di(sixq)2                 ⊳ Compute Euclidean distance Di
8:     WW+exp(θ×Di)                  ⊳ Calculate total weight W
9:   end for
10:  for i1 to n do         ⊳ Loop over each sample in the support set again
11:     wiexp(θ×Di)/W                      ⊳ Compute weight wi
12:    XprotoXproto+wi×si            ⊳ Update prototype vector Xproto
13:  end for
14:   Score(Xprotoqi)2                   ⊳ Calculate similarity score
15: else                             ⊳ If support set contains only one sample
16:   Score(s1×qi)          ⊳ Calculate similarity score for single sample
17: end if