KBOC16: Three baseline systems.
xxxxxxxxxx
import scipy as sc
import numpy as np
from scipy import linalg
import bob
def classifier_knn_norm(gallery_sample,test_sample):#This is the Combined Manhattan-Mahalanobis distance
vec_cov=np.linalg.pinv(np.cov(gallery_sample,rowvar=0))# pinv returns the pseudoinverse
vec_cov=sc.real(linalg.sqrtm(vec_cov+0.001))
final=np.size(gallery_sample,axis=0)
for i in range(0,final):
if i==0:
gallery_normalized=sc.transpose(np.dot(vec_cov,sc.transpose(gallery_sample[i])))
else:
gallery_normalized=np.vstack([gallery_normalized,sc.transpose(np.dot(vec_cov,sc.transpose(gallery_sample[i])))])
f1=sc.transpose(np.dot(vec_cov,sc.transpose(test_sample)))
d2=np.zeros((final,1))
try:
for i in range(0,final):
d2[i]=sc.sum(abs(f1-gallery_normalized[i]))
score=np.min(d2)+0.001
except:
score=-1
return score
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)
gallery_sample=np.asarray(np.asmatrix(gallery_sample))
test_sample=np.asarray(np.asmatrix(test_sample))
try:
vec_cov=np.linalg.pinv(np.cov(gallery_sample,rowvar=0))
vec_cov=sc.real(linalg.sqrtm(vec_cov+0.001))
#vec_cov=sc.real(vec_cov+0.001)
final=np.size(gallery_sample,axis=0)
d3=np.zeros((final,1))
for i in range(0,final):
d3[i]=np.dot(np.dot(test_sample-gallery_sample[i],vec_cov),sc.transpose(test_sample-gallery_sample[i]))
score=np.min(d3)+0.001
except:
score=-1
return score
def classifier_manhattand_scaled_modified(gallery_sample,test_sample):# This is Modified Scaled Manhattan distance and a normalization by standard deviation
gallery_sample=np.asarray(np.asmatrix(gallery_sample))
test_sample=np.asarray(np.asmatrix(test_sample))
medias_train = sc.mean(gallery_sample,axis=0)
sigmas_train = sc.std(gallery_sample,axis=0)
umbral_sigmas = 0.2*np.mean(sigmas_train)
sigmas_train[np.nonzero(sigmas_train<umbral_sigmas)]=umbral_sigmas;
if np.size(gallery_sample,axis=1)==np.size(test_sample,axis=1):
score=np.mean(abs(test_sample-medias_train)/sigmas_train)
else:
score=-1
return score
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)
Updated | Name | Actions | |
---|---|---|---|
Aug. 21, 2018 | loginofdeath/kboc_neoeyed/1 | ||
May 5, 2016 | Alberto/proof_1/1 (KBOC16: Participant block) | ||
April 7, 2016 | anjithgeorge/KBOC_IITKGP_ANJITH_APRIL7_1/14 (KBOC16: Participant block) | ||
March 8, 2016 | robertodaza/KBOC16_PARTICIPANT_BLOCK/2 (KBOC16: Participant block) | ||
March 2, 2016 | aythamimm/KBOC16_UAM_Tutorial_Example/1 (KBOC16: Participant block) | ||
Feb. 13, 2016 | robertodaza/KBOC16_PARTICIPANT_BLOCK/1 |