Rand

trait Rand[@specialized(Int, Double) +T] extends Serializable

A trait for monadic distributions. Provides support for use in for-comprehensions

Companion
object
trait Serializable
class Object
trait Matchable
class Any

Value members

Abstract methods

def draw(): T

Gets one sample from the distribution. Equivalent to sample()

Gets one sample from the distribution. Equivalent to sample()

Concrete methods

def condition(p: T => Boolean): Rand[T]
def drawOpt(): Option[T]

Overridden by filter/map/flatmap for monadic invocations. Basically, rejeciton samplers will return None here

Overridden by filter/map/flatmap for monadic invocations. Basically, rejeciton samplers will return None here

def filter(p: T => Boolean): Rand[T]
def flatMap[E](f: T => Rand[E]): Rand[E]

Converts a random sampler of one type to a random sampler of another type. Examples: randInt(10).flatMap(x => randInt(3 * x.asInstanceOf[Int]) gives a Rand[Int] in the range [0,30] Equivalently, for(x <- randInt(10); y <- randInt(30 *x)) yield y

Converts a random sampler of one type to a random sampler of another type. Examples: randInt(10).flatMap(x => randInt(3 * x.asInstanceOf[Int]) gives a Rand[Int] in the range [0,30] Equivalently, for(x <- randInt(10); y <- randInt(30 *x)) yield y

Value Params
f

the transform to apply to the sampled value.

def foreach(f: T => Unit): Unit

Samples one element and qpplies the provided function to it. Despite the name, the function is applied once. Sample usage:

Samples one element and qpplies the provided function to it. Despite the name, the function is applied once. Sample usage:

<pre> for(x &lt;- Rand.uniform) { println(x) } </pre>

Value Params
f

the function to be applied

def get(): T
def map[E](f: T => E): Rand[E]

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Converts a random sampler of one type to a random sampler of another type. Examples: uniform.map(_2) gives a Rand[Double] in the range [0,2] Equivalently, for(x <- uniform) yield 2x

Value Params
f

the transform to apply to the sampled value.

def sample(): T

Gets one sample from the distribution. Equivalent to get()

Gets one sample from the distribution. Equivalent to get()

def sample(n: Int): IndexedSeq[T]

Gets n samples from the distribution.

Gets n samples from the distribution.

def samples: Iterator[T]

An infinitely long iterator that samples repeatedly from the Rand

An infinitely long iterator that samples repeatedly from the Rand

Returns

an iterator that repeatedly samples

def samplesVector[U >: T](size: Int)(implicit m: ClassTag[U]): DenseVector[U]

Return a vector of samples.

Return a vector of samples.

def withFilter(p: T => Boolean): Rand[T]