def structure_plot(fig, molids, activations=None): """plot molecule structures""" if activations != None: assert len(activations[0]) == len(molids[0]) assert len(activations[1]) == len(molids[1]) id2name = defaultdict(str, rdl.get_id2name()) all_molids = molids[0] + molids[1] all_activations = np.hstack(activations) cr = utils.ceiled_root(len(all_molids)) for i, molid in enumerate(all_molids): ax = fig.add_subplot(cr, cr, i+1) try: img = plt.imread(os.path.join(structures_path, molid + '.png')) except Exception, e: img = np.zeros(img.shape) ax.imshow(img) ax.set_xticks([]) ax.set_yticks([]) if i >= len(molids[0]): for child in ax.get_children(): if isinstance(child, plt.matplotlib.spines.Spine): child.set_color('#ff0000') if activations != None: ax.set_title('{}: {:.2f}'.format(id2name[molid], all_activations[i]), rotation='20')
reload(plib) plt.close('all') active_thresh = 0.5 descriptor = 'saito_desc' method = 'svr_ens' selection = 'linear' inpath = '/Users/dedan/projects/master/results/predict/search/conv_features' outpath = '/Users/dedan/projects/master/results/predict' data_path = "/Users/dedan/projects/master/data" glomeruli = ['Or10a', 'Or42b', 'Or47b'] glom = 'Or42b' glom = sys.argv[1] # load stuff id2name = defaultdict(str, rdl.get_id2name()) door2id = json.load(open(os.path.join(data_path, 'door2id.json'))) id2cas = defaultdict(str, {val[0]: key for key, val in door2id.items() if val}) daniel_set = json.load(open(os.path.join(data_path, 'daniel_set.json'))) daniel_set_molid = [door2id[cas][0] for cas in daniel_set] # get the best parameters from the search result config = rdl.get_best_params(inpath, descriptor, glom, method, selection) features = run_lib.prepare_features(config) data, targets, molids = run_lib.load_data_targets(config, features) # fit model print("use {} molecules for training".format(data.shape[0])) sel_scores = run_lib.get_selection_score(config, data, targets) data = flib.select_k_best(data, sel_scores, config['feature_selection']['k_best'])