def plot_dimension_histograms_GMM_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_mu = self.cluster_details['EM_GMM_means_re'] + 1j*self.cluster_details['EM_GMM_means_im']
cluster_sigma = self.cluster_details['EM_GMM_variances_re'] + 1j*self.cluster_details['EM_GMM_variances_im']
dimensions = cluster_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)
tmp = instance_array_amps/np.sum(instance_array_amps, axis = 1)[:,np.newaxis]
#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_re, ax_re = make_grid_subplots(len(specific_dimensions), sharex = True, sharey = True)
fig_im, ax_im = make_grid_subplots(len(specific_dimensions), sharex = True, sharey = True)
for i,dim in enumerate(specific_dimensions):
ax_re[i].hist(np.real(tmp[:,dim]), bins=180,normed=True,histtype='stepfilled',range=[-np.pi,np.pi])
ax_im[i].hist(np.imag(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]):
cluster_sum = x*0
for cluster, cluster_prob in zip(cluster_list, cluster_prob_list):
Z_EM = cluster_prob * norm(loc=op(cluster_mu[cluster][dimension]), scale=np.sqrt(op(cluster_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]):
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()
评论列表
文章目录