1
我想找到最接近我的每個點的鄰居,我嘗試了使用karlhigley神經網絡模型。這是一段代碼Karlhigley LSH人工神經網絡模型尋找最近的鄰居給零結果
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給我所有的鄰居和他們的分數爲空。任何人都可以幫助我理解我在哪裏實施錯誤,以及如何以正確的方式做到這一點?
這是怎麼了打印輸出
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);
}
});