所以我正在使用指南针角度(度数)的应用程序。我已经成功地确定角度的平均值的计算,通过以下(在http://en.wikipedia.org/wiki/Directional_statistics#The_fundamental_difference_between_linear_and_circular_statistics找到):计算角度的标准偏差?
double calcMean(ArrayList<Double> angles){
double sin = 0;
double cos = 0;
for(int i = 0; i < angles.size(); i++){
sin += Math.sin(angles.get(i) * (Math.PI/180.0));
cos += Math.cos(angles.get(i) * (Math.PI/180.0));
}
sin /= angles.size();
cos /= angles.size();
double result =Math.atan2(sin,cos)*(180/Math.PI);
if(cos > 0 && sin < 0) result += 360;
else if(cos < 0) result += 180;
return result;
}
所以我正确地得到我的平均值/平均值,但我不能得到适当的方差/ stddev值。我很确定我正在计算我的方差,但不能想出一个正确的方法来做到这一点。
这里是我如何计算方差:
double calcVariance(ArrayList<Double> angles){
//THIS IS WHERE I DON'T KNOW WHAT TO PUT
ArrayList<Double> normalizedList = new ArrayList<Double>();
for(int i = 0; i < angles.size(); i++){
double sin = Math.sin(angles.get(i) * (Math.PI/180));
double cos = Math.cos(angles.get(i) * (Math.PI/180));
normalizedList.add(Math.atan2(sin,cos)*(180/Math.PI));
}
double mean = calcMean(angles);
ArrayList<Double> squaredDifference = new ArrayList<Double>();
for(int i = 0; i < normalizedList.size(); i++){
squaredDifference.add(Math.pow(normalizedList.get(i) - mean,2));
}
double result = 0;
for(int i = 0; i < squaredDifference.size(); i++){
result+=squaredDifference.get(i);
}
return result/squaredDifference.size();
}
虽然它的计算方差的正确方法,我不是我应该使用。我认为我应该使用反正切,但标准偏差/方差值似乎没有关系。帮帮我?
编辑: 实施例:输入值0,350,1,0,0,0,1,358,9,1结果与0.0014平均角(因为角度是如此接近零),但如果只是做一个非角度平均,你会得到72 ...这是离开的方式。由于我不知道如何操纵个人价值观,因此计算的方差是25074,导致158度的标准偏差,这是疯狂的! (它应该只是几度)我认为我需要做的是正确地对各个值进行标准化,以便我可以得到正确的方差/标准差值。
我没有完全分析,但是这个代码似乎需要Math.atan2(Y,X) – maniek
@maniek - 本来我做到了这一点(并把它放回最近),结果都是一样的。我尝试了上面的方法以及atan2,我得到的结果在12或13个数量级内是相同的。 – snotyak
编辑:看起来像使用atan2地址Chechulin的帖子。我会编辑我的问题。 – snotyak