2

Is there support for sampling from a multinomial distribution without replacement? I'm imagining some sort of code like:

import breeze.linalg._
import breeze.stats.distributions._


val params = DenseVector(0.1, 0.3, 0.2, 0.4)
val mult = new Multinomial(params)

val indices = (0 until 4).toArray
val sampled_indices = mult.sample(n = 2, replacement = false)
val other_indices = (indices.toSet.diff(sampled_indices.toSet)).toArray

, where the most relevant bit is the "replacement = false" argument passed to mult.sample(). I'd like to ensure that I sample unique indices, and I'd like to do so without defining a new multinomial distribution for each draw.

Or if there's a better way to accomplish the same result, I'd be happy to hear about that as well.

sinwav
  • 724
  • 1
  • 7
  • 20

1 Answers1

1

There's nothing built in, sorry. You could do something like

(0 until 2).foldLeft(Seq.empty[Int])( (seq, _) => mult.filter(!seq.contains(_)).draw :+ seq)

Really you want an unfold (or, I guess, a method that does what you listed. If you file an issue on GH, hopefully we'll get to it sometime soon...

dlwh
  • 2,257
  • 11
  • 23
  • Sure. I'm new to open source, so I don't know the conventions for filing an issue. Is it simply a message describing the feature I'd like? Or do I need to propose a solution? – sinwav Jun 29 '14 at 06:34
  • Just propose the feature. Ideally with the syntax you'd like to have. (Basically you can copy and paste your question here, maybe changing the wording from "Is there..." to "I'd like there to be"). If you have an idea on how to fix it, that's great, and a partial solution will make me more likely to get to it sooner. But definitely not required. – dlwh Jun 30 '14 at 03:11