Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Best way to create a large,iterative database of frequency count, of binary numbers varying by 1 bit?
2 ビュー (過去 30 日間)
古いコメントを表示
So, I have a general question, not necessarily looking for code, but just a general idea of how to accomplish this task in the best way possible.
To start, I will have a string, that will be several thousands bits long, of simple 1's and 0's. What I want to do, is for each new bit (1 or 0) added to my string, take the last n bits off the end, and store that sequence into a database.
If the string is a NEW/unique string not seen before, I'd like to add it to the database. If it is a repeated sequence, I'd like to add to the count.
What I initially did, since these are binary numbers, using n-bits, was to create a matrix of all possible permutations, where the possible events would be 2^n. So if n==3, I would have 000,001,010,011,100,101,110,111.
And run through my big string 1 bit at a time, look at the latest n bits on the end, and compare to each value in my list and update the count of each occurrence.
What is important, is that I am able to compare the frequency of the sequences that differ by the last bit. So if n==3, I would like to compare for example, the frequency/percentage of occurrence of:
- 00 0 vs 00 1
- 01 0 vs 01 1
- 10 0 vs 10 1
- 11 0 vs 11 1
For now I'm not too concerned with efficiency, just a basic working framework in place.
So in general I am wondering if there is a better way to accomplish what I am trying to do other than the way I just described above?
Thanks!
0 件のコメント
回答 (1 件)
Walter Roberson
2013 年 11 月 8 日
Let B be the bit values in numeric form (0 vs 1), already arranged n wide per row
IDX = 2.^(n-1:-1:0).' * B + 1; %matrix multiplication not .*
numents = length(IDX);
counts = accumarray(IDX(:), 1, [1, 2^n]);
Now counts(K) is the number of occurrences of the bit sequence whose decimal equivalent is K-1.
The marginals are now
T = 2 * (0:(2^(n-1)-1));
marginals = counts([T + 1, T + 2]);
I did not convert the marginal counts into ratios or relative percentages because of the possibility that one or both might be 0.
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!