def main(argv=None): if (argv == None): argv = sys.argv options = options_desc.parse_args(argv)[0] pool = Pool() found_parents = [n for n in pool if n.name == options.parent_node] assert (len(found_parents) == 1) parent = found_parents[0] chosen_idx = np.linspace(start=0, stop=parent.trajectory.n_frames - 1, num=options.numnodes).astype(int) print "choosen_idx: ", chosen_idx for i in chosen_idx: n = Node() n.parent_frame_num = i n.parent = parent n.state = "created" n.extensions_counter = 0 n.extensions_max = 0 n.extensions_length = 0 n.sampling_length = parent.sampling_length * 3 n.internals = parent.trajectory.getframe(i) pool.append(n) n.save()
def main(argv=None): if argv == None: argv = sys.argv options = options_desc.parse_args(argv)[0] pool = Pool() found_parents = [n for n in pool if n.name == options.parent_node] assert len(found_parents) == 1 parent = found_parents[0] chosen_idx = np.linspace(start=0, stop=parent.trajectory.n_frames - 1, num=options.numnodes).astype(int) print "choosen_idx: ", chosen_idx for i in chosen_idx: n = Node() n.parent_frame_num = i n.parent = parent n.state = "created" n.extensions_counter = 0 n.extensions_max = 0 n.extensions_length = 0 n.sampling_length = parent.sampling_length * 3 n.internals = parent.trajectory.getframe(i) pool.append(n) n.save()
def main(argv=None): if(argv==None): argv = sys.argv options = options_desc.parse_args(argv)[0] print("Options:\n%s\n"%pformat(eval(str(options)))) if(options.random_seed): # using numpy-random because python-random differs beetween 32 and 64 bit np.random.seed(hash(options.random_seed)) pool = Pool() old_pool_size = len(pool) print "pool", pool if(options.parent_node == "root"): parent = pool.root else: found = [n for n in pool if n.name == options.parent_node] assert(len(found) == 1) parent = found[0] print "### Generate nodes: %s ###" % options.methodnodes if(options.methodnodes == "kmeans"): chosen_idx = mknodes_kmeans(parent, options.numnodes) elif(options.methodnodes == "equidist"): chosen_idx = mknodes_equidist(parent, options.numnodes) elif(options.methodnodes == "maxdist"): chosen_idx = mknodes_maxdist(parent, options.numnodes) elif(options.methodnodes == "all"): chosen_idx = mknodes_all(parent) else: raise(Exception("Method unknown: "+options.methodnodes)) chosen_idx.sort() # makes preview-trajectory easier to understand if(options.write_preview): write_node_preview(pool, parent, chosen_idx) for i in chosen_idx: n = Node() n.parent_frame_num = i n.parent = parent n.state = "creating-a-partition" # will be set to "created" at end of script n.extensions_counter = 0 n.extensions_max = options.ext_max n.extensions_length = options.ext_length n.sampling_length = options.sampling_length n.internals = parent.trajectory.getframe(i) pool.append(n) print "\n### Obtain alpha: %s ###" % options.methodalphas old_alpha = pool.alpha if(options.methodalphas == "theta"): pool.alpha = calc_alpha_theta(pool) elif(options.methodalphas == "user"): pool.alpha = userinput("Please enter a value for alpha", "float") else: raise(Exception("Method unknown: "+options.methodalphas)) pool.history.append({'refined_node': (parent.name, parent.state), 'size':old_pool_size, 'alpha':old_alpha, 'timestamp':datetime.now()}) pool.save() # alpha might have changed print "\n### Obtain phi fit: %s ###" % options.methodphifit if(options.methodphifit == "harmonic"): do_phifit_harmonic(pool) elif(options.methodphifit == "switch"): do_phifit_switch(pool) elif(options.methodphifit == "leastsq"): do_phifit_leastsq(pool) else: raise(Exception("Method unkown: "+options.methodphifit)) for n in pool.where("state == 'creating-a-partition'"): n.state = "created" n.save() print "saving " +str(n) zgf_cleanup.main()
def main(): options = options_desc.parse_args(sys.argv)[0] pool = Pool() active_nodes = pool.where("isa_partition") if options.transition_level == "clusters": npz_file = np.load(pool.chi_mat_fn) chi_matrix = npz_file['matrix'] n_clusters = npz_file['n_clusters'] default_cluster_threshold = options.coreset_power # determine cluster #TODO this part is too cryptic # amount_phi[j] = amount of basis functions per cluster j amount_phi=np.ones(n_clusters,dtype=np.uint64) amount_phi=amount_phi*len(chi_matrix) amount_phi_total=len(chi_matrix) # sort columns of chi and return new sorted args arg_sort_cluster=np.argsort(chi_matrix,axis=0) # sort columns of chi and return new sorted chi # notice that the last row has to be [1 ... 1] sort_cluster=np.sort(chi_matrix,axis=0) # show_cluster contains arrays of the type [a b] where a is the row # and b the column of the entry from chi matrix where # chi_sorted(a,b) > default_cluster_threshold show_cluster=np.argwhere(sort_cluster > 0.5 ) # from the above it could be clear # that the amount of phi function # of cluster i is given by x where x the number so that # [x i] is in show_cluster and for all # [y i] in show_cluster we have x>y # we define amount_phi[i]=x for element in show_cluster: index=element[0] cluster=element[1] if amount_phi[cluster]>index: amount_phi[cluster]=index # create cluster list which contains arrays # each array consinst of a set of numbers corresponding to # the phi function of node_number cluster=[] for i in range(0,n_clusters): cluster_set=[] for j in range(amount_phi[i],amount_phi_total): #if (j < amount_phi[i] + 3): cluster_set.append(arg_sort_cluster[j][i]) cluster.append(cluster_set) for i in range(len(cluster)): counter = 0 for node_index in cluster[i]: counter += 1 # and ignore nodes which have a higher chi value then default_cluster_threshold if( chi_matrix[node_index][i] > default_cluster_threshold and counter>options.min_nodes): continue node = active_nodes[node_index] trajectory= node.trajectory print "-----" print "Generating transition nodes for node %s..."%node.name neighbour_frames = get_indices_equidist(node, options.num_tnodes) # create transition node for node_index for frame_number in neighbour_frames: print "Using frame %d as starting configuration."%frame_number n = Node() n.parent_frame_num = frame_number n.parent = node n.state = "created" n.extensions_counter = 0 n.extensions_max = options.num_runs-1 n.extensions_length = options.sampling_length n.sampling_length = options.sampling_length n.internals = trajectory.getframe(frame_number) n.save_mode = options.save_mode pool.append(n) n.save() print "%d transition nodes generated."%options.num_tnodes print "-----" zgf_setup_nodes.main() zgf_grompp.main() cluster_dict = {} for (ic,c) in enumerate(cluster): cluster_dict['cluster_%d'%ic] = c # save cluster np.savez(pool.analysis_dir+"core_set_cluster.npz", **cluster_dict) elif options.transition_level == "nodes": for node in active_nodes: trajectory= node.trajectory # TODO duplicate code... use the one above print "-----" print "Generating transition nodes for node %s..."%node.name neighbour_frames = get_indices_equidist(node, options.num_tnodes) # create transition point for node_index for frame_number in neighbour_frames: print "Using frame %d as starting configuration."%frame_number n = Node() n.parent_frame_num = frame_number n.parent = node n.state = "created" n.extensions_counter = 0 n.extensions_max = options.num_runs-1 n.extensions_length = options.sampling_length n.sampling_length = options.sampling_length n.internals = trajectory.getframe(frame_number) n.save_mode = options.save_mode pool.append(n) n.save() print "%d transition nodes generated."%options.num_tnodes print "-----" zgf_setup_nodes.main() zgf_grompp.main() instructionFile = pool.analysis_dir+"instruction.txt" f = open(instructionFile, "w") f.write("{'power': %f, 'tnodes': %d, 'level': '%s', 'min_nodes': %d}"%(options.coreset_power, options.num_tnodes, options.transition_level, options.min_nodes)) f.close()