我有时间序列数据。内部数据的值为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
?
我所面临的问题是,我在我的程序中运行了数十亿个这样的比较。完成的时间比我想要的要长得多。我了解这项工作的性质需要很长时间才能完成,但我想知道是否还有其他方法可以更快地实现这项工作(我已经在使用多线程,我正在更多地研究算法的更改、数据结构更改、开源库等)?