Julia,如何从截断正态分布中抽样?

huangapple go评论47阅读模式
英文:

Julia, how to sample from a Truncated Normal distribution?

问题

如何从截断在-1和1之间的正态分布中进行抽样?
可以通过以下方式从截断正态分布中进行抽样:

using Distributions

rand(Truncated(Normal(), -1, 1))

这样可以从截断在-1和1之间的正态分布中进行抽样,无需使用条件语句来自行裁剪值。

英文:

How can I sample from a Normal distribution that is truncated at -1 and 1?
I can sample from a Normal distribution by doing

using Distributions

rand(Normal())

but I'm not sure how to sample from a truncated normal distribution, at least not without an if statement to clip the values myself

答案1

得分: 5

rand(Truncated(Normal()), -1, 1)将实现你想要的功能。更多信息,请参阅文档

英文:

rand(Truncated(Normal()), -1, 1) will do what you want. See the docs for more info.

huangapple
  • 本文由 发表于 2023年2月24日 03:45:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549634.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定