08-14-2015 10:32 AM
Hello guys--
I have an array contains only zeros and ones.
For example: A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0]
I have created two arrays, Azeros and Aones. The Aones array holds counts of number of consecutive 1s. The Azeros array accumulates counts of consecutive 0s.
Given the array A = [1,1,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0], then
Aones = [2,1,6,4,3]
Azeros= [1,2,4,1,5]
So, Aones and Azeros hold the counts of each set of consecutive ones and zeros respectively.
I did an algorithm that uses loops and case structure to find the counts of consecutive ones sets and store them in Aones. Then run the algorithm again for zeros and store them in Azeros. The data sets I'm working on are huge! So, I'm lookign for the best solution (fastest algorithm) for above case.
Any help?
Thanks
WB
Solved! Go to Solution.
08-14-2015 10:35 AM
Why don't you start the ball rolling by posting your existing code. If this is a homework problem, you really need to put some effort into it ... Besides, it will prevent us from simply recreating your solution (and will give us a benchmark to which to compare our "fast" algorithms).
Bob Schor
08-14-2015 10:42 AM
This is a part of research project. Not a homework!! The way my algorithm is running is explained. If you have another way to do it please let me hear it and I take care of the performance analysis.
08-14-2015 10:49 AM
I did an algorithm that uses loops and case structure to find the counts of consecutive ones sets and store them in Aones. Then run the algorithm again for zeros and store them in Azeros. The data sets I'm working on are huge! So, I'm lookign for the best solution (fastest algorithm) for above case.
"I did an algorithm that uses loops and case structure" is not exactly a specific description of what you are doing. Posting the code is the best way for us to see exactly what you did and exactly how it can be improved.
08-14-2015 11:04 AM
I would initialize 2 arrays half size (worst case scenario, depends on your cluster sizes) with ones (or typical cluster size) and for looped the original array, replacing current element in the end of the cluster. Then cut away the not used portion.
Minimum change of array size, initializing with ones even does not update values, just shifts counter. only one big loop.
PS: cluster - portion of consecutive ones or zeros
08-14-2015 11:17 AM
Thanks Alex-- How many case structures would you need inside the big loop?
08-14-2015 11:29 AM
08-14-2015 11:33 AM - edited 08-14-2015 11:33 AM
Conditional Tunnels makes life a little easier...
08-14-2015 11:38 AM
Thanks crossrulz... This is a pretty way to do it! I will try it out and check if it will run faster. P.S. Each data set I have is >= 2.5GB. Could you please upload the VI you did?
08-14-2015 11:41 AM
I think this might be the fastest solution. Unfortunately shift registers won't let you do parallelization, but I think that's the only way.
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'