Skip to content

Instantly share code, notes, and snippets.

@danoneata
Created March 27, 2014 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danoneata/9317b11a26a927e42b11 to your computer and use it in GitHub Desktop.
Save danoneata/9317b11a26a927e42b11 to your computer and use it in GitHub Desktop.
Fisher vector normalization
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