Exemple #1
0
func (m *Minhash) hash(v FeatureVector) *bit.Vector {
	bitNum := m.data.BitNum()
	minValues := generateMinValuesBuffer(bitNum)
	hashes := make([]uint64, bitNum)
	for i := range v {
		dim := v[i].Dim
		x := v[i].Value
		keyHash := calcStringHash(dim)
		for j := 0; j < bitNum; j++ {
			hashVal := calcHash(keyHash, uint64(j), x)
			if hashVal < minValues[j] {
				minValues[j] = hashVal
				hashes[j] = keyHash
			}
		}
	}

	bv := bit.NewVector(bitNum)
	for i := 0; i < len(hashes); i++ {
		if (hashes[i] & 1) == 1 {
			bv.Set(i)
		}
	}

	return bv
}
Exemple #2
0
func binarize(proj []float32) *bit.Vector {
	ret := bit.NewVector(len(proj))
	for i, x := range proj {
		if x > 0 {
			ret.Set(i)
		}
	}
	return ret
}