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.GetDimension(), decoder.GetDimensionality(), this.rphashObject.GetRandomSeed()) lshfunc := defaults.NewLSH(decoder, projector, hash) var hash []int32 var centroids []types.Centroid for _, id := range this.rphashObject.GetPreviousTopID() { centroids = append(centroids, defaults.NewCentroid(this.rphashObject.GetDimension(), id)) } for vecs.HasNext() { hash = lshfunc.LSHHashStream(vec, blurValue) for _, cent := range centroids { for h := range hash { if cent.ids.Contains(h) { cent.UpdateVector(vec) break } } } vec = vecs.Next() } for _, cent := range centroids { this.rphashObject.AddCentroid(cent.Centroid()) } return this.rphashObject }
func (this *Stream) AddVectorOnlineStep(vec []float64) int32 { var hash []int32 c := defaults.NewCentroid(vec) tmpvar := this.varTracker.UpdateVarianceSample(vec) if this.variance != tmpvar { for _, lsh := range this.lshGroup { lsh.UpdateDecoderVariance(tmpvar) } this.variance = tmpvar } for _, lsh := range this.lshGroup { hash, _ = lsh.LSHHashStream(vec, this.rphashObject.GetNumberOfBlurs()) for _, h := range hash { c.AddID(h) } } this.centroidCounter.Add(c) return this.centroidCounter.GetCount() }