def plot_similarity_array(self): abs_corr_array = self.workflow.redundancy_method.similarity_array op_id_name_map = self.map_op_id_name_mult_task(self.workflow.tasks) names = hlp.ind_map_subset( op_id_name_map[0], op_id_name_map[1], self.workflow.redundancy_method.similarity_array_op_ids) measures = np.zeros((2, len(names))) tmp_ind = hlp.ismember( self.workflow.redundancy_method.similarity_array_op_ids, self.workflow.good_op_ids) # -- number of problems for which each good performing feature has been calculated measures[0, :] = (~self.workflow.stats_good_op[:, tmp_ind].mask).sum( axis=0) # -- z scored u-stat(for all features) for top features stats_good_op_z_score = fap.normalise_masked_array( self.workflow.stats_good_op_comb, axis=0, norm_type='zscore')[0] measures[1, :] = stats_good_op_z_score[tmp_ind] fiplt.plot_arr_dendrogram(abs_corr_array, names, max_dist_cluster=self.max_dist_cluster, measures=measures)
def plot_similarity_array(self): abs_corr_array = self.workflow.redundancy_method.similarity_array op_id_name_map = self.map_op_id_name_mult_task(self.workflow.tasks) names = hlp.ind_map_subset(op_id_name_map[0],op_id_name_map[1],self.workflow.redundancy_method.similarity_array_op_ids) measures = np.zeros((2,len(names))) tmp_ind = hlp.ismember(self.workflow.redundancy_method.similarity_array_op_ids, self.workflow.good_op_ids) # -- number of problems for which each good performing feature has been calculated measures[0,:] = (~self.workflow.stats_good_op[:,tmp_ind].mask).sum(axis=0) # -- z scored u-stat(for all features) for top features stats_good_op_z_score = fap.normalise_masked_array(self.workflow.stats_good_op_comb, axis= 0,norm_type = 'zscore')[0] measures[1,:] = stats_good_op_z_score[tmp_ind] fiplt.plot_arr_dendrogram(abs_corr_array,names,max_dist_cluster=self.max_dist_cluster,measures = measures)
def corelated_features_mask(data=None, abs_corr_array=None, calc_times=None, op_ids=None): """ Computes a mask that, when applied, removes correlated features from the data array. Parmeters: ---------- data : ndarray A data matrix with rows represent training samples and columns represent features abs_corr_array : ndarray The correlation matrix of all features. Has to be given id data == none calc_times : ndarray Array where the first row corresponds to operation id's and the second row to calculation times for these operation ids op_ids : The operation ids corresponding to the rows/columns in abs_corr_array Returns: ------- mask : ndarray,dtype=bool 1d array whose entries are one only for uncorrelated entries. abs_corr_arrayabs_corr_array : ndarray the correlation matrix """ if abs_corr_array == None: abs_corr_array = np.abs(np.ma.corrcoef(data, rowvar=0)) # -- Vector containing 0 for all operations we don't want mask = np.ones(abs_corr_array.shape[0], dtype='bool') for i in range(abs_corr_array.shape[0]): # -- if the current line represents an operation not yet eleminated if mask[i]: # -- remove operations which are highly correlated mask[(abs_corr_array[i] > 0.8)] = 0 #---------------------------------------------------------- # -- Use fastest operation in a set of correlated operations #---------------------------------------------------------- if calc_times != None and op_ids != None: # -- find ind in abs_corr_array of correlated features ind_corr = np.nonzero((abs_corr_array[i] > 0.8))[0] # -- translate ind_corr to op ids op_id_corr = hlp.ind_map_subset(range(abs_corr_array.shape[0]), op_ids, ind_corr) # -- get calculation time of correlated op ids t_corr = hlp.ind_map_subset(calc_times[0], calc_times[1], op_id_corr) # -- check if all entries are None -> no timing information for any of the operations if np.nonzero(t_corr)[0].shape[0] == 0: # -- pick the first operation as fastest as there is no timing information op_id_corr_fastest = op_id_corr[0] # -- else pick the fastest operation else: # -- get op_id of fastest operation in this correlated set op_id_corr_fastest = op_id_corr[np.nanargmin(t_corr)] # -- get index of fastest operation in this correlated set ind_corr_fastest = hlp.ind_map_subset( op_ids, range(abs_corr_array.shape[0]), op_id_corr_fastest) # -- add fastest index back in mask[ind_corr_fastest] = 1 #---------------------------------------------------------- # -- Use arbitrary operation in a set of correlated operations #---------------------------------------------------------- else: mask[i] = 1 return mask, abs_corr_array
op_ref_HCTSA_path = '/home/philip/work/OperationImportanceProject/results/done/HCTSA_Beef.mat' op, = mIO.read_from_mat_file(op_ref_HCTSA_path, ['Operations'], is_from_old_matlab=True) max_feat = 50 # -- calculate the correlation abs_corr_array, sort_good_ind, all_classes_avg_good_norm = idtop.calc_perform_corr_mat( all_classes_avg_good, norm='z-score', max_feat=max_feat) # -- save the op id's in order of performance (first entry = best performance) np.save(op_id_order_path, op_id_good[sort_good_ind]) # -- sort the permutation vector that would sort the data array containing the good operations only np.save(sort_good_ind_path, sort_good_ind) # -- extract the top feature names names = hlp.ind_map_subset(op['id'], op['name'], op_id_good[sort_good_ind][:max_feat]) # -- Calculate the measures to be plotted problems_succ = (~all_classes_avg_good[:, sort_good_ind[:max_feat]].mask).sum( axis=0) u_stat_mean = all_classes_avg_good_norm[:, sort_good_ind[:max_feat]].mean(axis=0) measures = np.vstack((problems_succ, u_stat_mean)) fiplt.plot_arr_dendrogram(abs_corr_array, names, measures=measures) plt.savefig('/home/philip/Desktop/tmp/figure_tmp/corr_array.png') plt.show()
def plot_stat_array(self): fig = plt.figure(figsize = ((15,15))) # -- plot layout ------------------------------------------------------ rect_ustat_arr = [0.25,0.175,.5,.5] rect_dendr = [0.755,0.175,.145,.5] rect_measures0 = [0.25,0.68,0.5,0.1] rect_measures1 = [0.25,0.785,0.5,0.1] rect_measures2 = [0.25,0.89,0.5,0.1] ax_ustat_arr = fig.add_axes(rect_ustat_arr) ax_dendr = fig.add_axes(rect_dendr) ax_measures00 = fig.add_axes(rect_measures0) ax_measures01 = plt.twinx(ax_measures00) ax_measures10 = fig.add_axes(rect_measures1) ax_measures10.set_xticklabels([]) ax_measures20 = fig.add_axes(rect_measures2) ax_measures20.set_xticklabels([]) ax_measures21 = plt.twinx(ax_measures20) # -- calculate and plot the dendrogram dist_dendrogram = hierarchy.dendrogram(self.linkage, orientation='left',no_plot=True) hierarchy.dendrogram(self.linkage, orientation='left',p=50,truncate_mode ='lastp',ax = ax_dendr) ax_dendr.set_yticks([]) ax_dendr.axvline(self.max_dist_cluster,ls='--',c='k') # -- plot sorted classification stat array ------------------------------------------ # -- create index that sort rows to correspond to dendrogram feat_sort_ind = dist_dendrogram['leaves'] # -- sort the good performant features so they have the same order as the similarity array sort_ind = hlp.ismember(self.workflow.redundancy_method.similarity_array_op_ids,self.workflow.redundancy_method.good_perf_op_ids) self.ops_base_perf_vals = self.ops_base_perf_vals[:,sort_ind] # -- create index that sort columns with respect to their mean value task_sort_ind = np.argsort(self.ops_base_perf_vals[:,feat_sort_ind].mean(axis=1)) #all_classes_avg_top = ((all_classes_avg_top - np.ma.mean(all_classes_avg_top,axis=0)) / np.ma.std(all_classes_avg_top,axis=0)) #all_classes_avg_top = fap.normalise_masked_array(self.ops_base_perf_vals, axis= 1,norm_type = 'zscore')[0] all_classes_avg_top = self.ops_base_perf_vals # -- plot the operation names as y-axis tick labels aspect = all_classes_avg_top.shape[0] / float(all_classes_avg_top.shape[1]) ax_ustat_arr.matshow(all_classes_avg_top[task_sort_ind,:][:,feat_sort_ind].T,aspect=aspect,origin='bottom') ax_ustat_arr.set_yticks(range(len(feat_sort_ind))) op_id_name_map = self.map_op_id_name_mult_task(self.workflow.tasks) names = hlp.ind_map_subset(op_id_name_map[0],op_id_name_map[1],self.workflow.redundancy_method.similarity_array_op_ids) ax_ustat_arr.set_yticklabels(np.array(names)[feat_sort_ind]) # -- plot the problem names as x axis labels ax_ustat_arr.xaxis.tick_bottom() ax_ustat_arr.set_xticks(range(all_classes_avg_top.shape[0])) ax_ustat_arr.set_xticklabels(self.task_names[task_sort_ind],rotation='vertical') # -- plot clusters ---------------------------------- cluster_bounds = np.nonzero(np.diff(self.workflow.redundancy_method.cluster_inds[feat_sort_ind]))[0]+0.5 for cluster_bound in cluster_bounds: ax_ustat_arr.axhline(cluster_bound,c='w',lw=2) # -------------------------------------------------------------------------------- # -- calculate and plot measures ------------------------------------------------- # -------------------------------------------------------------------------------- # -- nr samples and nr labels -------------------------------------------------- n_samples_avg = [np.array(self.workflow.tasks[i].ts['n_samples']).mean() for i in task_sort_ind] n_classes = [len(set(self.workflow.tasks[i].labels)) for i in task_sort_ind] x_loc = np.arange(0,len(self.workflow.tasks))+0.5 ax_measures00.scatter(x_loc,n_classes,c='b',s=40) ax_measures00.plot(x_loc,n_classes,c='b') [label.set_color('b') for label in ax_measures00.get_yticklabels()] ax_measures00.set_ylabel('nr classes') ax_measures00.yaxis.label.set_color('b') ax_measures00.set_ylim([0,max(n_classes)+1]) ax_measures00.set_xticklabels([]) ax_measures01.scatter(x_loc,n_samples_avg,c='r',s=40) ax_measures01.plot(x_loc,n_samples_avg,c='r') [label.set_color('r') for label in ax_measures01.get_yticklabels()] ax_measures01.set_ylabel('avg samples') ax_measures01.yaxis.label.set_color('r') ax_measures01.set_ylim([0,max(n_samples_avg)+100]) ax_measures00.set_xlim([0,len(self.workflow.tasks)]) ax_measures00.set_xticklabels([]) # -- Classification stat measures -------------------------------------------------- # -- minimum average classification stat for all features ax_measures10.plot(x_loc,np.min(self.workflow.stats_good_op[task_sort_ind,:],axis=1),marker='o',label='min. avg. classification stat all') # -- minimum average classification stat for top features ax_measures10.plot(x_loc,np.ma.min(self.ops_base_perf_vals[task_sort_ind,:],axis=1),marker='o',label='min. avg. classification stat top') # -- average minimum (for each class pair) classification stat for top features # XXX This would require task.pair_stats to be available (not saved as intermediate at the moment); then it is trivial to implement ax_measures10.legend(loc=2,fontsize='small',labelspacing=.1) ax_measures10.set_ylabel('classification stat') ax_measures10.set_xlim([0,len(self.workflow.tasks)]) ax_measures10.set_ylim([0,0.5]) # -- Classification stat measures and avg operations working-------------------------------------------------- # -- mean average classification stat for all features ax_measures20.plot(x_loc,np.ma.mean(self.workflow.stats_good_op[task_sort_ind,:],axis=1),marker='o') [label.set_color('b') for label in ax_measures20.get_yticklabels()] ax_measures20.set_ylabel('avrg classification stat all feat') ax_measures20.yaxis.label.set_color('b') # -- number of successfully calculated features ax_measures21.plot(x_loc,[len(self.workflow.tasks[i].op['id']) for i in task_sort_ind],c='r',marker='o') [label.set_color('r') for label in ax_measures21.get_yticklabels()] ax_measures21.set_ylabel('nr calc feat') ax_measures21.yaxis.label.set_color('r') ax_measures20.set_xlim([0,len(self.workflow.tasks)])
def plot_stat_array(self): fig = plt.figure(figsize = ((15,15))) # -- plot layout ------------------------------------------------------ rect_ustat_arr = [0.25,0.175,.5,.5] rect_dendr = [0.755,0.175,.145,.5] rect_measures0 = [0.25,0.68,0.5,0.1] rect_measures1 = [0.25,0.785,0.5,0.1] rect_measures2 = [0.25,0.89,0.5,0.1] ax_ustat_arr = fig.add_axes(rect_ustat_arr) ax_dendr = fig.add_axes(rect_dendr) ax_measures00 = fig.add_axes(rect_measures0) ax_measures01 = plt.twinx(ax_measures00) ax_measures10 = fig.add_axes(rect_measures1) ax_measures10.set_xticklabels([]) ax_measures20 = fig.add_axes(rect_measures2) ax_measures20.set_xticklabels([]) ax_measures21 = plt.twinx(ax_measures20) # -- calculate and plot the dendrogram dist_dendrogram = hierarchy.dendrogram(self.linkage, orientation='left',no_plot=True) hierarchy.dendrogram(self.linkage, orientation='left',p=50,truncate_mode ='lastp',ax = ax_dendr) ax_dendr.set_yticks([]) ax_dendr.axvline(self.max_dist_cluster,ls='--',c='k') # -- plot sorted U-Stat array ------------------------------------------ # -- create index that sort rows to correspond to dendrogram feat_sort_ind = dist_dendrogram['leaves'] # -- sort the good performant features so they have the same order as the similarity array sort_ind = hlp.ismember(self.workflow.redundancy_method.similarity_array_op_ids,self.workflow.redundancy_method.good_perf_op_ids) self.ops_base_perf_vals = self.ops_base_perf_vals[:,sort_ind] # -- create index that sort columns with respect to their mean value task_sort_ind = np.argsort(self.ops_base_perf_vals[:,feat_sort_ind].mean(axis=1)) #all_classes_avg_top = ((all_classes_avg_top - np.ma.mean(all_classes_avg_top,axis=0)) / np.ma.std(all_classes_avg_top,axis=0)) #all_classes_avg_top = fap.normalise_masked_array(self.ops_base_perf_vals, axis= 1,norm_type = 'zscore')[0] all_classes_avg_top = self.ops_base_perf_vals # -- plot the operation names as y-axis tick labels aspect = all_classes_avg_top.shape[0] / float(all_classes_avg_top.shape[1]) ax_ustat_arr.matshow(all_classes_avg_top[task_sort_ind,:][:,feat_sort_ind].T,aspect=aspect,origin='bottom') ax_ustat_arr.set_yticks(range(len(feat_sort_ind))) op_id_name_map = self.map_op_id_name_mult_task(self.workflow.tasks) names = hlp.ind_map_subset(op_id_name_map[0],op_id_name_map[1],self.workflow.redundancy_method.similarity_array_op_ids) ax_ustat_arr.set_yticklabels(np.array(names)[feat_sort_ind]) # -- plot the problem names as x axis labels ax_ustat_arr.xaxis.tick_bottom() ax_ustat_arr.set_xticks(range(all_classes_avg_top.shape[0])) ax_ustat_arr.set_xticklabels(self.task_names[task_sort_ind],rotation='vertical') # -- plot clusters ---------------------------------- cluster_bounds = np.nonzero(np.diff(self.workflow.redundancy_method.cluster_inds[feat_sort_ind]))[0]+0.5 for cluster_bound in cluster_bounds: ax_ustat_arr.axhline(cluster_bound,c='w',lw=2) # -------------------------------------------------------------------------------- # -- calculate and plot measures ------------------------------------------------- # -------------------------------------------------------------------------------- # -- nr samples and nr labels -------------------------------------------------- n_samples_avg = [np.array(self.workflow.tasks[i].ts['n_samples']).mean() for i in task_sort_ind] n_classes = [len(set(self.workflow.tasks[i].labels)) for i in task_sort_ind] x_loc = np.arange(0,len(self.workflow.tasks))+0.5 ax_measures00.scatter(x_loc,n_classes,c='b',s=40) ax_measures00.plot(x_loc,n_classes,c='b') [label.set_color('b') for label in ax_measures00.get_yticklabels()] ax_measures00.set_ylabel('nr classes') ax_measures00.yaxis.label.set_color('b') ax_measures00.set_ylim([0,max(n_classes)+1]) ax_measures00.set_xticklabels([]) ax_measures01.scatter(x_loc,n_samples_avg,c='r',s=40) ax_measures01.plot(x_loc,n_samples_avg,c='r') [label.set_color('r') for label in ax_measures01.get_yticklabels()] ax_measures01.set_ylabel('avg samples') ax_measures01.yaxis.label.set_color('r') ax_measures01.set_ylim([0,max(n_samples_avg)+100]) ax_measures00.set_xlim([0,len(self.workflow.tasks)]) ax_measures00.set_xticklabels([]) # -- U-stat measures -------------------------------------------------- # -- minimum average U-score for all features ax_measures10.plot(x_loc,np.min(self.workflow.stats_good_op[task_sort_ind,:],axis=1),marker='o',label='min. avg. U-score all') # -- minimum average U-score for top features ax_measures10.plot(x_loc,np.ma.min(self.ops_base_perf_vals[task_sort_ind,:],axis=1),marker='o',label='min. avg. U-score top') # -- average minimum (for each class pair) U-score for top features # XXX This would require task.pair_stats to be available (not saved as intermediate at the moment); then it is trivial to implement ax_measures10.legend(loc=2,fontsize='small',labelspacing=.1) ax_measures10.set_ylabel('u-score') ax_measures10.set_xlim([0,len(self.workflow.tasks)]) ax_measures10.set_ylim([0,0.5]) # -- U-stat measures and avg operations working-------------------------------------------------- # -- mean average U-score for all features ax_measures20.plot(x_loc,np.ma.mean(self.workflow.stats_good_op[task_sort_ind,:],axis=1),marker='o') [label.set_color('b') for label in ax_measures20.get_yticklabels()] ax_measures20.set_ylabel('avrg u-scrore all feat') ax_measures20.yaxis.label.set_color('b') # -- number of successfully calculated features ax_measures21.plot(x_loc,[len(self.workflow.tasks[i].op['id']) for i in task_sort_ind],c='r',marker='o') [label.set_color('r') for label in ax_measures21.get_yticklabels()] ax_measures21.set_ylabel('nr calc feat') ax_measures21.yaxis.label.set_color('r') ax_measures20.set_xlim([0,len(self.workflow.tasks)])
# abs_corr_array = np.abs(np.ma.corrcoef(all_classes_avg_top, rowvar=0)) # -- calculate the correlation array with respect to performance and mask nan. abs_corr_array,sort_good_ind,all_classes_avg_good_norm = idtop.calc_perform_corr_mat(all_classes_avg[:,op_id_good],norm='z-score', max_feat = max_feat) all_classes_avg_top = np.ma.masked_invalid(all_classes_avg[:,op_id_good][:,sort_good_ind[:max_feat]]) # -- calculate the linkage for the correlation corr_linkage = idtop.calc_linkage(abs_corr_array)[0] # -- extract operation names --- ------------------------------------------ # -- load a reference HCTSA_loc.mat containing all op_ids op_ref_HCTSA_path = '/home/philip/work/OperationImportanceProject/results/done/HCTSA_Beef.mat' op, = mIO.read_from_mat_file(op_ref_HCTSA_path,['Operations'],is_from_old_matlab = True) top_id = op_id_good[sort_good_ind][:max_feat] names = hlp.ind_map_subset(op['id'], op['name'], op_id_good[sort_good_ind][:max_feat]) # -- extract problem names --- ------------------------------------------ reg_ex = re.compile('.*\/HCTSA_(.*)_N_70_100_reduced.mat') problem_paths = np.load(problem_names_path) problem_names = np.array([reg_ex.match(problem_path).group(1) for problem_path in problem_paths]) # --------------------------------------------------------------------- # -- Plot ------------------------------------------------------------- # --------------------------------------------------------------------- fig = plt.figure(figsize = ((15,15))) # -- plot layout ------------------------------------------------------
def corelated_features_mask(data=None,abs_corr_array=None,calc_times=None,op_ids=None): """ Computes a mask that, when applied, removes correlated features from the data array. Parmeters: ---------- data : ndarray A data matrix with rows represent training samples and columns represent features abs_corr_array : ndarray The correlation matrix of all features. Has to be given id data == none calc_times : ndarray Array where the first row corresponds to operation id's and the second row to calculation times for these operation ids op_ids : The operation ids corresponding to the rows/columns in abs_corr_array Returns: ------- mask : ndarray,dtype=bool 1d array whose entries are one only for uncorrelated entries. abs_corr_arrayabs_corr_array : ndarray the correlation matrix """ if abs_corr_array == None: abs_corr_array = np.abs(np.ma.corrcoef(data, rowvar=0)) # -- Vector containing 0 for all operations we don't want mask = np.ones(abs_corr_array.shape[0],dtype='bool') for i in range(abs_corr_array.shape[0]): # -- if the current line represents an operation not yet eleminated if mask[i]: # -- remove operations which are highly correlated mask[(abs_corr_array[i] > 0.8)] = 0 #---------------------------------------------------------- # -- Use fastest operation in a set of correlated operations #---------------------------------------------------------- if calc_times != None and op_ids != None: # -- find ind in abs_corr_array of correlated features ind_corr = np.nonzero((abs_corr_array[i] > 0.8))[0] # -- translate ind_corr to op ids op_id_corr = hlp.ind_map_subset(range(abs_corr_array.shape[0]),op_ids,ind_corr) # -- get calculation time of correlated op ids t_corr = hlp.ind_map_subset(calc_times[0],calc_times[1],op_id_corr) # -- check if all entries are None -> no timing information for any of the operations if np.nonzero(t_corr)[0].shape[0] == 0: # -- pick the first operation as fastest as there is no timing information op_id_corr_fastest = op_id_corr[0] # -- else pick the fastest operation else: # -- get op_id of fastest operation in this correlated set op_id_corr_fastest = op_id_corr[np.nanargmin(t_corr)] # -- get index of fastest operation in this correlated set ind_corr_fastest = hlp.ind_map_subset(op_ids,range(abs_corr_array.shape[0]),op_id_corr_fastest) # -- add fastest index back in mask[ind_corr_fastest] = 1 #---------------------------------------------------------- # -- Use arbitrary operation in a set of correlated operations #---------------------------------------------------------- else: mask[i] = 1 return mask,abs_corr_array
# -- calculate the correlation array with respect to performance and mask nan. abs_corr_array, sort_good_ind, all_classes_avg_good_norm = idtop.calc_perform_corr_mat( all_classes_avg[:, op_id_good], norm="z-score", max_feat=max_feat ) all_classes_avg_top = np.ma.masked_invalid(all_classes_avg[:, op_id_good][:, sort_good_ind[:max_feat]]) # -- calculate the linkage for the correlation corr_linkage = idtop.calc_linkage(abs_corr_array)[0] # -- extract operation names --- ------------------------------------------ # -- load a reference HCTSA_loc.mat containing all op_ids op_ref_HCTSA_path = "/home/philip/work/OperationImportanceProject/results/done/HCTSA_Beef.mat" op, = mIO.read_from_mat_file(op_ref_HCTSA_path, ["Operations"], is_from_old_matlab=True) top_id = op_id_good[sort_good_ind][:max_feat] names = hlp.ind_map_subset(op["id"], op["name"], op_id_good[sort_good_ind][:max_feat]) # -- extract problem names --- ------------------------------------------ reg_ex = re.compile(".*\/HCTSA_(.*)_N_70_100_reduced.mat") problem_paths = np.load(problem_names_path) problem_names = np.array([reg_ex.match(problem_path).group(1) for problem_path in problem_paths]) # --------------------------------------------------------------------- # -- Plot ------------------------------------------------------------- # --------------------------------------------------------------------- fig = plt.figure(figsize=((15, 15))) # -- plot layout ------------------------------------------------------
def plot_stat_array(self): fig = plt.figure(figsize=((15, 15))) # -- plot layout ------------------------------------------------------ #rect_ustat_arr = [0.01,0.01,0.75,0.75] #[0.25,0.175,.5,.5] #rect_dendr = [0.76,0.01,.2175,.75] #[0.755,0.175,.145,.5] rect_ustat_arr = fig.add_axes([0.15, 0.2, 0.7, 0.8]) #rect_dendr = fig.add_axes([0.7, 0.1, 0.145, 0.8]) rect_dendr = fig.add_axes([0.15, 0.8, 0.873, 0.2]) '''rect_measures0 = [0.25,0.68,0.5,0.1] rect_measures1 = [0.25,0.785,0.5,0.1] rect_measures2 = [0.25,0.89,0.5,0.1]''' ax_ustat_arr = fig.add_axes(rect_ustat_arr) ax_dendr = fig.add_axes(rect_dendr) '''ax_measures00 = fig.add_axes(rect_measures0) ax_measures01 = plt.twinx(ax_measures00) ax_measures10 = fig.add_axes(rect_measures1) ax_measures10.set_xticklabels([]) ax_measures20 = fig.add_axes(rect_measures2) ax_measures20.set_xticklabels([]) ax_measures21 = plt.twinx(ax_measures20)''' # -- calculate and plot the dendrogram dist_dendrogram = hierarchy.dendrogram(self.linkage, orientation='top', no_plot=True) hierarchy.dendrogram(self.linkage, orientation='top', p=50, truncate_mode='lastp', ax=ax_dendr) ax_dendr.set_xticks([]) ax_dendr.axvline(self.max_dist_cluster, ls='--', c='k') # -- plot sorted classification stat array ------------------------------------------ # -- create index that sort rows to correspond to dendrogram feat_sort_ind = dist_dendrogram['leaves'] # -- sort the good performant features so they have the same order as the similarity array sort_ind = hlp.ismember( self.workflow.redundancy_method.similarity_array_op_ids, self.workflow.redundancy_method.good_perf_op_ids) self.ops_base_perf_vals = self.ops_base_perf_vals[:, sort_ind] # -- create index that sort columns with respect to their mean value task_sort_ind = np.argsort( self.ops_base_perf_vals[:, feat_sort_ind].mean(axis=1)) #all_classes_avg_top = ((all_classes_avg_top - np.ma.mean(all_classes_avg_top,axis=0)) / np.ma.std(all_classes_avg_top,axis=0)) #all_classes_avg_top = fap.normalise_masked_array(self.ops_base_perf_vals, axis= 1,norm_type = 'zscore')[0] all_classes_avg_top = self.ops_base_perf_vals # -- plot the operation names as y-axis tick labels aspect = all_classes_avg_top.shape[0] / float( all_classes_avg_top.shape[1]) im = ax_ustat_arr.matshow( all_classes_avg_top[task_sort_ind, :][:, feat_sort_ind], aspect=aspect, origin='bottom', cmap='turbo') ax_ustat_arr.set_yticks(range(all_classes_avg_top.shape[0])) op_id_name_map = self.map_op_id_name_mult_task(self.workflow.tasks) names = hlp.ind_map_subset( op_id_name_map[0], op_id_name_map[1], self.workflow.redundancy_method.similarity_array_op_ids) ax_ustat_arr.set_yticklabels(self.task_names[task_sort_ind]) # -- plot the problem names as x axis labels ax_ustat_arr.xaxis.tick_bottom() ax_ustat_arr.set_xticks(range(len(feat_sort_ind))) ax_ustat_arr.set_xticklabels(np.array(names)[feat_sort_ind], rotation='vertical') fig.colorbar(im) # -- plot clusters ---------------------------------- '''cluster_bounds = np.nonzero(np.diff(self.workflow.redundancy_method.cluster_inds[feat_sort_ind]))[0]+0.5