Best Python code snippet using localstack_python
main.py
Source: main.py
1from Phase1.preprocess.persian_preprocessor import PersianPreprocessor as PP2from Phase2.preprocessor import Preprocessor as EP23from Phase1.preprocess.english_preprocessor import EnglishPreprocessor as EP4from Phase1.index.indexer import Indexer5from Phase1.preprocess.document_io import read_csv_file_as_list as read_english, \6 read_persian_xml_file_as_list as read_persian7from Phase2.document_io import read_csv_file as read_english28from Phase1.edit_query.edit_query import EditQuery as EQ9from Phase1.search import Searcher10from Phase2.my_tfidf_vectorizer import MyTfIdfVectorizer11from sklearn.svm import LinearSVC12from Phase2.svm import TfIdfClassifier as Classifier13import os14if __name__ == '__main__':15 # Classifier16 train_data = read_english2('../Phase2/source/phase2_train.csv')17 test_data = read_english2('../Phase2/source/phase2_test.csv')18 tfidf_vectorizer = MyTfIdfVectorizer(train_data['text'], EP2())19 best_model = LinearSVC(C=0.5)20 classifier = Classifier(train_data, test_data, tfidf_vectorizer, best_model)21 classifier.fit()22 ep_all = EP()23 pp_all = PP()24 eng_docs = ep_all.preprocess(read_english())25 per_docs = pp_all.preprocess(read_persian())26 indexer = Indexer()27 while True:28 print('Enter the section number:')29 section = input()30 print('Enter subsection number:')31 subsection = input()32 if section == '1':33 if subsection == '1':34 print('Enter the text:')35 txt = input()36 is_eng = EQ.is_english(query=txt)37 if is_eng:38 norm_text = EP().preprocess([txt])39 else:40 norm_text = PP().preprocess([txt])41 print(norm_text)42 elif subsection == '2':43 print('English Repetitive Words:')44 print(ep_all.get_high_accured_words())45 print('Persian Repetitive Words:')46 print(pp_all.get_high_accured_words())47 elif section == '2':48 if subsection == '1':49 for doc in eng_docs:50 indexer.add_doc(doc)51 for doc in per_docs:52 indexer.add_doc(doc)53 print('Indexing is done')54 elif subsection == '2':55 print('Enter the term:')56 term = input()57 ed_term = EQ(term, indexer, ep_all, pp_all).edit()58 print(indexer.get_posting(ed_term))59 elif subsection == '3':60 print('Enter the term:')61 term = input()62 ed_term = EQ(term, indexer, ep_all, pp_all).edit()63 print(indexer.get_pos_posting(ed_term))64 elif section == '3':65 indexer.save_dictionary(file_name='normal_dict.txt')66 print("normal dict size: " + str(os.path.getsize('normal_dict.txt')))67 if subsection == '1':68 indexer.save_dictionary(method='var', file_name='var_dict.txt')69 print("â«âªvariableâ¬â¬ â«âªbyteâ¬â¬ dict size: " + str(os.path.getsize('var_dict.txt')))70 indexer.load_dictionary(method='var', file_name='var_dict.txt')71 print('Indexer saved and loaded')72 elif subsection == '2':73 indexer.save_dictionary(method='gamma', file_name='gamma_dict.txt')74 print("gamma codeâ¬â¬ dict size: " + str(os.path.getsize('gamma_dict.txt')))75 # indexer.load_dictionary(method='gamma', file_name='gamma_dict.txt')76 print('Indexer saved and loaded')77 elif section == '4':78 if subsection == '1':79 print('Enter the query:')80 query = input()81 print(EQ(query, indexer, ep_all, pp_all).edit())82 elif section == '5':83 if subsection == '1':84 print('Enter the query:')85 query = input()86 print('Enter the subject (0 for none):')87 subject = int(input())88 if subject == 0:89 subject = None90 ed_query = EQ(query, indexer, ep_all, pp_all).edit()91 print(Searcher(indexer, classifier).search(ed_query, subject))92 elif subsection == '2':93 print('Enter the query:')94 query = input()95 print('Enter the window size')96 size = int(input())97 print('Enter the subject (0 for none):')98 subject = int(input())99 if subject == 0:100 subject = None101 ed_query = EQ(query, indexer, ep_all, pp_all).edit()102 print(Searcher(indexer, classifier).search_prox(ed_query, size, subject))103 elif section == '6':104 print("Classify all the English docs")105 tags = classifier.predict_docs(eng_docs)106 print(list(zip(range(len(eng_docs)), tags)))107 elif section == 'exit':108 break109 else:...
overall_EP.py
Source: overall_EP.py
1"""2RDX Overall EP3"""4def overall_EP(N, TIME, solutionM, Tset, Rlist, Slist, lg, expmatrixF, coeffmatrixF, expmatrixB, coeffmatrixB, targets, reduction_type, EPmin, graph):5 import numpy as np 6 from my_mech_obj import my_mech_obj7 from RDX_EP import local_error_propagation8 9 t_array = np.linspace(0,max(TIME), N)10 index = np.zeros((N))11 time = np.zeros((N))12 if reduction_type in ['species', 'S']:13 EP_all = np.zeros((len(Slist),N))14 DIC_ind = np.zeros((len(Slist)))15 DIC = np.zeros((len(Slist),len(Slist), N))16 17 else:18 EP_all = np.zeros((len(Rlist),N))19 20 ind_list = []21 ind_list_f = []22 coeffs = []23 #coeff_list = []24 #coeffs = np.zeros((len(Slist), 2, N))25 iterations = np.zeros((N))26 for i in range(N):27 a = 128 while TIME[a] < t_array[i] and a <= len(TIME):29 a = a+130 index[i] = a31 time[i] = TIME[int(a)]32 33 for i in range(len(Slist)):34 ind_list_f.append([])35 36 37 for i in range(N):38 39 t = time[i]40 41 #sample = solutionM[int(index[i]),0:len(Slist)]42 sample = solutionM[int(index[i])][:len(Slist)]43 samplesign = sample >= 044 45 #if samplesign.all:46 if t > -100:47 48 #print(np.shape(sample))49 50 mechobj = my_mech_obj(sample, t, Tset, Rlist, Slist, lg, expmatrixF, coeffmatrixF, expmatrixB, coeffmatrixB)51 52 53 if reduction_type in ['species', 'S']:54 [EP_i, ind_listi, DIC_i, coeffs_i] = local_error_propagation(mechobj, sample, targets, reduction_type, EPmin)55 56 EP_all[:,i] = EP_i57 ind_list.append(ind_listi)58 DIC[:,:,i] = DIC_i[:-1,:]59 coeffs.append(coeffs_i[:,1:])60 elif reduction_type in ['reactions', 'R']:61 EP_i = local_error_propagation(mechobj, sample, targets, reduction_type, EPmin)62 EP_all[:,i] = EP_i63 64 65 EP = np.max(EP_all, axis = 1)66 if graph:67 if reduction_type in ['species', 'S']:68 for i in range(len(Slist)):69 if sum(EP[i] == EP_all[i,:]) == 1:70 ind = np.where(EP[i] == EP_all[i,:])71 ind_list_f[i] = ind_list[int(ind[0])][i]72 DIC_ind[i] = int(ind[0])73 74 #coeff_list.append(coeffs[int(ind[0])][i][1:])75 76 elif sum(EP[i] == EP_all[i,:]) > 1:77 print('Multiple Matches: ', Slist[i]['name'])78 ind_list_f[i] = ind_list[N-1][i]79 DIC_ind[i] = int(N-1)80 #coeff_list.append(coeffs[N-1][i][1:])81 else:82 print('Error: ', Slist[i]['name'])83 84 85 return [EP, mechobj, ind_list_f, DIC, DIC_ind, coeffs]86 87 else:88 89 return [EP, mechobj]90 '''91# Uncomment below if making graphs! 92 if reduction_type in ['species', 'S']:93 for i in range(len(Slist)):94 if sum(EP[i] == EP_all[i,:]) == 1:95 ind = np.where(EP[i] == EP_all[i,:])96 ind_list_f[i] = ind_list[int(ind[0])][i]97 DIC_ind[i] = int(ind[0])98 99 #coeff_list.append(coeffs[int(ind[0])][i][1:])100 101 elif sum(EP[i] == EP_all[i,:]) > 1:102 print('Multiple Matches: ', Slist[i]['name'])103 ind_list_f[i] = ind_list[N-1][i]104 DIC_ind[i] = int(N-1)105 #coeff_list.append(coeffs[N-1][i][1:])106 else:107 print('Error: ', Slist[i]['name'])108 109 110 return [EP, mechobj, ind_list_f, DIC, DIC_ind, coeffs]111 112 elif reduction_type in ['reactions', 'R']:113 return [EP, mechobj]...
fitdir.py
Source: fitdir.py
1"""2Point estimates of Dirichlet parameters, based on3Thomas P. Minka 2009, "Estimating a Dirichlet distribution"4http://research.microsoft.com/en-us/um/people/minka/papers/dirichlet/minka-dirichlet.pdf5"""6from __future__ import division7import numpy as np8def moment_match_ronning(pvecs):9 """Minka eq. 23. not extensively tested"""10 N,K = pvecs.shape11 if N < 10:12 print "warning, N={} is unreliable for moment matching".format(N)13 ep_all = pvecs.mean(0)14 vp_all = pvecs.var(0)15 vp_all[vp_all < 1e-5] = 1e-516 ep = ep_all[:(K-1)]17 vp = vp_all[:(K-1)]18 terms = np.log(ep*(1-ep)/vp - 1)19 sumalpha = np.exp( np.mean(terms) )20 return ep_all * sumalpha21fitdir = moment_match_ronning22if __name__=='__main__':23 import random24 C=1025 N=2026 K=527 alpha = C * np.ones(K) / K28 for outer in range(10):29 d = np.random.dirichlet(alpha, N)30 # bootstrap31 results = []32 for itr in range(10000):33 samp=np.array([random.randrange(N) for i in range(N)])34 a=fitdir(d[samp])35 results.append(a)36 r = np.array(results)37 print "Real ", alpha38 print "Estimates:"39 print "low ",r.mean(0)-r.std(0)*240 print "mean ",r.mean(0)41 print "high ",r.mean(0)+r.std(0)*2...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!