简体   繁体   English

我想知道如何使用特定的归一化分布函数生成随机数

[英]I would like to know how how to generate random numbers with a specific normalized distribution funtion

Basically, if my distribution function is f(v)= NormalDistribution(-u,sigma)+ NormalDistribution(u,sigma)基本上,如果我的分布 function 是 f(v)= NormalDistribution(-u,sigma)+ NormalDistribution(u,sigma)

How do I define f as a PDF, normalize it and then apply some random variate command to my PDF?如何将 f 定义为 PDF,对其进行规范化,然后将一些随机变量命令应用于我的 PDF?

Well, you have sum of two normalized Gaussian,好吧,你有两个归一化高斯的总和,

f(x) = N(x|μ,σ) + N(x|-μ,σ) f(x) = N(x|μ,σ) + N(x|-μ,σ)

∫ f(x) dx = 1 + 1 = 2 ∫ f(x) dx = 1 + 1 = 2

PDF(x|μ,σ) = N(x|μ,σ)/2 + N(x|-μ,σ)/2 PDF(x|μ,σ) = N(x|μ,σ)/2 + N(x|-μ,σ)/2

Because PDF is symmetric, sampling is simple: select one gaussian or another with 50% probability因为 PDF 是对称的,所以采样很简单: select 一个高斯或另一个有 50% 的概率

Along the lines (untested)沿线(未经测试)

import random

def sample(μ, σ):
    if random.random() < 0.5:
        return random.gauss(μ,σ)
    return random.gauss(-μ,σ)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何生成具有预定义概率分布的随机数? - How to generate random numbers with predefined probability distribution? 如何使用Scipy生成特定分布的随机值 - How to generate random values of specific distribution with Scipy 如何在高斯分布的两个值之间产生随机数 - How would I produce random numbers between two values with a Gaussian distribution 如何生成特定数量的随机数? - How do I generate a specific amount of random numbers? 如何在 Python 中为截断正态分布生成相关随机数? - How to generate correlated random numbers for truncated normal distribution in Python? 如何在 Python 中使用帕累托分布生成特定范围内的随机数 - How to generate random numbers in specyfic range using pareto distribution in Python 如何在 Python 中为对数正态分布和指数分布生成 N 个随机数? - How to generate N random numbers in Python for lognormal and exponential distribution? 如何在Python中生成特定的随机数? - How to generate specific random numbers in Python? 如何在python中生成具有特定概率的随机数? - How to generate random numbers with specific probabilities in python? 如何生成具有特定标准差的随机正态分布 - How to generate a random normal distribution with specific standard deviation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM