def BCAFunction(df, tol, list_treat, list_score, verbose, split): print('----------------------') print('') print('BCA Method') print('') print('----------------------') start = datetime.now() step = 0 if verbose: print('step : ', step) # list_treat = list(df.columns.values) list_delete = list(set(list(df.columns.values)) - set(list_treat)) df = df.drop(list_delete, axis=1) features = list(df.columns.values) features.remove('Label') df_X = df[features] N = df_X.shape[1] df_X_init = df_X.copy() df_Y = df['Label'] condition = True X_opt = np.zeros(N) y_opt = score(X_opt, df_X_init, df_Y, split) while condition: step += 1 for i in range(N): X = X_opt.copy() X[i] = int(not X_opt[i]) score_X = score(X, df_X_init, df_Y, split) score_X_opt = score(X_opt, df_X_init, df_Y, split) if score_X >= score_X_opt: if score_X > list_score[-1]: print('score : ', score(X, df_X_init, df_Y, split)) list_score.append(score_X) else: list_score.append(list_score[-1]) X_opt = X.copy() else: if score_X > list_score[-1]: list_score.append(score_X) else: list_score.append(list_score[-1]) y = score(X_opt, df_X_init, df_Y, split) if verbose: print('step : {0}\ny_opt : {1}\ny :{2}'.format(step, y_opt, y)) if abs(y - y_opt) < tol or step > 10: condition = False y_opt = y list_features = selec_feat(X_opt, df_X_init, False) if verbose: print('It took : ', datetime.now() - start) return X_opt, y_opt, list_features, df_X_init, df_Y, list_score
def random_sampling(protein, configurations, fold_factor): protein_coor = get_coor_array(protein) len_protein = len(protein_coor) print len_protein protein_array = [] j = 0 while j < configurations: folds = random.randint(0, fold_factor*len_protein) print folds start_coor = copy.deepcopy(protein_coor) # print start_coor for i in range(folds): new_coor = folder_protein(start_coor, random.randint(2,len_protein), random.randint(1,3)) # print 'made fold' start_coor = copy.deepcopy(new_coor) new_protein = update_objects(protein, new_coor) # print 'made protein' grid = functions.protein_visual(new_protein) score = functions.score(new_protein, grid) protein_info = [score, copy.deepcopy(new_protein)] # print new_protein if protein_info not in protein_array: # print 'unique' protein_array.append(protein_info) j += 1 else: # print 'not unique' print protein_info print protein_array return protein_array
def evaluate_(self): if self.EVALUATETeamui.comboBox.currentIndex() == 0: error_dialog = QtWidgets.QErrorMessage() error_dialog.showMessage('Oops! please select match.') error_dialog.exec_() elif self.EVALUATETeamui.comboBox_2.currentIndex() == 0: error_dialog = QtWidgets.QErrorMessage() error_dialog.showMessage('Oops! please select team.') error_dialog.exec_() else: player_data.cur.execute( "SELECT * FROM teams WHERE name=?;", (self.EVALUATETeamui.comboBox_2.currentText(), )) player_ = [] for temp in tuple(player_data.cur.fetchall()): player_.append(temp[1]) score = 0 for temp in player_: player_data.cur.execute( "SELECT * FROM " + self.EVALUATETeamui.comboBox.currentText() + ''' WHERE player="''' + temp + '''";''') t = functions.score(player_data.cur.fetchone()) score += t self.EVALUATETeamui.label_5.setText(str(score))
def ajax_search(request): try: query = request.POST[u'query'] except KeyError: try: query = request.GET[u'query'] except KeyError: return HttpResponse(u'') tokens = re.split(ur'(?u)[^-\w]', query) while u'' in tokens: tokens.remove(u'') candidates = [] for candidate in models.Entity.objects.all(): candidates.append([candidate, 0]) for token in tokens: new_candidates = [] for candidate in candidates: if score(candidate[0], token) > 0: candidate[1] += score(candidate[0], token) new_candidates.append(candidate) candidates = new_candidates candidates.sort(lambda a, b: -cmp(a[1], b[1])) export = [] for candidate in candidates: if candidate[0].image_mimetype: image = True else: image = False export.append({ u'department': name, u'description': candidate[0].description, u'id': candidate[0].id, u'image': image, u'name': candidate[0].name, u'title': candidate[0].title, }) first_portion = export[:settings.INITIAL_RESULTS] second_portion = export[settings.INITIAL_RESULTS:] return render_to_response(u'search_internal.html', { u'first_portion': first_portion, u'second_portion': second_portion, u'query': urllib.quote(query), })
def find_best(protein_object, rep_num, high_score): # array with times and iterations result_array = [] start = timer() result_array.append(['start', start]) high_protein_object = copy.deepcopy(protein_object) high_coor_array = [] coor_array = get_coor_array(protein_object) count = 0 rep_count = 0 # folds random amino acid rep_num times # rep_count checks if protein changes and returns # best protein if protein stays the same after 30 folds while count < rep_num and rep_count < 50: start_ran = timer() - start fold_coor = folder_protein(coor_array, random.randint(2, len(coor_array) - 1)) protein_object_new = update_objects(protein_object, fold_coor) grid = functions.protein_visual(protein_object_new) score = functions.score(protein_object_new, grid) # checks if coordinates stay the same (no change) if fold_coor == coor_array: rep_count += 1 else: coor_array = copy.deepcopy(fold_coor) count += 1 # updates high score and object that belongs to high score if score < high_score: high_score = copy.copy(score) high_protein_object = copy.deepcopy(protein_object_new) high_coor_array = copy.deepcopy(coor_array) # adds end time and score after every fold set completion end_ran = timer() - start result_array.append(['best ran', start_ran, end_ran, count + rep_count, high_score]) end = timer() result_array.append(['end', end]) return [high_score, high_protein_object]
def change_(self): self.EVALUATETeamui.listWidget_2.clear() if self.EVALUATETeamui.comboBox.currentIndex() != 0: player_data.cur.execute( "SELECT * FROM teams WHERE name=?;", (self.EVALUATETeamui.comboBox_2.currentText(), )) player_ = [] for temp in tuple(player_data.cur.fetchall()): player_.append(temp[1]) if self.EVALUATETeamui.comboBox_2.currentIndex() != 0: for temp in player_: player_data.cur.execute( "SELECT * FROM " + self.EVALUATETeamui.comboBox.currentText() + ''' WHERE player="''' + temp + '''";''') self.EVALUATETeamui.listWidget_2.addItem( str(functions.score(player_data.cur.fetchone()))) self.EVALUATETeamui.label_5.setText(' ##')
# COMMON PRIMER DESIGN # Forward Common Primers # Common forward primer for all reactions are send for optimization. forwcom, forwcom_left, forwcom_right = justtrim( nucsequence, nucsequence[common_fwd_pos[0]:common_fwd_pos[1]], common_fwd_pos[0], common_fwd_pos[1], tm_target) if forwcom_left: for forward_common, pos in zip([forwcom, forwcom_left, forwcom_right], ['both', 'left', 'right']): tm_common_forward = tmcalculator(forward_common) primers[pos]['forward'] = [forward_common, None, tm_common_forward] a, b, c, d = score( forward_common, tm_target, 1) # 1 is a flag to score function telling no NNS in primer. df.loc[len(df)] = [ 0, 'Forward Common (' + pos + ')', str(forward_common), reversecomplement(forward_common, 0), str(tm_common_forward), gccontent(forward_common), len(forward_common), a, b, c, np.nan, d ] else: tm_common_forward = tmcalculator(forwcom) primers['both']['forward'] = \ primers['right']['forward'] = \ primers['left']['forward'] = [forwcom, None, tm_common_forward]
def anneal(protein_object, name, temperature): result_array = [] cur_score = 0 start = timer() result_array.append(['start', start]) # make starting point # cur_protein_array = folder_iter.find_best(protein_object, rep_num, 0) # cur_score = cur_protein_array[0] cur_protein = copy.deepcopy(protein_object) cur_coor = folder_iter.get_coor_array(cur_protein) start_temp = temperature #set high_score high_score = cur_score high_protein = copy.deepcopy(cur_protein) j = 0 # i = 0 counter = 0 while j < 15: start_an = timer() - start # functions.Visualizer2D(cur_protein, 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH', cur_score, "test%s+%s" %(i,counter)) # i+=1 result_array.append(['Start Anneal', start_an, temperature]) while temperature > 0.01: # functions.Visualizer2D(cur_protein, 'HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH', cur_score, "test%s+%s" %(i,counter)) # i+=1 # make next protein object next_coor = folder_iter.folder_protein(cur_coor, random.randint(2,len(cur_protein) - 1), random.randint(1,3)) next_protein = folder_iter.update_objects(cur_protein, next_coor) next_grid = functions.protein_visual(next_protein) next_score = functions.score(next_protein, next_grid) # calculate acceptation_chance acceptation_chance = calc_chance(next_score, cur_score, temperature) # print acceptation_chance if acceptation_chance < temperature: # print "CHANGE" cur_score = next_score cur_protein = copy.deepcopy(next_protein) cur_coor = copy.deepcopy(next_coor) # temperature is updated (not in function, because it is more effort, lines of code and time) temperature -= temperature * 0.005 # print "temperature:" + str(temperature) # print temperature if cur_score < high_score: # print "NEW HIGHSCORE" high_score = copy.copy(cur_score) high_protein = copy.deepcopy(cur_protein) result_array.append(['Score Iteration', high_score, counter, temperature]) counter += 1 # print cur_score, next_score, high_score, acceptation_chance cur_protein = copy.deepcopy(high_protein) cur_score = high_score cur_coor = folder_iter.get_coor_array(high_protein) start_temp = start_temp * 1.1 temperature = start_temp end = timer() - start result_array.append(['Result SA %s' %name, start_an, end, counter, high_score]) j+=1 # functions.Visualizer2D(cur_protein, main_SA.protein, cur_score, "test") return [high_score, high_protein, result_array]
corr.sort_values(key=lambda x: abs(x), ascending=False)) DO_LIN_FIT = 0 DO_NN_FIT = 1 DO_NNLIN_FIT = 0 if DO_LIN_FIT: print("-----------------------------------------") print(" ######## LIN MODEL ########") print("-----------------------------------------") ### Linear Model linModel, w = F.linRegression(x_train, y_train, x_test, y_test) w.plot.barh() plt.title("Weights") linPred = linModel.predict(x_test) scoreLin = F.score(linPred, y_test) print("Score:", np.round(scoreLin, 3)) ## linear shap explainer = shap.LinearExplainer(linModel, x_train, feature_dependence="independent") shap_valsLin = explainer.shap_values(x_test) ## summary plot plt.figure() shap.summary_plot(shap_valsLin, x_test.values, x_train.columns, alpha=0.5) ## one sample person # i=1 # shap.force_plot(explainer.expected_value,shap_valsLin[i,:],x_test.values[i,:],x_test.columns,matplotlib=True) shap.force_plot(explainer.expected_value, shap_valsLin, x_test.values,
def homepage(request): id = u'null' try: query = request.REQUEST[u'query'] except KeyError: query = u'' try: id = request.REQUEST[u'id'] if id: template = get_template(u'profile_internal.html') entity = models.Entity.objects.filter(id=int(id))[0] if entity.gps: gps = entity.gps elif entity.location and entity.location.gps: gps = entity.location.gps else: gps = u'' if gps: gps_url = u'http://maps.google.com/maps?f=q&hl=en&q=' + gps.replace(u' ', u'+') + "&iwloc=A&hl=en" else: gps_url = u'' profile = template.render(RequestContext(request, { u'entities': models.Entity.objects.filter(is_invisible=False), u'entity': entity, u'first_statuses': models.Status.objects.filter(entity=id).order_by(u'-timestamp')[:settings.INITIAL_STATUSES], u'gps': gps, u'gps_url': gps_url, u'id': int(id), u'emails': models.Email.objects.filter(entity=entity, is_invisible=False), u'phones': models.Phone.objects.filter(entity=entity, is_invisible=False), u'query': urllib.quote(query), u'second_statuses': models.Status.objects.filter(entity=id).order_by(u'-timestamp')[settings.INITIAL_STATUSES:], u'time_zones': models.TIME_ZONE_CHOICES, u'tags': models.Tag.objects.filter(entity=entity, is_invisible=False).order_by(u'name'), u'urls': models.URL.objects.filter(entity=entity, is_invisible=False), })) except KeyError: profile = u'' try: if query: template = get_template(u'search_internal.html') tokens = re.split(ur'(?u)[^-\w]', query) while u'' in tokens: tokens.remove(u'') candidates = [] for candidate in models.Entity.objects.all(): candidates.append([candidate, 0]) for token in tokens: new_candidates = [] for candidate in candidates: if score(candidate[0], token) > 0: candidate[1] += score(candidate[0],token) new_candidates.append(candidate) candidates = new_candidates candidates.sort(lambda a, b: -cmp(a[1], b[1])) export = [] for candidate in candidates: if candidate[0].image_mimetype: image = True else: image = False export.append({ u'department': candidate[0].department, u'description': candidate[0].description, u'id': candidate[0].id, u'image': image, u'name': candidate[0].name, u'title': candidate[0].title, }) first_portion = export[:settings.INITIAL_RESULTS] second_portion = export[settings.INITIAL_RESULTS:] template = get_template(u'search_internal.html') search_results = template.render(RequestContext(request, { u'first_portion': first_portion, u'query': query, u'second_portion': second_portion, })) else: search_results = u'' except KeyError: search_results = u'' return render_to_response(u'search.html', RequestContext(request, { u'profile': profile, u'query': urllib.quote(query), u'search_results': search_results, u'settings': settings, }))
# main loop run = True while run: clock.tick(30) # 30 fps for event in pygame.event.get(): # checks if the player closed the screen if event.type == pygame.QUIT: run = False keys = pygame.key.get_pressed() # read the keyboard inputs # left player commands if keys[pygame.K_w] and left_P.y != 0: left_P.y -= left_P.vel if keys[pygame.K_s] and left_P.y != (WIND_HEIGHT - left_P.height): left_P.y += left_P.vel # right player commands if keys[pygame.K_UP] and right_P.y != 0: right_P.y -= right_P.vel if keys[pygame.K_DOWN] and right_P.y != (WIND_HEIGHT - right_P.height): right_P.y += right_P.vel f.movement(ball, left_P, right_P) # checks the ball movement if f.score(ball, left_P, right_P): # checks score ball = cb.ball(10) drawScreen() # draw screen after inputs pygame.quit() # finish the game
def find_best_p(protein_object, rep_num, best_score): result_array = [] start = timer() result_array.append(['start', start]) high_protein_object = copy.deepcopy(protein_object) # arrays with h, p and c amino acid chain numbers h_loc = [] p_loc = [] c_loc = [] # gets coordinates array coor_array = get_coor_array(protein_object) # fills H and P arrays for i in range(len(protein_object)): if protein_object[i].ac_type == 'H': h_loc.append(i) elif protein_object[i].ac_type == 'P': p_loc.append(i) elif protein_object[i].ac_type == 'C': c_loc.append(i) count = 0 rep_count = 0 # folds random P amino acid rep_num times # rep_count checks if protein changes and returns # best protein if protein stays the same after 30 folds while count < rep_num and rep_count < 30: start_p = timer() - start random_bend = 0 # gets random amino num form p array (not amino num 0 and 1) while random_bend == 0 or random_bend == 1: random_bend = random.choice(p_loc) # bool to chose between two folds or one rand_bool = random.randint(0, 1) # if two P's are next to each other the both get folded to form a U turn if random_bend + 1 in p_loc and rand_bool == 1: # folds amino num, amino num + 1 for i in range(2): fold_coor = folder_protein(coor_array, random_bend) protein_object_new = copy.deepcopy(update_objects(protein_object, fold_coor)) grid = functions.protein_visual(protein_object_new) score = functions.score(protein_object_new, grid) if fold_coor == coor_array: rep_count += 1 else: coor_array = copy.deepcopy(fold_coor) count += 1 random_bend += 1 # checks if current score is new high score and updates score + object if score < best_score: best_score = copy.copy(score) best_protein_object = copy.deepcopy(protein_object_new) # folds random amino num else: fold_coor = folder_protein(coor_array, random_bend) protein_object_new = copy.deepcopy(update_objects(protein_object, fold_coor)) grid = functions.protein_visual(protein_object_new) score = functions.score(protein_object_new, grid) protein_object = copy.deepcopy(protein_object_new) # only updates coor array if it differs from previous coor array if fold_coor == coor_array: rep_count += 1 else: coor_array = copy.deepcopy(fold_coor) count += 1 if score < best_score: best_score = copy.copy(score) best_protein_object = copy.deepcopy(protein_object_new) # adds end time and score after every fold set completion end_p = timer() - start result_array.append(['get best P', start_p, end_p, count + rep_count, best_score]) end = timer() result_array.append(['end', end]) return [best_score, best_protein_object]
def home(): # if request.method == 'POST': # user = request.form['nm'] # return redirect(url_for('success',name = user)) # else: # user = request.args.get('nm') # return redirect(url_for('success',name = user)) # LOAD DATA location = 'data/dataobat.xml' documentNumber = func.docNumber(location) documentHeadline = func.docHeadline(location) documentText = func.docText(location) documentTotal = len(documentNumber) konten = [] for i in range(documentTotal): konten.append(documentHeadline[i] + documentText[i]) # PREPROCESSING text = func.removePunctuation(konten) text = func.caseFolding(text) text = func.tokenize(text) text = func.stopwordRemove(text) text = func.numberRemove(text) text = func.stemming(text) # GET ALL TERMS IN COLLECTION terms = func.getAllTerms(text) # INDEXING # index = createIndex(text,documentNumber, terms) index = func.createIndex(text, documentNumber) # tambahan untuk query yang belum di ekspan raw_query = ["100 mg of dacarbazine, "] # raw_query = newQuery query = func.removePunctuation(raw_query) query = func.caseFolding(query) query = func.tokenize(query) query = func.stopwordRemove(query) query = func.numberRemove(query) query = func.stemming(query) query = query[0] # Check Query In Index query = func.queryInIndex(query, index) # RANKED RETRIEVAL N = documentTotal tfidf_list = [] docFrequency = func.df(query, index) invDocFrequency = func.idf(docFrequency, N) termFrequency = func.tf(query, index) TFIDF = func.tfidf(termFrequency, invDocFrequency) sc = func.score(TFIDF) relevanceDocNumber = [] count = 0 print('Query: ', raw_query, '\n\n') print('RESULTS: \n') for i in range(len(sc)): relevanceDocNumber.append(int(sc[i])) a = documentNumber.index(sc[i]) print(documentHeadline[a] + 'Document Number: ', sc[i]) # print('\nContent:') # print(documentText[a][0:400], '[read more]>>') print('-------------------------------------------\n') count = count + 1 if (count >= 5): break # akhir tambahan return render_template('home.html', title='Load_data', raw_query=raw_query, dh=documentHeadline)