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 |
---|---|---|
featureSet | system/array_2d_floats/1 | Input |
class | system/text/1 | Input |
subspace | tutorial/linear_machine/1 | Output |
xxxxxxxxxx
import numpy
import bob
import bob.learn.linear
#same functionality as version 2, but implemented using bob-v2.
class Algorithm:
def __init__(self):
self.data = [[], []]
def process(self, inputs, outputs):
# accumulates the input data in different
# containers for hit or miss
flat_image = inputs["featureSet"].data.value
if inputs["class"].data.text == 'real':
self.data[1].append(flat_image) #positive/real class
else:
self.data[0].append(flat_image) #negative/attack class
if not(inputs.hasMoreData()):
# trains the LDA projection
self.data[0] = numpy.vstack(self.data[0])
self.data[1] = numpy.vstack(self.data[1])
#first, normalize the input features
trSet = numpy.vstack((self.data[1], self.data[0]))
trMean = trSet.mean(axis=0)
trStd = trSet.std(axis=0)
posTS = self.data[1] - trMean
posTS /= trStd
negTS = self.data[0] - trMean
negTS /=trStd
del trSet
trainer = bob.learn.linear.FisherLDATrainer(use_pinv=True)
machine, eigen_values = trainer.train([negTS, posTS])
machine.resize(machine.shape[0], 1)
# save the normalization parameters
machine.input_subtract = trMean
machine.input_divide = trStd
#using training-data scores to 'set the sign' of the classifier
flipSign = 1
scores_train_pos = machine(posTS)[:,0]
scores_train_neg = machine(negTS)[:,0]
medPosScore = numpy.median(scores_train_pos)
medNegScore = numpy.median(scores_train_neg)
if medPosScore < medNegScore : flipSign = -1
machine.weights = flipSign*machine.weights
# outputs data
outputs["subspace"].write({
'input_subtract': machine.input_subtract,
'input_divide': machine.input_divide,
'weights': machine.weights,
'biases': machine.biases,
})
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.
[LDA] | http://en.wikipedia.org/wiki/Linear_Discriminant_analysis |
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 |
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.