Github user ChengXiangLi commented on a diff in the pull request:
https://github.com/apache/flink/pull/1110#discussion_r39003398
--- Diff:
flink-java/src/main/java/org/apache/flink/api/java/sampling/PoissonSampler.java
---
@@ -93,29 +98,59 @@ public boolean hasNext() {
}
}
}
-
- private void moveToNextElement() {
- while (input.hasNext()) {
+
+ public int poisson_ge1(double p){
+ // sample 'k' from Poisson(p), conditioned to k
>= 1
+ double q = Math.pow(Math.E, -p);
+ // simulate a poisson trial such that k >= 1
+ double t = q + (1 - q)*random.nextDouble();
+ int k = 1;
+ // continue standard poisson generation trials
+ t = t * random.nextDouble();
+ while (t > q) {
+ k++;
+ t = t * random.nextDouble();
+ }
+ return k;
+ }
+
+ private void moveToNextElement(int num) {
+ // skip elements with replication factor zero
+ int elementCount = 0;
+ while (input.hasNext() && elementCount < num){
currentElement = input.next();
- currentCount =
poissonDistribution.sample();
- if (currentCount > 0) {
- break;
+ elementCount++;
+ }
+ }
+
+ private void samplingProcess(){
+ if (fraction <= THRESHOLD) {
+ double u =
Math.max(random.nextDouble(), EPSILON);
+ int gap = (int) (Math.log(u) /
-fraction);
+ moveToNextElement(gap);
+ if (input.hasNext()) {
+ currentElement = input.next();
+ currentCount =
poisson_ge1(fraction);
+ }
+ }
+ else {
+ while (input.hasNext()){
+ currentElement = input.next();
+ currentCount =
poissonDistribution.sample();
+ if (currentCount > 0) {
+ break;
+ }
}
}
}
@Override
public T next() {
--- End diff --
Format: aggregate the public method at the top and private methods at the
bottom.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---