clustering.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:PyFusionGUI 作者: SyntaxVoid 项目源码 文件源码
def plot_dimension_histograms_VMM_GMM(self,pub_fig = 0, filename='plot_dim_hist.pdf',specific_dimensions = None, extra_txt_labels = '', label_loc = [-2,1.5], ylim = None):
        '''For each dimension in the data set, plot the histogram of the real and imag part of the measurements
        overlay the GMM's - used for the GMM-GMM clustering method

        SRH: 18May2014
        '''
        suptitle = self.settings.__str__().replace("'",'').replace("{",'').replace("}",'')
        cluster_GMM_mu = self.cluster_details['EM_GMM_means']
        cluster_GMM_sigma = self.cluster_details['EM_GMM_std']
        dimensions = cluster_GMM_mu.shape[1]

        instance_array_amps = self.feature_obj.misc_data_dict['mirnov_data']
        tmp = np.zeros((instance_array_amps.shape[0], instance_array_amps.shape[1]-1),dtype=complex)
        for i in range(1,instance_array_amps.shape[1]): tmp[:,i-1] = instance_array_amps[:,i]/instance_array_amps[:,i-1]
        if specific_dimensions == None: specific_dimensions = range(dimensions)
        fig_ang, ax_ang = make_grid_subplots(len(specific_dimensions), sharex = True, sharey = True)
        fig_abs, ax_abs = make_grid_subplots(len(specific_dimensions), sharex = True, sharey = True)
        amp_vals = np.abs(tmp)
        amp_vals[np.angle(tmp)<0]*= (-1)
        for i,dim in enumerate(specific_dimensions):
            ax_abs[i].hist(amp_vals[:,dim], bins=180,normed=True,histtype='stepfilled',range=[-np.pi,np.pi])
            ax_ang[i].hist(np.angle(tmp[:,dim]), bins=180,normed=True,histtype='stepfilled',range=[-np.pi,np.pi])

        if self.cluster_assignments!=None: cluster_list = list(set(self.cluster_assignments))
        x = np.linspace(-np.pi, np.pi, 300)
        cluster_prob_list = []
        for cluster in cluster_list:
            cluster_prob_list.append(float(np.sum(self.cluster_assignments==cluster))/float(len(self.cluster_assignments)))
        for i, dimension in enumerate(specific_dimensions):
            #for ax_cur, op in zip([ax_re,ax_im],[np.real, np.imag]):
            #for ax_cur, op in zip([ax_ang,ax_abs],[np.angle, np.abs]):
            for ax_cur, op in zip([ax_abs],[np.abs]):
                cluster_sum = x*0
                for cluster, cluster_prob in zip(cluster_list, cluster_prob_list):
                    Z_EM = cluster_prob * norm(loc=cluster_GMM_mu[cluster][dimension], scale=cluster_GMM_sigma[cluster][dimension]).pdf(x)
                    cluster_sum += Z_EM
                    tmp = ax_cur[i].plot(x,Z_EM,'-',linewidth=0.8)
                tmp = ax_cur[i].plot(x,cluster_sum,'-',linewidth=2)
                print '{area},'.format(area = np.sum(cluster_sum*(x[1]-x[0]))),
                ax_cur[i].text(label_loc[0], label_loc[1],r'$\Delta \psi_%d$ '%(dimension+1,) + extra_txt_labels, fontsize = 8)#,bbox=dict(facecolor='white', alpha=0.5))
                ax_cur[i].locator_params(nbins=7)
        print ''
        #for ax_cur, fig_cur in zip([ax_re, ax_im],[fig_re, fig_im]):
        for ax_cur, fig_cur in zip([ax_ang, ax_abs],[fig_ang, fig_abs]):
            ax_cur[-1].set_xlim([-np.pi,np.pi])
            ax_cur[-1].set_ylim([0,1.3])
            fig_cur.subplots_adjust(hspace=0, wspace=0,left=0.05, bottom=0.05,top=0.95, right=0.95)
            fig_cur.suptitle(suptitle.replace('_','\char`_'),fontsize = 8)
            fig_cur.canvas.draw(); fig_cur.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号