results_clause_dict = {} if args.p != None: with open(path_to_selected_patterns, 'r') as f: for line in f.readlines(): line = line.replace("RESULTS", "PATTERNS") line = line.replace("PATTERNS_400_BATCH_10_MAX_SAME_SEED", "PATTERNS_400_BATCH") line = line.replace( "/cw/dtaijupiter/NoCsBack/dtai/irma/MARTIN_EXPERIMENTS_BACKUP/", "/data/leuven/311/vsc31168/MARTIN_EXPERIMENTS/PATTERNS/") for file in os.listdir(line.rstrip()): if file.endswith(".gml"): pattern = nx.read_gml(os.path.join( line.rstrip(), file)) readable_format = an.get_readable_text_format(pattern) convert(readable_format[0], readable_format[1], line.rstrip()) clause = os.path.join(line.rstrip(), 'clause.info') res = os.path.join( line.replace("PATTERNS", "RESULTS").rstrip(), 'sdm') results_clause_dict[res] = clause if args.r != None: pattern = nx.read_gml(os.path.join(args.r.rstrip())) readable_format = an.get_readable_text_format(pattern) convert(readable_format[0], readable_format[1], "/".join(args.r.split("/")[:-1])) try: os.makedirs(os.path.join(args.c, 'sdm'))
def get_row_exhaustive(general_path, pattern_result, pattern_path): row = {} print "Pattern exhaustive ", pattern_result print "Pattern path: ", pattern_path pattern = nx.read_gml(os.path.join(general_path, 'input_pattern.gml')) nr_randvar_values = man.count_nr_randvars_in_graph(pattern) cycles = man.is_there_cycle_in_graph(pattern) max_degree = man.get_maximum_node_degree(pattern) average_degree = man.get_average_node_degree(pattern) n_target_nodes = man.get_nr_target_nodes_other_than_head(pattern) parent_id = get_parent_id(os.path.join(pattern_path)) #get nr embeddings of exhaustive nr_emb = None time = None print general_path.split('/') pattern_name = general_path.split('/')[-1] if pattern_name == "": pattern_name = general_path.split('/')[-2] nr_obs = None print "Exists? ", os.path.join( general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res'), os.path.exists( os.path.join(general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res')) if os.path.exists( os.path.join(general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res')): nr_emb, time, nr_obs = extract_nr_embeddings( os.path.join(general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res')) #get the results if os.path.exists(os.path.join(pattern_result, 'monitoring')): embeddings, stdev, klds = get_stat( os.path.join(pattern_result, 'monitoring'), 'exhaustive') else: embeddings = [None] * 120 klds = [None] * 120 is_timeout = False if os.path.exists( os.path.join(general_path, 'exhaustive_approach', 'timeout.info')): is_timeout = True print "Nr of records for embeddings: ", len(embeddings) nodes, edges = man.get_readable_text_format(pattern) row['pattern_name'] = pattern_result row['parent_id'] = parent_id row['nr_randvar_values'] = int(nr_randvar_values) row['nodes'] = nodes row['edges'] = edges row['has_cycles'] = cycles row['density'] = nx.density(pattern) row['max_degree'] = float(max_degree) row['avg_deg'] = float(average_degree) row['nr_targets'] = int(n_target_nodes) if nr_emb: row['exh_emb'] = float(nr_emb) else: row['exh_emb'] = nr_emb row['time'] = time row['timeout'] = is_timeout row['nr_observations'] = nr_obs for i in xrange(1, len(embeddings) + 1): if embeddings[i - 1] == None: row["emb_" + str(i)] = None else: row["emb_" + str(i)] = float(embeddings[i - 1]) return row
def get_row(general_path, pattern_result, experiment_name, pattern_path): row = {} pattern = nx.read_gml(os.path.join(general_path, 'input_pattern.gml')) parent_id = get_parent_id(os.path.join(pattern_path)) nr_randvar_values = man.count_nr_randvars_in_graph(pattern) cycles = man.is_there_cycle_in_graph(pattern) max_degree = man.get_maximum_node_degree(pattern) average_degree = man.get_average_node_degree(pattern) n_target_nodes = man.get_nr_target_nodes_other_than_head(pattern) #get nr embeddings of exhaustive nr_emb = None sel_emb = None has_obd = True emb_stds = [] if os.path.exists(os.path.join(pattern_result, 'no_obdecomp.info')): has_obd = False if os.path.exists( os.path.join(os.path.dirname(pattern_result), "selected.info")): sel_emb = extract_nr_embeddings_NS( os.path.join(os.path.dirname(pattern_result), "selected.info")) print "General path: ", general_path print os.path.join( general_path, 'exhaustive_approach', 'results_' + general_path.split('/')[-1] + '.res'), "exists?", os.path.exists( os.path.join(general_path, 'exhaustive_approach', 'results_' + general_path.split('/')[-1] + '.res')) pattern_name = None print general_path.split('/') if general_path.split('/')[-1] == "": pattern_name = general_path.split('/')[-2] else: pattern_name = general_path.split('/')[-1] print pattern_name if os.path.exists( os.path.join(general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res')): nr_emb, time, nr_obs = extract_nr_embeddings( os.path.join(general_path, 'exhaustive_approach', 'results_' + pattern_name + '.res')) #get the results if os.path.exists(os.path.join(pattern_result, 'monitoring')): embeddings, emb_stds, klds = get_stat( os.path.join(pattern_result, 'monitoring'), experiment_name) else: embeddings = [None] * 120 klds = [None] * 120 print "EMBEDDINGS: ", embeddings unequal_size_warning = False OBD = None if os.path.exists( os.path.join(general_path, 'results_furer', 'OBDDecomp.info')): OBD = getOBDecomp( os.path.join(general_path, 'results_furer', 'OBDDecomp.info')) nodes, edges = man.get_readable_text_format(pattern) print "PATTERN NAME: ", pattern_result row['pattern_name'] = pattern_result row['parent_id'] = parent_id row['nr_randvar_values'] = int(nr_randvar_values) row['nodes'] = nodes row['edges'] = edges row['has_cycles'] = cycles row['density'] = float(nx.density(pattern)) row['shape'] = man.get_graph_shape(pattern) row['max_degree'] = float(max_degree) row['avg_deg'] = float(average_degree) row['nr_targets'] = n_target_nodes if sel_emb: row['sel_emb'] = float(sel_emb) else: row['sel_emb'] = sel_emb if nr_emb: row['exh_emb'] = float(nr_emb) else: row['exh_emb'] = nr_emb row['has_obd'] = has_obd #row['unequal_size_warn']=unequal_size_warning row['OBD'] = OBD print "Nr embeddingS: ", len(embeddings) for i in xrange(0, len(embeddings)): row["emb_" + str(i + 1)] = embeddings[i] for i in xrange(0, len(emb_stds)): row["std_" + str(i + 1)] = emb_stds[i] for i in xrange(0, len(klds)): row["KLD_" + str(i + 1)] = klds[i] return row
def get_row_NS(general_path, pattern_result, experiment_name): row = {} if not (os.path.exists(os.path.join(general_path, 'input_pattern.gml'))): row['pattern_name'] = pattern_result row['nr_randvar_values'] = "NC" row['nodes'] = "NC" row['edges'] = "NC" row['has_cycles'] = "NC" row['density'] = "NC" row['shape'] = "NC" row['max_degree'] = "NC" row['avg_deg'] = "NC" row['nr_targets'] = "NC" row['nr_emb'] = "NC" row['has_obd'] = "NC" row['unequal_size_warn'] = "NC" row['OBD'] = "NC" return row pattern = nx.read_gml(os.path.join(general_path, 'input_pattern.gml')) nr_randvar_values = man.count_nr_randvars_in_graph(pattern) cycles = man.is_there_cycle_in_graph(pattern) max_degree = man.get_maximum_node_degree(pattern) average_degree = man.get_average_node_degree(pattern) n_target_nodes = man.get_nr_target_nodes_other_than_head(pattern) nr_emb = None has_obd = True if os.path.exists(os.path.join(pattern_result, 'no_obdecomp.info')): has_obd = False if os.path.exists(os.path.join(general_path, 'not_selected.info')): nr_emb = extract_nr_embeddings_NS( os.path.join(general_path, 'not_selected.info')) nodes, edges = man.get_readable_text_format(pattern) unequal_size_warning = False if os.path.exists( os.path.join(general_path, 'results_furer', 'unequal_size.warning')): unequal_size_warning = True OBD = None if os.path.exists( os.path.join(general_path, 'results_furer', 'OBDDecomp.info')): OBD = getOBDecomp( os.path.join(general_path, 'results_furer', 'OBDDecomp.info')) row['pattern_name'] = pattern_result row['nr_randvar_values'] = nr_randvar_values row['nodes'] = nodes row['edges'] = edges row['has_cycles'] = cycles row['density'] = nx.density(pattern) row['shape'] = man.get_graph_shape(pattern) row['max_degree'] = max_degree row['avg_deg'] = average_degree row['nr_targets'] = n_target_nodes row['nr_emb'] = nr_emb #row['has_obd']=has_obd #row['unequal_size_warn']=unequal_size_warning row['OBD'] = OBD return row
def __repr__(self): return str(man.get_readable_text_format(self.pattern_graph))