Documentation ¶
Index ¶
- Constants
- Variables
- func D8Decode(f []float64) [8]float64
- func DistSquared(f1 []float64, f2 []float64) float64
- func E8Decode(f []float64) ([8]float64, float64)
- func FindTableIndex(v [8]int8) uint8
- func GetRandomRotation(dim int) []*vec.Vec
- func Identity(dim int) []*vec.Vec
- func Is4E8Point(v [8]int8) bool
- func LeechLatticeClosest(f []float64) ([256][3][8]float64, [256][3]float64)
- func LeechLatticeClosestPoint(f []float64) ([]float64, float64)
- func LeechLatticeClosestPoints(f []float64, numPoints int) ([][]float64, []float64)
- func LeechLatticeClosestVector(v *vec.Vec) (*vec.Vec, float64)
- func LeechLatticeClosestVectors(v *vec.Vec, numPoints int) ([]*vec.Vec, []float64)
- func Normals(size int) *vec.Vec
- func Precompute()
- func RandomRotationMatrix(dim int) []*vec.Vec
- func RandomTranslationVector(dim int, max float64) *vec.Vec
- func RandomVector(dim int) *vec.Vec
- func Sign(v float64) int
- func Spans(total int, numSpans int) [][2]int
- type Candidates
- type DistanceSearchQueue
- func (d *DistanceSearchQueue) GetBest() []*Element
- func (d *DistanceSearchQueue) GetNextCandidateToExpand() *Element
- func (d *DistanceSearchQueue) Insert(e *Element) bool
- func (d *DistanceSearchQueue) Len() int
- func (d *DistanceSearchQueue) Less(i, j int) bool
- func (d *DistanceSearchQueue) Pop() interface{}
- func (d *DistanceSearchQueue) Push(x interface{})
- func (d *DistanceSearchQueue) Search() []*Element
- func (d *DistanceSearchQueue) Swap(i, j int)
- type Element
- type Hash
- type HashCommon
- type LatticeHash
- type MultiLatticeHash
- type UniversalHash
Constants ¶
const Prime = 18446744073709551557
largest 64 bit prime
Variables ¶
var TableIVa = [16][8]int8{
{0, 0, 0, 0, 0, 0, 0, 0},
{4, 0, 0, 0, 0, 0, 0, 0},
{2, 2, 2, 2, 0, 0, 0, 0},
{-2, 2, 2, 2, 0, 0, 0, 0},
{2, 2, 0, 0, 2, 2, 0, 0},
{-2, 2, 0, 0, 2, 2, 0, 0},
{2, 2, 0, 0, 0, 0, 2, 2},
{-2, 2, 0, 0, 0, 0, 2, 2},
{2, 0, 2, 0, 2, 0, 2, 0},
{-2, 0, 2, 0, 2, 0, 2, 0},
{2, 0, 2, 0, 0, 2, 0, 2},
{-2, 0, 2, 0, 0, 2, 0, 2},
{2, 0, 0, 2, 2, 0, 0, 2},
{-2, 0, 0, 2, 2, 0, 0, 2},
{2, 0, 0, 2, 0, 2, 2, 0},
{-2, 0, 0, 2, 0, 2, 2, 0},
}
We use table IV instead of table V, it is slower but more understandable
var TableIVt = [18][8]int8{
{0, 0, 0, 0, 0, 0, 0, 0},
{2, 2, 2, 0, 0, 2, 0, 0},
{2, 2, 0, 2, 0, 0, 0, 2},
{2, 0, 2, 2, 0, 0, 2, 0},
{0, 2, 2, 2, 2, 0, 0, 0},
{2, 2, 0, 0, 2, 0, 2, 0},
{2, 0, 2, 0, 2, 0, 0, 2},
{2, 0, 0, 2, 2, 2, 0, 0},
{-3, 1, 1, 1, 1, 1, 1, 1},
{3, -1, -1, 1, 1, -1, 1, 1},
{3, -1, 1, -1, 1, 1, 1, -1},
{3, 1, -1, -1, 1, 1, -1, 1},
{3, 1, 1, 1, 1, -1, -1, -1},
{3, -1, 1, 1, -1, 1, -1, 1},
{3, 1, -1, 1, -1, 1, 1, -1},
{3, 1, 1, -1, -1, -1, 1, 1},
}
var TableVi = [256][8]int8{}
var TableVii = [4096][3]uint8{}
Functions ¶
func DistSquared ¶
func E8Decode ¶
The E_8 lattice consists of two copies of D_8, offset by the vector (1/2,1/2,1/2,1/2,1/2,1/2,1/2,1/2) See https://en.wikipedia.org/wiki/E8_lattice#Lattice_points for details We follow the algorithm in neilsloane.com/doc/Me83.pdf We first find the closest point in each of the two copies of D_8 Then we return the closer of the two
func FindTableIndex ¶
func GetRandomRotation ¶
func Is4E8Point ¶
Determine if v is a point of the lambda_8 = E_8 * 4 lattice
func LeechLatticeClosest ¶
Out lattice is scaled by sqrt8, so we are actually using lambda_8 = E8 * 4 - where all coordinates are multiplied by 4 Thus all lattice points are integers instead of half integers (in fact they are only even integers) This function iterates through the possible arrangements as given in table 6 and stores the closest points to each in p It also stores the (squared) distances to those points in d
func LeechLatticeClosestPoint ¶
This function iterates through each of the possible arrangements as given in Table 7 And finds the distance given by the arrangement It then returns the closest point and its corresponding distance
func LeechLatticeClosestPoints ¶
This function returns the k closest points and distances instead
func Precompute ¶
func Precompute()
This function implements the precomputation steps as described in https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1057135
func RandomRotationMatrix ¶
Return a random rotation matrix chosen uniformly
func RandomTranslationVector ¶
Return a random vector chosen uniformly from the cube
Types ¶
type Candidates ¶
helper to sort points because golang A heap or priority queue would be more efficient
func (*Candidates) Len ¶
func (c *Candidates) Len() int
func (*Candidates) Less ¶
func (c *Candidates) Less(i, j int) bool
func (*Candidates) Swap ¶
func (c *Candidates) Swap(i, j int)
type DistanceSearchQueue ¶
type DistanceSearchQueue struct {
// contains filtered or unexported fields
}
func NewDistanceSearchQueue ¶
func NewDistanceSearchQueue(length int, sources [][]*Element) *DistanceSearchQueue
func (*DistanceSearchQueue) GetBest ¶
func (d *DistanceSearchQueue) GetBest() []*Element
func (*DistanceSearchQueue) GetNextCandidateToExpand ¶
func (d *DistanceSearchQueue) GetNextCandidateToExpand() *Element
func (*DistanceSearchQueue) Insert ¶
func (d *DistanceSearchQueue) Insert(e *Element) bool
func (*DistanceSearchQueue) Len ¶
func (d *DistanceSearchQueue) Len() int
func (*DistanceSearchQueue) Less ¶
func (d *DistanceSearchQueue) Less(i, j int) bool
func (*DistanceSearchQueue) Pop ¶
func (d *DistanceSearchQueue) Pop() interface{}
func (*DistanceSearchQueue) Push ¶
func (d *DistanceSearchQueue) Push(x interface{})
func (*DistanceSearchQueue) Search ¶
func (d *DistanceSearchQueue) Search() []*Element
func (*DistanceSearchQueue) Swap ¶
func (d *DistanceSearchQueue) Swap(i, j int)
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
func (*Element) CombineWith ¶
type Hash ¶
type Hash interface { Hash(*vec.Vec) uint64 // return k hashes (for multiprobing) MultiHash(*vec.Vec, int) []uint64 }
Hash is an abstract hash function
type HashCommon ¶
type HashCommon struct { ProjectionLines []*vec.Vec Offsets *vec.Vec Orthogonal bool UHash *UniversalHash }
func NewHashCommon ¶
func NewHashCommon(dim, amplification int, max float64, Orthogonal bool) *HashCommon
Rotation and translation and dimension scaling that are common to many LSH hash functions Dimensionality reduction is a random rotation followed by a projection (e.g taking the first k coordinates).
type LatticeHash ¶
type LatticeHash struct { H *HashCommon Scale float64 }
func NewLatticeHash ¶
func NewLatticeHash(dim int, width, max float64) *LatticeHash
This constructs a new leech lattice hash where the lattice points are the centers of spheres of radius sqrt(8) A random rotation and translation are applied and the space is scaled for the desired "R" - LSH hash width The JL-transform step is performed in the same matrix as rotation
func (*LatticeHash) HashWithDist ¶
This computes the hash and the squared distance to the closest vector
func (*LatticeHash) MultiProbeHashWithDist ¶
This returns the k closest hashes and squared distances
type MultiLatticeHash ¶
type MultiLatticeHash struct { Hashes []*LatticeHash Permutation []int Spans [][2]int UHash *UniversalHash }
func NewMultiLatticeHash ¶
func NewMultiLatticeHash(dim, copies int, width, max float64) *MultiLatticeHash
func (*MultiLatticeHash) HashWithDist ¶
func (*MultiLatticeHash) MultiHash ¶
func (m *MultiLatticeHash) MultiHash(v *vec.Vec, probes int) []uint64
func (*MultiLatticeHash) MultiProbeHashWithDist ¶
We have to iterate through each of the closest points of the sublattices to find the closest point
type UniversalHash ¶
func NewUniversalHash ¶
func NewUniversalHash(dim int) *UniversalHash