ruoguang / Abnormal-check

An algorithm based on Java implementation, can automatically check the set of outliers in a set of data, eliminate these outliers, and finally get normal data.基于java实现的能够自动检查出一组数据中的异常值的集合,剔除这些异常集,得到正常数据。
https://github.com/ruoguang/Abnormal-check
11 stars 6 forks source link

fusionToList方法存在bug,因为Set是无序集合 #1

Open shileiyuan86 opened 2 years ago

shileiyuan86 commented 2 years ago

fusionToList方法存在bug,Set是无序集合,里面异常数据索引有可能不是按照正常顺序存放的。所以在for循环中不会与datas索引一样按顺序取数据。 @Override public double[] fusionToList(int sensitivity, double[] datas) { Set set = oc(sensitivity, datas); double[] doubles = new double[datas.length - set.size()]; Iterator iterator = set.iterator(); Integer next = iterator.hasNext() ? iterator.next() : null; int index = 0; for (int i = 0; i < datas.length; i++) { if (next != null && next.equals(i)) { next = iterator.hasNext() ? iterator.next() : null; continue; } doubles[index++] = datas[i]; } return doubles; }

shileiyuan86 commented 2 years ago

可以这样,可不用考虑索引顺序影响: Set set = oc(sensitivity, datas); double[] doubles = new double[datas.length - set.size()]; int index = 0; for (int i = 0; i < datas.length; i++) { if (!set.contains(i)) { doubles[index++] = datas[i]; } } return doubles;