示例#1
0
func (this *Simple) Reduce() types.RPHashObject {
	vecs := this.rphashObject.GetVectorIterator()
	if !vecs.HasNext() {
		return this.rphashObject
	}
	vec := vecs.Next()
	blurValue := this.rphashObject.GetNumberOfBlurs()
	hash := defaults.NewHash(this.rphashObject.GetHashModulus())
	decoder := this.rphashObject.GetDecoderType()
	projector := defaults.NewProjector(this.rphashObject.GetDimensions(), decoder.GetDimensionality(), this.rphashObject.GetRandomSeed())
	lshfunc := defaults.NewLSH(hash, decoder, projector)
	var hashA []int64
	var centroids []types.Centroid
	for _, id := range this.rphashObject.GetPreviousTopID() {
		centroids = append(centroids, defaults.NewCentroidSimple(this.rphashObject.GetDimensions(), id))
	}
	for vecs.HasNext() {
		hashA = lshfunc.LSHHashStream(vec, blurValue)
		for _, cent := range centroids {
			for _, h := range hashA {
				if cent.GetIDs().Contains(h) {
					cent.UpdateVector(vec)
					break
				}
			}
		}
		vec = vecs.Next()
	}
	for _, cent := range centroids {
		this.rphashObject.AddCentroid(cent.Centroid())
	}
	return this.rphashObject
}
示例#2
0
func NewStream(_rphashObject types.RPHashObject) *Stream {
	_random := rand.New(rand.NewSource(_rphashObject.GetRandomSeed()))
	_hash := defaults.NewHash(_rphashObject.GetHashModulus())
	_decoder := _rphashObject.GetDecoderType()
	_statTest := defaults.NewStatTest(0.01)
	projections := _rphashObject.GetNumberOfProjections()
	k := _rphashObject.GetK() * projections
	_centroidCounter := defaults.NewCentroidCounter(k)
	_lshGroup := make([]types.LSH, projections)
	var _projector types.Projector
	for i := 0; i < projections; i++ {
		_projector = defaults.NewProjector(_rphashObject.GetDimensions(), _decoder.GetDimensionality(), _random.Int63())
		_lshGroup[i] = defaults.NewLSH(_hash, _decoder, _projector)
	}
	return &Stream{
		counts:          nil,
		centroids:       nil,
		variance:        0,
		centroidCounter: _centroidCounter,
		random:          _random,
		rphashObject:    _rphashObject,
		lshGroup:        _lshGroup,
		hash:            _hash,
		decoder:         _decoder,
		projector:       _projector,
		varTracker:      _statTest,
	}
}
示例#3
0
func (this *Simple) Map() types.RPHashObject {
	hash := defaults.NewHash(this.rphashObject.GetHashModulus())
	vecs := this.rphashObject.GetVectorIterator()
	if !vecs.HasNext() {
		return this.rphashObject
	}
	decoder := this.rphashObject.GetDecoderType()
	projector := defaults.NewProjector(this.rphashObject.GetDimensions(), decoder.GetDimensionality(), this.rphashObject.GetRandomSeed())
	lshfunc := defaults.NewLSH(hash, decoder, projector)
	var hashMod int64
	k := int(float64(this.rphashObject.GetK()) * math.Log(float64(this.rphashObject.GetK())))
	countMin := defaults.NewCountMinSketch(k)
	for vecs.HasNext() {
		vec := vecs.Next()
		hashMod = lshfunc.LSHHashSimple(vec)
		countMin.Add(hashMod)
	}
	this.rphashObject.SetPreviousTopID(countMin.GetTop())
	return this.rphashObject
}