Bernoulli#

  • Domain: ai.onnx

  • Since version: 22

Draws binary random numbers (0 or 1) from a Bernoulli distribution. The input tensor should be a tensor containing probabilities p (a value in the range [0,1]) to be used for drawing the binary random number, where an output of 1 is produced with probability p and an output of 0 is produced with probability (1-p).

This operator is non-deterministic and may not produce the same values in different implementations (even if a seed is specified).

Inputs

  • input (T1): All values in input have to be in the range:[0, 1].

Outputs

  • output (T2): The returned output tensor only has values 0 or 1, same shape as input tensor.

Attributes

  • dtype (int): The data type for the elements of the output tensor. if not specified, we will use the data type of the input tensor.

  • seed (float): (Optional) Seed to the random generator, if not specified we will auto generate one.

Type Constraints

  • T1: Constrain input types to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

  • T2: Constrain output types to all numeric tensors and bool tensors. Allowed types: tensor(bfloat16), tensor(bool), tensor(double), tensor(float), tensor(float16), tensor(int16), tensor(int32), tensor(int64), tensor(int8), tensor(uint16), tensor(uint32), tensor(uint64), tensor(uint8).

Examples#

test_cc_bernoulli

Node:
  Bernoulli(x) -> (y)
Inputs:
  x: shape=(10,), dtype=float32
    [0.  , 0.1 , 0.25, 0.4 , 0.5 , 0.6 , 0.75, 0.9 , 1.  , 0.5 ]

Outputs:
  y: shape=(10,), dtype=float32
    [0., 0., 0., 0., 0., 1., 1., 1., 1., 1.]

test_cc_bernoulli_double

Node:
  Bernoulli(x) -> (y)
  Attributes:
    dtype = 11
Inputs:
  x: shape=(10,), dtype=float32
    [0.  , 0.1 , 0.25, 0.4 , 0.5 , 0.6 , 0.75, 0.9 , 1.  , 0.5 ]

Outputs:
  y: shape=(10,), dtype=float64
    [0., 0., 0., 0., 0., 1., 1., 1., 1., 1.]

test_cc_bernoulli_seed

Node:
  Bernoulli(x) -> (y)
  Attributes:
    seed = 0.0
Inputs:
  x: shape=(10,), dtype=float32
    [0.  , 0.1 , 0.25, 0.4 , 0.5 , 0.6 , 0.75, 0.9 , 1.  , 0.5 ]

Outputs:
  y: shape=(10,), dtype=float32
    [0., 0., 0., 0., 0., 1., 1., 1., 1., 1.]

Differences with previous version (15)#

SchemaDiff: Bernoulli (domain 'ai.onnx')

  • old version: 15

  • new version: 22

  • breaking: no

Type constraints:

  • changed ‘T1’: added types: [‘tensor(bfloat16)’]

Version History#