Documentation
API
SampleSet

SampleSet

Sample set distributions are one of the three distribution formats. Internally, they are stored as a list of numbers. It's useful to distinguish point set distributions from arbitrary lists of numbers to make it clear which functions are applicable.

Monte Carlo calculations typically result in sample set distributions.

All regular distribution function work on sample set distributions. In addition, there are several functions that only work on sample set distributions.

Constructors

make

Calls the correct conversion constructor, based on the corresponding input type, to create a sample set distribution

Signatures
SampleSet.make(Dist) => SampleSetDist
SampleSet.make(Number) => SampleSetDist
SampleSet.make(List(Number)) => SampleSetDist
SampleSet.make((index?: Number) => Number) => SampleSetDist
Examples
SampleSet(5)
SampleSet.make([3,5,2,3,5,2,3,5,2,3,3,5,3,2,3,1,1,3])
SampleSet.make({|i| sample(normal(5,2))})

Conversions

fromDist

Converts any distribution type into a sample set distribution.

Signatures
SampleSet.fromDist(Dist) => SampleSetDist
Examples
SampleSet.fromDist(Sym.normal(5,2))

fromNumber

Convert a number into a sample set distribution that contains n copies of that number. n refers to the model sample count.

Signatures
SampleSet.fromNumber(Number) => SampleSetDist
Examples
SampleSet.fromNumber(3)

fromList

Convert a list of numbers into a sample set distribution.

Signatures
SampleSet.fromList(List(Number)) => SampleSetDist
Examples
SampleSet.fromList([3,5,2,3,5,2,3,5,2,3,3,5,3,2,3,1,1,3])

toList

Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length.

Signatures
SampleSet.toList(SampleSetDist) => List(Number)
Examples
SampleSet.toList(SampleSet.fromDist(normal(5,2)))

fromFn

Convert a function into a sample set distribution by calling it n times.

Signatures
SampleSet.fromFn((index?: Number) => Number) => SampleSetDist
Examples
SampleSet.fromFn({|i| sample(normal(5,2))})

Transformations

map

Transforms a sample set distribution by applying a function to each sample. Returns a new sample set distribution.

Signatures
SampleSet.map(SampleSetDist, fn: (Number) => Number) => SampleSetDist
Examples
SampleSet.map(SampleSet.fromDist(normal(5,2)), {|x| x + 1})

map2

Transforms two sample set distributions by applying a function to each pair of samples. Returns a new sample set distribution.

Signatures
SampleSet.map2(SampleSetDist, SampleSetDist, fn: (Number, Number) => Number) => SampleSetDist
Examples
SampleSet.map2(
  SampleSet.fromDist(normal(5,2)),
  SampleSet.fromDist(normal(5,2)),
  {|x, y| x + y}
)

map3

Signatures
SampleSet.map3(SampleSetDist, SampleSetDist, SampleSetDist, fn: (Number, Number, Number) => Number) => SampleSetDist
Examples
SampleSet.map3(
  SampleSet.fromDist(normal(5,2)),
  SampleSet.fromDist(normal(5,2)),
  SampleSet.fromDist(normal(5,2)),
  {|x, y, z| max([x,y,z])}
)

mapN

Signatures
SampleSet.mapN(List(SampleSetDist), fn: (List(Number)) => Number) => SampleSetDist
Examples
SampleSet.mapN(
  [
    SampleSet.fromDist(normal(5,2)),
    SampleSet.fromDist(normal(5,2)),
    SampleSet.fromDist(normal(5,2))
  ],
  max
)