def find_centers_gmm(data, gridpoints, n_components=2):
r""" Provided 1D data and a grid of points, return the indices of the points closest to
the centers of an assumed n-modal distribution behind "data"
data : 1D data ndarray, of shape (N, 1)
gridpoints: 1D gridpoints
returns: idxs, igmm
idxs: 1D ndarray
INDICES of gridpoints that are closest to the centers of the gaussians
igmm: gaussian mixture model (sklearn type)
tested = true
"""
igmm = _GMM(n_components=n_components)
igmm.fit(data)
return _np.abs(gridpoints-_np.sort(igmm.means_, 0)).argmin(1), igmm
评论列表
文章目录