java - Data Structure for keeping frequency count of pairwise data? -
I have one hundred records in which a field is appended with same field based on ID. I want to know what is a good data structure to maintain the frequency calculation of that sequence, in whatever order in the sequence with a pair.
Sample data:
id feature 5F1.5F2 6F1 6F27F3 7F1 7F2 8F1 9 F1 10 F1
is the sample output:
F1 F2 F3 F1 0 3 1F 2 3 0 1F3 1 1 0
One The option is to use a 2-dimensional int array to sort all attributes and represent pairing data, but then waste / copy 2/3 of the array. For example array [i] [i] = 0
and array [i] [j] = array [j] [i]
. Given that I have hundreds of characteristics, this method will not work.
I thought about using a map but then one important example is to represent a pair (F1, F3). I am hoping for other solutions, if no one, I will use the map.
-
Create a square, say to use for hash keys < Code> MyPair that stores and overrides the pairs of your items
the object # is equal to (...)
(andobject # hashhead ()
) So that the order does not matter (for example, according to lexifography sequence). -
To store the frequency calculation
map & lt; MyPair, Integer & gt;
Create your pairs.
class mpeier {public end string attribute 1; Public end string feature2; Public MyPair (String S1, String S2) {// Order Features: So much comparison is order-independent (s1.compareTo (s2) & lt; = 0) {// TODO: zero probability 1 = s1; Feature2 = s2; } And {feature1 = s2; Feature2 = s1; }} @ Override Public Ent Hashod () {Return (S1 + S2). Hosh code (); // TODO: Cache for display} @ Override Public Boolean equivalent (return) {Return (such as MyPayport of Ipire) & amp; Amp; (It features 1. Angels (This feature 1)) & amp; Amp; (That.feature2.equals (this.feature2)); }}
Then a hash may be added as expected:
Maps & lt; MyPair, Integer & gt; Freq = new Hashmap & lt; MyPair, integer & gt; (); MyPair couple1 = New MyPair ("F1", "F2"); Freq.get (pair1); // = & gt; Zero freq.put (pair 1, 1); MyPair couple2 = new MyPayer ("F2", "F1"); Freq.get (pair2); // = & gt; 1
Comments
Post a Comment