Forked from robertodaza/prueba1/3

This algorithm is a legacy one. The API has changed since its implementation. New versions and forks will need to be updated.
This algorithm is splittable

Algorithms have at least one input and one output. All algorithm endpoints are organized in groups. Groups are used by the platform to indicate which inputs and outputs are synchronized together. The first group is automatically synchronized with the channel defined by the block in which the algorithm is deployed.

Group: probes

Endpoint Name Data Format Nature
comparison_ids system/array_1d_text/1 Input
keystroke tutorial/atvs_keystroke/1 Input
probe_client_id system/text/1 Input
scores elie_khoury/string_probe_scores/1 Output

Group: templates

Endpoint Name Data Format Nature
template_client_id system/text/1 Input
id system/text/1 Input
features tutorial/atvs_keystroke/1 Input

Parameters allow users to change the configuration of an algorithm when scheduling an experiment

Name Description Type Default Range/Choices
field Data field used to generate the feature template string given_name given_name, family_name, email, nationality, id_number, all_five
distance Distance to obtain the matching score string Modified Scaled Manhattan Scaled Manhattan, Modified Scaled Manhattan, Combined Manhattan-Mahalanobis, Mahalanobis + Nearest Neighbor

Algorithms may use functions and classes declared in libraries. Here you can see the libraries and import names used by this library. You don't need to import the library manually on your code, the platform will do it for you. Just use the object as it has been imported with the selected named. For example, if you choose to import a library using the name lib, then access function f within your code like lib.f().

Library Import as
robertodaza/competition--modified_scaled_distance--scaled_distance--mad-/1 prueba
xxxxxxxxxx
302
 
1
import numpy
2
#en la libreria robertodaza/competition--modified_scaled_distance--scaled_distance--mad-/1 que la hemos nombrado como prueba tenemos todas las funciones que usaremos
3
class Algorithm:
4
5
    def __init__(self):#primer modulo donde definimos las variables globales
6
        self._features1 = [] #definimos 5 listas
7
        self._features2 = [] 
8
        self._features3 = [] 
9
        self._features4 = [] 
10
        self._features5 = []   
11
        self._templates=None#lo ponemoscon valor none
12
        self._field='given_name' #Por defecto el nombre
13
        self._distance='Modified Scaled Manhattan'#Por defecto modified scaled manhattan
14
    
15
    def setup(self, parameters): #Funcion que define los parametros  (PODEMOS CAMBIAR EN PARAMETRO EL VALOR DE FIELD Y DISTANCE CON ESTA FUNCION)     
16
        self._field = parameters.get('field', self._field)#si el parametro field no toma valor se deja el nombre si toma valor se pondra el que sea(correo,DNI,etc)
17
        self._distance = parameters.get('distance', self._distance)#igual pero con distance
18
        
19
        return True
20
21
22
    def process(self, inputs, outputs):#trabajamos con objetos
23
24
        if self._templates is None:#La primera vez entra aqui
25
            self._templates = {}#define un diccionario
26
            group = inputs.groupOf('features')#como tenemos un bloque que le entran entradas de dos bloques diferentes y no estan sincronizados tenemos que hacer grupos, con esta funcion abrimos un grupo
27
            while group.hasMoreData():#Mientras tenga datos se ejecuta
28
                group.next()# pedir dato nuevo del grupo
29
        
30
                f1 = group['features'].data.holdtime.given_name#abrimos features que es las muestras que nos dan de la base de datos y cogemos de holdtime el nombre
31
                f2 = group['features'].data.rplatency.given_name#igual pero con rplatency
32
                feature_vector=[]#lista
33
                l_f=len(f1)#es la longitud son caracteres
34
                for i_k in range(l_f):#hacemos un for para ponerlos en el vector features_vector transformando a float
35
                    feature_vector.append(float(f1[i_k]))
36
        
37
                l_f=len(f2)#igual
38
                for i_k in range(l_f):
39
                    feature_vector.append(float(f2[i_k]))              
40
                
41
                self._features1.append(feature_vector)#vamos haciendo una lista que es una matriz con cada prueba de las personas asi que seran 6 filas
42
                      
43
                f1 = group['features'].data.holdtime.family_name#igual con family
44
                f2 = group['features'].data.rplatency.family_name
45
                feature_vector=[]
46
                l_f=len(f1)
47
                for i_k in range(l_f):
48
                    feature_vector.append(float(f1[i_k]))
49
        
50
                l_f=len(f2)
51
                for i_k in range(l_f):
52
                    feature_vector.append(float(f2[i_k]))              
53
                
54
                self._features2.append(feature_vector)
55
                
56
                f1 = group['features'].data.holdtime.email#igual con email
57
                f2 = group['features'].data.rplatency.email
58
                feature_vector=[]
59
                l_f=len(f1)
60
                for i_k in range(l_f):
61
                    feature_vector.append(float(f1[i_k]))
62
        
63
                l_f=len(f2)
64
                for i_k in range(l_f):
65
                    feature_vector.append(float(f2[i_k]))              
66
                
67
                self._features3.append(feature_vector)
68
        
69
                f1 = group['features'].data.holdtime.nationality#igual con nationality
70
                f2 = group['features'].data.rplatency.nationality 
71
                feature_vector=[]
72
                l_f=len(f1)
73
                for i_k in range(l_f):
74
                    feature_vector.append(float(f1[i_k]))
75
        
76
                l_f=len(f2)
77
                for i_k in range(l_f):
78
                    feature_vector.append(float(f2[i_k]))              
79
                
80
                self._features4.append(feature_vector)
81
        
82
                f1 = group['features'].data.holdtime.id_number#igual con id_number
83
                f2 = group['features'].data.rplatency.id_number 
84
                feature_vector=[]
85
                l_f=len(f1)
86
                for i_k in range(l_f):
87
                    feature_vector.append(float(f1[i_k]))
88
        
89
                l_f=len(f2)
90
                for i_k in range(l_f):
91
                    feature_vector.append(float(f2[i_k]))              
92
                
93
                self._features5.append(feature_vector) 
94
          
95
        # Calculate mean and std
96
                if inputs["id"].isDataUnitDone():#id es el numero por el usuario por el que va, si ha terminado con el usuario entra y realiza lo siguiente
97
                    features11 = numpy.average(self._features1, axis=0)#calcula la media quedandote solo una fila, media por columnas
98
                    features12 = numpy.std(self._features1, axis=0)#std igual
99
                    features13 = prueba.mad(self._features1)#mad igual
100
                    features21 = numpy.average(self._features2, axis=0)
101
                    features22 = numpy.std(self._features2, axis=0)
102
                    features23 = prueba.mad(self._features2)     
103
                    features31 = numpy.average(self._features3, axis=0)
104
                    features32 = numpy.std(self._features3, axis=0)
105
                    features33 = prueba.mad(self._features3)
106
                    features41 = numpy.average(self._features4, axis=0)
107
                    features42 = numpy.std(self._features4, axis=0) 
108
                    features43 = prueba.mad(self._features4) 
109
                    features51 = numpy.average(self._features5, axis=0)
110
                    features52 = numpy.std(self._features5, axis=0) 
111
                    features53 = prueba.mad(self._features5)
112
                    template_id = group['id'].data.text#miramos por el numero por el que va
113
                    if self._field == 'all_five':# si es con todos
114
                        self._templates[template_id] = dict(  #creamos un diccionario y guardamos en cada posicion del usuario por el que va los valores
115
                                client_id = group['template_client_id'].data.text,#guardamos el nombre del usuario por el que va ejemplo(Genuine_12)
116
                                model_average1 = features11,
117
                                model_std1 = features12,
118
                                model_mad1  = features13,
119
                                model_average2= features21,
120
                                model_std2= features22,
121
                                model_mad2= features23,
122
                                model_average3= features31,
123
                                model_std3= features32,
124
                                model_mad3= features33,
125
                                model_average4= features41,
126
                                model_std4= features42,
127
                                model_mad4= features43,
128
                                model_average5= features51,
129
                                model_std5= features52,
130
                                model_mad5= features53,
131
                       
132
                            )
133
                    if self._field == 'given_name':#si es el nombre hacemos lo mismo que antes pero solo guardamos los datos del nombre
134
                        self._templates[template_id] = dict(  
135
                                client_id = group['template_client_id'].data.text,
136
                                model_average = features11,
137
                                model_std  = features12,
138
                                model_mad= features13,
139
                            )
140
                    if self._field == 'family_name':#igual
141
                        self._templates[template_id] = dict(  
142
                                client_id = group['template_client_id'].data.text,
143
                                model_average= features21,
144
                                model_std= features22,
145
                                model_mad= features23,
146
                            ) 
147
                    if self._field == 'email':#igual
148
                        self._templates[template_id] = dict(  
149
                                client_id = inputs['template_client_id'].data.text,
150
                                model_average= features31,
151
                                model_std= features32,
152
                                model_mad= features33,
153
                            )
154
                    if self._field == 'nationality':#igual
155
                        self._templates[template_id] = dict(  
156
                                 client_id = inputs['template_client_id'].data.text,
157
                                 model_average= features41,
158
                                 model_std= features42,
159
                                 model_mad= features43,
160
                            )
161
                    if self._field == 'id_number':#igual
162
                        self._templates[template_id] = dict(  
163
                                 client_id = inputs['template_client_id'].data.text, 
164
                                 model_average= features51,
165
                                 model_std= features52,
166
                                 model_mad= features53,
167
                            )
168
             
169
                    self._features1 = []#cuando termina ponemos las listas a cero para volver a empezar
170
                    self._features2 = []
171
                    self._features3 = []
172
                    self._features4 = []
173
                    self._features5 = []
174
        comparison_ids = inputs['comparison_ids'].data.text#cuando ha terminado con el grupo de templates empieza con probe, aqui guardamos el numero por el que va de las de prueba
175
        data = inputs['keystroke'].data     #son los datos de las muestras de prueba
176
        if self._field == 'given_name':#si es el nombre coge el hotdtime y rplatency
177
            f1 = data.holdtime.given_name
178
            f2 = data.rplatency.given_name
179
        if self._field == 'family_name':#igual
180
            f1 = data.holdtime.family_name
181
            f2 = data.rplatency.family_name
182
        if self._field == 'email':#igual
183
            f1 = data.holdtime.email
184
            f2 = data.rplatency.email
185
        if self._field == 'nationality':
186
            f1 = data.holdtime.nationality
187
            f2 = data.rplatency.nationality        
188
        if self._field == 'id_number':
189
            f1 = data.holdtime.id_number
190
            f2 = data.rplatency.id_number
191
        if self._field == 'all_five':#Si es todo coge los cinco
192
            f11 = data.holdtime.given_name
193
            f12 = data.rplatency.given_name        
194
            f21 = data.holdtime.family_name
195
            f22 = data.rplatency.family_name      
196
            f31 = data.holdtime.email
197
            f32 = data.rplatency.email       
198
            f41 = data.holdtime.nationality
199
            f42 = data.rplatency.nationality 
200
            f51 = data.holdtime.id_number
201
            f52 = data.rplatency.id_number 
202
        if self._field != 'all_five':#si es distinto de los 5 pasw solo lo hace para uno
203
            feature_vector=[] #definimos una lista
204
            l_f=len(f1)#longitud de la lista
205
            for i_k in range(l_f):#vamos poniendo los valores en una fila y transformando a float
206
                feature_vector.append(float(f1[i_k]))
207
            
208
            l_f=len(f2)
209
            for i_k in range(l_f):#igual pero con rplatency
210
                feature_vector.append(float(f2[i_k]))        
211
            
212
            probe_features=feature_vector#igualamos el vector
213
        if self._field == 'all_five':#con los cindo si es all_five
214
            feature_vector1=[]
215
            l_f=len(f11)
216
            for i_k in range(l_f):
217
                feature_vector1.append(float(f11[i_k]))
218
        
219
            l_f=len(f12)
220
            for i_k in range(l_f):
221
                feature_vector1.append(float(f12[i_k]))        
222
            
223
            feature_vector2=[]
224
            l_f=len(f21)
225
            for i_k in range(l_f):
226
                feature_vector2.append(float(f21[i_k]))
227
        
228
            l_f=len(f22)
229
            for i_k in range(l_f):
230
                feature_vector2.append(float(f22[i_k]))  
231
            
232
            feature_vector3=[]
233
            l_f=len(f31)
234
            for i_k in range(l_f):
235
                feature_vector3.append(float(f31[i_k]))
236
        
237
            l_f=len(f32)
238
            for i_k in range(l_f):
239
                feature_vector3.append(float(f32[i_k]))  
240
            
241
            feature_vector4=[]
242
            l_f=len(f41)
243
            for i_k in range(l_f):
244
                feature_vector4.append(float(f41[i_k]))
245
        
246
            l_f=len(f42)
247
            for i_k in range(l_f):
248
                feature_vector4.append(float(f42[i_k]))  
249
            
250
            feature_vector5=[]
251
            l_f=len(f51)
252
            for i_k in range(l_f):
253
                feature_vector5.append(float(f51[i_k]))
254
        
255
            l_f=len(f52)
256
            for i_k in range(l_f):
257
                feature_vector5.append(float(f52[i_k])) 
258
        
259
            probe_features1=feature_vector1#tenemos las cinco muestras de una fila
260
            probe_features2=feature_vector2
261
            probe_features3=feature_vector3
262
            probe_features4=feature_vector4
263
            probe_features5=feature_vector5
264
        scores = []#creamos una lista
265
        for comparison_id in comparison_ids:#for con el numero de usuario de prueba por el que va
266
            template_client_identity = self._templates[comparison_id]['client_id']   #guardamos el nombre del usuario por el que va         
267
            if self._field != 'all_five':#Hacemos las distancias para solo un pasw
268
                if self._distance == 'Modified Scaled Manhattan':
269
                    score=prueba.modified_scaled_distance(self._templates[comparison_id]['model_average'],self._templates[comparison_id]['model_std'],probe_features);
270
                if self._distance == 'Scaled Manhattan':
271
                    score=prueba.scaled_distance(self._templates[comparison_id]['model_average'],self._templates[comparison_id]['model_mad'],probe_features); 
272
                
273
            if self._field == 'all_five':#para los cinco pasw
274
                score=[] 
275
                if self._distance == 'Modified Scaled Manhattan':
276
                    score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average1'],self._templates[comparison_id]['model_std1'],probe_features1))
277
                    score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average2'],self._templates[comparison_id]['model_std2'],probe_features2))
278
                    score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average3'],self._templates[comparison_id]['model_std3'],probe_features3))
279
                    score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average4'],self._templates[comparison_id]['model_std4'],probe_features4))
280
                    score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average5'],self._templates[comparison_id]['model_std5'],probe_features5))                    
281
                
282
                if self._distance == 'Scaled Manhattan':
283
                    score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average1'],self._templates[comparison_id]['model_std1'],probe_features1))
284
                    score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average2'],self._templates[comparison_id]['model_std2'],probe_features2))
285
                    score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average3'],self._templates[comparison_id]['model_std3'],probe_features3))
286
                    score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average4'],self._templates[comparison_id]['model_std4'],probe_features4))
287
                    score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average5'],self._templates[comparison_id]['model_std5'],probe_features5))
288
                    
289
                score=numpy.average(score)#media de todos los scores por fila
290
                
291
            scores.append({#creamos una variable que tiene dos valores dentro score y el usuario genuine
292
                'template_identity': template_client_identity,
293
                'score': score,
294
            })
295
        outputs['scores'].write({#escribimos en la salida por el usuario de prueba por el que va, ejemplo impostor_2, y scores
296
                'client_identity': inputs['probe_client_id'].data.text,
297
                'scores': scores
298
            },            
299
        )   
300
  
301
            
302
        return True

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

This algorithm is designed to be used as a simple enrollment strategy of keystroke data. It enrolls a model from several features by computing the average and standard deviation of the enrollment features.

Note

All features must have the same length.

Experiments

Updated Name Databases/Protocols Analyzers
robertodaza/robertodaza/example2/2/article_one_block atvskeystroke/1@A robertodaza/analyzercompetition/2
robertodaza/robertodaza/example2/2/article_one_block1 atvskeystroke/1@A robertodaza/analyzerahora/1
Created with Raphaël 2.1.2[compare]robertodaza/competition/1robertodaza/competition/2Jan262016Feb1

This table shows the number of times this algorithm has been successfully run using the given environment. Note this does not provide sufficient information to evaluate if the algorithm will run when submitted to different conditions.

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