KBOC16: Three baseline systems.

This library does not use any other libraries.
xxxxxxxxxx
61
 
1
import scipy as sc
2
3
import numpy as np
4
5
from scipy import linalg
6
7
import bob
8
    
9
def classifier_knn_norm(gallery_sample,test_sample):#This is the Combined Manhattan-Mahalanobis distance
10
    vec_cov=np.linalg.pinv(np.cov(gallery_sample,rowvar=0))#  pinv returns the pseudoinverse
11
    vec_cov=sc.real(linalg.sqrtm(vec_cov+0.001))
12
    final=np.size(gallery_sample,axis=0)
13
    for i in range(0,final):
14
        if i==0:
15
            gallery_normalized=sc.transpose(np.dot(vec_cov,sc.transpose(gallery_sample[i])))
16
        else:
17
            gallery_normalized=np.vstack([gallery_normalized,sc.transpose(np.dot(vec_cov,sc.transpose(gallery_sample[i])))])
18
    f1=sc.transpose(np.dot(vec_cov,sc.transpose(test_sample))) 
19
    d2=np.zeros((final,1))
20
    try:
21
        for i in range(0,final):
22
            d2[i]=sc.sum(abs(f1-gallery_normalized[i]))
23
        score=np.min(d2)+0.001
24
    except:
25
        score=-1
26
    return score    
27
 
28
def classifier_knn_mahal(gallery_sample,test_sample):#This is the Mahalanobis + Nearest Neighbor distance(Classification of keystroke timing based on knn and cityblock distance)
29
    gallery_sample=np.asarray(np.asmatrix(gallery_sample))
30
    test_sample=np.asarray(np.asmatrix(test_sample))
31
    try:
32
        vec_cov=np.linalg.pinv(np.cov(gallery_sample,rowvar=0))
33
        vec_cov=sc.real(linalg.sqrtm(vec_cov+0.001))
34
        #vec_cov=sc.real(vec_cov+0.001)
35
        final=np.size(gallery_sample,axis=0)
36
        d3=np.zeros((final,1))
37
        for i in range(0,final):
38
            d3[i]=np.dot(np.dot(test_sample-gallery_sample[i],vec_cov),sc.transpose(test_sample-gallery_sample[i]))
39
        score=np.min(d3)+0.001    
40
    except:
41
        score=-1
42
    return score
43
44
def classifier_manhattand_scaled_modified(gallery_sample,test_sample):# This is Modified Scaled Manhattan distance and a normalization  by standard deviation
45
    gallery_sample=np.asarray(np.asmatrix(gallery_sample))
46
    test_sample=np.asarray(np.asmatrix(test_sample))
47
    medias_train = sc.mean(gallery_sample,axis=0)
48
    sigmas_train = sc.std(gallery_sample,axis=0) 
49
    umbral_sigmas = 0.2*np.mean(sigmas_train)
50
    sigmas_train[np.nonzero(sigmas_train<umbral_sigmas)]=umbral_sigmas;
51
    if np.size(gallery_sample,axis=1)==np.size(test_sample,axis=1):
52
        score=np.mean(abs(test_sample-medias_train)/sigmas_train)
53
    else:
54
        score=-1
55
    return score    
56
    
57
         
58
        
59
    
60
        
61

The code for this algorithm in Python
The ruler at 80 columns indicate suggested POSIX line breaks (for readability).
The editor will automatically enlarge to accomodate the entirety of your input
Use keyboard shortcuts for search/replace and faster editing. For example, use Ctrl-F (PC) or Cmd-F (Mac) to search through this box

Three baseline systems (Combined Manhattan-Mahalanobis distance,Mahalanobis + Nearest Neighbor,Modified Scaled Manhattan distance)

Created with Raphaël 2.1.2[compare]robertodaza/kboc16_baseline_matchers/5IDRND_DSPlabs_/ksd_library/12016Feb132017Apr29

This table shows the number of times this library has been successfuly used at a given environment. Note this does not provide sufficient information to evaluate if the library will work when submitted to different conditions.

Terms of Service | Contact Information | BEAT platform version 2.2.1b0 | © Idiap Research Institute - 2013-2025