我有时间序列数据。里面的数据要么是 1 要么是 0(可以是真或假,或任何其他二进制表示)。
例如,我有两个时间序列数据变量:
byte[] a1 = new byte[]{1,0,0,1,0};
byte[] a2 = new byte[]{1,1,1,0,1};
我现在比较这两个数组来计算组合发生的次数:
Map<String,Integer> count = new HashMap<String,Integer>();
//all the time series arrays have the same length. In real life each would timeseries array would have a length of about 100
for(int i=0; i<ai.length(); i++){
//a1[i] and a[2] occured. If this keys exists incremnt the count by one, otherwise insert the new key
count.merge(a1[i]+":"+a2[i], 1, Integer::sum)
}
基本上我正在寻找的输出是a1 = 1多少次a2 = 1和多少次a2 = 0?同样,什么时候a1 = 0有多少次a2 = 1,有多少次a2 = 0?
我面临的问题是我在我的程序中运行了数十亿次这些比较。完成的时间比我想要的要长得多。我知道这需要很长时间才能完成,但想知道是否有任何其他方法可以实现它以更快地计算它(我已经在使用多线程,我正在更多地研究可能的算法、数据结构的变化更改,开源库等)?
梵蒂冈之花
相关分类