mygrad.logaddexp2#
- class mygrad.logaddexp2(x1: ArrayLike, x2: ArrayLike, out: Tensor | ndarray | None = None, *, where: Mask = True, dtype: DTypeLikeReals = None, constant: bool | None = None)#
Logarithm of the sum of exponentiations of the inputs in base-2.
Calculates
log2(2**x1 + 2**x2)
. This function is useful in machine learning when the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the base-2 logarithm of the calculated probability can be used instead. This function allows adding probabilities stored in such a fashion.This docstring was adapted from that of numpy.logaddexp2 [1]
- Parameters:
- x1, x2ArrayLike
Input values. If
x1.shape != x2.shape
, they must be broadcastable to a common shape (which becomes the shape of the output).- outOptional[Union[Tensor, ndarray]]
A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated tensor is returned.
- constantOptional[bool]
If
True
, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e.constant.grad
will always returnNone
).Defaults to
False
for float-type data. Defaults toTrue
for integer-type data.Integer-type tensors must be constant.
- whereMask
This condition is broadcast over the input. At locations where the condition is True, the
out
tensor will be set to the ufunc result. Elsewhere, theout
tensor will retain its original value. Note that if an uninitialized out tensor is created via the defaultout=None
, locations within it where the condition is False will remain uninitialized.- dtypeOptional[DTypeLikeReals]
The dtype of the resulting tensor.
- Returns:
- logaddexp2Tensor
Base-2 logarithm of
2**x1 + 2**x2
.
See also
logaddexp
Logarithm of the sum of exponentiations of the inputs.
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.logaddexp2.html
Examples
>>> import mygrad as mg >>> prob1 = mg.log2(1e-50) >>> prob2 = mg.log2(2.5e-50) >>> prob12 = mg.logaddexp2(prob1, prob2) >>> prob1, prob2, prob12 (Tensor(-166.09640474436813), Tensor(-164.77447664948076), Tensor(-164.28904982231052)) >>> 2 ** prob12 Tensor(3.4999999999999914e-50)
- Attributes:
- signature
Methods
accumulate
([axis, dtype, out, constant])Not implemented
at
(indices[, b, constant])Not implemented
outer
(b, *[, dtype, out])Not Implemented
reduce
([axis, dtype, out, keepdims, ...])Not Implemented
reduceat
(indices[, axis, dtype, out])Not Implemented
resolve_dtypes
(dtypes, *[, signature, ...])Find the dtypes NumPy will use for the operation.
- __init__(*args, **kwargs)#
Methods
__init__
(*args, **kwargs)accumulate
([axis, dtype, out, constant])Not implemented
at
(indices[, b, constant])Not implemented
outer
(b, *[, dtype, out])Not Implemented
reduce
([axis, dtype, out, keepdims, ...])Not Implemented
reduceat
(indices[, axis, dtype, out])Not Implemented
resolve_dtypes
(dtypes, *[, signature, ...])Find the dtypes NumPy will use for the operation.
Attributes
identity
nargs
nin
nout
ntypes
signature
types