Skip to content

Commit

Permalink
Simplify LiLSampling powers
Browse files Browse the repository at this point in the history
  • Loading branch information
gstamatelat committed Jul 2, 2018
1 parent 610a5f7 commit 9a0eba0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/gr/james/sampling/LiLSampling.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static <E> RandomSamplingCollector<E> collector(int sampleSize, Random ra

@Override
void init(int sampleSize, Random random) {
W = Math.exp(Math.log(RandomSamplingUtils.randomExclusive(random)) / sampleSize);
// W = Math.exp(Math.log(RandomSamplingUtils.randomExclusive(random)) / sampleSize);
W = Math.pow(RandomSamplingUtils.randomExclusive(random), 1.0 / sampleSize);
}

@Override
Expand All @@ -63,7 +64,8 @@ long skipLength(long streamSize, int sampleSize, Random random) {
if (skip == Long.MIN_VALUE) { // Sometimes when W is very small, 1 - W = 1 and Math.log(1) = +0 instead of -0
skip = Long.MAX_VALUE; // This results in negative infinity skip
}
W = W * Math.exp(Math.log(random2) / sampleSize);
// W = W * Math.exp(Math.log(random2) / sampleSize);
W = W * Math.pow(random2, 1.0 / sampleSize);
return skip;
}
}
2 changes: 1 addition & 1 deletion src/test/java/gr/james/sampling/RandomSamplingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Collection<Supplier<RandomSampling<Integer>>> implementations() {
@Test
public void correctness() {
final int[] streamSizes = {1, 20, 100};
final int[] repsSizes = {1000000, 1000000, 1000000};
final int[] repsSizes = {1000000, 1000000, 2000000};

Assert.assertEquals(streamSizes.length, repsSizes.length);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static Collection<Supplier<WeightedRandomSampling<Integer>>> implementati
@Test
public void correctness() {
final int[] streamSizes = {1, 20, 100};
final int[] repsSizes = {1000000, 1000000, 1000000};
final int[] repsSizes = {1000000, 1000000, 2000000};

Assert.assertEquals(streamSizes.length, repsSizes.length);

Expand Down

0 comments on commit 9a0eba0

Please sign in to comment.