【发布时间】:2013-04-06 01:57:07
【问题描述】:
当我在计算标准差的过程中尝试检索单个值以查找方差时出现错误。我不知道是使用 .get() 还是 .getValue 我迷路了。我已经计算了平均值。
final ArrayList<Map.Entry<String,NumberHolder>> entries = new ArrayList<Map.Entry<String,NumberHolder>>(uaCount.entrySet());
for(Map.Entry<String,NumberHolder> entry : entries) //iterating over the sorted hashmap
{
double temp = 0;
double variance = 0;
for (int i = 0; i <= entry.getValue().occurrences ; i ++)
{
temp += ((entry.getValue(i).singleValues) - average)*((entry.getValue(i).singleValues) - average);
variance = temp/entry.getValue().occurrences;
}
double stdDev = Math.sqrt(variance);
这是我的 NumberHolder 类,我填充在我的主要功能中。我使用这个方程来计算标准偏差:http://www.mathsisfun.com/data/standard-deviation-formulas.html
根据我的代码,出现次数为 N,singleValues 数组列表中的值为 Xi
public static class NumberHolder
{
public int occurrences = 0;
public int sumtime_in_milliseconds = 0;
public ArrayList<Long> singleValues = new ArrayList<Long>();
}
这是我得到的错误。 :
The method getValue() in the type Map.Entry<String,series3.NumberHolder> is not applicable for the arguments (int).
如果您需要查看更多代码,请尽管问,我不想放任何不必要的东西,但我可能错过了一些东西。
【问题讨论】:
标签: java arraylist hashmap standard-deviation