Я выполняю моделирование сточасти c системы многих тел, и в настоящее время мне нужно получить многомерное распределение вероятностей из сгенерированных данных. Для этой цели я пытался использовать np.histogramdd
как в:
bins = np.linspace(start = -x_max, stop = x_max, num = n_bins)
hists = np.histogramdd(Data, bins = [bins] * dimensions, density = True)
Однако этот код выдает ошибку MemoryError (или генерирует исключение о том, что какой-то массив слишком велик) уже для n_bins = 20
, dimensions = 5
и np.shape(Data) = (1000, 5)
, что намного ниже целевых значений. Количество корзин растет экспоненциально с увеличением числа измерений, поэтому легко понять, почему возникают такие проблемы. Итак, возникает вопрос: как можно сгенерировать, сохранить и обработать гистограмму большой размерной величины в Python? Существуют ли для этого какие-либо рамки? Лучше переключиться на что-то другое?
Edit: MCEV и примеры кодов ошибок.
x_max = 10
n_bins = 20
Data = np.random.uniform(-x_max, x_max, size=(1000, dimensions))
bins = np.linspace(start = -x_max, stop = x_max, num = n_bins)
hists = np.histogramdd(Data, bins = [bins] * dimensions, density = True)
Ставя dimensions = 7
, получаю:
lib\site-packages\numpy\lib\histograms.py in histogramdd(sample, bins, range, normed, weights, density)
1066 # Compute the number of repetitions in xy and assign it to the
1067 # flattened histmat.
-> 1068 hist = np.bincount(xy, weights, minlength=nbin.prod())
MemoryError:
dimensions = 15
:
1062 # Compute the sample indices in the flattened histogram matrix.
1063 # This raises an error if the array is too large.
-> 1064 xy = np.ravel_multi_index(Ncount, nbin)
1065
1066 # Compute the number of repetitions in xy and assign it to the
ValueError: invalid dims: array size defined by dims is larger than the maximum possible size.
dimensions = 10
1066 # Compute the number of repetitions in xy and assign it to the
1067 # flattened histmat.
-> 1068 hist = np.bincount(xy, weights, minlength=nbin.prod())
1069
1070 # Shape into a proper matrix
ValueError: 'minlength' must not be negative