nimble.random.data

nimble.random.data(numPoints, numFeatures, sparsity, pointNames='automatic', featureNames='automatic', elementType='float', returnType=None, name=None, randomSeed=None, *, useLog=None)

Generate a data object with random contents.

The range of values and the distribution are dependent on the elementType. For the default elementType “float”, the data will be a normal distribution of values with mean 0 and standard deviation of 1. If the elementType is “int”, values are sampled from a uniform distribution of the range 1 to 100.

Parameters:
  • numPoints (int) – The number of points in the returned object.

  • numFeatures (int) – The number of features in the returned object.

  • sparsity (float) – The likelihood that the value of a (point,feature) pair is zero.

  • elementType (str) – If ‘float’ (default) then the value of (point, feature) pairs are sampled from a normal distribution (location 0, scale 1). If elementType is ‘int’ then value of (point, feature) pairs are sampled from uniform integer distribution [1 100]. Zeros are not counted in/do not affect the aforementioned sampling distribution.

  • pointNames ('automatic', list, dict) – Names to be associated with the points in the returned object. If ‘automatic’, default names will be generated. Otherwise, may be specified explictly by a list-like or dict-like object, so long as all points in the data are assigned a name and the names for each point are unique.

  • featureNames ('automatic', list, dict) – Names to be associated with the features in the returned object. If ‘automatic’, default names will be generated. Otherwise, may be specified explictly by a list-like or dict-like object, so long as all features in the data are assigned a name and the names for each feature are unique.

  • returnType (str, None) – Indicates which Nimble data object to return. Options are the case sensitive strings “List”, “Matrix”, “Sparse” and “DataFrame”. If None, Nimble will detect the most appropriate type from the data and/or packages available in the environment.

  • name (str) – When not None, this value is set as the name attribute of the returned object.

  • randomSeed (int) – Provide a randomSeed for generating the random data. When None, the randomness is controlled by Nimble’s random seed.

  • useLog (bool, None) – Local control for whether to send object creation to the logger. If None (default), use the value as specified in the “logger” “enabledByDefault” configuration option. If True, send to the logger regardless of the global option. If False, do NOT send to the logger, regardless of the global option.

Returns:

nimble.core.data.Base – Subclass of Base object corresponding with the returnType.

Examples

Random integers.

>>> nimble.random.setSeed(42)
>>> ptNames = ['a', 'b', 'c', 'd', 'e']
>>> random = nimble.random.data(5, 5, 0, pointNames=ptNames,
...                             elementType='int')
>>> random
<Matrix 5pt x 5ft
     0   1   2   3   4
   ┌───────────────────
 a │ 22  54  72  91  21
 b │ 32  19   2  46  49
 c │ 86   1  91  91  69
 d │ 30  44  97  39  63
 e │ 42  92  32  55  65
>

Random floats, high sparsity.

>>> nimble.random.setSeed(42)
>>> sparse = nimble.random.data(5, 5, .9, returnType="Sparse")
>>> sparse
<Sparse 5pt x 5ft
       0      1       2      3       4
   ┌────────────────────────────────────
 0 │ 0.000   0.000  0.000   0.000  0.000
 1 │ 0.000   0.000  0.000  -1.283  0.000
 2 │ 0.000  -0.298  0.000   0.000  0.000
 3 │ 0.000   0.000  0.000   0.000  0.000
 4 │ 0.000   0.000  0.000   0.000  0.000
>