File size: 598 Bytes
0cfefd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""对称对数归一化算子 symlog / symexp。

公式:
    symlog(x) = sign(x) * log(|x| + 1)
    symexp(y) = sign(y) * (exp(|y|) - 1)

用于运动学 / 坐标 / 内外参的归一化,使大幅值被压缩、保持可逆。
"""

from __future__ import annotations

import torch


def symlog(x: torch.Tensor) -> torch.Tensor:
    """对称对数压缩:sign(x) * log(|x| + 1)。"""
    return torch.sign(x) * torch.log1p(torch.abs(x))


def symexp(y: torch.Tensor) -> torch.Tensor:
    """symlog 的逆:sign(y) * (exp(|y|) - 1)。"""
    return torch.sign(y) * torch.expm1(torch.abs(y))