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

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: main

Endpoint Name Data Format Nature
featureSet system/array_2d_floats/1 Input
class system/text/1 Input
subspace tutorial/linear_machine/1 Output
xxxxxxxxxx
63
 
1
import numpy
2
import bob
3
import bob.learn.linear
4
5
#same functionality as version 2, but implemented using bob-v2.
6
7
class Algorithm:
8
9
    def __init__(self):
10
        self.data = [[], []]
11
12
13
    def process(self, inputs, outputs):
14
        
15
        # accumulates the input data in different
16
        # containers for hit or miss
17
        flat_image = inputs["featureSet"].data.value
18
        if inputs["class"].data.text == 'real':
19
            self.data[1].append(flat_image) #positive/real class
20
        else:
21
            self.data[0].append(flat_image) #negative/attack class
22
        
23
        if not(inputs.hasMoreData()):
24
            # trains the LDA projection
25
            self.data[0] = numpy.vstack(self.data[0])
26
            self.data[1] = numpy.vstack(self.data[1])
27
            
28
            #first, normalize the input features
29
            trSet = numpy.vstack((self.data[1], self.data[0]))
30
            trMean = trSet.mean(axis=0)
31
            trStd = trSet.std(axis=0)
32
            posTS = self.data[1] - trMean
33
            posTS /= trStd
34
            negTS = self.data[0] - trMean
35
            negTS /=trStd
36
            del trSet 
37
38
            trainer = bob.learn.linear.FisherLDATrainer(use_pinv=True)
39
            machine, eigen_values = trainer.train([negTS, posTS])
40
            machine.resize(machine.shape[0], 1)
41
            # save the normalization parameters
42
            machine.input_subtract = trMean
43
            machine.input_divide = trStd
44
            
45
            #using training-data scores to 'set the sign' of the classifier
46
            flipSign = 1
47
            scores_train_pos = machine(posTS)[:,0]
48
            scores_train_neg = machine(negTS)[:,0]
49
            medPosScore = numpy.median(scores_train_pos)
50
            medNegScore = numpy.median(scores_train_neg)
51
            if medPosScore < medNegScore : flipSign = -1
52
            machine.weights = flipSign*machine.weights
53
54
55
            # outputs data
56
            outputs["subspace"].write({
57
                'input_subtract': machine.input_subtract,
58
                'input_divide':   machine.input_divide,
59
                'weights':        machine.weights,
60
                'biases':         machine.biases,
61
            })
62
63
        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 will run Linear Discriminant Analysis [LDA] for a binary classification problem using images as inputs.

Inputs:
featureSet: a 2d float array of size Nxd, where N is the number of patterns and d is the length of each pattern. class: a text label. The label can take one of two values: 'real' or 'attack'
[LDA]http://en.wikipedia.org/wiki/Linear_Discriminant_analysis

Experiments

Updated Name Databases/Protocols Analyzers
sbhatta/sbhatta/iqm-face-antispoofing-test/2/replay2-antispoofing-iqm-lda replay/2@grandtest sbhatta/iqm_spoof_eer_analyzer/9
Created with Raphaël 2.1.2[compare]sbhatta/iqm_train_lda/82015Nov18

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