Java 在hadoop上运行时,kmeans中的BoundsException数组

Java 在hadoop上运行时,kmeans中的BoundsException数组,java,hadoop,k-means,Java,Hadoop,K Means,我正在尝试使用eclipse在hadoop上运行KMeans算法。我提到了这个程序 为此,数据被硬编码。不需要外部数据文件。 当我运行这个程序时,我得到了DistanceMeasurer方法中BoundsException的数组。我不明白为什么会出现这个错误。 这是测距仪的代码 package com.clustering.model; public class DistanceMeasurer{ public static final double measureDistance(Cluste

我正在尝试使用eclipse在hadoop上运行KMeans算法。我提到了这个程序

为此,数据被硬编码。不需要外部数据文件。 当我运行这个程序时,我得到了DistanceMeasurer方法中BoundsException的数组。我不明白为什么会出现这个错误。 这是测距仪的代码

package com.clustering.model;
public class DistanceMeasurer{
public static final double measureDistance(ClusterCenter center,Vector v){
double sum=0;
int length=v.getVector().length;
for(int i=0; i<length; i++){
sum+=Math.abs(center.getCenter().getVector()[i]-v.getVector()[i]);
}
return sum;
}
}
请帮我解决这个问题。
谢谢

那么,你确定“中心”和“向量”的维数相同吗?为什么不在循环之前打印出“中心”的长度


另外,顺便提一下,为什么要使用L1距离?

您的循环条件是错误的,它应该检查向量中两个数组的长度。 您可以将两个数组的长度设置为条件,也可以根据需要进行更改

int length=v.getVector().length;
for(int i=0; i<length && i< center.getCenter().getVector().length; i++){
sum+=Math.abs(center.getCenter().getVector()[i]-v.getVector()[i]);
}

也许这个center.getCenter.getVector的长度不同?嘿,谢谢你的建议。现在,map和reduce阶段都被执行,并且100%。但是现在我得到了这个security.UserGroupInformation:priviledededActionException as:hduser原因:java.io.IOException:java.io.IOException:org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatusFileInputFormat.java:193 at处的作业中没有指定输入路径org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat.listStatusSequenceFileInputFormat.java:55@Bhimasen您可以发布新问题:
int length=v.getVector().length;
for(int i=0; i<length && i< center.getCenter().getVector().length; i++){
sum+=Math.abs(center.getCenter().getVector()[i]-v.getVector()[i]);
}