예제 #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# libpylshbox_example2.py
import libpylshbox
import numpy
import time
print 'prepare test data'
float_file = 'audio.data'
float_query = numpy.random.rand(192)
print ''
print 'Test itqLsh'
print ''
print 'First time, need to constructing index.' #About 1.5s.
start = time.time()
itq_file = libpylshbox.itqlsh()
itq_file.init_file(float_file, 'pyitq.lsh', 521, 5, 8, 100, 50)
result = itq_file.query(float_query.tolist(), 2, 10)
indices, dists = result[0],result[1]
for i in range(len(indices)):
	print indices[i], '\t', dists[i]
print 'Elapsed time is %f seconds.' % (time.time() - start)
print ''
print 'Second time, no need to re-indexing.' #About 0.05s.
start = time.time()
itq_file2 = libpylshbox.itqlsh()
itq_file2.init_file(float_file, 'pyitq.lsh', 521, 5, 8, 100, 50)
result = itq_file2.query(float_query.tolist(), 2, 10)
indices, dists = result[0],result[1]
for i in range(len(indices)):
	print indices[i], '\t', dists[i]
print 'Elapsed time is %f seconds.' % (time.time() - start)
psdL1_mat = libpylshbox.psdlsh()
psdL1_mat.init_mat(float_mat.tolist(), '', 521, 5, 1, 5)
result = psdL1_mat.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
print ''
print 'Test psdlsh with param.T = 2'
psdL2_mat = libpylshbox.psdlsh()
psdL2_mat.init_mat(float_mat.tolist(), '', 521, 5, 2, 0.5)
result = psdL2_mat.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
print ''
print 'Test shLsh'
sh_mat = libpylshbox.shlsh()
sh_mat.init_mat(float_mat.tolist(), '', 521, 5, 4, 100)
result = sh_mat.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
print ''
print 'Test itqLsh'
itq_mat = libpylshbox.itqlsh()
itq_mat.init_mat(float_mat.tolist(), '', 521, 5, 8, 100, 50)
result = itq_mat.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
예제 #3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# libpylshbox_example2.py
import libpylshbox
import numpy
import time
print 'prepare test data'
float_file = 'audio.data'
float_query = numpy.random.rand(192)
print ''
print 'Test itqLsh'
print ''
print 'First time, need to constructing index.'  # About 1.5s.
start = time.time()
itq_file = libpylshbox.itqlsh()
itq_file.init_file(float_file, 'pyitq.lsh', 521, 5, 8, 100, 50)
result = itq_file.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
print 'Elapsed time is %f seconds.' % (time.time() - start)
print ''
print 'Second time, no need to re-indexing.'  # About 0.05s.
start = time.time()
itq_file2 = libpylshbox.itqlsh()
itq_file2.init_file(float_file, 'pyitq.lsh', 521, 5, 8, 100, 50)
result = itq_file2.query(float_query.tolist(), 2, 10)
indices, dists = result[0], result[1]
for i in range(len(indices)):
    print indices[i], '\t', dists[i]
print 'Elapsed time is %f seconds.' % (time.time() - start)