def process_smbh_cluster(H0, WM, WV): smbh_cluster_file = 'SMBH_cluster' smbh_cluster = get_cluster_file(os.path.join(cluster_folder, smbh_cluster_file)) for i, line in enumerate(smbh_cluster): sys.stdout.write(''.join(['\rConverting z to age in SMBH Cluster for #', str(i+1), ' of ', str(len(smbh_cluster))])) sys.stdout.flush() z = float(line[0]) input_params= [z, H0, WM, WV] age = CC.get_output_params(input_params) line.insert(1, age) print smbh_cluster = np.array(smbh_cluster, dtype=object) smbh_cluster = sorted(smbh_cluster, key=lambda l:l[2]) F = open(os.path.join(cluster_folder, 'smbh_cluster.pkl'), 'wb') pickle.dump(smbh_cluster, F) F.close() print('Saved SMBH Cluster array to pickle') print print(smbh_cluster[0]) print(smbh_cluster[int(len(smbh_cluster)/4)]) print(smbh_cluster[int(len(smbh_cluster)/2)]) print(smbh_cluster[3*int(len(smbh_cluster)/4)]) print(smbh_cluster[len(smbh_cluster)-1]) return smbh_cluster
def process_galaxies_cluster(H0, WM, WV): galaxies_cluster_file = 'galaxies_cluster' galaxies_cluster = get_cluster_file(os.path.join(cluster_folder, galaxies_cluster_file)) galaxies_cluster_length = len(galaxies_cluster) for i, line in enumerate(galaxies_cluster): if len(line) >= 6: line[5] = line[5:] if len(line) >= 7: line[6:] = [] sys.stdout.write(''.join(['\rConverting z to age in Galaxy Cluster for #', str(i+1), ' of ', str(galaxies_cluster_length)])) sys.stdout.flush() z = float(line[0]) input_params= [z, H0, WM, WV] age = CC.get_output_params(input_params) line.insert(1, age) print #galaxies_cluster = np.array([np.array(line, dtype=object) for line in galaxies_cluster], dtype=object) galaxies_cluster = np.array(galaxies_cluster, dtype=object) galaxies_cluster = sorted(galaxies_cluster, key=lambda l:l[2]) # print(galaxies_cluster) F = open(os.path.join(cluster_folder, 'galaxies_cluster.pkl'), 'wb') pickle.dump(galaxies_cluster, F) F.close() print('Saved Galaxies Cluster array to pickle') return galaxies_cluster
def highlight_each_cc_driver(file, verbose=False, min_size=-1): s = time.perf_counter() cc_im = CC.CC_Image(file, verbose) if (min_size == -1): min_size = .0001 * cc_im.original.size / 3 print("No minimum component size given, defaulting to .01%: " + str(min_size) + " pixels") gray_img = cc_im.rgb_to_gray(deepcopy(cc_im.original)) binary_img = cc_im.gray_to_binary(gray_img) labels = cc_im.remove_small_ccs(cc_im.two_pass_cc(binary_img), min_size) colored_img, color_dict = cc_im.color_all_ccs(labels) cc_count = cc_im.number_of_ccs(labels) unique_labels = np.unique(labels) ul_len = len(unique_labels) t = time.perf_counter() components = [] for i, x in enumerate( np.delete(unique_labels, np.argwhere(unique_labels == 0))): img = cc_im.highlight_one_cc(labels, colored_img, x) components.append(img) global img_counter fig = plt.figure() fig.canvas.set_window_title("Component # " + str(img_counter)) fig.canvas.mpl_connect( 'key_press_event', lambda event: change_component_with_key( event.key, fig, components, colored_img, cc_im.original)) print("Highlight all CC's:", '%.6f' % (time.perf_counter() - t)) plt.subplot(1, 3, 1) plt.imshow(cc_im.original) plt.axis('off') plt.subplot(1, 3, 2) plt.imshow(colored_img) plt.axis('off') plt.subplot(1, 3, 3) plt.imshow(components[img_counter]) plt.axis('off') #img_counter += 1 print("Full runtime:", '%.6f' % (time.perf_counter() - s)) print("Found " + str(cc_count) + " connected components") plt.show() return
def __init__(self): self.c_s_c = 0 # current slave count self.slave_count = 1 self.start_time = 0.0 self.f_complexity_list = [] # file complexity list file_list, path = CC.git_expand( "https://github.com/Vkanishka/ChatApp.git") self.path = path self.file_list = file_list self.total_file = len(self.file_list) print("number count of commits: {}".format(self.total_file))
def Classes(self, dept, teacher, name, number, week, sect): dept = CC.S2T(dept) teacher = CC.S2T(teacher) name = CC.S2T(name) result = [] sql = "SELECT * FROM `classes` WHERE `Department` LIKE '%" + str(dept) + "%' AND `Teacher` LIKE '%" + str(teacher) + "%' AND `Name` LIKE '%" + str(name) + "%' AND `Number` LIKE '%" + str(number) + "%';" for r in self.Query(sql): c = ClassDetail(r[1:]) t = c.Table if week != '' and sect != '' and t[int(week) - 1].find(sect) >= 0: result.append(c) elif week == '' and sect != '': for i in range(7): if t[i].find(sect) >= 0: result.append(c) elif week != '' and sect == '': if t[int(week) - 1] != '': result.append(c) elif week == '' and sect == '': result.append(c) return result
def Crawl(self, obj=False): bs = self.FixToBS() # 找寻其所有页数 final_tr = bs.find_all('tr')[-1] pattern = RE.compile(r'第 ([0-9]+) \/ ([0-9]+) 頁') match = pattern.match(final_tr.get_text()) self.Pages = int(match[2]) # 开始把找到的列物件化 result = [] for tr in bs.find_all('tr')[3:-2]: # 去头去尾 tmp = [] idx = 0 for td in tr.find_all('td'): # 学校代码问题,会超出 25 if idx < 25: tmp_text = td.get_text().strip().replace(' ', '-') if idx == 7: # 课名只取中文 name = td.find('a').get_text().strip() tmp.append(name) tmp.append(CC.T2S(name)) # 简体字课名 tmp.append(td.find('a')['href']) # 课纲网址 elif idx == 3 or idx == 15: # 简体字系所、老师 tmp.append(tmp_text) tmp.append(CC.T2S(tmp_text)) else: tmp.append(tmp_text) else: break idx += 1 if obj: result.append(ClassDetail(tmp)) else: result.append(tmp) return result
def run(): # z_s = [4, 3.1, 2.8, 2.5, 2.2, 2.0, 1.9, 1.75, 1.6, 1.5, 1.35, 1.3, 1.25, 1.2, 1.15, 1.1, 1.05, 1.0, 0.95, 0.9, 0.85, # 0.8, 0.75, 0.7, 0.65, 0.6, 0.55, 0.5, 0.45, 0.4, 0.35, 0.25, 0.2, 0.15, 0.1, 0.05, 0.0] z_s = np.linspace(4., 0., num=1000) print z_s age = [] for z in z_s: input_params= [z, H0, WM, WV] age.append(CC.get_output_params(input_params)) print age sigma = np.ones(len(age)) sigma[[0, -1]] = 0.02 popt, pcov = scipy.optimize.curve_fit(func, age, z_s, sigma=sigma) print popt z_est = np.array([func(x, *tuple(popt)) for x in age]) # print zip(age, z_est) plt.figure(1) plt.plot(age, z_s, label='t-to-z func') plt.plot(age, z_est, label='curve fit') locs, labels = plt.xticks() plt.setp(labels, rotation=45) # plt.xticks(np.arange(1.5, 14., 0.5)) plt.yticks(np.arange(0., 4.5, 0.5)) plt.legend() plt.grid(b=True, which='both', color='0.65',linestyle='-') plt.xlabel('Age (Gyr)') plt.ylabel('Z') plt.figure(2) diff = [(zest-zs)/zs for (zest, zs) in zip(z_est, z_s)] plt.plot(age, diff) plt.xlabel('Age (Gyr)') plt.ylabel('(z_est-z_s)/z_s') locs, labels = plt.xticks() plt.setp(labels, rotation=45) plt.xticks(np.arange(1.5, 14., 0.5)) plt.yticks(np.arange(-0.5, 9., 0.5)) plt.grid(b=True, which='both', color='0.65',linestyle='-') plt.title('Difference ratio between curve fit and z_function') plt.show()
def runkMeans(X,initial_centroids,max_iters,plot_progress=None): if plot_progress == None : plot_progress=False #if plot_progress: shape=X.shape m=shape[0] K=initial_centroids.shape[0] centroids=initial_centroids previous_centroids=centroids idx=np.zeros((m,1)) for i in range(max_iters): print 'K-Means iteration: %d %d' % (i,max_iters) idx=FCC.findClosestCentroids(X,centroids) if plot_progress: PPKM.plotProgresskMeans(X,centroids,previous_centroids,idx,K,i) previous_centroids=centroids centroids= CC.computeCentroids(X,idx,K) return (centroids,idx)
def rgb_to_ccs_driver(file, verbose=False, min_size=-1): s = time.perf_counter() cc_im = CC.CC_Image(file, verbose) if (min_size == -1): min_size = .0001 * cc_im.original.size / 3 print("No minimum component size given, defaulting to .01%: " + '%.6f' % (min_size) + " pixels") gray_img = cc_im.rgb_to_gray(deepcopy(cc_im.original)) binary_img = cc_im.gray_to_binary(gray_img) labels = cc_im.remove_small_ccs(cc_im.two_pass_cc(binary_img), min_size) colored_img, color_dict = cc_im.color_all_ccs(labels) plt.subplot(2, 2, 1) plt.imshow(cc_im.original) plt.axis('off') plt.subplot(2, 2, 2) plt.imshow(gray_img, cmap="gray") plt.axis('off') plt.subplot(2, 2, 3) plt.imshow(binary_img, cmap="gray") plt.axis('off') plt.subplot(2, 2, 4) plt.imshow(colored_img) plt.axis('off') print("Full runtime:", '%.6f' % (time.perf_counter() - s)) print("Found " + str(cc_im.number_of_ccs(labels)) + " connected components") plt.show() return
def main(argv=None): if argv == None: argv = sys.argv # this is the global time, it goes up every tick, it is global global global_time global_time = 0 sending_link = Link(8, True) recving_link = Link(8, False) # TODO P4 accept neural network configuration and network topology from # command line or input file hidden_neurons = 7 max_send_queue = 5 logfilename = "ssim.trc" oracle = Oracle() oracle.reg_link(sending_link) oracle.reg_link(recving_link) for i in range(1, 5): snd_agt = sending_agent(sending_link, CC.NCC(hidden_neurons, max_send_queue), i) rcv_agt = recving_agent(recving_link, 0 - i) sending_link.register(i, snd_agt) recving_link.register(0 - i, rcv_agt) oracle.reg_agt(snd_agt) try: logout = open(logfilename, 'w') oracle.begin_log(logout) except IOError as e: print "Failed to open log." net = Master_link(sending_link, recving_link) net.tock() oracle.flush_logs() net.tock() oracle.flush_logs() net.tock() oracle.flush_logs() logout.close()
print 'One: =============Find Closest Centroids...' data=sio.loadmat('ex7data2') X=data['X'] K=3 initial_centroids=np.array([[3,3],[6,2],[8,5]]) idx=FCC.findClosestCentroids(X,initial_centroids) print 'Closest Centroids for the first 3 examples: ' print idx[0:3] print '(the closest centroids should be 1, 3, 2 respectively)' #Part Two: Compute Means print 'Two: =============Compute Means ...' centroids=CC.computeCentroids(X,idx,K) print 'Centroids computed after initial finding of closest centroids: ' print centroids print '( the centroids should be [ [ 2.428301 3.157924 ] [ 5.813503 2.633656 ] [ 7.119387 3.616684 ]]' #Part Three: K-Means Clustering print 'Three: ================== K-Means Clustering ...' max_iters=10 res=RKM.runkMeans(X,initial_centroids,max_iters,True) plt.show() print 'K-Means Done...' #Part Four: K-Means Clustering on Pixels print 'Running K-Means clustering on pixels from an image ' img=cv2.imread('bird_small.png')
from time import time from GeneralisedWick import * import CC, texify, pickle fockTensor = Tensor("f", ['g'], ['g']) h2Tensor = Tensor("v", ['g', 'g'], ['g', 'g']) fockTensor.getAllDiagramsGeneral() h2Tensor.getAllDiagramsGeneral() t1Tensor = Tensor("{t_{1}}", ['p'], ['h']) t2Tensor = Tensor("{t_{2}}", ['p', 'p'], ['h', 'h']) normalOrderedHamiltonian = sum( fockTensor.diagrams) + (1. / 2.) * sum(h2Tensor.diagrams) BCH = CC.BCHSimilarityTransform(normalOrderedHamiltonian, t1Tensor + 0.5 * t2Tensor, 4) t0 = time() energyEquation = CC.getEnergyEquation(BCH) t1 = time() print("Time to find energy equation:", t1 - t0) print("number of terms:", len(energyEquation.summandList)) singlesAmplitudeEquation = CC.getAmplitudeEquation(BCH, 1) t2 = time() print("Time to find singles amplitude equation:", t2 - t1) print("number of terms:", len(singlesAmplitudeEquation.summandList)) doublesAmplitudeEquation = CC.getAmplitudeEquation(BCH, 2) #for summand in doublesAmplitudeEquation.summandList: # summand.prefactor *= (1. / 2.) t3 = time() print("Time to find doubles amplitude equation:", t3 - t2)
print("\n") print("CCSD") trueCCSD = cc.CCSD(mf) #old_update_amps = trueCCD.update_amps #def update_amps(t1, t2, eris): # t1, t2 = old_update_amps(t1, t2, eris) # print(t1) # return (np.zeros_like(t1[0]), np.zeros_like(t1[1])), t2 #trueCCD.update_amps = update_amps print(trueCCSD.kernel()) t7 = time() print("CCSD time:", t7 - t6) singlesResidual = Tensor("R", ['p'], ['h']) singlesResidual.array = contractTensorSum(singlesAmplitudeEquation) doublesResidual = Tensor("R", ['p', 'p'], ['h', 'h']) doublesResidual.array = contractTensorSum(doublesAmplitudeEquation) #print(residual.array) #print(h2Tensor.diagrams[12].array) CC.iterateDoublesAmplitudes(t2Tensor, doublesResidual, fockTensor.array) t5 = time() print("Time for MP2 calculation:", t5 - t7) print(contractTensorSum(energyEquation)) print(t2Tensor.array) CC.convergeCCSDAmplitudes(t1Tensor, t2Tensor, energyEquation, singlesAmplitudeEquation, doublesAmplitudeEquation, fockTensor) t2 = time() print("Time for CCSD calculation:", t2 - t5)
game = Game( first_screen='Wybrales KPNLS .....', possible_choices='KPNLS', choice_screen= 'Podaj swoj wybor: \nK - kamien \nP - papier \nN - nozyczki\n L - lizard\n S - spock', remis=['KK', 'PP', 'NN', 'LL', 'SS'], win=['PK', 'NP', 'KN', 'SK', 'LP', 'SN', 'NL', 'KL', 'PS', 'LS'], loss=['KP', 'PN', 'NK', 'KS', 'PL', 'NS', 'LN', 'LK', 'SP', 'SL']) game.play() if data == []: print('KONIEC GRY\n') else: import CC a = CC.win_loss_sequence(data, 'W') b = len(data) c = CC.win_loss_sequence(data, 'P') print('wyniki rozgrywek: ', data) print('ilosc WYGRANYCH uzytkownika: ', data.count('W')) print('ilosc PRZEGRANYCH uzytkownika: ', data.count('P')) # jesli W = 0 i P = 0 => ZeroDivisionError (np. dla data = ['remis', 'remis'] dlatego: if (data.count('W') + data.count('P')) > 0: print('ilosc WYGRANYCH uzytkownika w %: ', data.count('W') / (data.count('W') + data.count('P')) * 100, '%') print('ilosc PRZEGRANYCH uzytkownika w %: ', data.count('P') / (data.count('W') + data.count('P')) * 100, '%') else: print(
print("\n") print("CCD") trueCCD = cc.CCSD(mf) old_update_amps = trueCCD.update_amps def update_amps(t1, t2, eris): t1, t2 = old_update_amps(t1, t2, eris) # print(t1) return (np.zeros_like(t1[0]), np.zeros_like(t1[1])), t2 trueCCD.update_amps = update_amps print(trueCCD.kernel()) t7 = time() print("CCD time:", t7 - t6) residual = Tensor("R", ['p', 'p'], ['h', 'h']) residual.array = contractTensorSum(doublesAmplitudeEquation) print(residual.array) print(h2Tensor.diagrams[12].array) CC.iterateDoublesAmplitudes(t2Tensor, residual, fockTensor.array) t5 = time() print("Time for MP2 calculation:", t5 - t7) print(contractTensorSum(energyEquation)) print(t2Tensor.array) CC.convergeDoublesAmplitudes(t2Tensor, energyEquation, doublesAmplitudeEquation, fockTensor) t2 = time() print("Time for CCD calculation:", t2 - t5)
first_screen='Wybrales KPNLS .....', possible_choices='KPNLS', choice_screen = 'Podaj swoj wybor: \nK - kamien \nP - papier \nN - nozyczki\n L - lizard\n S - spock', remis = ['KK', 'PP', 'NN', 'LL', 'SS'], win = ['PK', 'NP', 'KN', 'SK', 'LP', 'SN', 'NL', 'KL', 'PS', 'LS'], loss = ['KP', 'PN', 'NK', 'KS', 'PL', 'NS', 'LN', 'LK', 'SP', 'SL'] ) game.play() if data == []: print ('KONIEC GRY\n') else: import CC a = CC.win_loss_sequence(data, 'W') b = len(data) c = CC.win_loss_sequence(data, 'P') print ('wyniki rozgrywek: ', data) print ('ilosc WYGRANYCH uzytkownika: ', data.count('W')) print ('ilosc PRZEGRANYCH uzytkownika: ', data.count('P')) # jesli W = 0 i P = 0 => ZeroDivisionError (np. dla data = ['remis', 'remis'] dlatego: if (data.count('W') + data.count('P')) > 0: print ('ilosc WYGRANYCH uzytkownika w %: ', data.count('W')/(data.count('W') + data.count('P'))*100, '%') print ('ilosc PRZEGRANYCH uzytkownika w %: ', data.count('P')/(data.count('W') + data.count('P'))*100, '%') else: print ('ilosc WYGRANYCH uzytkownika w %: 0\nilosc PRZEGRANYCH uzytkownika w %: 0') print ('najdluzsza sekwencja WYGRANYCH uzytkownika:', a)
H 0.000000, 0.000000, 2.6437904102 ''', basis='sto-3g', #basis = 'cc-pVDZ', symmetry='C2v', ) ##---------------------------------------------------------## mf = scf.RHF(mol).run() #mp2_res = MP2.MP2(mf) #mp2_res.nfo = 1 #mp2_res.run() cc_res = CC.state(mf) cc_res.variant = 'CCSD' if (cc_res.variant == 'ICCSD'): cc_res.no_act = 1 cc_res.nv_act = 1 cc_res.maxsub = 7 #cc_res.conv = 1e-7 cc_res.maxiter = 50 cc_res.energy.run() cc_res.maxiter = 30 cc_res.conv = 1e-6 cc_res.maxsub = 40
def createCC(self, last4, custId, name, ccNum, ccExp, ccv): self.userCCDic[last4] = CC(last4, custId, name, ccNum, ccExp, ccv)
from time import time from GeneralisedWick import * import CC, texify from pyscf import cc, mp fockTensor = Tensor("f", ['g'], ['g']) h2Tensor = Tensor("v", ['g', 'g'], ['g', 'g']) fockTensor.getAllDiagramsGeneral() h2Tensor.getAllDiagramsGeneral() t1Tensor = Tensor("{t_{1}}", ['p'], ['h']) t2Tensor = Tensor("{t_{2}}", ['p', 'p'], ['h', 'h']) normalOrderedHamiltonian = sum(fockTensor.diagrams) + (1. / 2.) * sum(h2Tensor.diagrams) BCH = CC.BCHSimilarityTransform(normalOrderedHamiltonian, t1Tensor + 0.25 * t2Tensor, 4) t0 = time() energyEquation = CC.getEnergyEquation(BCH) t1 = time() print("Time to find energy equation:", t1 - t0) print("number of terms:", len(energyEquation.summandList)) singlesAmplitudeEquation = CC.getAmplitudeEquation(BCH, 1) t2 = time() print("Time to find singles amplitude equation:", t2 - t1) print("number of terms:", len(singlesAmplitudeEquation.summandList)) doublesAmplitudeEquation = CC.getAmplitudeEquation(BCH, 2) t3 = time() print("Time to find doubles amplitude equation:", t3 - t2) print("number of terms:", len(doublesAmplitudeEquation.summandList))
# links.npz can be downloaded from https://s3.amazonaws.com/Harvard-CS205/wikipedia/links.npz # It is an (130148107, 2) array of np.uint32_t, generated by preprocess_to_npz.py # Self-links have been removed. # link names can be downloaded from https://s3.amazonaws.com/Harvard-CS205/wikipedia/titles-sorted.txt # Note that the code below converts link indices from 1-indexed to 0-indexed. if __name__ == '__main__': with timer.Timer() as t: print("Reading links") links = np.load('links.npz')['links'] - 1 print(" {} links in graph".format(links.shape[0])) print("Reading names") names = [l.strip() for l in open('titles-sorted.txt')] print(" {} nodes in graph".format(len(names))) print("Loading: {} seconds\n".format(t.interval)) num_nodes = len(names) total_time = 0 for i in range(10): links_copy = links.copy() # just in case with timer.Timer() as t: labels = CC.connected_components(num_nodes, links_copy) unique_labels = np.unique(labels) print("iter: {}: {} components".format(i + 1, unique_labels.size)) total_time += t.interval print("Total time: {} seconds".format(total_time))