简体   繁体   English

Python截断指数分布

[英]Python truncated exponential distribution

I am trying to generate 3 random numbers that has truncated exponential distribution with distribution function of: F(x) = 1-(math.exp(-(x+100*math.log(1-((1-0.05)** (1/100))))/1.5)) , when x>-100*math.log(1-((1-0.05)**(1/100))) . 我正在尝试生成具有 F(x) = 1-(math.exp(-(x+100*math.log(1-((1-0.05)** (1/100))))/1.5)) 指数分布且具有以下分布函数的3个随机数: F(x) = 1-(math.exp(-(x+100*math.log(1-((1-0.05)** (1/100))))/1.5)) ,当x>-100*math.log(1-((1-0.05)**(1/100)))

The problem is that I don't get the concept how to set x values when there is no upper boundary. 问题是当没有上限时,我不知道如何设置x值的概念。 Any ideas how to get those 3 numbers mathematically correct? 有什么想法如何使这3个数字在数学上正确吗?

I am not sure about your distribution function, it looks a bit messy to me (note: (1-0.05)** (1/100) = (0.95**0.01)) but you can use the system max-bound as an upper bound to generate a random variable x using random.uniform() then you can compute F(x) to get the random value belonging to your distribution. 我不确定您的分布函数,对我来说有点混乱(请注意:(1-0.05)**(1/100)=(0.95 ** 0.01)),但您可以将系统的最大界限用作上限以使用random.uniform()生成随机变量x,则可以计算F(x)以获得属于您的分布的随机值。 This can be done like in the following: 可以像下面这样完成:

import sys
import math 
import random 

def F(x):
    return 1-(math.exp(-(x + 100*math.log(1-(0.95**0.01)))/1.5))

def get_random_value_from_distribution():
    x = random.uniform(-100 * math.log(1- (0.95**0.01)), sys.maxsize)
    y = F(x)
    return y

print("x1:", get_random_value_from_distribution())
print("x2:", get_random_value_from_distribution())
print("x3:", get_random_value_from_distribution())

Note: Your distribution function is fixed to 1 in a certain interval, so you need to look into that: 注意:您的分布函数在一定间隔内固定为1,因此需要注意以下几点: 在此处输入图片说明

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM