wearelumenai / distclus

Distance based clustering
MIT License
3 stars 2 forks source link

Return distance in Predic func #4

Closed ydarma closed 4 years ago

ydarma commented 5 years ago

In OnlineClust interface, the Predict function should return also the distance to the nearest cluster. This information could be useful to the user.

Predict(elemt Elemt) (Elemt, int, error)

should become

Predict(elemt Elemt) (Elemt, int, float64, error)
ydarma commented 5 years ago

Implementation is trivial : in algo.go:

func (algo *Algo) Predict(elemt Elemt) (pred Elemt, label int, dist float64, err error) {
    var clust Clust
    clust, err = algo.Centroids()

    if err == nil {
        pred, label, dist = clust.Assign(elemt, algo.space)
    }

    return
}