这里有一个使用pymc的方法。该方法在混合模型中使用固定数量的组分(n_分量)。您可以尝试附加一个prior-to-n-u组件并在该previor上采样。或者,您可以选择一些合理的东西,或者从我的其他答案中使用网格搜索技术来估计组件的数量。在下面的代码中,我使用了10000次迭代,但这可能不足以获得良好的结果。我建议使用大得多的磨合机。我也有点武断地选择了优先权,所以这些可能是值得一看的东西。你得试试看。祝你好运。这是密码。在import numpy as np
import pymc as mc
import scipy.stats as stats
from matplotlib import pyplot
def generate_random_histogram():
# Random bin locations between 0 and 100
bin_locations = np.random.rand(10,) * 100
bin_locations.sort()
# Random counts on those locations
bin_counts = np.random.randint(50, size=len(bin_locations))
return {'loc': bin_locations, 'count':bin_counts}
def bin_widths(loc):
widths = []
for i in range(len(loc)-1):
widths.append(loc[i+1] - loc[i])
widths.append(widths[-1])
widths = np.array(widths)