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
image system/array_2d_uint8/1 Input
client_id system/uint64/1 Input
subspace_lda tutorial/linear_machine/1 Output
subspace_pca tutorial/linear_machine/1 Output

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

Name Description Type Default Range/Choices
number-of-pca-components uint32 5
number-of-lda-components uint32 2
xxxxxxxxxx
74
 
1
import bob
2
import numpy
3
4
5
class Algorithm:
6
7
    def __init__(self):
8
        self.number_of_pca_components = 5
9
        self.number_of_lda_components = 2
10
        self.data = {}
11
12
13
    def setup(self, parameters):
14
        self.number_of_pca_components = parameters.get('number-of-pca-components',
15
                                                   self.number_of_pca_components)
16
        self.number_of_lda_components = parameters.get('number-of-lda-components',
17
                                                   self.number_of_lda_components)
18
        return True
19
20
    def _project_data_for_lda(self, machine):
21
        tdata = []
22
        for client_id, client_files in self.data.iteritems():
23
            # at least two files per client are required!
24
            if len(client_files) < 2:
25
                # "Skipping client since the number of client files is only %d" %len(client_files)
26
                continue
27
            tdata.append(numpy.vstack([machine(feature.astype('float')) for feature in client_files]))
28
        return tdata
29
30
    def _perform_pca(self, pca_machine, training_set):
31
        """Perform PCA on data"""
32
        data = []
33
        for client_features in training_set:
34
            data.append(numpy.vstack([machine(feature) for feature in client_features]))
35
        return data
36
37
    def process(self, inputs, outputs):
38
        image = inputs["image"].data.value.flatten()
39
        c_id = inputs["client_id"].data.value
40
        if c_id in self.data.keys(): self.data[c_id].append(image)
41
        else: self.data[c_id] = [image]
42
43
        if not(inputs.hasMoreData()):
44
            # PCA
45
            data_pca = numpy.vstack([self.data[c_id] for c_id in self.data.keys()])
46
            trainer = bob.trainer.PCATrainer()
47
            data_pca = data_pca.astype('float')
48
            pca_machine, eigen_values = trainer.train(data_pca)
49
            del data_pca # Reduce memory usage
50
            pca_machine.resize(pca_machine.shape[0], int(self.number_of_pca_components))
51
            # outputs data
52
            outputs["subspace_pca"].write({
53
                'input_subtract': pca_machine.input_subtract,
54
                'input_divide':   pca_machine.input_divide,
55
                'weights':        pca_machine.weights,
56
                'biases':         pca_machine.biases,
57
            })
58
59
            # LDA
60
            data_lda = self._project_data_for_lda(pca_machine)
61
            lda_trainer = bob.trainer.FisherLDATrainer()
62
            lda_machine, lda_variances = lda_trainer.train(data_lda)
63
            del data_lda # Reduce memory usage
64
            lda_machine.resize(lda_machine.shape[0], int(self.number_of_lda_components))
65
            # outputs data
66
            outputs["subspace_lda"].write({
67
                'input_subtract': lda_machine.input_subtract,
68
                'input_divide':   lda_machine.input_divide,
69
                'weights':        lda_machine.weights,
70
                'biases':         lda_machine.biases,
71
            })
72
73
74
        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 performs principal component analysis (PCA) [PCA] on a given dataset using the singular value decomposition (SVD) [SVD], followed by linear discriminant analysis (LDA) [LDA].

This implementation relies on the Bob library.

The inputs are:

  • image: A training set of floating point vectors as a two-dimensional array of floats (64 bits), the number of rows corresponding to the number of training samples, and the number of columns to the dimensionality of the training samples.
  • client_id: Client (class/subject) identifier as an unsigned 64 bits integer.

The outputs are subspace_pca and subspace_lda for the PCA and LDA transformation, respectively.

[SVD]http://en.wikipedia.org/wiki/Singular_value_decomposition
[PCA]http://en.wikipedia.org/wiki/Principal_component_analysis
[LDA]http://en.wikipedia.org/wiki/Linear_discriminant_analysis
No experiments are using this algorithm.
Created with Raphaël 2.1.2[compare]tutorial/pca_lda/1tutorial/pca_lda/2Jun27tutorial/pca_lda/32014Sep6tutorial/pca_lda/4tutorial/pca_lda/52015Sep3

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