def go(code): verify_closings = errors.unclosed_symbols_verification(code) if len(verify_closings) > 1: if verify_closings[1] == "char": errors.pup_error( errors.get_error("0004", str(verify_closings[2] + 1))) elif verify_closings[1] == "str": errors.pup_error( errors.get_error("0005", str(verify_closings[2] + 1))) elif verify_closings[1] == "too_much_opening_parn": errors.pup_error( errors.get_error("0006", str(verify_closings[2] + 1))) elif verify_closings[1] == "too_much_closing_parn": errors.pup_error( errors.get_error("0007", str(verify_closings[2] + 1))) else: for i in tokenizer.go(code): for i2 in i: print(i2) print("-----------")
def try_several_h(h_list, x_validate_1, x_validate_2, N_classify): x_mix, label_real = rand_gen.rand_mix(N_classify) for h in h_list: # Estimate densities with parzen px_given_1 = parzen_estimate(x_validate_1, x_mix, h) px_given_2 = parzen_estimate(x_validate_2, x_mix, h) # Bayesian classification label_test = by.bayesian_classify(px_given_1, px_given_2) # Plot myplt.plot_est_vs_theo(x_mix, px_given_1, px_given_2, 'o', 'h=' + str(h)) # Error error_rate = err.get_error(label_real, label_test) print("h=" + str(h) + " error=" + str(error_rate))
def tokenize_line(line, line_counter, return_raw=False): line_result_raw = [] line_result = [] adder = 0 counter = -1 line += "." for i2 in line: counter += 1 if i2 in info.tokenizing_symbols: line_result_raw.append(line[adder:counter]) line_result_raw.append(i2) adder = counter + 1 if return_raw: return line_result_raw opened_str = False opened_char = False build_str = "" build_char = "" i3_counter = 0 for i3 in line_result_raw: if opened_str: if not i3 == "\"": build_str += i3 continue if opened_char: if not i3 == "\'": build_char += i3 continue if not opened_str and not opened_char and not i3 == "\"" and not i3 == "\'": line_result.append(i3) if i3 == "\"": if not opened_str: build_str += i3 opened_str = True else: build_str += i3 line_result.append(build_str) build_str = "" opened_str = False elif i3 == "\'": if not opened_char: build_char += i3 opened_char = True else: build_char += i3 line_result.append(build_char) build_char = "" opened_char = False line_result_copy = [] line_result_copy_1 = [] line_result_final = [] counter_1 = 0 x = 0 line_result.append("/") line_result.append("/") precedent_i8 = "" for i8 in line_result: if not i8.strip() == "": line_result_copy.append(i8.strip()) for i9 in line_result_copy: if i9 == "/": x = 0 try: char_after = line_result_copy[counter_1 + 1] if char_after == "/": break except: x += 1 else: line_result_copy_1.append(i9) counter_1 += 1 # Symbols-Repetition Errors Verification (fast) # last_symb = "" symb_black = [";", ",", ".", "!", "{", "}"] # Symbols to prevent from repeating in the code for i10 in line_result_copy_1[0:len(line_result_copy_1) - 1]: if last_symb == i10 and i10 in symb_black: errors.pup_error( errors.get_error("0003", str(line_counter + 2), i10, str(counter))) last_symb = i10 ############################################################## if line_result_copy_1[len( line_result_copy_1 ) - 2] == ";": # Detects and remove an eventually existing semicolon at the end of the line. line_result_copy_1.pop(len(line_result_copy_1) - 2) # return line_result_copy_1[0:len(line_result_copy_1) - 1]
print('ITEM d) Bayes classifier with parzen and knn estimation') # Generate mixture distribution N_test = 100 x_test, label_real = rand_gen.rand_mix(N_test) # Bayesian classification with parzen estimate h = 0.3 px_given_1_parzen = parzen.parzen_estimate(x_samples_1, x_test, h) px_given_2_parzen = parzen.parzen_estimate(x_samples_2, x_test, h) label_test_parzen = by.bayesian_classify(px_given_1_parzen, px_given_2_parzen) myplt.plot_with_labels( x_test, label_real, label_test_parzen, 'Clasificacion bayesiana con estimacion Parzen, h=' + str(h)) err_parzen = err.get_error(label_real, label_test_parzen) print('Error with parzen is: ' + str(err_parzen)) # Bayesian classification with knn estimate for k in k_list: px_given_1_knn = knn.knn_estimate(k, x_samples_1, x_test) px_given_2_knn = knn.knn_estimate(k, x_samples_2, x_test) label_test_knn = by.bayesian_classify(px_given_1_knn, px_given_2_knn) myplt.plot_with_labels( x_test, label_real, label_test_knn, 'Clasificacion bayesiana con estimacion KNN, k=' + str(k)) err_knn = err.get_error(label_real, label_test_knn) print('Error with knn is: ' + str(err_knn) + " k=" + str(k)) print('ITEM e) knn classifier') k_list = [1, 11, 51]
import sys import info import errors import start_modules counter = 0 file_to_interpret = "" for i in sys.argv: if i.startswith("--"): raw_arg = i[2:len(i)] if raw_arg.lower() == "file": try: err_test = sys.argv[counter + 1] except: errors.pup_error(errors.get_error("0001")) file_name = " " for i2 in range(counter + 1, len(sys.argv)): if not sys.argv[i2].startswith("--"): file_name += sys.argv[i2] + " " else: break file_name = file_name.strip() file_read = "" try: fstream = open(file_name) file_read = fstream.read() fstream.close()