Skip to main content

A fast Python implementation of locality sensitive hashing with cosine distance.

Project description

A fast Python implementation of locality sensitive hashing with cosine distance

Installation

LSHCos depends on the following libraries:

  • numpy

To install:

$ pip install lshcos

Quickstart

To create band 2 row 6 hashes for input data of 8 dimensions:

import numpy as np
from lshcos import LSHCos

### usage one:
lshcos = LSHCos(2, 6, 8)
lshcos.add([1,2,3,4,5,6,7,8],'v_1')
lshcos.add([2,3,4,5,6,7,8,9],'v_2')
lshcos.add([10,12,99,1,5,31,2,3],'v_3')
lshcos.query([1,2,3,4,5,6,7,7],2)

### usage two:
lshcos = LSHCos(2, 6, 8)
xxx = [('v_'+str(i),np.random.randn(8)) for i in range(100)]
yyy = np.random.randn(8)
for name,v in xxx:
    lshcos.add(v,name)
lshcos.query(yyy)

Main Interface

  • To initialize a LSHCos instance:

LSHCos(band_num, row_num, v_dim)

parameters:

band_num:

The number of band.

row_num:

The number of row for each band.

v_dim:

The dimension of the input vector.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lshcos-0.0.1.tar.gz (2.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page