I used to code this below for my monte carlo simulation and it worked well. (Beta distribution)

import numpy as np

from scipy import stats

from scipy.stats import beta

from distfit import distfit

import matplotlib.pyplot as plt

import seaborn as sns

# Set the random seed for reproducibility

np.random.seed(1)

a = 0.141753

b = 269.581

# Perform the Monte Carlo simulation

nr_simulations = 10000

data = np.empty(1)

for i in range(nr_simulations-1):

sam=np.random.beta(a, b,1)

data=np.append(data,sam)

if sam < 0:

nr_simulations+= 1

print(np.size(data))

print(*data)

# ==============================================================

But I encounter memory error when my data is lognormal distribution and the code is below.

import numpy as np

from scipy import stats

from scipy.stats import beta

from distfit import distfit

import matplotlib.pyplot as plt

import seaborn as sns

# Set the random seed for reproducibility

np.random.seed(0)

# Define the parameters of the lognormal distribution

s = 6.0195

loc = -2.27181e-17

scale = 0.373877

# Perform the Monte Carlo simulation

nr_simulations = 10000

data = np.empty(1)

for i in range(nr_simulations-1):

sam=np.random.lognormal(mean=loc, sigma=s, size=1)

data=np.append(data,sam)

if sam < 0:

nr_simulations+= 1

dist = distfit()

result=dist.fit_transform(data)

dist.plot_summary()

dist.plot()

plt.show()

print(result)

fig, ax = dist.plot(chart=‘pdf’)

fig, ax = dist.plot(chart=‘cdf’)

===============================================

I think the “transform” coding is making a problem.

How can I solve this trouble?

I hope to hear any kinds of advice. Thank you!