python类mlab()的实例源码

dtopotools_horiz_okada_and_1d.py 文件源码 项目:finite_volume_seismic_model 作者: cjvogl 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def dZ_at_t(self, t):
        """
        Interpolate dZ to specified time t and return deformation.
        """
        from matplotlib.mlab import find
        if t <= self.times[0]:
            return self.dZ[0,:,:]
        elif t >= self.times[-1]:
            return self.dZ[-1,:,:]
        else:
            n = max(find(self.times <= t))
            t1 = self.times[n]
            t2 = self.times[n+1]
            dz = (t2-t)/(t2-t1) * self.dZ[n,:,:] + \
                 (t-t1)/(t2-t1) * self.dZ[n+1,:,:]
            return dz
dtopotools_horiz_okada_and_1d.py 文件源码 项目:finite_volume_seismic_model 作者: cjvogl 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def dZ_at_t(self, t):
        """
        Interpolate dZ to specified time t and return deformation.
        """
        from matplotlib.mlab import find
        if t <= self.times[0]:
            return self.dZ[0,:,:]
        elif t >= self.times[-1]:
            return self.dZ[-1,:,:]
        else:
            n = max(find(self.times <= t))
            t1 = self.times[n]
            t2 = self.times[n+1]
            dz = (t2-t)/(t2-t1) * self.dZ[n,:,:] + \
                 (t-t1)/(t2-t1) * self.dZ[n+1,:,:]
            return dz
gmm2.0.py 文件源码 项目:Music-Classification-MedleyDB 作者: DeepeshAgarawal 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
toy.py 文件源码 项目:pytorch-geometric-gan 作者: lim0606 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def save_contour(netD, filename, cuda=False):
    #import warnings
    #warnings.filterwarnings("ignore", category=FutureWarning)
    #import numpy as np
    #import matplotlib
    #matplotlib.use('Agg')
    #import matplotlib.cm as cm
    #import matplotlib.mlab as mlab
    #import matplotlib.pyplot as plt

    matplotlib.rcParams['xtick.direction'] = 'out'
    matplotlib.rcParams['ytick.direction'] = 'out'
    matplotlib.rcParams['contour.negative_linestyle'] = 'solid' 

    # gen grid 
    delta = 0.1
    x = np.arange(-25.0, 25.0, delta)
    y = np.arange(-25.0, 25.0, delta)
    X, Y = np.meshgrid(x, y)

    # convert numpy array to to torch variable
    (h, w) = X.shape
    XY = np.concatenate((X.reshape((h*w, 1, 1, 1)), Y.reshape((h*w, 1, 1, 1))), axis=1)
    input = torch.Tensor(XY)
    input = Variable(input)
    if cuda:
        input = input.cuda()

    # forward
    output = netD(input)

    # convert torch variable to numpy array
    Z = output.data.cpu().view(-1).numpy().reshape(h, w)

    # plot and save 
    plt.figure()
    CS1 = plt.contourf(X, Y, Z)
    CS2 = plt.contour(X, Y, Z, alpha=.7, colors='k')
    plt.clabel(CS2, inline=1, fontsize=10, colors='k')
    plt.title('Simplest default with labels')
    plt.savefig(filename)
    plt.close()
gmm.py 文件源码 项目:Music-Classification-MedleyDB 作者: DeepeshAgarawal 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号