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.2.tar.gz (2.8 kB view details)

Uploaded Source

File details

Details for the file lshcos-0.0.2.tar.gz.

File metadata

  • Download URL: lshcos-0.0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for lshcos-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6140c593ee190082d9033b196ca4a43509986d05846eff02b2510120bee1d390
MD5 2174fcbb5733ad20ea926782514664d9
BLAKE2b-256 f533d3a3f94a1f82fe0c3ffbeceb4ea9148b1eb391de8a51c3103d84e3393065

See more details on using hashes here.

Supported by

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