def is_grounded(self): R = self.resolution ground_layer = [ Pos(x, 0, y) for x in range(R) for z in range(R) if self.matrix[x, 0, z] == FillState.Full ] if len(ground_layer) == 0: return False full_unvisited = Set() for x in range(R): for y in range(R): for z in range(R): if self.matrix[x, y, z] == FillState.Full: full_unvisited.add(Pos(x, y, z)) core = Set([pos for pos in full_unvisited if pos.y == 0]) boundary = Set([ pos for pos in self.neighbors(core) if pos in full_unvisited and pos not in core ]) while boundary: for pos in boundary: core.add(pos) full_unvisited.remove(pos) boundary = Set([ pos for pos in self.neighbors(core) if pos in full_unvisited and pos not in core ]) return not bool(full_unvisited)
def pos_neighbors(coords): vals = [-1, 0, 1] deltas = [ Vec(dx, dy, dz) for dx in vals for dy in vals for dz in vals ] nbrs = Set([ coords + delta for delta in deltas if (not delta.is_zero()) and self.is_coord_valid(coords + delta) ]) return nbrs
def graph_search(problem, priority_func, heuristic=None): # start fringe (state, actions, cost) """ :param problem: problem :param priority_func: func(Fringe) returns int :param heuristic: func(state, problem) :return: actions for the problem :rtype: list """ goal_fringe = fringe = Fringe(problem.getStartState(), [], 0, 0) # closed set closed = Set() # all possible states from util import PriorityQueueWithFunction fringe_queue = PriorityQueueWithFunction(priority_func) fringe_queue.push(fringe) while not fringe_queue.isEmpty(): # pop fringe = fringe_queue.pop() # goal test if problem.isGoalState(fringe.state): goal_fringe = fringe break # closed set if contains(closed, fringe.state): continue closed.add(fringe.state) # expand for successor in problem.getSuccessors(fringe.state): next_state, action, cost = successor expanded_fringe = Fringe(next_state, fringe.actions[:], fringe.cost_backward + cost, 0) expanded_fringe.actions.append(action) if heuristic is not None: expanded_fringe.cost_forward = heuristic( expanded_fringe.state, problem) # push fringe_queue.push(expanded_fringe) return goal_fringe.actions if goal_fringe is not None else []
def split_data(new_split = True): if new_split: A_files = glob.glob("{}/*-T1_resliced.nii.gz".format(A_dir)) subjects = Set() for A_file in A_files: subjects.add(get_subject_id(A_file)) B_files = glob.glob("{}/*-color_fa.nii.gz".format(B_dir)) N = len(B_files) indexes = np.random.permutation(N) train_indexes = indexes[0 : int(N*0.7)] val_indexes = indexes[int(N*0.7)+1 : int(N*0.8)] test_indexes = indexes[int(N*0.8)+1 : N] def save_split(split, files, ids): outputfile = "{}/{}_volumes.txt".format(destination_dir, split) rlt_files = [] with open(outputfile, 'w') as f: for i in ids: if get_subject_id(files[i]) in subjects: rlt_files.append(files[i]) f.write("{}\n".format(files[i])) return rlt_files train_files = save_split("train", B_files, train_indexes) val_files = save_split("val", B_files, val_indexes) test_files = save_split("test", B_files, test_indexes) else: def read_split(split): filename = "{}/{}_volumes.txt".format(destination_dir, split) with open(filename, 'r') as f: content = f.readlines() rlt_files = [] for line in content: rlt_files.append(line) return rlt_files train_files = read_split("train") val_files = read_split("val") test_files = read_split("test") return train_files, val_files, test_files
def generate_test_class_type(g): """ :param g: rdflib graph :return: """ classes_set = Set() try: # for rdf_type, _ in g.subject_objects(predicate=RDF.type): # for _, rdf_type in g.subject_objects(predicate=RDFS.Class): for rdf_type in g.subjects(predicate=RDF.type, object=OWL.Class): classes_set.add(rdf_type) tests = [] for c in classes_set: t = "%s type Class" % c print(t) tests.append(t) return tests except Exception as e: dolog("error in generating themis class_type tests") dolog(str(e))