1

각 포인트에 가장 가까운 이웃을 찾고 karlhigley ANN 모델을 사용해 보았습니다. 다음은 코드 조각입니다.Karlhigley LSH ANN 결과가 null 인 가장 가까운 이웃을 찾는 모델

List<Tuple2<Object, SparseVector>> svList = new ArrayList<>(); 
     svList.add(new Tuple2<Object, SparseVector>(3L, 
       (Vectors.sparse(20, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, 
         new double[] { 5.0f, 3.0f, 4.0f, 5.0f, 5.0f, 1.0f, 5.0f, 3.0f, 4.0f, 5.0f, 5.0f, 3.0f, 4.0f, 
           5.0f, 5.0f, 1.0f, 5.0f, 3.0f, 4.0f, 5.0f }) 
         .toSparse()))); 
     svList.add(new Tuple2<Object, SparseVector>(4L, 
       (Vectors.sparse(20, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, 
         new double[] { 1.0f, 2.0f, 1.0f, 5.0f, 1.0f, 5.0f, 1.0f, 4.0f, 1.0f, 3.0, 1.0f, 2.0f, 1.0f, 
           5.0f, 1.0f, 5.0f, 1.0f, 4.0f, 1.0f, 3.0f }) 
         .toSparse()))); 
     svList.add(new Tuple2<Object, SparseVector>(6L, 
       (Vectors.sparse(20, new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 }, 
         new double[] { 5.0f, 3.0f, 4.0f, 1.0f, 5.0f, 4.0f, 1.0f, 3.0f, 4.0f, 5.0f, 5.0f, 3.0f, 4.0f, 
           1.0f, 5.0f, 4.0f, 1.0f, 3.0f, 4.0f, 5.0f }) 
         .toSparse()))); 

RDD<Tuple2<Object, SparseVector>> points = sc.parallelize(svList).rdd(); 

ANNModel annModel = 
       new ANN(20, "cosine") 
       .setTables(1) 
       .setSignatureLength(20).setRandomSeed(3) 
       .train(points,StorageLevel.MEMORY_AND_DISK()); 

JavaRDD<Tuple2<Object, Tuple2<Object, Object>[]>> neighbors2 = annModel.neighbors(3).toJavaRDD(); 

JavaRDD neighbors2는 모든 이웃과 그 점수를 null로 제공합니다. 아무도 내가 잘못 구현하고 올바른 방법으로 그것을 수행하는 방법을 이해하는데 도움이 될 수 있습니까?

이 내가 출력을

neighbors2.foreach(f->{ 
      for(int i=0;i<f._2.length;i++){ 
       System.out.println(f._1+"====="+f._2[i]._1+"---"+f._2[i]._2); 
      } 
     }); 

답변