<s> import numpy <EOL> import unittest <EOL> import logging <EOL> from nearpy import Engine <EOL> from nearpy . distances import CosineDistance <EOL> from nearpy . hashes import HashPermutations <EOL> from nearpy . hashes import RandomBinaryProjections <EOL> from past . builtins import xrange <EOL> class TestPermutation ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> logging . basicConfig ( level = logging . WARNING ) <EOL> numpy . random . seed ( <NUM_LIT:11> ) <EOL> self . permutations = HashPermutations ( '<STR_LIT>' ) <EOL> rbp = RandomBinaryProjections ( '<STR_LIT>' , <NUM_LIT:4> , rand_seed = <NUM_LIT> ) <EOL> rbp_conf = { '<STR_LIT>' : <NUM_LIT:50> , '<STR_LIT>' : <NUM_LIT:10> , '<STR_LIT>' : <NUM_LIT:100> } <EOL> self . permutations . add_child_hash ( rbp , rbp_conf ) <EOL> self . engine_perm = Engine ( <NUM_LIT:200> , lshashes = [ self . permutations ] , distance = CosineDistance ( ) ) <EOL> self . engine = Engine ( <NUM_LIT:200> , lshashes = [ rbp ] , distance = CosineDistance ( ) ) <EOL> def test_runnable ( self ) : <EOL> matrix = numpy . zeros ( ( <NUM_LIT:1000> , <NUM_LIT:200> ) ) <EOL> for i in xrange ( <NUM_LIT:1000> ) : <EOL> v = numpy . random . randn ( <NUM_LIT:200> ) <EOL> matrix [ i ] = v <EOL> self . engine . store_vector ( v ) <EOL> self . engine_perm . store_vector ( v ) <EOL> self . permutations . build_permuted_index ( ) <EOL> query = numpy . random . randn ( <NUM_LIT:200> ) <EOL> results = self . engine_perm . neighbours ( query ) <EOL> permuted_dists = [ x [ <NUM_LIT:2> ] for x in results ] <EOL> results = self . engine . neighbours ( query ) <EOL> dists = [ x [ <NUM_LIT:2> ] for x in results ] <EOL> self . assertLess ( permuted_dists [ <NUM_LIT:0> ] , dists [ <NUM_LIT:0> ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
