I am faced with the following problem : I have binomial data, ie. data of the form trials/successes, with a list of features.
What I need is to sample without replacement from that data, ie. take a fraction $p$ (in my case 50%)of the examples. Since the data is aggregated, this is tricky.
So far my algorithm is the following : Denote by $h_i,c_i$ the number of trials/successes on each line, and $h'_i,c'_i$ the sampled trials/successes. I compute the total number of trials $H$ and then randomly generate $pH$ distinct integers between $1$ and $H$. I also compute the cumulative sum $(s_i = \sum_{t\leq i}h_t)_{i<n}$ of successes. Then for each sampled integer $k$, I find the first index $i$ such that $k \geq s_i$, and increment $h'_i$. If $k-s_i \leq c_i$ then I increment $c'_i$.
This algorithm works, but the problem is that when generating the random integers, I must store the whole list of integers, which means allocating space proportional to $H$, which in my case is incredibly large, and causes heap to overflow (I use JAVA with a 2Gb heap).
Any ideas to avoid storing that huge vector ? Or another simpler algorithm would be nice (I'm sure this one is largely suboptimal).
Edit : I want to add that the overall complexity of the algorithm should not be more than $O(log(n)H)$ where $n$ is the number of lines.