Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add sample stage #23

Merged
merged 2 commits into from
Aug 29, 2016
Merged

Conversation

zhxiaogg
Copy link
Contributor

ref #21

I started by a simple implementation.

questions:

  • I tried def apply(maxStep:Int, random:Random=Random) for random sampling, but looks wired. Any suggestion?
  • need to implement time-based sampling?

Feel free to review or close it.

completeStage()
}

@throws[Exception](classOf[Exception])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these throws should not be needed, since this is scala

@patriknw
Copy link
Member

patriknw commented Jul 1, 2016

looking good, @zhxiaogg


@throws[Exception](classOf[Exception])
override def onUpstreamFinish(): Unit = {
completeStage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the default anyway, no need for the override.

@drewhk
Copy link
Member

drewhk commented Jul 1, 2016

Small improvements needed, otherwise looks good.

@johanandren
Copy link
Member

LGTM

*/
def random[T](maxStep: Int = 1000): Sample[T] = {
require(maxStep > 0, "max step for a random sampling must > 0")
Sample[T](() => ThreadLocalRandom.current().nextInt(maxStep) + 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the numbers returned by this call are super-bad quality from a scientific point of view. I think this should be detailed in the scaladoc and recommend people that need really good behaved sampling to use their own (XorShift family for example) explicitly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this does not provide truly independent sampling either, so maybe call this randomStep instead of random.

@drewhk
Copy link
Member

drewhk commented Aug 8, 2016

I don't want to prolong this review forever, but I feel an interface T => Boolean instead of T => Int can be more useful if mutable state is allowed in the function. That can model both the current sampling methods, and also new ones that are not covered by these. WDYT?

@2m
Copy link
Member

2m commented Aug 11, 2016

@zhxiaogg can you address latest comments and move these two files under contrib directory because of #39?

@zhxiaogg
Copy link
Contributor Author

@2m sure, no problem.

@drewhk I think the current interface of Sample case class is enough for people to inject their own sampling logic (eg. XorShift).
My first thought is that sampling is based on time or space, irrelevant of what the element is or looks like. So the current constructor parameter of Sample is actually () => Int(based on space), not T => Int. Besides if we change it to T => Boolean, we can use filter directly and eventually there seems no need of Sample.

@drewhk
Copy link
Member

drewhk commented Aug 29, 2016

Ok, thanks for explaining. LGTM

@@ -0,0 +1,74 @@
package akka.stream.contrib
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do license headers in this repo?
Thought we should

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do. Missing header here was an indication that sbt did not see that file. And that was because it was not moved to the contrib dir. I created a PR to fix it: #55

@ktoso
Copy link
Member

ktoso commented Aug 29, 2016

It's useful enough, thanks @zhxiaogg - LGTM

@ktoso ktoso merged commit a2602a8 into akka:master Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants