In [ ]:
# Quantization

Attemps to reduce the feature vector size from $200*32 = 6400$ bits to a lower size.

TODO

  • remove normalization from quantization : we should keep the norm value appart to avoid to compute it at match test
  • compute means with learning data and not all the data
  • find a way to represent the size compression gain vs the precision

In [1]:
%pylab inline
from tools import *
from stats import *


Populating the interactive namespace from numpy and matplotlib

Using uniform LBP with WPCA as descriptor.


In [2]:
descs = np.load("descriptors/ulbp_wpca.npy")

In [3]:
quantization_labels = ["No quantization"]
quantization_rocs = [descs]

Binary quantization

Simple very basic quantization : for each value if $x \geq 0$ assign $x = +1$ else $x = -1$

Reduces the feature vector's size by 32, i.e. brings it to 200 bits.


In [12]:
def binary_quantization(descs):
    quantized_descs = np.array(descs, copy=True)
    for i in range(quantized_descs.shape[0]):
        quantized_descs[i][quantized_descs[i] >= 0] = 1.0
        quantized_descs[i][quantized_descs[i] < 0] = -1.0
        quantized_descs[i] = quantized_descs[i] / np.linalg.norm(quantized_descs[i])
    return quantized_descs

In [13]:
quantization_labels.append("Binary quantization")
quantization_rocs.append(binary_quantization(descs))

In [14]:
print descs[:2,:5]
print binary_quantization(descs[:2,:5])


[[-0.0543737   0.19670664  0.13146679  0.03137031  0.05212525]
 [-0.08220888 -0.10292438  0.20455836 -0.12267879 -0.10575336]]
[[-0.44721359  0.44721359  0.44721359  0.44721359  0.44721359]
 [-0.44721359 -0.44721359  0.44721359 -0.44721359 -0.44721359]]

Simple reconstruction

Simple reconstruction method : for each feature vector $x$, for each of its dimension, $x_k= \overline{x_k^{+}}$ if $x_k \geq 0$ otherwise $x_k = \overline{x_k^{-}}$ where $\overline{x_k^+}$ is the mean of the positive values for the dimension #k and $\overline{x_k^-}$ is the mean of the negative values for the dimension #k.

Brings the feature vector's size to : 200 + 2*32 = 264 bits


In [7]:
def compute_means(descs):
    pos_means = np.zeros(descs.shape[1])
    neg_means = np.zeros(descs.shape[1])
    for i in range(descs.shape[1]):
        values = descs[:,i]
        pos_means[i] = np.mean(values[values >= 0.0])
        neg_means[i] = np.mean(values[values < 0.0])
    return pos_means,neg_means

def simple_reconstruction(descs, pos_means, neg_means):
    quantized_descs = np.array(descs, copy=True)
    for i in range(quantized_descs.shape[0]):
        for j in range(quantized_descs.shape[1]):
            if quantized_descs[i,j] >= 0:
                quantized_descs[i,j] = pos_means[j]
            else:
                quantized_descs[i,j] = neg_means[j]
        quantized_descs[i] = quantized_descs[i] / np.linalg.norm(quantized_descs[i])
    return quantized_descs

In [8]:
quantization_labels.append("Simple reconstruction")

pos_means, neg_means = compute_means(descs)
quantization_rocs.append(simple_reconstruction(descs, pos_means, neg_means))

In [9]:
print descs[:2,:5]
print simple_reconstruction(descs[:2,:5], pos_means, neg_means)


[[-0.0543737   0.19670664  0.13146679  0.03137031  0.05212525]
 [-0.08220888 -0.10292438  0.20455836 -0.12267879 -0.10575336]]
[[-0.46440601  0.46047288  0.42453903  0.44648463  0.43898717]
 [-0.46262574 -0.46750778  0.42291161 -0.43328559 -0.44813311]]

Asymetric Distance Computation (ADC)


In [ ]:

ITQ


In [10]:
"""
quantization_labels.append("ITQ")
"""


Out[10]:
'\nquantization_labels.append("ITQ")\n'

Results


In [11]:
from dataset import loadSetsGroundTruth
sets_ground_truth = loadSetsGroundTruth()

rocs = computeMeanROC(quantization_rocs, sets_ground_truth)

In [12]:
plotROC(rocs, quantization_labels, title="ROC curve for several quantization methods")



In [12]: