dirichlet#

ivy.dirichlet(alpha, /, *, size=None, dtype=None, seed=None, out=None)[source]#

Draw size samples of dimension k from a Dirichlet distribution. A Dirichlet- distributed random variable can be seen as a multivariate generalization of a Beta distribution. The Dirichlet distribution is a conjugate prior of a multinomial distribution in Bayesian inference.

Parameters:
  • alpha (Union[Array, NativeArray, float, Sequence[float]]) – Sequence of floats of length k

  • size (Optional[Union[Shape, NativeShape]], default: None) – optional int or tuple of ints, Output shape. If the given shape is, e.g., (m, n), then m * n * k samples are drawn. Default is None, in which case a vector of length k is returned.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default floating-point data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – The drawn samples, of shape (size, k).

Examples

>>> alpha = [1.0, 2.0, 3.0]
>>> ivy.dirichlet(alpha)
ivy.array([0.10598304, 0.21537054, 0.67864642])
>>> alpha = [1.0, 2.0, 3.0]
>>> ivy.dirichlet(alpha, size = (2,3))
ivy.array([[[0.48006698, 0.07472073, 0.44521229],
    [0.55479872, 0.05426367, 0.39093761],
    [0.19531053, 0.51675832, 0.28793114]],
[[0.12315625, 0.29823365, 0.5786101 ],

[0.15564976, 0.50542368, 0.33892656], [0.1325352 , 0.44439589, 0.42306891]]])

Array.dirichlet(self, /, *, size=None, dtype=None, seed=None, out=None)[source]#

ivy.Array instance method variant of ivy.dirichlet. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.

Parameters:
  • self (Array) – Sequence of floats of length k

  • size (Optional[Union[Shape, NativeShape]], default: None) – optional int or tuple of ints, Output shape. If the given shape is, e.g., (m, n), then m * n * k samples are drawn. Default is None, in which case a vector of length k is returned.

  • dtype (Optional[Union[Dtype, NativeDtype]], default: None) – output array data type. If dtype is None, the output array data type will be the default floating-point data type. Default None

  • seed (Optional[int], default: None) – A python integer. Used to create a random seed distribution

  • out (Optional[Array], default: None) – optional output array, for writing the result to.

Return type:

Array

Returns:

ret – The drawn samples, of shape (size, k).

Examples

>>> alpha = ivy.array([1.0, 2.0, 3.0])
>>> alpha.dirichlet()
ivy.array([0.10598304, 0.21537054, 0.67864642])
>>> alpha = ivy.array([1.0, 2.0, 3.0])
>>> alpha.dirichlet(size = (2,3))
ivy.array([[[0.48006698, 0.07472073, 0.44521229],
    [0.55479872, 0.05426367, 0.39093761],
    [0.19531053, 0.51675832, 0.28793114]],
[[0.12315625, 0.29823365, 0.5786101 ],

[0.15564976, 0.50542368, 0.33892656], [0.1325352 , 0.44439589, 0.42306891]]])

Container.dirichlet(self, /, *, size=None, dtype=None, seed=None, out=None)[source]#

ivy.Container instance method variant of ivy.dirichlet. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.

Parameters:
  • self (Container) – Sequence of floats of length k

  • size (Optional[Union[Shape, NativeShape, Container]], default: None) – optional container including ints or tuple of ints, Output shape for the arrays in the input container.

  • dtype (Optional[Union[Dtype, NativeDtype, Container]], default: None) – output container array data type. If dtype is None, the output data type will be the default floating-point data type. Default None

  • seed (Optional[Union[int, Container]], default: None) – A python integer. Used to create a random seed distribution

  • out (Optional[Container], default: None) – optional output container, for writing the result to.

Return type:

Container

Returns:

ret – container including the drawn samples.

Examples

>>> alpha = ivy.Container(a=ivy.array([7,6,5]),                                   b=ivy.array([8,9,4]))
>>> size = ivy.Container(a=3, b=5)
>>> alpha.dirichlet(size)
{
    a: ivy.array(
        [[0.43643127, 0.32325703, 0.24031169],
         [0.34251311, 0.31692529, 0.3405616 ],
         [0.5319725 , 0.22458365, 0.24344385]]
        ),
    b: ivy.array(
        [[0.26588406, 0.61075421, 0.12336174],
         [0.51142915, 0.25041268, 0.23815817],
         [0.64042903, 0.25763214, 0.10193883],
         [0.31624692, 0.46567987, 0.21807321],
         [0.37677699, 0.39914594, 0.22407707]]
        )
}