secure_inner_join.lsh

This implements Locality-Sensitive Hashing for dates and zip2-codes.

Functions

get_hyper_planes(…)

Construct a specified number of hyper planes with a set seed.

encode(→ tuple[int, int, int, int])

Encodes day, month, year and zip2 to a Tuple.

lsh_hash(→ bitarray.bitarray)

Computes a hash encoding for a given encoded input, given a collection of hyperplanes

weighted_hamming_distance(→ tuple[float, tuple[float, ...)

if score ~= 1 than we expect at most one element to be one-off

Module Contents

secure_inner_join.lsh.get_hyper_planes(amount: int = ..., seed: int = ..., mask: True = ...) tuple[numpy.typing.NDArray[numpy.int_], bitarray.bitarray][source]
secure_inner_join.lsh.get_hyper_planes(amount: int, seed: int, mask: False) numpy.typing.NDArray[numpy.int_]
secure_inner_join.lsh.get_hyper_planes(amount: int = ..., seed: int = ..., mask: bool = ...) numpy.typing.NDArray[numpy.int_] | tuple[numpy.typing.NDArray[numpy.int_], bitarray.bitarray]

Construct a specified number of hyper planes with a set seed. We assume the following order: (day, month, year, zip2-code).

Parameters:
  • amount – number of hyper planes to construct

  • seed – seed to use for the random generator

  • mask – set to true to generate a bit mask to use for masking

Returns:

array containing the random hyper planes

secure_inner_join.lsh.encode(day: int, month: int, year: int, zip4_code: int) tuple[int, int, int, int][source]

Encodes day, month, year and zip2 to a Tuple.

Parameters:
  • day – day of birth

  • month – month of birth

  • year – year of birth

  • zip4_code – the four digits of the postal code

Returns:

encoded representation

secure_inner_join.lsh.lsh_hash(day: int, month: int, year: int, zip4_code: int, hyper_planes: numpy.typing.NDArray[numpy.int_], bit_mask: bitarray.bitarray | None = None) bitarray.bitarray[source]

Computes a hash encoding for a given encoded input, given a collection of hyperplanes

Parameters:
  • day – day of birth

  • month – month of birth

  • year – year of birth

  • zip4_code – the four digits of the postal code

  • hyper_planes – $n$ hyperplanes sampled from $[0,62) imes[0,12) imes[0,100) imes[10,100)$

  • bit_mask – masking to apply to the hashing

Returns:

an encode hash, first for $n$ bits belong to day, second $n$ bits belong to month, etc.

secure_inner_join.lsh.weighted_hamming_distance(hash_1: bitarray.bitarray, hash_2: bitarray.bitarray) tuple[float, tuple[float, float, float, float]][source]

if score ~= 1 than we expect at most one element to be one-off

The score represents the actual distance between two encodings if the number of buckets is large enough :param hash_1: first hash :param hash_2: second hash :return: an x-off distance score, and a tuple of x-off distances per (day, month, year, zip2)