def _loadFuncs(self): self.log('Start files loading...') filesMap = self.filesMap for key in filesMap: filePath = filesMap[key] self.log(f'Try to load {key} file: {filePath}') func = None if filePath.endswith('.pickle'): grid = utils.loadPickle(filePath, 'rb') if grid is None: self.error( f'Unable to load {key} function as pickle:\n{filePath}.' ) func = num_methods.interpolation.SplineInterpolation(grid) elif filePath.endswith('.json'): jsn = utils.loadJson(filePath, 'r') if jsn is None: self.error( f'Unable to load {key} function interpolation as json:\n{filePath}.' ) func = num_methods.interpolation.SplineInterpolation( None).load_from_dict(jsn) else: grid = utils.loadCSV(filePath) if grid is None: self.error( f'Unable to load {key} function as csv:\n{filePath}.') func = num_methods.interpolation.SplineInterpolation(grid) self.funcDict[key] = func self.log('Successful') self.log('All files loaded')
def initStimuli(): """called whenever a new run starts. all stimulus will run from the beginig. """ global repNo, stimulusListLoc, stimulusList repNo = 0 stimulusListLoc = 0 stimulusList = loadCSV(STIMULUS_CONFIG) initShape(stimulusList[0])
def __init__(self, canvas, app, output_device=None): self.output_device = output_device self.batchNo = 0 self.canvas = canvas self.app = app self.stimulusObjList = [] stim_id = 0 for st in loadCSV(STIMULUS_CONFIG): stim_id += 1 self.stimulusObjList.append(Stimulus(st, canvas, app, stim_id)) self.print_stimulus_list()
def initApp(): global vsWidth, vsHeight, vsX, vsY, appConfig, stimulusList, f9CommunicationEnabled, bgColor, vsColor, stimulusColor appConfig = loadCSV(APP_CONFIG_FILE) vsX = getAppConfig("fishScreenStartX") vsY = getAppConfig("fishScreenStartY") vsWidth = getAppConfig("fishScreenWidth") vsHeight = getAppConfig("fishScreenHeight") bgColor = getAppConfig("backgroundColor", "str") vsColor = getAppConfig("virtualScreenColor", "str") stimulusColor = getAppConfig("stimulusColor", "str") f9CommunicationEnabled = getAppConfig("f9CommunicationEnabled", "str") if f9CommunicationEnabled.lower() == "on": f9CommunicationEnabled = False else: f9CommunicationEnabled = False logging.info("f9CommunicationEnabled=" + str(f9CommunicationEnabled)) printVirtualScreenData()
GAMMA = para.GAMMA # decay rate of past observations original 0.99 OBSERVATION = para.OBSERVATION # timesteps to observe before training EXPLORE = para.EXPLORE # frames over which to anneal epsilon FINAL_EPSILON = para.FINAL_EPSILON # final value of epsilon INITIAL_EPSILON = para.INITIAL_EPSILON # starting value of epsilon REPLAY_MEMORY = para.REPLAY_MEMORY # number of previous transitions to remember BATCH = para.BATCH # size of minibatch FRAME_PER_ACTION = para.FRAME_PER_ACTION LEARNING_RATE = para.LEARNING_RATE loss_file_path = para.loss_file_path actions_file_path = para.actions_file_path q_value_file_path = para.q_value_file_path scores_file_path = para.scores_file_path loss_df = utils.loadCSV(loss_file_path, 'loss') scores_df = utils.loadCSV(scores_file_path, 'scores') actions_df = utils.loadCSV(actions_file_path, 'actions') q_values_df = utils.loadCSV(q_value_file_path, 'qvalues') ''' main training module Parameters: * model => Keras Model to be trained * game_state => Game State module with access to game environment and dino * observe => flag to indicate wherther the model is to be trained(weight updates), else just play ''' def trainNetwork(model, game_state, observe=False): last_time = time.time() # store the previous observations in replay memory
def __init__(self, screen): self.debug = False self.controlMode = "l" # l = location, s = size # user by the x (cross) button to show virtual screen cross self.xMode = False # false - no x is displayed in the middle of the screen self.xVertical = 0 self.xHorizental = 0 self.xBoundry = 0 # used by the y (mid button) button to show mid screen marker self.yMode = False # False - no midScreen marker is displayed self.yVertical = 0 self.yHorizental = 0 ##### self.bgColor = 0 self.vsColor = 0 self.stimulusColor = 0 self.appConfig = loadCSV(constants.APP_CONFIG_FILE) self.vsX = self.getAppConfig("fishScreenStartX") self.vsY = self.getAppConfig("fishScreenStartY") self.vsWidth = self.getAppConfig("fishScreenWidth") self.vsHeight = self.getAppConfig("fishScreenHeight") self.bgColor = self.getAppConfig("backgroundColor", "str") self.vsColor = self.getAppConfig("virtualScreenColor", "str") self.stimulusColor = self.getAppConfig("stimulusColor", "str") self.f9CommunicationEnabled = self.getAppConfig( "f9CommunicationEnabled", "str") self.NiDaqPulseEnabled = self.getAppConfig("NiDaqPulseEnabled", "str") self.DishRadiusSize = self.getAppConfig("DishRadiusSize") self.VirtualScreenDegrees = self.getAppConfig("VirtualScreenDegrees") self.VirtualScreenWidthActualSize = self.getAppConfig( "VirtualScreenWidthActualSize") self.VirtualScreenHeightActualSize = self.getAppConfig( "VirtualScreenHeightActualSize") self.projectorOnMonitor = self.getAppConfig("projectorOnMonitor") self.deltaX = 0 self.deltaY = 0 self.positionDegreesToVSTable = [] self.calcConvertPositionToPixelsTable() # populate the above table if self.NiDaqPulseEnabled.lower() == "on": # try to add channel try: task = NiDaqPulse(device_name="Dev2/port{0}/line{1}".format( self.port, self.line)) self.output_device = task except nidaqmx.DaqError as e: print(e) task.stop() else: self.output_device = None if self.f9CommunicationEnabled.lower() == "on": self.f9CommunicationEnabled = False else: self.f9CommunicationEnabled = False logging.info("f9CommunicationEnabled=" + str(self.f9CommunicationEnabled)) self.printVirtualScreenData() self.screen_width = int(screen.winfo_screenwidth() / 4) self.screen_height = int(screen.winfo_screenheight() / 4) screen.geometry( self.calcGeometry(self.screen_width, self.screen_height)) self.canvas = Canvas(screen, background="black") self.textVar = tkinter.StringVar() self.label = ttk.Label(self.canvas, textvariable=self.textVar) self.label.config(font=("Courier", 20)) self.label.grid(column=0, row=0) self.canvas.pack(fill=BOTH, expand=1) self.vs = self.canvas.create_rectangle(self.vsX, self.vsY, self.vsX + self.vsWidth, self.vsY + self.vsHeight, fill=self.vsColor) screen.bind('<Up>', self.processEvent) screen.bind('<Down>', self.processEvent) screen.bind('<Left>', self.processEvent) screen.bind('<Right>', self.processEvent) screen.bind(constants.DEBUG, self.turnDebug) screen.bind(constants.LOCATION, self.changeControlMode) screen.bind(constants.SIZE, self.changeControlMode) screen.bind(constants.UPDATE, self.updateConfig) screen.bind(constants.EXIT, self.leaveProg) screen.bind(constants.RUN, self.manageStimulus) screen.bind(constants.PAUSE, self.manageStimulus) screen.bind(constants.CROSS, self.showCrossAndBoundries) screen.bind(constants.MID_SCREEN, self.showMidScreen) screen.bind('?', self.printHelp) self.printHelp("")
parser = argparse.ArgumentParser() parser.add_argument('case', help='PINN ID') parser.add_argument('plot', help='Plot or not(key in 1 to plot)') args = parser.parse_args() project_name = args.case model_path = '/home/zhida/Documents/PINN/2d_inviscid_model/%s/'%project_name for f in os.listdir(model_path): if (f.endswith('.csv') and f[-5] != 's'): pb = (f[f.index('=')+1:-4]) test_path = '/home/zhida/Documents/PINN/data/bp=%s.csv'%pb predict_path = model_path + '%s_bp=%s.csv' %(project_name,pb) P_back_test,x_test,y_test,P_test,rho_test,u_test,v_test,T_test,Et_test,E_test = utils.loadCSV(test_path) P_back_pred,x_pred,y_pred,P_pred,rho_pred,u_pred,v_pred,T_pred,Et_pred,E_pred = utils.loadCSV(predict_path) print(Et_pred.shape) print(Et_test.shape) #Error error_P = np.linalg.norm(P_test-P_pred,2)/np.linalg.norm(P_test,2) print("Test Error in P: "+str(error_P)) error_rho = np.linalg.norm(rho_test-rho_pred,2)/np.linalg.norm(rho_test,2) print("Test Error in rho: "+str(error_rho)) error_u = np.linalg.norm(u_test-u_pred,2)/np.linalg.norm(u_test,2) print("Test Error in u: "+str(error_u)) error_v = np.linalg.norm(v_test-v_pred,2)/np.linalg.norm(v_test,2) print("Test Error in v: "+str(error_v)) error_Et = np.linalg.norm(Et_test- Et_pred,2)/np.linalg.norm(Et_test,2)