Created
March 27, 2014 16:47
-
-
Save danoneata/9317b11a26a927e42b11 to your computer and use it in GitHub Desktop.
Fisher vector normalization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def power_normalize(xx, alpha=0.5): | |
"""Computes a alpha-power normalization for the matrix xx.""" | |
return np.sign(xx) * np.abs(xx) ** alpha | |
def L2_normalize(xx): | |
"""L2-normalizes each row of the data xx.""" | |
Zx = np.sum(xx * xx, 1) | |
xx_norm = xx / np.sqrt(Zx[:, np.newaxis]) | |
xx_norm[np.isnan(xx_norm)] = 0 | |
return xx_norm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment