Hướng dẫn generate random numbers from exponential distribution in python - tạo số ngẫu nhiên từ phân phối theo cấp số nhân trong python

Random.Exentential (tỷ lệ = 1.0, size = none)#exponential(scale=1.0, size=None)#

Vẽ các mẫu từ phân phối theo cấp số nhân.

Hàm mật độ xác suất của nó là

\ [f (x; \ frac {1} {\ beta}) = \ frac {1} {\ beta} \ exp (-\ frac {x} {\ beta}), \]

cho x > 0 và 0 ở nơi khác. \ (\ beta \) là tham số tỷ lệ, là nghịch đảo của tham số tốc độ \ (\ lambda = 1/\ beta \). Tham số tốc độ là một tham số thay thế, được sử dụng rộng rãi của phân phối theo cấp số nhân [3].\(\beta\) is the scale parameter, which is the inverse of the rate parameter \(\lambda = 1/\beta\). The rate parameter is an alternative, widely used parameterization of the exponential distribution [3].

Phân phối theo cấp số nhân là một sự tương tự liên tục của phân phối hình học. Nó mô tả nhiều tình huống phổ biến, chẳng hạn như kích thước của các hạt mưa được đo trên nhiều cơn mưa [1] hoặc thời gian giữa các yêu cầu trang đến Wikipedia [2].

Ghi chú

Mã mới nên sử dụng phương thức exponential của một thể hiện default_rng() thay thế; Vui lòng xem bắt đầu nhanh chóng.Quick Start.

Tham sốScalefloat hoặc Array_like of Floatsscalefloat or array_like of floats

Tham số tỷ lệ, \ (\ beta = 1/\ lambda \). Phải không âm.\(\beta = 1/\lambda\). Must be non-negative.

kích thước hoặc tuple của int, tùy chọnint or tuple of ints, optional

Hình dạng đầu ra. Nếu hình dạng đã cho là, ví dụ, (m, n, k), thì các mẫu m * n * k được rút ra. Nếu kích thước là None (mặc định), một giá trị duy nhất được trả về nếu scale là vô hướng. Nếu không, các mẫu

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
0 được rút ra.

ReturnSoutNDarray hoặc vô hướngoutndarray or scalar

Các mẫu rút ra từ phân phối theo cấp số nhân được tham số hóa.

Người giới thiệu

1

Peyton Z. Peebles Jr., Xác suất, biến ngẫu nhiên và nguyên tắc tín hiệu ngẫu nhiên, Ed, 4th, 2001, tr. 57.

2

Wikipedia, Poisson Process, https://en.wikipedia.org/wiki/poisson_process

3

Wikipedia, Phân phối theo cấp số nhân, https://en.wikipedia.org/wiki/Exponential_distribution

residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
2
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
3
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
4exponential5
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
6
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
7
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
8regression problem, which is what Praveen was suggesting.

exponential9

residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
3 default_rng()1
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
7
residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)
8

import matplotlib.pyplot as plt
from math import exp
from scipy.stats import norm


x = range(0, 16)
Y = [0.27*exp(-0.27*_) for _ in x]
error = norm.rvs(0, scale=0.05, size=9)
simulated_data = [max(0, y+e) for (y,e) in zip(Y[:9],error)]

plt.plot(x, Y, 'b-')
plt.plot(x[:9], simulated_data, 'r.')
plt.show()

print (x[:9])
print (simulated_data)

Đây là cốt truyện. Lưu ý rằng tôi lưu các giá trị đầu ra để sử dụng tiếp theo.

Hướng dẫn generate random numbers from exponential distribution in python - tạo số ngẫu nhiên từ phân phối theo cấp số nhân trong python

Bây giờ tôi có thể tính toán hồi quy phi tuyến của các giá trị phân rã theo cấp số nhân, bị nhiễm nhiễu, trên biến độc lập, đó là những gì

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
2 làm.

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)

Phần thưởng là, không chỉ tính toán ước tính cho tham số - 0.207962159793 - nó còn đưa ra ước tính cho phương sai ước tính này - 0,00086071 - như một yếu tố của

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
4. Đây dường như là một giá trị khá nhỏ, với kích thước mẫu nhỏ.

Đây là cách tính phần dư. Lưu ý rằng mỗi phần dư là chênh lệch giữa giá trị dữ liệu và giá trị ước tính từ

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
5 bằng cách sử dụng ước tính tham số.

residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
print (residuals)

Nếu bạn muốn tiếp tục kiểm tra rằng chức năng của tôi thực sự đang đi qua các điểm dữ liệu 'thì tôi sẽ đề nghị tìm kiếm các mẫu trong phần dư. Nhưng các cuộc thảo luận như thế này có thể vượt ra ngoài những gì được hoan nghênh trên các lô Stackoverflow: Q-Q và P-P, các lô của phần dư so với

from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
6 hoặc
from math import exp
from scipy.optimize import curve_fit
import numpy as np

def model(x, p):
    return p*np.exp(-p*x)

x = list(range(9))
Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]

popt, pcov = curve_fit(model, x, Y)
print (popt[0])
print (pcov)
5, v.v.

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọcnumpy.random.exponential() method, we can get the random samples from exponential distribution and returns the numpy array of random samples by using this method.

    Hướng dẫn generate random numbers from exponential distribution in python - tạo số ngẫu nhiên từ phân phối theo cấp số nhân trong python

    Bàn luận

    Với sự trợ giúp của phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên từ phân phối theo cấp số nhân và trả về mảng vô dụng của các mẫu ngẫu nhiên bằng cách sử dụng phương pháp này.numpy.random.exponential(scale=1.0, size=None)

    Phân phối theo cấp số nhânReturn the random samples of numpy array.

    Cú pháp: numpy.random.exponential (tỷ lệ = 1.0, size = none)

    Trả về: Trả về các mẫu ngẫu nhiên của mảng numpy.numpy.random.exponential() method, we are able to get the random samples of exponential distribution and return the samples of numpy array.

    Python3

    Ví dụ 1 :

    Trong ví dụ này, chúng ta có thể thấy rằng bằng cách sử dụng phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên phân phối theo cấp số nhân và trả về các mẫu của mảng numpy.

    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    8
    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    9

    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    8
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    1

    x > 07

    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    2
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    3
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    4
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    5
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    6
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    7
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    8

    Hướng dẫn generate random numbers from exponential distribution in python - tạo số ngẫu nhiên từ phân phối theo cấp số nhân trong python

    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    9
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    3 x > 01x > 02x > 03
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    3 x > 05
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    8

    Python3

    Ví dụ 1 :

    Trong ví dụ này, chúng ta có thể thấy rằng bằng cách sử dụng phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên phân phối theo cấp số nhân và trả về các mẫu của mảng numpy.

    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    8
    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    9

    from math import exp
    from scipy.optimize import curve_fit
    import numpy as np
    
    def model(x, p):
        return p*np.exp(-p*x)
    
    x = list(range(9))
    Y = [0.22219001972988275, 0.15537454187341937, 0.15864069451825827, 0.056411162886672819, 0.037398831058143338, 0.10278251869912845, 0.03984605649260467, 0.0035360087611421981, 0.075855255999424692]
    
    popt, pcov = curve_fit(model, x, Y)
    print (popt[0])
    print (pcov)
    
    8
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    1

    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    2
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    3
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    4
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    5
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    6
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    7
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    8

    x > 07

    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    2
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    3
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    4
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    5
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    6
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    7
    residuals = [y-model(_, popt[0]) for (y, _) in zip(Y, x)]
    print (residuals)
    
    8

    Hướng dẫn generate random numbers from exponential distribution in python - tạo số ngẫu nhiên từ phân phối theo cấp số nhân trong python


    Làm thế nào để bạn tạo ra một số ngẫu nhiên từ phân phối theo cấp số nhân trong Python?

    Với sự trợ giúp của phương thức numpy.random.exponential (), chúng ta có thể lấy các mẫu ngẫu nhiên từ phân phối theo cấp số nhân và trả về mảng vô dụng của các mẫu ngẫu nhiên bằng cách sử dụng phương pháp này.numpy. random. exponential() method, we can get the random samples from exponential distribution and returns the numpy array of random samples by using this method.

    Làm thế nào để bạn tạo ra một số ngẫu nhiên từ phân phối theo cấp số nhân?

    Các bước liên quan như sau ...
    Tính toán CDF của biến ngẫu nhiên mong muốn.Đối với phân phối theo cấp số nhân, CDF là ..
    Đặt r = f (x) trên phạm vi của.....
    Giải phương trình f (x) = r cho.....
    Tạo (khi cần) số ngẫu nhiên đồng nhất và tính toán các biến thể ngẫu nhiên mong muốn bằng cách ..

    Làm thế nào để bạn tìm thấy xác suất của một phân phối theo cấp số nhân trong Python?

    Phân phối theo cấp số nhân là một phân phối xác suất được sử dụng để mô hình hóa thời gian chúng ta phải đợi cho đến khi một sự kiện nhất định xảy ra.Trong đó: λ: tham số tốc độ (được tính là = 1/μ)..
    P (x ≤ x) = 1 - e.-λx.
    P (x ≤ 50) = 1 - e.-.025 (50).
    P (x ≤ 50) = 0,7135 ..

    Quy mô theo cấp số nhân ngẫu nhiên numpy là gì?

    numpy.random.exponential (tỷ lệ = 1.0, size = none) phân phối theo cấp số nhân.Hàm mật độ xác suất của nó là.cho x> 0 và 0 ở nơi khác.là tham số tỷ lệ, là nghịch đảo của tham số tốc độ.scale=1.0, size=None) Exponential distribution. Its probability density function is. for x > 0 and 0 elsewhere. is the scale parameter, which is the inverse of the rate parameter.