Skip to content

Commit

Permalink
Simplify VitterXSampling
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jun 28, 2018
1 parent 39da9b6 commit 1d19c8f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/gr/james/sampling/VitterXSampling.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ public static <E> RandomSamplingCollector<E> collector(int sampleSize, Random ra

@Override
long skipLength(long streamSize, int sampleSize, Random random) {
long currentStream = streamSize + 1;
streamSize++;

final double r = random.nextDouble();
long gamma = 0;
long skipCount = 0;

double quot = (currentStream - sampleSize) / (double) currentStream;
while (quot > r && currentStream > 0) {
gamma++;
currentStream++;
quot = (quot * (currentStream - sampleSize)) / (double) currentStream;
double quot = (streamSize - sampleSize) / (double) streamSize;
while (quot > r && streamSize > 0) {
skipCount++;
streamSize++;
quot = (quot * (streamSize - sampleSize)) / (double) streamSize;
}

return gamma;
return skipCount;
}

/**
Expand Down

0 comments on commit 1d19c8f

Please sign in to comment.