我认为我将对数据进行排序(如果尚未排序),然后采用相邻的差异。将差异除以较小的数字,即得出百分比变化之间的差异。设置一个阈值,当更改超过该阈值时,启动一个新的“集群”。
编辑:C ++中的快速演示代码:
#include <iostream>#include <vector>#include <algorithm>#include <iterator>#include <numeric>#include <functional>int main() { std::vector<double> data{ 1.91, 2.87, 3.61, 10.91, 11.91, 12.82, 100.73, 100.71, 101.89, 200 }; // sort the input data std::sort(data.begin(), data.end()); // find the difference between each number and its predecessor std::vector<double> diffs; std::adjacent_difference(data.begin(), data.end(), std::back_inserter(diffs)); // convert differences to percentage changes std::transform(diffs.begin(), diffs.end(), data.begin(), diffs.begin(), std::divides<double>()); // print out the results for (int i = 0; i < data.size(); i++) { // if a difference exceeds 40%, start a new group: if (diffs[i] > 0.4) std::cout << "n"; // print out an item: std::cout << data[i] << "t"; } return 0;}结果:
1.91 2.87 3.6110.91 11.91 12.82100.71 100.73 101.89200



