服从正态分布的正弦函数、余弦函数期望

服从正态分布的正弦函数期望

服从正态分布的正弦函数、余弦函数期望。

如果X服从均值为 μ \mu μ,方差为 σ 2 \sigma^2 σ2的正态分布,计算sin(X)cos(X)的数学期望。

利用特征函数(Characteristic Function)Wiki-Characteristic Function,我们知道 X ∼ N ( μ , σ 2 ) X\sim N(\mu, \sigma^2) X∼N(μ,σ2)的特征函数为:
φ X ( t ) = E ( e i t X ) = e x p ( i μ t − σ 2 t 2 2 ) = e x p ( − σ 2 t 2 / 2 ) e x p ( i μ t ) \varphi_{X(t)}=E(e^{itX})=exp\left({i\mu t - \dfrac{\sigma^2t^2}{2}}\right)=exp(-\sigma^2t^2/2)exp(i\mu t) φX(t)=E(eitX)=exp(iμt−2σ2t2)=exp(−σ2t2/2)exp(iμt)

根据欧拉公式:
e i x = cos ⁡ ( x ) + i sin ⁡ ( x ) e^{ix} = \cos(x)+i\sin(x) eix=cos(x)+isin(x)

E ( e i t X ) = e x p ( i μ t − σ 2 t 2 2 ) = e x p ( − σ 2 t 2 / 2 ) e x p ( i μ t ) = e x p ( − σ 2 t 2 / 2 ) [ cos ⁡ ( μ t ) + i sin ⁡ ( μ t ) ] = e x p ( − σ 2 t 2 / 2 ) cos ⁡ ( μ t ) + e x p ( − σ 2 t 2 / 2 ) sin ⁡ ( μ t ) i = R e a l ( E ( e i t X ) ) + i I m ( E ( e i t X ) ) \begin{aligned} E(e^{itX})&=exp\left({i\mu t - \dfrac{\sigma^2t^2}{2}}\right) \\ &=exp(-\sigma^2t^2/2)exp(i\mu t) \\ &=exp(-\sigma^2t^2/2)\left[\cos(\mu t)+i\sin(\mu t)\right]\\ &=exp(-\sigma^2t^2/2)\cos(\mu t) +exp(-\sigma^2t^2/2)\sin(\mu t)i \\ &=Real(E(e^{itX}))+iIm(E(e^{itX})) \end{aligned} E(eitX)=exp(iμt−2σ2t2)=exp(−σ2t2/2)exp(iμt)=exp(−σ2t2/2)[cos(μt)+isin(μt)]=exp(−σ2t2/2)cos(μt)+exp(−σ2t2/2)sin(μt)i=Real(E(eitX))+iIm(E(eitX))

上述数学期望变为:
E ( e i t X ) = E ( cos ⁡ ( t X ) + i sin ⁡ ( t X ) ) = E ( c o s ( t X ) ) + i E ( s i n ( t X ) ) = R e a l ( E ( e i t X ) ) + i I m ( E ( e i t X ) ) \begin{aligned} E(e^{itX})&=E\left(\cos(tX)+i\sin(tX)\right)\\ &= E(cos(tX)) + iE(sin(tX))\\ &=Real(E(e^{itX}))+iIm(E(e^{itX})) \end{aligned} E(eitX)=E(cos(tX)+isin(tX))=E(cos(tX))+iE(sin(tX))=Real(E(eitX))+iIm(E(eitX))

对比上述的实数部分和虚数部分,得到:
E ( cos ⁡ ( t X ) ) = e x p ( − σ 2 t 2 / 2 ) cos ⁡ ( μ t ) E ( sin ⁡ ( t X ) ) = e x p ( − σ 2 t 2 / 2 ) s i n ( μ t ) E(\cos(tX))=exp(-\sigma^2t^2/2)\cos(\mu t)\\ E(\sin(tX))=exp(-\sigma^2t^2/2)sin(\mu t) E(cos(tX))=exp(−σ2t2/2)cos(μt)E(sin(tX))=exp(−σ2t2/2)sin(μt)

最后,当t=1的时候:
E ( cos ⁡ ( X ) ) = e x p ( − σ 2 / 2 ) cos ⁡ ( μ ) E ( sin ⁡ ( X ) ) = e x p ( − σ 2 / 2 ) s i n ( μ ) E(\cos(X))=exp(-\sigma^2/2)\cos(\mu)\\ E(\sin(X))=exp(-\sigma^2/2)sin(\mu) E(cos(X))=exp(−σ2/2)cos(μ)E(sin(X))=exp(−σ2/2)sin(μ)

参考资料:Mean and variance of Y=cos(bX) when X has a Gaussian distribution

应用:IPE位置编码中,对服从高斯分布正弦函数的数学期望计算:

python 复制代码
# Code Source: 
# https://github.com/liuyuan-pal/NeRO/blob/3b4d421a646097e7d59557c5ea24f4281ab38ef1/network/field.py#L369-L378
def expected_sin(mean, var):
  """Compute the mean of sin(x), x ~ N(mean, var)."""
  return torch.exp(-0.5 * var) * torch.sin(mean)  # large var -> small value.

def IPE(mean,var,min_deg,max_deg):
    scales = 2**torch.arange(min_deg, max_deg)
    shape = mean.shape[:-1] + (-1,)
    scaled_mean = torch.reshape(mean[..., None, :] * scales[:, None], shape)
    scaled_var = torch.reshape(var[..., None, :] * scales[:, None]**2, shape)
    return expected_sin(torch.concat([scaled_mean, scaled_mean + 0.5 * np.pi], dim=-1), torch.concat([scaled_var] * 2, dim=-1))
相关推荐
python1568 分钟前
OpenWebUI新突破,MCPO框架解锁MCP工具新玩法
人工智能·语言模型·自然语言处理
墨绿色的摆渡人21 分钟前
pytorch小记(二十一):PyTorch 中的 torch.randn 全面指南
人工智能·pytorch·python
东临碣石821 小时前
【AI论文】EnerVerse-AC:用行动条件来构想具身环境
人工智能
lqjun08271 小时前
PyTorch实现CrossEntropyLoss示例
人工智能·pytorch·python
心灵彼岸-诗和远方2 小时前
芯片生态链深度解析(三):芯片设计篇——数字文明的造物主战争
人工智能·制造
小蜗笔记2 小时前
显卡、Cuda和pytorch兼容问题
人工智能·pytorch·python
高建伟-joe2 小时前
内容安全:使用开源框架Caffe实现上传图片进行敏感内容识别
人工智能·python·深度学习·flask·开源·html5·caffe
Cloud Traveler2 小时前
迁移学习:解锁AI高效学习与泛化能力的密钥
人工智能·学习·迁移学习
IT_xiao小巫2 小时前
AI 实践探索:辅助生成测试用例
人工智能·测试用例
一切皆有可能!!2 小时前
ChromaDB 向量库优化技巧实战
人工智能·语言模型