get_score compares two authorship signatures and returns a single score. Lower scores indicate greater similarity, supporting identification of the closest known signature. section 11.3.1
The function works by:
- Taking two signatures and a list of feature weights. section 11.3.1
- Finding the absolute difference between corresponding feature values. section 11.5.12
- Multiplying each difference by its weight and adding the contributions into one score. section 11.5.12
Comparing two signatures
For signatures [4.6, 0.1, 0.05, 10, 2] and [4.3, 0.1, 0.04, 16, 4], with weights [11, 33, 50, 0.4, 4], get_score returns 14.2. Matching feature values contribute zero; larger weighted differences contribute more. section 11.3.1 section 11.5.12
Listing 11.15 Compare two signatures
def get_score(signature1, signature2, weights):
'''
signature1 and signature2 are signatures.
weights is a list of five weights.
Return the score for signature1 and signature2.
>>> get_score([4.6, 0.1, 0.05, 10, 2],\
[4.3, 0.1, 0.04, 16, 4],\
[11, 33, 50, 0.4, 4]) #1
14.2
'''
score = 0
for i in range(len(signature1)): #2
score += abs(signature1[i] - signature2[i]) \ #3
* weights[i] #3
return score
Inspect the complete Python implementation, including its parameters, loop, weighted absolute differences, return value, and doctest. section 11.5.12
