我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用matplotlib.mlab.bivariate_normal()。
def draw(X, pred, means, covariances, output): xp = cupy.get_array_module(X) for i in six.moves.range(2): labels = X[pred == i] if xp is cupy: labels = labels.get() plt.scatter(labels[:, 0], labels[:, 1], c=np.random.rand(3)) if xp is cupy: means = means.get() covariances = covariances.get() plt.scatter(means[:, 0], means[:, 1], s=120, marker='s', facecolors='y', edgecolors='k') x = np.linspace(-5, 5, 1000) y = np.linspace(-5, 5, 1000) X, Y = np.meshgrid(x, y) for i in six.moves.range(2): Z = mlab.bivariate_normal(X, Y, np.sqrt(covariances[i][0]), np.sqrt(covariances[i][1]), means[i][0], means[i][1]) plt.contour(X, Y, Z) plt.savefig(output)
def plot_model(model, data): """ :param model: the GMM model :param data: the data set 2D :return: """ delta = 0.025 x = np.arange(0.0, 4, delta) y = np.arange(0.0, 4, delta) X, Y = np.meshgrid(x, y) z = np.zeros((np.size(x), np.size(y))) # sum of Gaussian plt.figure() for i in range(np.size(model)): ztemp = mlab.bivariate_normal(X, Y, np.sqrt(model['cov'][i][0, 0]), np.sqrt(model['cov'][i][1, 1]), model['mu'][i][0], model['mu'][i][1], model['cov'][i][0,1]) plt.contour(X, Y, model['w'][i]*ztemp) z = np.add(z, ztemp) plt.scatter(data[0, :], data[1, :], s=5) plt.figure() plt.contour(X, Y, z*np.size(model)) plt.scatter(data[0, :], data[1, :], s=5)
def main(): # Part of the example at # http://matplotlib.sourceforge.net/plot_directive/mpl_examples/pylab_examples/contour_demo.py delta = 0.025 x = numpy.arange(-3.0, 3.0, delta) y = numpy.arange(-2.0, 2.0, delta) X, Y = numpy.meshgrid(x, y) Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) Z = 10.0 * (Z2 - Z1) pyplot.figure() CS = pyplot.contour(X, Y, Z) pyplot.show()
def gen_gaussian_plot_vals(?, C): "Z values for plotting the bivariate Gaussian N(?, C)" m_x, m_y = float(?[0]), float(?[1]) s_x, s_y = np.sqrt(C[0, 0]), np.sqrt(C[1, 1]) s_xy = C[0, 1] return bivariate_normal(X, Y, s_x, s_y, m_x, m_y, s_xy)
def __likelihood(self, px_est, pw, z_l): '''????? ??? px_est?????????????x(k+1) pw?????????? z_l??????????????LandMark ???? pw_update?????????????? ''' sigma_xx = np.sqrt(self.__R[0][0]) sigma_yy = np.sqrt(self.__R[1][1]) sigma_xy = np.sqrt(self.__R[0][1]) # ????? bn = np.zeros(self.__NP) for i in range(self.__NP): px = np.array([px_est[:, i]]).T pz_l = tf.world2robot(px, self.__LM) diff_pz = pz_l - z_l dx = diff_pz[:, 0] dy = diff_pz[:, 1] bnlm = mlab.bivariate_normal(dx, dy, sigma_xx, sigma_yy, 0.0, 0.0, sigma_xy) bn[i] = bnlm.prod() pw_update = pw * bn # ?????? pw_update = self.__normalize(pw_update) return pw_update
def plot_model(model, data): """ :param model: the GMM model :param data: the data set 2D :return: """ delta = 0.025 x = np.arange(0.0, 4, delta) y = np.arange(0.0, 4, delta) X, Y = np.meshgrid(x, y) z = np.zeros((np.size(x), np.size(y))) # sum of Gaussian plt.figure() for i in range(np.size(model)): ztemp = mlab.bivariate_normal(X, Y, np.sqrt(model['cov'][i][0, 0]), np.sqrt(model['cov'][i][1, 1]), model['mu'][i][0], model['mu'][i][1], model['cov'][i][0,1]) plt.contour(X, Y, model['w'][i]*ztemp) z = np.add(z, ztemp) plt.scatter(data[0, :], data[1, :], s=5) plt.figure() plt.contour(X, Y, z) plt.scatter(data[0, :], data[1, :], s=5)