def __init__(self): ''' :) ''' debug_msg(">>> %s.%s" % (__name__, sys._getframe().f_code.co_name)) self.database = Initialization().get_global_db() self.db_helper = database_helper(self.database)
def __init__(self): self.database = Initialization().get_global_db() self.helper = database_helper(self.database) debug_msg(">>> %s.%s" % (__name__, sys._getframe().f_code.co_name)) self.uid = Users.query.count() self.nick_name = 'fake_user' + str(self.uid) self.password = '******' + str(self.uid) self.primary_id = Primary_Category.query.count() self.primary_name = 'fake_category' + str(self.primary_id) self.primary_color = '#f23456' self.primary_logo = './logo.png' self.secondary_id = Secondary_Category.query.count() self.secondary_name = 'fake_secondary' + str(self.secondary_id) self.secondary_color = "#b33321" self.secondary_logo = './secondary_logo.png' self.date_id = Date.query.count() self.date_date = datetime.date(2017,3,10) self.date_last_changed_time = datetime.datetime.now() self.blocks_id = Blocks.query.count()
def __init__(self): print("\n\n\n\n\n\n\n\n\n\n\n\n!!!day_controller_tester!!!") self.database = Initialization().get_global_db() self.db_helper = database_helper.database_helper(self.database) self.db_helper.rebuild_database() self.db_tester = database_tester() self.db_tester.generate_fake_data() self.db_helper.dump_all_data()
def __init__(self, date_string=None, id=None, user_id=None): debug_msg(">>> %s.%s" % (__name__, sys._getframe().f_code.co_name)) self.date = None if date_string != None: self.date = self.__query_date_from_string(date_string, user_id) if id != None: self.date = self.__query_date_from_id(id, user_id) self.database = Initialization().get_global_db() self.db_helper = database_helper(self.database)
def __init__(self): print("\n\n\n\n\n\n\n\n\n\n\n\n!!!users_controller_tester!!!") self.database = Initialization().get_global_db() self.db_helper = database_helper.database_helper(self.database) self.db_helper.rebuild_database() self.db_tester = database_tester() self.db_tester.generate_fake_user(nick_name='tester1', password='******') self.db_tester.generate_fake_user(nick_name='tester2', password='******') self.db_helper.dump_all_data()
def __init__(self, url_argv): sys.setrecursionlimit(10000000) """ 调度数据库接口, 引入初始化, 调度器, 爬取器, 分析器 """ self.db = DbManager.DbManager(db_config).mysql_connect() self.config = spider_config.spider_config() self.initialization = Initialization.Initialization( self.db, self.config, url_argv) self.manager = UrlManager.UrlManager(self.db, self.config) self.craw = UrlCraw.UrlCraw(self.db, self.config) self.analyse = UrlAnalyse.UrlAnalyse(self.db, self.config) self.sprint = SpiderPrint.SpiderPrint() self.initialize_spider()
def __init__(self): print("\n\n\n\n\n\n\n\n\n\n\n\n!!!users_controller_tester!!!") self.database = Initialization().get_global_db() self.db_helper = database_helper.database_helper(self.database) self.db_helper.rebuild_database() self.db_tester = database_tester() self.db_tester.generate_fake_data() new_pri = self.db_tester.generate_fake_primary_category() new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) self.db_helper.dump_all_data()
def __init__(self): print("\n\n\n\n\n\n\n\n\n\n\n\n!!!statics_controller_tester!!!") self.database = Initialization().get_global_db() self.db_helper = database_helper.database_helper(self.database) self.db_helper.rebuild_database() self.db_tester = database_tester() self.db_tester.generate_fake_data() new_pri = self.db_tester.generate_fake_primary_category() new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_pri = self.db_tester.generate_fake_primary_category() new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) new_sec = self.db_tester.generate_fake_secondary_category(new_pri) blocks_con = blocks_controller('0') blocks_con.update_a_block(1, 2) blocks_con.update_a_block(2, 1) blocks_con.update_a_block(3, 4) blocks_con.update_a_block(4, 4) blocks_con.update_a_block(5, 6) blocks_con.update_a_block(6, 5) self.db_helper.dump_all_data()
class InitialPop: BestSol.Cost = 10e10 nPop = Initialization().nPop NumVariable = Initialization().NumVariable Varmin = Initialization().Varmin Varmax = Initialization().Varmax a = Initialization().a f = Initialization().f trial = Initialization().trial Costfunction = ObjectiveFunc.Costfunction nEval = 0 # Create inital population for i in range(0, nPop): a[i, :] = numpy.random.uniform(Varmin, Varmax, NumVariable) f[i] = Costfunction(a[i, :]) trial[i] = 0 nEval = nEval + 1 if f[i] < BestSol.Cost: BestSol.Position = a[i, :] BestSol.Cost = f[i] BestSol.Trial = trial[i] nPop1 = nPop
import os, sys, time, datetime, copy from flask_sqlalchemy import SQLAlchemy from Initialization import Initialization from Utilities import debug_msg db = Initialization().get_global_db() class Users(db.Model): __tablename__ = 'Users' uid = db.Column(db.Integer, primary_key=True) nick_name = db.Column(db.String(64)) password = db.Column(db.String(64)) #uid_foreignkey = db.relationship('Second_Category',backref='primary_category') @property def serialize(self): return { 'uid': self.uid, 'nick_name': self.nick_name, 'password': self.password } @staticmethod def generate_fake_data(): uid = Users.query.count() nick_name = "fake_User" password = "******" new_user = Users(uid=uid, nick_name=nick_name, password=password)
class FDE(BestSol): # Start FDE trial = InitialPop().trial inum = Initialization().inum nPop = Initialization().nPop nPop1 = InitialPop().nPop1 Beta = Initialization().Beta FCost = Initialization().FCost Costfunction = ObjectiveFunc.Costfunction a = InitialPop().a f = InitialPop().f nEval = InitialPop().nEval for it in range (0,Initialization().Maxit): k=0 for i in range (0,nPop): if trial[i] > 30: inum[k]=i k=k+1 if k>0 and nPop>0.1*nPop1: for ii in range (0,k-1): tt=int(inum[ii]) a= numpy.delete(a, (tt), axis=0) f=numpy.delete(f, (tt), axis=0) trial=numpy.delete(trial, (tt), axis=0) nPop=nPop-1 if nPop<=0.1*nPop1: break inum=numpy.zeros(nPop) if nPop<=int(0.1*nPop1): # Restart nPop1=int(1.1*nPop1) nPop=nPop1 a=numpy.zeros((nPop,Initialization().NumVariable)) f=numpy.zeros(nPop) trial=numpy.zeros(nPop) BestSol.Cost=10e10 for i in range (0,nPop1): a[i,:] = numpy.random.uniform(Initialization().Varmin,Initialization().Varmax,Initialization().NumVariable) f[i]=Costfunction(a[i,:]) trial[i]=0 nEval=nEval+1 if f[i]<BestSol.Cost: BestSol.Position=a[i,:] BestSol.Cost=f[i] BestSol.Trial=trial[i] for i in range (0,nPop): # Mutation and Crossover A = numpy.random.permutation(range(nPop)) A=numpy.delete(A, (i), axis=0) A1=A[1] A2=A[2] A3=A[3] x=a[A1,:] TTT=sum(abs(BestSol.Position-a[A1,:]))>0 and sum(abs(BestSol.Position-a[A2,:]))>0 and sum(abs(BestSol.Position-a[A3,:]))>0 if TTT == True: Y=a[A1,:]+Beta*(BestSol.Position-a[A2,:]) Y=numpy.minimum(Y,Initialization().Varmax) Y=numpy.maximum(Y,Initialization().Varmin) Z=numpy.zeros(Initialization().NumVariable) for j in range (0,Initialization().NumVariable): t=numpy.random.uniform(0,1,[1]) if t<=Initialization().Pcr: Z[j]=Y[j] else: Z[j]=x[j] NewSol=Z NewCost=Costfunction(NewSol) nEval=nEval+1 if NewCost<f[i]: # Selection a[i,:]=NewSol f[i]=NewCost trial[i]=0 if f[i]<BestSol.Cost: BestSol.Position=a[i,:] BestSol.Cost=f[i] BestSol.Trial=trial[i] else: BestSol.Trial=BestSol.Trial+1 else: trial[i]=trial[i]+1 if BestSol.Cost<FCost: FCost=BestSol.Cost print('iteration',it,'Cost Function',FCost,) #Create the plots fig = plt.figure(figsize=(8,8)) ax = plt.subplot(111) nn=ax.scatter(8,8, s=0.1, alpha=1) mm=ax.scatter(0,0, s=150, alpha=1) colors = numpy.random.rand(len(a[:,0])) area = (3 * numpy.random.rand(len(a[:,0])))**2 # 0 to 15 point radii bb=ax.scatter(a[:,0],a[:,1], s=area, c=colors, alpha=0.5) plt.pause(0.35) plt.show()
import os import sys import datetime from flask import Flask, render_template from flask_cors import CORS, cross_origin from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand from Initialization import Initialization from MyConfig import MyConfig from Utilities import debug_msg Initialization().global_create_app(__name__, 'database/db_tester.sqlite') init_app = Initialization().get_global_app() #debug_msg("enable CORS") #CORS(init_app, send_wildcard=True) init_db = Initialization().global_create_db(init_app) from DB_Model import database_helper db_helper = database_helper.database_helper(init_db) db_helper.rebuild_database() from DB_Model.database_tester import database_tester db_tester = database_tester() db_tester.generate_fake_data() db_tester = database_tester()
def SingleIteration(k, T, rglist, methodlist, xnum, thetanum): print(k) #Initialize np.random.seed(rglist[k]) xspace, yspace, thetalist = Initialization(xnum, thetanum) # errormat = np.ones([20, T]) ymatpile = np.zeros([len(xspace), T]) thetaridx = np.random.randint(len(thetalist)) dataidx = [] #Problem Setting if multiclass: problem = Methods_M.Problem(xspace, yspace, thetalist, pz_theta_model, py_eq_z, classnum = classnum) else: problem = Methods.Problem(xspace, yspace, thetalist, pz_theta_model, py_eq_z) if yspace is None: #that is synthetic data thetar = thetalist[thetaridx] bayesian_error = problem.BayesianError(thetar) for t in range(T): ymatpile[:, t] = problem.fr(xspace, thetar) else: clf = LogisticRegression(max_iter = 200, penalty = 'none').fit(xspace, yspace) thetar = np.append(clf.coef_, clf.intercept_) thetar = thetar[np.newaxis] thetalist = np.concatenate((thetalist, thetar), axis = 0) thetar = np.reshape(thetar, (-1)) problem = Methods.Problem(xspace, yspace, thetalist, pz_theta_model, py_eq_z, dataidx = dataidx) # thetar = thetar[np.newaxis] bayesian_error = problem.BayesianError(thetar) # bayesian_error = 1 - clf.score(xspace, yspace) for t in range(T): ymatpile[:, t] = yspace #Active Learning for i in methodlist: # for i in [0, 1, 2]: dataidx = [] pi_theta = np.ones(len(thetalist)) pi_theta /= pi_theta.sum() problem.Initialize(xspace, yspace, pi_theta, dataidx) if i == 0: str_label = 'random' elif i == 1: str_label = 'MES' elif i == 2: str_label = 'BALD' elif i == 3: str_label = 'ELR' elif i == 4: str_label = 'Weighted_MOCU' elif i == 5: str_label = 'Weighted_MOCU2' # elif i == 6: # str_label = 'Soft_MOCU10' # elif i == 7: # str_label = 'Soft_MOCU2' # elif i == 8: # str_label = 'Soft_MOCU20' elif i == 9: str_label = 'Soft_MOCU2_20' elif i == 10: str_label = 'Soft_MOCU2_10' elif i == 11: str_label = 'Soft_MOCU2_1' elif i == 12: str_label = 'Soft_MOCU2_2' elif i == 13: str_label = 'Soft_MOCU2_5' elif i == 14: str_label = 'Soft_MOCU2_50' elif i == 15: str_label = 'Soft_MOCU2_100' elif i == 16: str_label = 'Soft_MOCU2_1000' elif i == 17: str_label = 'Soft_MOCU2_10000' elif i <0: str_label = 'Soft_MOCU_'+str(-i) error_txt = open(str_label+'error.txt', 'a') data_txt = open(str_label+'data.txt', 'a') for t in range(T): # start_time = time() if i == 0: xidx = np.random.randint(len(problem.xspace)) xstar = problem.xspace[xidx] elif i == 1: xstar, _, xidx = problem.Selector(problem.UncertaintyWhole) elif i == 2: xstar, _, xidx = problem.Selector(problem.EntropyWhole) elif i == 3: xstar, _, xidx = problem.Selector(problem.MinIbrResidualWhole) # elif i == 4: # xstar, _, xidx = problem.Selector(problem.Weighted_MOCUWhole) elif i == 4: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(softtype = 4)) elif i == 5: if multiclass: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(softtype = 3)) else: xstar, _, xidx = problem.Selector(problem.Weighted_MOCUWhole2) # elif i == 6: # xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 10)) # elif i == 7: # xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 2)) # elif i == 8: # xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 20)) elif i == 9: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 20, softtype = 2)) elif i == 10: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 10, softtype = 2)) elif i == 11: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 1, softtype = 2)) elif i == 12: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 2, softtype = 2)) elif i == 13: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 5, softtype = 2)) elif i == 14: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 50, softtype = 2)) elif i == 15: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 100, softtype = 2)) elif i == 16: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 1000, softtype = 2)) elif i == 17: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = 10000, softtype = 2)) elif i < 0: xstar, _, xidx = problem.Selector(problem.SoftMOCUWhole(k = -i, softtype = 2)) # print("--- %s is %s seconds ---" % (str_label, time() - start_time)) if yspace is None: ystar = ymatpile[xidx, t] else: problem.dataidx.append(xidx) ystar = problem.yspace[xidx] problem.Update(xstar, ystar, xidx) # errormat[i, t] = problem.ClassifierError(thetar, problem.pi_theta) - bayesian_error if yspace is None: errortemp = problem.ClassifierError(thetar, problem.pi_theta) - bayesian_error else: # errortemp = problem.ClassifierError(thetar, problem.pi_theta, xspace) - bayesian_error errortemp = problem.ClassifierError(thetar, problem.pi_theta) - bayesian_error error_txt.write(str(errortemp)+'\t') data_txt.write(str([xstar, ystar])+'\t') error_txt.write('\n') data_txt.write('\n') error_txt.close() data_txt.close()
def __init__(self): """Create the TCC Frame""" wx.Frame.__init__(self, None, -1, self.title, size=(900, 675)) #Wxpython frame object ############################################################# #Dictionaries of relevant telescope information #Most of Bifrost's functions rely on and alter the contents of these dictionaries. #Bifrost has been designed such that these dictionaries provide a quick summary of the overall observing #session. #Telescope Status: Contains information on dynamic processes in GUI operation self.telescope_status = { 'connectState': False, 'RA': 'Unknown', 'Dec': 'Unknown', 'slewing': False, 'tracking': False, 'guiding': False, 'pointState': False, 'precession': True, 'initState': False, 'guider_rot': False } #Initilization Status: Contains information on (typically) static processes in GUI operation or information #from past observing sessions. self.dict = { 'lat': None, 'lon': None, 'elevation': None, 'lastRA': None, 'lastDEC': None, 'lastGuiderRot': None, 'lastFocusPos': None, 'maxdRA': None, 'maxdDEC': None, 'RAtrackingRate': None } #Target Coordinates: For pointing, align telescope coordinates with these values once pointing is carried out. self.target_coords = {"Name": None, "RA": None, "Dec": None} ############################################################# #Additional variables self.protocol = None # twisted python connection protocol to server, overwrite during connection self.server = DataForwardingProtocol( ) # Twisted Python server identification self.calculate = True # Flag for dynamic airmass calculation self.night = True # Send GUI to night mode self.export_active = False # Track the status of the export target list window self.d_color = wx.SystemSettings.GetColour( wx.SYS_COLOUR_BACKGROUND) #Default background color for OS self.list_count = 0 #Tracks the number of targets currently in the targetlist. self.active_threads = {} #Keep track of threads open in GUI self.thread_to_close = -1 self.current_timezone = "PST" #Current timezone is Pacific Standard Time at MRO self.mro = ephem.Observer( ) #Ephem object for mro location (To do: Roll this into Astroplan's Observer object) self.mrolat = 46.9528 * u.deg #Latitude of Manastash Ridge Observatory self.MRO = Observer( longitude=-120.7278 * u.deg, #Astroplan Observer Object for MRO latitude=46.9528 * u.deg, elevation=1198 * u.m, name="Manastash Ridge Observatory") #self.at_MRO = True #Dev variable for ease of development offsite self.process_list = [] debug = True #Debug mode, currently no functionality ico = wx.Icon("bifrost_small.ico", wx.BITMAP_TYPE_ICO) #GUI Icon self.SetIcon(ico) self.dir = os.getcwd() #Current path for file IO #if self.at_MRO == True: self.stordir = "/home/mro/storage/tcc_data" #else: #self.stordir = self.dir self.plot_open = False self.code_timer_W = wx.Timer(self) self.code_timer_E = wx.Timer(self) self.code_timer_N = wx.Timer(self) self.code_timer_S = wx.Timer(self) self.code_timer_Slew = wx.Timer(self) self.stop_time = 250 #Waiting time for tracking to finish 500 works #self.targetlists=glob.glob('/home/mro/Desktop/targetlists/*') #self.targetlists=glob.glob('/home/doug/TCC/targetlists/*') ############################################################# #Setup Notebook p = wx.Panel(self) nb = wx.Notebook(p) controlPage = Control(nb, debug, self.night) #Telescope Control Tab targetPage = Target(nb, debug, self.night) #Target List Tab guiderControlPage = GuiderControl(nb, debug, self.night) #Guider Control Tab initPage = Initialization(nb, debug, self.night) #Initialization Tab logPage = NightLog(nb, debug, self.night) #Night Log Tab nb.AddPage(controlPage, "Telescope Control") self.control = nb.GetPage(0) nb.AddPage(targetPage, "Target List") self.target = nb.GetPage(1) nb.AddPage(guiderControlPage, "Guider Control") self.guiderControl = nb.GetPage(2) nb.AddPage(initPage, "Initialization") self.init = nb.GetPage(3) #nb.AddPage(logPage,"Night Log") #self.nl=nb.GetPage(3) #Control Tab Bindings self.Bind(wx.EVT_BUTTON, self.startSlew, self.control.slewButton) self.Bind(wx.EVT_BUTTON, self.toggletracksend, self.control.trackButton) self.Bind(wx.EVT_BUTTON, self.pointing, self.control.pointButton) self.Bind(wx.EVT_BUTTON, self.haltmotion, self.control.stopButton) self.Bind(wx.EVT_BUTTON, self.Noffset, self.control.jogNButton) self.Bind(wx.EVT_BUTTON, self.Soffset, self.control.jogSButton) self.Bind(wx.EVT_BUTTON, self.Eoffset, self.control.jogEButton) self.Bind(wx.EVT_BUTTON, self.Woffset, self.control.jogWButton) self.Bind(wx.EVT_BUTTON, self.focusIncPlus, self.control.focusIncPlusButton) self.Bind(wx.EVT_BUTTON, self.focusIncNeg, self.control.focusIncNegButton) self.Bind(wx.EVT_BUTTON, self.setfocus, self.control.focusAbsMove) #Target Tab Bindings self.Bind(wx.EVT_BUTTON, self.set_target, self.target.selectButton) self.Bind(wx.EVT_BUTTON, self.addToList, self.target.enterButton) self.Bind(wx.EVT_BUTTON, self.populateCurrPos, self.target.popButton) self.Bind(wx.EVT_BUTTON, self.readToList, self.target.listButton) self.Bind(wx.EVT_BUTTON, self.removeFromList, self.target.removeButton) self.Bind(wx.EVT_BUTTON, self.ExportOpen, self.target.exportButton) self.Bind(wx.EVT_BUTTON, self.target_plot, self.target.plot_button) self.Bind(wx.EVT_BUTTON, self.airmass_plot, self.target.airmass_button) self.Bind(wx.EVT_BUTTON, self.FinderOpen, self.target.finder_button) #self.Bind(wx.EVT_BUTTON,self.refreshList,self.target.refresh_button) #Guider Control Tab Bindings #self.Bind(wx.EVT_BUTTON,self.on_Rot,self.guiderControl.guiderRotButton) # Init Tab Bindings self.Bind(wx.EVT_BUTTON, self.setTelescopeZenith, self.init.atZenithButton) self.Bind(wx.EVT_BUTTON, self.setTelescopePosition, self.init.syncButton) self.Bind(wx.EVT_BUTTON, self.onInit, self.init.initButton) self.Bind(wx.EVT_BUTTON, self.setRATrackingRate, self.init.rateRAButton) self.Bind(wx.EVT_BUTTON, self.resetRATrackingRate, self.init.resetTRButton) self.Bind(wx.EVT_BUTTON, self.setmaxdRA, self.init.dRAButton) self.Bind(wx.EVT_BUTTON, self.setmaxdDEC, self.init.dDECButton) self.Bind(wx.EVT_BUTTON, self.coverpos, self.init.coverposButton) self.Bind(wx.EVT_BUTTON, self.parkscope, self.init.parkButton) #self.Bind(wx.EVT_BUTTON, self.pointing, self.init.onTargetButton) self.Bind(wx.EVT_TIMER, self.timeW, self.code_timer_W) self.Bind(wx.EVT_TIMER, self.timeE, self.code_timer_E) self.Bind(wx.EVT_TIMER, self.timeN, self.code_timer_N) self.Bind(wx.EVT_TIMER, self.timeS, self.code_timer_S) self.Bind(wx.EVT_TIMER, self.timeSlew, self.code_timer_Slew) self.createMenu() self.sb = self.CreateStatusBar(5) self.sb.SetStatusWidths([150, 150, 150, -2, -1]) sizer = wx.BoxSizer() sizer.Add(nb, 1, wx.EXPAND | wx.ALL) p.SetSizer(sizer) p.Layout() ############################################################# self.readConfig() """Target testing parameters """ #self.target.nameText.SetValue('M31') #self.target.raText.SetValue('00h42m44.330s') #self.target.decText.SetValue('+41d16m07.50s') #self.target.epochText.SetValue('J2000') #self.target.magText.SetValue('3.43') img_default = os.path.join(self.dir, 'gimg', 'gcam_56901_859.jpg') img = mpimg.imread(img_default)
def SingleIteration(k, T, rglist, methodlist, xnum, thetanum): print(k) #Initialize np.random.seed(rglist[k]) xspace, yspace, hyperlist = Initialization(xnum, thetanum) # errormat = np.ones([20, T]) ymatpile = np.zeros([len(xspace), T]) dataidx = [] # thetaridx = np.random.randint(len(thetalist)) # thetalist = np.random.beta(alist, blist, size = (thetanum, bins)) #Problem Setting # thetalist = np.zeros if multiclass: problem = Methods_M.Problem(xspace, yspace, hyperlist, pz_theta_model, py_eq_z, classnum=classnum, dataidx=dataidx) # else: # problem = Methods.Problem(xspace, yspace, thetalist, pz_theta_model, py_eq_z) if yspace is None: #that is synthetic data thetar = thetalist[thetaridx] bayesian_error = problem.BayesianError(thetar) for t in range(T): ymatpile[:, t] = problem.fr(xspace, thetar) else: bins = np.max(xspace) + 1 count0 = np.zeros(bins) count1 = np.zeros(bins) for i, x in enumerate(xspace): if yspace[i] == 0: count0[x] += 1 else: count1[x] += 1 error_list = np.minimum(count0, count1) # bayesian_error = np.sum(error_list)/len(xspace) bayesian_error = 0 #Active Learning for i in methodlist: # for i in [0, 1, 2]: dataidx = [] # pi_theta = np.ones(len(thetalist)) # pi_theta /= pi_theta.sum() problem.Initialize(xspace, yspace, hyperlist, dataidx) if i == 0: str_label = 'random' elif i == 1: str_label = 'MES' elif i == 2: str_label = 'BALD' elif i == 3: str_label = 'ELR' elif i == 5: str_label = 'Weighted_MOCU' error_txt = open(str_label + 'error.txt', 'a') data_txt = open(str_label + 'data.txt', 'a') for t in range(T): start_time = time() if i == 0: xidx = np.random.randint(len(problem.xspace)) xstar = problem.xspace[xidx] elif i == 1: xstar, _, xidx = problem.Selector(problem.UncertaintyWhole) elif i == 2: xstar, _, xidx = problem.Selector(problem.EntropyWhole) elif i == 3: xstar, _, xidx = problem.Selector(problem.MinIbrResidualWhole) elif i == 5: if multiclass: xstar, _, xidx = problem.Selector( problem.SoftMOCUWhole(softtype=3)) else: xstar, _, xidx = problem.Selector( problem.Weighted_MOCUWhole2) if yspace is None: ystar = ymatpile[xidx, t] else: problem.dataidx.append(xidx) ystar = problem.yspace[xidx] problem.Update(xstar, ystar, xidx) # errormat[i, t] = problem.ClassifierError(thetar, problem.pi_theta) - bayesian_error errortemp = problem.ClassifierError(xspace, yspace) - bayesian_error error_txt.write(str(errortemp) + '\t') data_txt.write(str([xstar, ystar]) + '\t') error_txt.write('\n') data_txt.write('\n') error_txt.close() data_txt.close()
def initialize_api(self): self.app = Initialization().get_global_app(); self.api = Api(self.app) self.api.add_resource(Resource_Date,"/Date/<string:date>") self.api.add_resource(Resource_Category,"/Category/") self.api.add_resource(Resource_Blocks,"/Blocks/<int:data>")
def initialize_api(self): self.app = Initialization().get_global_app() self.api = Api(self.app) self.api.add_resource(mainpage_date, "/MainPage/<int:uid>/date/<string:date>")
import os import sys import datetime from flask import Flask, render_template from flask_cors import CORS, cross_origin from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand from Initialization import Initialization from MyConfig import MyConfig from Utilities import debug_msg Initialization().global_create_app(__name__, None) init_app = Initialization().get_global_app() #debug_msg("enable CORS") #CORS(init_app, send_wildcard=True) init_db = Initialization().global_create_db(init_app) from DB_Model import database_helper db_helper = database_helper.database_helper(init_db) db_helper.rebuild_database() from DB_Model.database_tester import database_tester db_tester = database_tester() db_tester.generate_fake_data() from Data_Controllers.blocks_controller import blocks_controller
import os, sys, datetime from flask import Flask, render_template from flask_cors import CORS, cross_origin from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand from Initialization import Initialization from MyConfig import MyConfig from Utilities import debug_msg Initialization().global_create_app(__name__) init_app = Initialization().get_global_app() debug_msg("enable CORS") #CORS(init_app, send_wildcard = True) init_db = Initialization().global_create_db(init_app) ''' datamodel initialization ''' from ModelMainPage import ModelMainPage, Users, Primary_Category, Second_Category, Date, Blocks ModelMainPage().initialize_database(init_db) from ViewMainPage import ViewMainPage view = ViewMainPage() from ControllerMainPage import ControllerMainPage ControllerMainPage().initialize_api() migrate = Migrate(init_app, init_db) manager = Manager(init_app)
import os from Move_2_Nas import Move2Nas from Initialization import Initialization os.chdir('/root/spiderItem/HongKong/HCK_l') Initialization().InitializeMain2() os.system("scrapy crawl HCK_Execute1") os.system("scrapy crawl HCK_Execute2") os.system("scrapy crawl HCK_pdf_spider") os.system("scrapy crawl HCK_information") try: Initialization().InitializeMain() except FileNotFoundError: pass Move2Nas().Move2NasMain("/data/spiderData/HongKong", "/homes3/HongKong/")
import os reload(sys) sys.setdefaultencoding("utf-8") # 根据id自增的url地址 # 将需要递增的id改成**** # python id_spider.py http://www.xxx.com?id=**** 0 4000000 1 """ 初始化爬虫 """ # 获取简易版url,去除参数,去除http,https url_argv_base = sys.argv[1] start = sys.argv[2] end = sys.argv[3] step = sys.argv[4] # 将传入的url地址id改成1 url_argv = url_argv_base.replace('****', '1') initialization = Initialization.Initialization(url_argv) base_url = initialization.initialization_url() table = initialization.initialization_create_table(base_url) initialization.initialization_close() # 是否设置代理 spider_config = spider_config() proxy = spider_config['proxy'] def spider(i): """ 配置mysql连接 """ connect_config = db_config.connect_config() mysql_config = connect_config['mysql'] mysql_connect = MysqlConnect.MysqlConnect(mysql_config) url_craw = UrlCraw.UrlCraw()