Forked from robertodaza/prueba1/3
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.
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 |
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
import numpy
#en la libreria robertodaza/competition--modified_scaled_distance--scaled_distance--mad-/1 que la hemos nombrado como prueba tenemos todas las funciones que usaremos
class Algorithm:
def __init__(self):#primer modulo donde definimos las variables globales
self._features1 = [] #definimos 5 listas
self._features2 = []
self._features3 = []
self._features4 = []
self._features5 = []
self._templates=None#lo ponemoscon valor none
self._field='given_name' #Por defecto el nombre
self._distance='Modified Scaled Manhattan'#Por defecto modified scaled manhattan
def setup(self, parameters): #Funcion que define los parametros (PODEMOS CAMBIAR EN PARAMETRO EL VALOR DE FIELD Y DISTANCE CON ESTA FUNCION)
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)
self._distance = parameters.get('distance', self._distance)#igual pero con distance
return True
def process(self, inputs, outputs):#trabajamos con objetos
if self._templates is None:#La primera vez entra aqui
self._templates = {}#define un diccionario
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
while group.hasMoreData():#Mientras tenga datos se ejecuta
group.next()# pedir dato nuevo del grupo
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
f2 = group['features'].data.rplatency.given_name#igual pero con rplatency
feature_vector=[]#lista
l_f=len(f1)#es la longitud son caracteres
for i_k in range(l_f):#hacemos un for para ponerlos en el vector features_vector transformando a float
feature_vector.append(float(f1[i_k]))
l_f=len(f2)#igual
for i_k in range(l_f):
feature_vector.append(float(f2[i_k]))
self._features1.append(feature_vector)#vamos haciendo una lista que es una matriz con cada prueba de las personas asi que seran 6 filas
f1 = group['features'].data.holdtime.family_name#igual con family
f2 = group['features'].data.rplatency.family_name
feature_vector=[]
l_f=len(f1)
for i_k in range(l_f):
feature_vector.append(float(f1[i_k]))
l_f=len(f2)
for i_k in range(l_f):
feature_vector.append(float(f2[i_k]))
self._features2.append(feature_vector)
f1 = group['features'].data.holdtime.email#igual con email
f2 = group['features'].data.rplatency.email
feature_vector=[]
l_f=len(f1)
for i_k in range(l_f):
feature_vector.append(float(f1[i_k]))
l_f=len(f2)
for i_k in range(l_f):
feature_vector.append(float(f2[i_k]))
self._features3.append(feature_vector)
f1 = group['features'].data.holdtime.nationality#igual con nationality
f2 = group['features'].data.rplatency.nationality
feature_vector=[]
l_f=len(f1)
for i_k in range(l_f):
feature_vector.append(float(f1[i_k]))
l_f=len(f2)
for i_k in range(l_f):
feature_vector.append(float(f2[i_k]))
self._features4.append(feature_vector)
f1 = group['features'].data.holdtime.id_number#igual con id_number
f2 = group['features'].data.rplatency.id_number
feature_vector=[]
l_f=len(f1)
for i_k in range(l_f):
feature_vector.append(float(f1[i_k]))
l_f=len(f2)
for i_k in range(l_f):
feature_vector.append(float(f2[i_k]))
self._features5.append(feature_vector)
# Calculate mean and std
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
features11 = numpy.average(self._features1, axis=0)#calcula la media quedandote solo una fila, media por columnas
features12 = numpy.std(self._features1, axis=0)#std igual
features13 = prueba.mad(self._features1)#mad igual
features21 = numpy.average(self._features2, axis=0)
features22 = numpy.std(self._features2, axis=0)
features23 = prueba.mad(self._features2)
features31 = numpy.average(self._features3, axis=0)
features32 = numpy.std(self._features3, axis=0)
features33 = prueba.mad(self._features3)
features41 = numpy.average(self._features4, axis=0)
features42 = numpy.std(self._features4, axis=0)
features43 = prueba.mad(self._features4)
features51 = numpy.average(self._features5, axis=0)
features52 = numpy.std(self._features5, axis=0)
features53 = prueba.mad(self._features5)
template_id = group['id'].data.text#miramos por el numero por el que va
if self._field == 'all_five':# si es con todos
self._templates[template_id] = dict( #creamos un diccionario y guardamos en cada posicion del usuario por el que va los valores
client_id = group['template_client_id'].data.text,#guardamos el nombre del usuario por el que va ejemplo(Genuine_12)
model_average1 = features11,
model_std1 = features12,
model_mad1 = features13,
model_average2= features21,
model_std2= features22,
model_mad2= features23,
model_average3= features31,
model_std3= features32,
model_mad3= features33,
model_average4= features41,
model_std4= features42,
model_mad4= features43,
model_average5= features51,
model_std5= features52,
model_mad5= features53,
)
if self._field == 'given_name':#si es el nombre hacemos lo mismo que antes pero solo guardamos los datos del nombre
self._templates[template_id] = dict(
client_id = group['template_client_id'].data.text,
model_average = features11,
model_std = features12,
model_mad= features13,
)
if self._field == 'family_name':#igual
self._templates[template_id] = dict(
client_id = group['template_client_id'].data.text,
model_average= features21,
model_std= features22,
model_mad= features23,
)
if self._field == 'email':#igual
self._templates[template_id] = dict(
client_id = inputs['template_client_id'].data.text,
model_average= features31,
model_std= features32,
model_mad= features33,
)
if self._field == 'nationality':#igual
self._templates[template_id] = dict(
client_id = inputs['template_client_id'].data.text,
model_average= features41,
model_std= features42,
model_mad= features43,
)
if self._field == 'id_number':#igual
self._templates[template_id] = dict(
client_id = inputs['template_client_id'].data.text,
model_average= features51,
model_std= features52,
model_mad= features53,
)
self._features1 = []#cuando termina ponemos las listas a cero para volver a empezar
self._features2 = []
self._features3 = []
self._features4 = []
self._features5 = []
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
data = inputs['keystroke'].data #son los datos de las muestras de prueba
if self._field == 'given_name':#si es el nombre coge el hotdtime y rplatency
f1 = data.holdtime.given_name
f2 = data.rplatency.given_name
if self._field == 'family_name':#igual
f1 = data.holdtime.family_name
f2 = data.rplatency.family_name
if self._field == 'email':#igual
f1 = data.holdtime.email
f2 = data.rplatency.email
if self._field == 'nationality':
f1 = data.holdtime.nationality
f2 = data.rplatency.nationality
if self._field == 'id_number':
f1 = data.holdtime.id_number
f2 = data.rplatency.id_number
if self._field == 'all_five':#Si es todo coge los cinco
f11 = data.holdtime.given_name
f12 = data.rplatency.given_name
f21 = data.holdtime.family_name
f22 = data.rplatency.family_name
f31 = data.holdtime.email
f32 = data.rplatency.email
f41 = data.holdtime.nationality
f42 = data.rplatency.nationality
f51 = data.holdtime.id_number
f52 = data.rplatency.id_number
if self._field != 'all_five':#si es distinto de los 5 pasw solo lo hace para uno
feature_vector=[] #definimos una lista
l_f=len(f1)#longitud de la lista
for i_k in range(l_f):#vamos poniendo los valores en una fila y transformando a float
feature_vector.append(float(f1[i_k]))
l_f=len(f2)
for i_k in range(l_f):#igual pero con rplatency
feature_vector.append(float(f2[i_k]))
probe_features=feature_vector#igualamos el vector
if self._field == 'all_five':#con los cindo si es all_five
feature_vector1=[]
l_f=len(f11)
for i_k in range(l_f):
feature_vector1.append(float(f11[i_k]))
l_f=len(f12)
for i_k in range(l_f):
feature_vector1.append(float(f12[i_k]))
feature_vector2=[]
l_f=len(f21)
for i_k in range(l_f):
feature_vector2.append(float(f21[i_k]))
l_f=len(f22)
for i_k in range(l_f):
feature_vector2.append(float(f22[i_k]))
feature_vector3=[]
l_f=len(f31)
for i_k in range(l_f):
feature_vector3.append(float(f31[i_k]))
l_f=len(f32)
for i_k in range(l_f):
feature_vector3.append(float(f32[i_k]))
feature_vector4=[]
l_f=len(f41)
for i_k in range(l_f):
feature_vector4.append(float(f41[i_k]))
l_f=len(f42)
for i_k in range(l_f):
feature_vector4.append(float(f42[i_k]))
feature_vector5=[]
l_f=len(f51)
for i_k in range(l_f):
feature_vector5.append(float(f51[i_k]))
l_f=len(f52)
for i_k in range(l_f):
feature_vector5.append(float(f52[i_k]))
probe_features1=feature_vector1#tenemos las cinco muestras de una fila
probe_features2=feature_vector2
probe_features3=feature_vector3
probe_features4=feature_vector4
probe_features5=feature_vector5
scores = []#creamos una lista
for comparison_id in comparison_ids:#for con el numero de usuario de prueba por el que va
template_client_identity = self._templates[comparison_id]['client_id'] #guardamos el nombre del usuario por el que va
if self._field != 'all_five':#Hacemos las distancias para solo un pasw
if self._distance == 'Modified Scaled Manhattan':
score=prueba.modified_scaled_distance(self._templates[comparison_id]['model_average'],self._templates[comparison_id]['model_std'],probe_features);
if self._distance == 'Scaled Manhattan':
score=prueba.scaled_distance(self._templates[comparison_id]['model_average'],self._templates[comparison_id]['model_mad'],probe_features);
if self._field == 'all_five':#para los cinco pasw
score=[]
if self._distance == 'Modified Scaled Manhattan':
score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average1'],self._templates[comparison_id]['model_std1'],probe_features1))
score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average2'],self._templates[comparison_id]['model_std2'],probe_features2))
score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average3'],self._templates[comparison_id]['model_std3'],probe_features3))
score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average4'],self._templates[comparison_id]['model_std4'],probe_features4))
score.append(prueba.modified_scaled_distance(self._templates[comparison_id]['model_average5'],self._templates[comparison_id]['model_std5'],probe_features5))
if self._distance == 'Scaled Manhattan':
score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average1'],self._templates[comparison_id]['model_std1'],probe_features1))
score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average2'],self._templates[comparison_id]['model_std2'],probe_features2))
score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average3'],self._templates[comparison_id]['model_std3'],probe_features3))
score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average4'],self._templates[comparison_id]['model_std4'],probe_features4))
score.append(prueba.scaled_distance(self._templates[comparison_id]['model_average5'],self._templates[comparison_id]['model_std5'],probe_features5))
score=numpy.average(score)#media de todos los scores por fila
scores.append({#creamos una variable que tiene dos valores dentro score y el usuario genuine
'template_identity': template_client_identity,
'score': score,
})
outputs['scores'].write({#escribimos en la salida por el usuario de prueba por el que va, ejemplo impostor_2, y scores
'client_identity': inputs['probe_client_id'].data.text,
'scores': scores
},
)
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.
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 |
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.