Skip to content

Utils¤

soft_maximum(a, b, k) ¤

Soft differentiable maximum function.

Arguments:

  • a: First input tensor.
  • b: Second input tensor.
  • k: Hardness.
Source code in blackbirds/utils.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
def soft_maximum(a: torch.Tensor, b: torch.Tensor, k: float):
    """
    Soft differentiable maximum function.

    **Arguments:**

    - `a`: First input tensor.
    - `b`: Second input tensor.
    - `k`: Hardness.
    """
    return torch.log(torch.exp(k * a) + torch.exp(k * b)) / k

soft_minimum(a, b, k) ¤

Soft differentiable minimum function.

Arguments:

  • a: First input tensor.
  • b: Second input tensor.
  • k: Hardness.
Source code in blackbirds/utils.py
17
18
19
20
21
22
23
24
25
26
27
def soft_minimum(a: torch.Tensor, b: torch.Tensor, k: float):
    """
    Soft differentiable minimum function.

    **Arguments:**

    - `a`: First input tensor.
    - `b`: Second input tensor.
    - `k`: Hardness.
    """
    return -soft_maximum(-a, -b, k)