Search in sources :

Example 1 with IntObjMap

use of primal.primitive.adt.map.IntObjMap in project suite by stupidsing.

the class KmeansCluster method kNearestNeighbor.

public int kNearestNeighbor(List<float[]> points, float[] point0) {
    var map = new IntObjMap<AtomicInteger>();
    // 
    Read.from(// 
    points).index().map(// 
    (i, point) -> IntDblPair.of(i, sqdist(point0, point))).sortBy(// 
    pair -> pair.t1).take(// 
    points.size()).forEach(bin -> map.computeIfAbsent(bin.t0, c -> new AtomicInteger()).incrementAndGet());
    return ReadInt.from2(map).min((k, v) -> -v.v.get()).k;
}
Also used : ObjIntMap(primal.primitive.adt.map.ObjIntMap) ReadInt(primal.primitive.IntMoreVerbs.ReadInt) DblObjPair(primal.primitive.adt.pair.DblObjPair) New(primal.Verbs.New) Read(primal.MoreVerbs.Read) IntDblPair(primal.primitive.adt.pair.IntDblPair) ArrayList(java.util.ArrayList) IntObjMap(primal.primitive.adt.map.IntObjMap) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Vector(suite.math.linalg.Vector) Map(java.util.Map) LiftInt(primal.primitive.IntMoreVerbs.LiftInt) Obj_Int(primal.primitive.IntPrim.Obj_Int) Left(primal.Verbs.Left) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntObjMap(primal.primitive.adt.map.IntObjMap)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Read (primal.MoreVerbs.Read)1 Left (primal.Verbs.Left)1 New (primal.Verbs.New)1 LiftInt (primal.primitive.IntMoreVerbs.LiftInt)1 ReadInt (primal.primitive.IntMoreVerbs.ReadInt)1 Obj_Int (primal.primitive.IntPrim.Obj_Int)1 IntObjMap (primal.primitive.adt.map.IntObjMap)1 ObjIntMap (primal.primitive.adt.map.ObjIntMap)1 DblObjPair (primal.primitive.adt.pair.DblObjPair)1 IntDblPair (primal.primitive.adt.pair.IntDblPair)1 Vector (suite.math.linalg.Vector)1