def reordered(graph, reorderedLists): # Only write a warning if values were reordered. if len(reorderedLists) > 0: text = [] text.append('Input values have been reordered.') text.append('At least one of the tasks in the pipeline has arguments that are linked together. ' + \ 'This is usually the case, when there are two arguments whose values need to be connected with one ' + \ 'another (for example, the two fastq files from paired end sequencing). In constructing the pipeline, ' + \ 'gkno reordered the values supplied to some tasks, outlined below:') text.append('\t') for task, nodeId, linkedNodeId, originalList, reorderedList, referenceList in reorderedLists: longFormArgument = graph.getGraphNodeAttribute(nodeId, 'longFormArgument') text.append('- task: ' + task + ', argument: ' + longFormArgument) string = originalList[0] for i in range(1, len(originalList)): string += ', ' + originalList[i] text.append('\toriginally: ' + string) string = reorderedList[0] for i in range(1, len(reorderedList)): string += ', ' + reorderedList[i] text.append('\tmodified to: ' + string) string = referenceList[0] for i in range(1, len(referenceList)): string += ', ' + referenceList[i] text.append('\tto match: ' + string) text.append('\t') text.append('Please check that these files are ordered correctly. To disable reordering of input values, ' + \ 'include the argument \'--do-not-reorder (-dnr)\' on the command line.') # Write the warning to screen. errors.errors().writeFormattedText(text, 'warning')
def two_cities(city1, city2): """The main 'two-cities' function""" if city1 == "" and city2 == "": return errors("City1AndCity2ValueError") if city1 == "": return errors("City1ValueError") if city2 == "": return errors("City2ValueError") try: rows = reading_tsv_two_cities(city1, city2) except TypeError: return errors("NoneTypesError") except AttributeError: return errors("NoneTypesError") except FileNotFoundError: return errors("FileNotFoundDBError") if rows[0][14] == '-1' and rows[1][14] == '-1': return errors("NoSuchCitiesError") if rows[0][14] == '-1': return errors("NoSuchCity1Error") if rows[1][14] == '-1': return errors("NoSuchCity2Error") d = making_json(rows, len(rows), "two_cities") return complete_json_two_cities(d, city1, city2)
def page_with_cities(page, number): """The main 'page-with-cities' function""" if (page == "" and number == "") or (page == "0" and number == "0"): return errors("PageAndNumberValueError") if (page == "") or (page == "0"): return errors("PageValueError") if (number == "") or (number == "0"): return errors("NumberValueError") try: first_city = ((int(page) - 1) * int(number)) + 1 last_city = int(page) * int(number) except ValueError: return errors("IntValueError") except TypeError: return errors("NoneTypesError") except AttributeError: return errors("NoneTypesError") try: rows = reading_tsv_page_with_cities(first_city, last_city) except FileNotFoundError: return errors("FileNotFoundDBError") if len(rows) != last_city - first_city + 1: return errors("NotEnoughCitiesError") return making_json(rows, len(rows), "page_with_cities")
def city_info(geonameid): """The main 'city-info' function""" if geonameid == "": return errors("GeonameidValueError") try: row = reading_tsv_city_info(geonameid) except FileNotFoundError: return errors("FileNotFoundDBError") if row is None: return errors("NoSuchGeonameidError") row = [row] return making_json(row)
def test_404_error(self): errorCheck = errors() urlopen = self.get_url_open() url = self.get_url("/does_not_exist.html") response = errorCheck.check_errors(url) self.assertEqual(url +" -- Error code: 404", response)
def test_200_error(self): errorCheck = errors() urlopen = self.get_url_open() url = self.get_url("/index.html") response = errorCheck.check_errors(url) self.assertEqual(url +" -- Status code: 200", response)
def __init__(self): # Get general error writing and termination methods. self.errors = errors.errors() # The error messages are stored in the following list. self.text = [] # Errors encountered with the admin portion of gkno generate an error code of '2'. # The error codes associated with other aspects of the code are as follows: # # Admin errors generate an error code of '2'. # Command line errors generate an error code of '3'. # File handling errors generate an error code of '4'. # General configuration file errors generate an error code of '5'. # Tool configuration file errors generate an error code of '6'. # Pipeline configuration file errors generate an error code of '7'. # Errors associated with the graph construction generate an error code of '8'. # Errors associated with handling arguments generate an error code of '9'. # Data consistency errors generate an error code of '10'. # Errors coming from help requests generate an error code of '11'. # Errors with plotting the pipeline graph generate an error code of '12'. # Errors with makefile generation generate an error code of '13'. # Errors with parameter sets generate an error code of '14'. # Errors associated with constructing filenames generate an error code of '15'. self.errorCode = '2'
def name_hint(name): """The main 'name-hint' function""" if name == "": return errors("NameValueError") try: names = reading_tsv_name_hint(name) except TypeError: return errors("NoneTypeError") except AttributeError: return errors("NoneTypeError") except FileNotFoundError: return errors("FileNotFoundDBError") if len(names) == 0: return errors("NoSuitableCities", name) return {'possible_city_names': list(sorted(names))}
def test_errors(): import errors as er list1 = [0.5, 3, 4, 5, 6, 7, 10, 3, 0.6, 5.2] list2 = [1, 0, 2, 16, 5.5, 6.7, 11, 3.5, .5, 18] out = 10 # test errors mae = er.errors('mae', list1, list2=list2, outlim=out) assert mae == pytest.approx(0.9875) mape = er.errors('mape', list1, list2=list2, outlim=out) assert mape == pytest.approx(38.244, 0.00001) mse = er.errors('mse', list1, list2=list2, outlim=out) assert mse == 1.85625 rmse = er.errors('rmse', list1, list2=list2, outlim=out) assert rmse == pytest.approx(1.36244, 0.00001)
def __init__(self): # Get general error writing and termination methods. self.errors = err.errors() # The error messages are stored in the following list. self.text = [] # For a list of all error code values, see adminErrors.py. self.errorCode = '11'
def make_model_result(value): rmse, mae, low, high = errors.errors(value.actuals, value.predictions) result = ModelResults( rmse=rmse, mae=mae, ci95_low=low, ci95_high=high, predictions=value.predictions, ) return result
def make_data(control): 'return the reduction dictionary' result = {} for test_month in control.test_months: path = '%s%s.pickle' % ( control.path_in_valavm_dir, test_month, ) print 'make_data reading', path assert control.k == 1 with open(path, 'rb') as f: # read each fitted model and keep the k best lowest_mae = None best_key = None best_importances = None counter = collections.Counter() input_record_number = 0 while True: counter['attempted to read'] += 1 input_record_number += 1 try: record = pickle.load(f) key, value = record actuals_predictions, importances = value actuals = actuals_predictions.actuals predictions = actuals_predictions.predictions rmse, mae, ci95_low, ci95_high = errors.errors(actuals, predictions) if (lowest_mae is None) or (mae < lowest_mae): lowest_mae = mae best_key = key best_importances = importances except ValueError as e: counter['ValueError'] += 1 print e print 'ignoring ValueError for record %d' % input_record_number except EOFError: counter['EOFError'] += 1 print 'stopping read at EOFError for record %d' % input_record_number break except pickle.UnpicklingError as e: counter['UnpicklingError'] += 1 print e print 'ignoring UnpicklingError for record %d' % input_record_number print 'test_month', test_month, 'type(best_key)', type(best_key) print key = ReductionKey( test_month=test_month) value = ReductionValue( model=best_key, importances=best_importances, mae=lowest_mae, ) result[key] = value return result
def __init__(self): # Get general error writing and termination methods. self.errors = errors.errors() # The error messages are stored in the following list. self.text = [] # Different segments of gkno produce different error codes. The list of which # values correspond to which aspect of the code are held in the adminErrors. # For a list of all error code values, see adminErrors.py. self.errorCode = '9'
def __init__(self): self.urlCorrect = urlCorrector() self.HTML_corrector_helper = HTML_corrector_help() self.download = download() self.errors = errors() self.parsers = parsers() self.choices = { '1': 'download', '2': 'error', '3': 'search', '4': 'crawl', '5': 'web structure' } self.choice = self.choices['4'] #the default is crawl self.list_of_links = self.urlCorrect.list_of_links self.NOT_LINK = self.urlCorrect.NOT_LINK self.SCHEME_HTTP = self.urlCorrect.SCHEME_HTTP self.SCHEME_HTTPS = self.urlCorrect.SCHEME_HTTPS self.SUPPORTED_SCHEMES = self.urlCorrect.SUPPORTED_SCHEMES
def complete_json_two_cities(d, city1, city2): """Makes additional info for 'two-cities' json response""" d['info'] = {} # Latitude d['info']['nothern'] = {} if float(d['city1']['latitude']) > float(d['city2']['latitude']): d['info']['nothern']['geonameid'] = d['city1']['geonameid'] d['info']['nothern']['name'] = d['city1']['name'] d['info']['nothern']['russian_name'] = city1 else: d['info']['nothern']['geonameid'] = d['city2']['geonameid'] d['info']['nothern']['name'] = d['city2']['name'] d['info']['nothern']['russian_name'] = city2 # Same timezone if d['city1']['timezone'] == d['city2']['timezone']: d['info']['same_timezone'] = True else: d['info']['same_timezone'] = False # Timezone difference d['info']['timezone_difference'] = {} try: time_abs, time_not_abs = compare_timezones(d['city1']['timezone'], d['city2']['timezone']) except FileNotFoundError: return errors("FileNotFoundTZError") if not time_abs and not time_not_abs: # If there is no data d['info']['timezone_difference'][ 'not_absolute_difference'] = 'missing data' d['info']['timezone_difference'][ 'absolute_difference'] = 'missing data' # If the data exists d['info']['timezone_difference']['not_absolute_difference'] = time_not_abs d['info']['timezone_difference']['absolute_difference'] = time_abs return d
def make_chart_efh(k, reduction, actuals, median_price, control): '''Write charts e and f, return median-absolute-relative_regret object''' def interesting(): return k == 5 def trace_if_interesting(): if interesting(): print 'k', k pdb.set_trace() return True else: return False ensemble_weighting = 'exp(-MAE/100000)' mae = {} debug = False my_validation_months = [] my_ensemble_mae = [] my_best_mae = [] my_price = [] for validation_month in control.validation_months: e = ChartEReport(k, ensemble_weighting, control.column_definitions, control.test) h = ChartHReport(k, ensemble_weighting, control.column_definitions, control.test) if debug: print validation_month pdb.set_trace() query_month = Month(validation_month).increment(1).as_str() if query_month not in reduction: control.exceptions.append('%s not in reduction (charts ef)' % query_month) print control.exception continue cum_weighted_predictions = None cum_weights = 0 mae_validation = None check_key_order(reduction[validation_month]) # write lines for the k best individual models # accumulate info needed to build the ensemble model index0_mae = None for index, query_month_key in enumerate(reduction[query_month].keys()): # print only k rows if index >= k: break print index, query_month_key validation_month_value = reduction[validation_month][ query_month_key] print query_month query_month_value = reduction[query_month][query_month_key] if mae_validation is not None and False: # turn off this test for now trace_unless( mae_validation <= validation_month_value.mae, 'should be non-decreasing', mae_previous=mae_validation, mae_next=validation_month_value.mae, ) mae_validation = validation_month_value.mae mae_query = query_month_value.mae if index == 0: index0_mae = mae_query eta = 1.0 weight = math.exp(-eta * (mae_validation / 100000.0)) e.detail_line( validation_month=validation_month, model=query_month_key.model, n_months_back=query_month_key.n_months_back, n_estimators=query_month_key.n_estimators, max_features=query_month_key.max_features, max_depth=query_month_key.max_depth, learning_rate=query_month_key.learning_rate, rank=index + 1, mae_validation=mae_validation, weight=weight, mae_query=mae_query, ) h.detail_line( validation_month=validation_month, model_description=short_model_description(query_month_key), mae_validation=mae_validation, mae_query=mae_query, ) # need the mae of the ensemble # need the actuals and predictions? or is this already computed predictions_next = query_month_value.predictions if cum_weighted_predictions is None: cum_weighted_predictions = weight * predictions_next else: cum_weighted_predictions += weight * predictions_next cum_weights += weight # write line comparing the best individual model in the next month # to the ensemble model trace_if_interesting() ensemble_predictions = cum_weighted_predictions / cum_weights ensemble_rmse, ensemble_mae, ensemble_ci95_low, ensemble_ci95_high = errors.errors( actuals[query_month], ensemble_predictions, ) best_key = reduction[query_month].keys()[0] best_value = reduction[query_month][best_key] e.detail_line( validation_month=validation_month, mae_ensemble=ensemble_mae, model=best_key.model, n_months_back=best_key.n_months_back, n_estimators=best_key.n_estimators, max_features=best_key.max_features, max_depth=best_key.max_depth, learning_rate=best_key.learning_rate, ) h.detail_line( validation_month=validation_month, model_description='ensemble', mae_query=ensemble_mae, ) my_validation_months.append(validation_month) my_ensemble_mae.append(ensemble_mae) my_best_mae.append(best_value.mae) e.write(control.path_out_e_txt % (k, validation_month)) mae[validation_month] = Bunch( index0=index0_mae, ensemble=ensemble_mae, best_next_month=best_value.mae, ) my_ensemble_mae = [] my_best_mae = [] my_price = [] for month in my_validation_months: my_ensemble_mae.append(mae[month].ensemble) my_best_mae.append(mae[month].best_next_month) my_price.append(median_price[Month(month)]) width = 0.35 fig = plt.figure() fig1 = fig.add_subplot(211) fig1.bar( [x + width for x in range(len(my_validation_months))], my_best_mae, width, color='white', ) fig1.bar( range(len(my_validation_months)), my_ensemble_mae, width, color='black', ) plt.ylim(0, 180000) labels = my_validation_months plt.xticks( [x + .4 for x in range(len(my_validation_months))], labels, rotation=-70, size='xx-small', ) plt.ylabel('MAE ($)') plt.xlabel('Year-Month') white_patch = mpatches.Patch( facecolor='white', edgecolor='black', hatch='', lw=1, label="MAE of Best Model in Validation Month", ) black_patch = mpatches.Patch( facecolor='black', edgecolor='black', hatch='', lw=1, label="MAE of Ensemble of " + str(k) + " Best Models in Validation Month", ) plt.legend(handles=[white_patch, black_patch], loc=2) fig2 = fig.add_subplot(212) fig2.bar( [x + width for x in range(len(my_validation_months))], [int(m) / int(p) for m, p in zip(my_best_mae, my_price)], width, color='white', ) fig2.bar( range(len(my_validation_months)), [int(m) / int(p) for m, p in zip(my_ensemble_mae, my_price)], width, color='black', ) plt.ylim(0, .5) labels = my_validation_months plt.xticks( [x + .4 for x in range(len(my_validation_months))], labels, rotation=-70, size='xx-small', ) plt.ylabel('Absolute Relative Error') plt.xlabel('Year-Month') white_patch = mpatches.Patch( facecolor='white', edgecolor='black', hatch='', lw=1, label="ARE of Best Model in Validation Month", ) black_patch = mpatches.Patch( facecolor='black', edgecolor='black', hatch='', lw=1, label="ARE of Ensemble of " + str(k) + " Best Models in Validation Month", ) plt.legend(handles=[white_patch, black_patch], loc=2) plt.tight_layout(pad=0.8, w_pad=0.8, h_pad=1.0) plt.savefig(control.path_out_e_pdf % k) plt.close() f = ChartFReport(k, ensemble_weighting, control.column_definitions, control.test) regrets = [] relative_errors = [] for validation_month in control.validation_months: query_month = Month(validation_month).increment(1).as_str() print query_month print "need to define best_next_month --> best_query_month" pdb.set_trace() query_month_value = reduction[query_month][query_month_key] regret = mae[validation_month].ensemble - mae[ validation_month].best_next_month regrets.append(regret) relative_error = regret / median_price[Month(validation_month)] relative_errors.append(relative_error) median_price_next = median_price[Month(query_month)] f.detail_line( validation_month=validation_month, mae_index0=mae[validation_month].index0, mae_ensemble=mae[validation_month].ensemble, mae_best_next_month=mae[validation_month].best_next_month, median_price=median_price[Month(validation_month)], fraction_median_price_next_month_index0=mae[validation_month]. index0 / median_price_next, fraction_median_price_next_month_ensemble=mae[validation_month]. ensemble / median_price_next, fraction_median_price_next_month_best=mae[validation_month]. best_next_month / median_price_next, ) median_absolute_regret = np.median(np.abs(regrets)) median_absolute_relative_regret = np.median(np.abs(relative_errors)) f.write(control.path_out_f % k) return median_absolute_regret, median_absolute_relative_regret
from rollPageMain import * from aboutMainPage import * from bugsPageMain import * from deletePageMain import * from newfeatures import * from pkg_resources import * import logging import os logging.basicConfig() # shortcuts version = version() # itemSearch = itemSearch() errors = errors() def resource_path(relative): if hasattr(sys, "_MEIPASS"): return os.path.join(sys._MEIPASS, relative) return os.path.join(relative) class helpPageMain(Page): def __init__(self, *args, **kwargs): Page.__init__(self, *args, **kwargs) self.photo = tk.PhotoImage(file=resource_path(os.path.join('images',"notready.gif"))) label = tk.Label(self, image=self.photo) label.pack() class MainView(tk.Frame): def __init__(self, master=None, *args, **kwargs):
def _setup_errors(self): # create error object err = errors(self.logger, self.params['daemon']) return err
T = 0.1 data = (S0, sig, r, T, K) bins = args.get('bins') error_c = args.get('error_c') bins_list = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] # Ready for painting distinct bins max_error_gate = 0.005 error_name = 'depolarizing' repeats = 100 measure = True thermal = False steps = 51 # Create error objecterror= Err = errors(data, max_error_gate, steps) #Err.paint_AE_unary_run_bins(bins_list, error_name, repeats, M=4, step=3, measure_error=measure, thermal_error=thermal) #Err.paint_cl_payoff(100) #print('binary') # Compute payoff errors in binary # Err.compute_save_errors_binary(bins, error_name, repeats, measure_error=measure, thermal_error=thermal, error_c=error_c) #print('unary') # Compute payoff errors in unary #Err.compute_save_errors_unary(bins, error_name, repeats, measure_error=measure, thermal_error=thermal) #print('paint errors') #Paint errors corresponding to Fig. 14 Err.paint_errors(bins, error_name, repeats, measure_error=measure,
# Set train1 index back to normal train1 = train1.set_index('date') # We'll need to forecast the next 3 months. So we will be forecasting the lasst 3 months of the training data from the # previous data and see the results. # Period to forecast starti = '2017-10-01' endi = '2017-12-30' # Create SARIMAX model with exogenous variables model1 = sm.tsa.statespace.SARIMAX(endog=train1.sales[:starti], exog=ex_data[:starti], trend='n', order=(7, 1, 0), seasonal_order=(0, 1, 1, 7)).fit() # Create a forecast columns to train1 data for easier plotting. endi_1 = '2017-12-31' train1['forecast'] = model1.predict(start=pd.to_datetime(starti), end=pd.to_datetime(endi_1), exog=ex_data[starti:endi], dynamic=True) # Plot the sales and the forecast. train1[starti:endi][['sales', 'forecast']].plot(figsize=(10, 6)) plt.show() errors(train1[starti:endi]['sales'], train1[starti:endi]['forecast']) # Errors are still over 20% and the plot shows a great difference between the prediction and the real values. # TODO: We'll need to find a more suitable way to forecast the sales than SARIMAX-models.
from token import Token, matchToken from seeker import Handler from errors import errors from sintatico import programa, TokenTree from symb import SymbolTable from inter import Instrucao, gerarCodigoIntermediario #Essa seria a main do programa. Nela, um handler é instanciado #e vai solicitando os tokens. Ao invés desse while, teria que ser #chamado o analisador sintático, passando o handler para que ele #possa verificar os próximos tokens. filename = sys.argv[1] handler = Handler(filename) tknList = [] err = errors() table = SymbolTable() tree = programa(handler, err, table) '''while True: t = handler.nextToken() linha = handler.getLinha() tkn = matchToken(t, linha) if(tkn.getTokenCode() == 0): break elif(tkn.getTokenCode() == -1): err.addErr(tkn.getSymbol(), "TError", tkn.getLinha()) else: tknList.append(tkn)
norm = np.linalg.norm(X, axis=0) perc = np.percentile(norm[norm > mad(norm)], 50) #Do not trust the largest entries X3 = X.copy() X3[:, norm > perc] = 0 R = np.dot(X3, X3.T) D, V = np.linalg.eig(R) A = V[:, 0:dS['n']] #Initial mixing matrix, normalized #Calls of the algorithms# AMCA # Sest, Aest = AMCA(X, A, amca=1) angle5A[indexParam, indexIte], deltaA[indexParam, indexIte] = errors(Aest, Sest, Aori, S) if pS['verboseAMCA']: print 'Errors AMCA: ', angle5A[indexParam, indexIte] * dS[ 'n'], 'recovered columns, ', deltaA[indexParam, indexIte], ' for DeltaA' #GMCA# Sest, Aest = AMCA(X, A, amca=0) angle5G[indexParam, indexIte], deltaG[indexParam, indexIte] = errors(Aest, Sest, Aori, S) if pS['verboseGMCA']: print 'Errors GMCA: ', angle5G[indexParam, indexIte] * dS[ 'n'], 'recovered columns, ', deltaG[indexParam, indexIte], ' for DeltaA'
if params['cpType'] != 2: #not inductive pValMat = p2mat.computePVal(scidict.data,scidict.testData,scidict.target,scidict.testTarget,params) else: #inductive pValMat = p2mat.computePVal(scidict.data,scidict.testData,scidict.target,scidict.testTarget,params,scidict.calibIndices) for i in xrange(len(pValMat)): print pValMat[i,:], scidict.testTarget[i] #for manual check of results #for i in xrange(len(pValMat)): # print pValMat[i,:],scidict.testTarget[i] #four dimensional array object; tuple is mneumonic #runs an error test errorArray = np.zeros( (len(['emptyError','predError','multiError']),len(pValMat),len(params['confList'])) ) #for confIndex in xrange(len(params['confList'])): for confIndex in xrange(2,3): confLevel = params['confList'][confIndex] for p in xrange(len(pValMat)): errorArray[:,p,confIndex] = er.errors(pValMat[p,:],confLevel,scidict.testTarget[p],params,outType=1) print errorArray[:,p,confIndex] print "sum" print sum(errorArray[:,:,2],axis=1) ep.errorPlot(pValMat,errorArray,params)
import sys import sqlite3 from PyQt5 import uic from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox, QInputDialog from errors import errors errors() class Voting(QMainWindow): def __init__(self, parent=None): super().__init__() self.con = sqlite3.connect("users_db.sqlite") self.cur = self.con.cursor() uic.loadUi('voting.ui', self) self.initUI() def initUI(self): self.list_results.hide() self.btn_makeVoting.clicked.connect(self.makeVoting) self.hide_objects(True) self.btn_vote.clicked.connect(self.vote) self.btn_results.clicked.connect(self.results) self.btn_finish.clicked.connect(self.finish) def hide_objects(self, flag): if flag: self.label.hide() self.label_2.hide() self.theme.hide()
plt.legend(['Normal dist. ($\mu=$ {:.2f} and $\sigma=$ {:.2f} )'.format(mu, sigma)], loc='best') plt.ylabel('Frequency') plt.title('Residual distribution') # plt.show() # The residuals seem to look like they come from the normal distribution. Lets use this model to predict the last # 30 days and evaluate the prediction w.r.t. the real values. start = 1730 end = 1826 train_1['forecast'] = model.predict(start = start, end= end, dynamic=True) train_1[start:end][['sales', 'forecast']].plot(figsize=(12, 8)) # plt.show() errors(train_1[1730:1825]['sales'], train_1[1730:1825]['forecast']) # The prediction is not optimal. Lets add exogenous variables (Holidays of USA). # We'll continue with that in prediction2.py file. # CLOSE ALL PLOTS! plt.close('all') # !!!!!
def __init__(self): # Define the errors class for use in writing out error messages. self.errors = er.errors()