DistributionRange
- class DistributionRange(n, dist, ...params)
Wraps a distributing function into a RangeObject-like API, so a statistical distribution (e.g. normal, poisson, binomial) can be dropped directly into a job’s input set, or used as one of the ranges inside a MultiRangeObject.
DistributionRange objects are normally created via the factory functions in the
setexport ofdcp/stats-ranges, e.g.stats.set.normal(10, 0, 1), rather than by calling this constructor directly.- Arguments:
n (number) – Size of the generated set.
dist (string) – Name of a distributing function exported by
dcp/stats-ranges’sdistributorobject (e.g.'normal','poisson','binomial').params – Additional parameters passed through to the named distributing function, following its
kandnparameters.
Properties
length
- DistributionRange.length
- Type:
number
Size of the generated set, as passed to the constructor.
dist
- DistributionRange.dist
- Type:
string
Name of the distributing function backing this object.
params
- DistributionRange.params
- Type:
Array
Additional parameters passed to the distributing function.
Methods
filter
slice
nthValue
- nthValue(n)
Returns the nth value of the distribution, by calling the underlying distributing function with (n, length, …params). If the distribution has already been resolved (see
DistributionRange.materialize()), returns the nth value of the resolved array instead.- Arguments:
n (number) – Index to look up.
- Return type:
number
materialize
- DistributionRange.materialize(now=true)
Resolve the distribution to a static array
- Arguments:
now – If false, then set a flag to materialize on the scheduler. Default: materialize now
toObject
- toObject()
Resolves the distribution (see
DistributionRange.materialize()) and returns a plain object with length, dist, params, and the resolved values, suitable for reconstructing an equivalent DistributionRange later.- Return type:
object
toString
- toString()
Returns a descriptor string, e.g.
[object DistributionRange normal(10,0,1)], which can be passed back into the DistributionRange constructor to reconstruct an equivalent object.- Return type:
string
Example
const stats = require('dcp/stats-ranges');
const job = compute.for(stats.set.normal(10, 0, 1), function (x) {
progress(1);
return x;
});