def __init__(self,count,popParam,callback=None): ''' 进化任务,一个进化任务是将多次执行进化,每次进化为一个session :param count: int 运行次数 :param popParam: dict 种群参数 :param callback: function(event,monitor) 回调函数 monitor Monitor对象 event str 包括 'task.begin' 'epoch.begin' 'session.begin' 'session.end' 'epoch.end' 'task.end' ''' self.count = count if isinstance(popParam,dict): popParam = Properties(popParam) if isinstance(popParam.genomeDefinition,dict): popParam.genomeDefinition = Properties(popParam.genomeDefinition) self.popParam = popParam self.runParam = None self.sessions = [] self.curSession = None self.monitor = None self.callback = callback self.__verifyParam()
def createPopParam(**kwargs): ''' 创建种群参数 :param kwargs: dict 参见pop_param_info :return: Properties 种群参数字典对象 ''' return Properties.create_from_dict(pop_param_info, **kwargs)
class Url: def __init__(self): self.prop = Properties() def read(self, key): base_url = self.prop.get('base_url') uri = self.prop.get(key) url = base_url + uri return url def get_url(self, key): if key == Interface.SYSTEMLIB_SEARCH.value: return self.read(Interface.SYSTEMLIB_SEARCH.value) if key == Interface.QUESTION_PAGELIST.value: return self.read(Interface.QUESTION_PAGELIST.value) if key == Interface.CORE_TABLERECORD_INSERT.value: return self.read(Interface.CORE_TABLERECORD_INSERT.value)
def __init__(self,netdef): ''' HyperNEAT :param substrate: list,基座,例如:[(-1, -1), (-1, 0), (-1, 1)], [(0, -1), (0, 0), (0, 1)], [(1, 0)] ''' self.netdef = Properties(netdef) self.networks = {}
def __init__(self,count,popParam,callback): ''' 进化任务,一个进化任务是将多次执行进化,每次进化为一个session :param count: int 运行次数 :param popParam: dict 种群参数 ''' self.count = count popParam = Properties(popParam) popParam.genomeDefinition = Properties(popParam.genomeDefinition) self.popParam = popParam self.runParam = None self.sessions = [] self.curSession = None self.monitor = None self.callback = callback self.__verifyParam()
def createRunParam(maxIterCount, maxFitness, **kwargs): ''' 创建运行参数 :param maxIterCount: int 最大迭代次数 :param maxFitness: float 最大适应度 :param kwargs: dict 其他参数,参见run_params_info :return: ''' kwargs['maxIterCount'] = maxIterCount kwargs['maxFitness'] = maxFitness return Properties.create_from_dict(run_params_info, **kwargs)
def createNetDef(task,**kwargs): ''' 执行 :return: ''' if kwargs is None: kwargs = {} if 'neuronCounts' not in kwargs:raise RuntimeError('can not find neuronCounts in createNetDef ') # 定义网络 netdef = { 'netType' : NetworkType.Perceptron if 'netType' not in kwargs else kwargs['netType'], # NetworkType,网络类型,必须 'neuronCounts' : kwargs['neuronCounts'], # list(初始)网络各层神经元数量,必须 'idGenerator' : 'neat' if 'idGenerator' not in kwargs else kwargs['idGenerator'], # str 生成网络,神经元,突触id的类,参见DefauleIDGenerator,list idgenerator命令可以列出所有的id生成器对象 'config' : { 'layered' : True if 'layered' not in kwargs else kwargs['layered'], # bool 是否分层,可选 'substrate' : True if 'substrate' not in kwargs else kwargs['substrate'], # bool 是否使用基座,可选 'acyclie' : False if 'acyclie' not in kwargs else kwargs['acyclie'], # bool 是否允许自身连接,可选 'recurrent':False if 'recurrent' not in kwargs else kwargs['recurrent'], # bool 是否允许同层连接,可选 'reversed':False if 'reversed' not in kwargs else kwargs['reversed'], # bool 是否允许反向连接,可选 'dimension':2 if 'dimension' not in kwargs else kwargs['dimension'], # int 空间坐标维度,可选 'range':NeuralNetwork.MAX_RANGE if 'dimension' not in kwargs else kwargs['dimension'], # list 坐标范围,可选' }, 'runner':{ 'name' : 'simple' if 'runnername' not in kwargs else kwargs['runnername'] , # str 网络运行器名称,必须 'task' : task, # NeuralNetworkTask,网络运行任务,必须 }, 'models':kwargs['models'] if 'models' in kwargs else { # dict 神经元计算模型的配置信息,必须 'input':{ # str 模型配置名称(不是模型名称) 'name' : 'input', # str,名称,与上面总是一样,可选 'modelid':'input', # str,模型id,必须,用这个来找到对应的计算模型对象,因此应确保该计算模型已注册 }, 'hidden':{ 'name':'hidden', # str 隐藏神经元配置名称,可选 'modelid':'hidden', # str 隐藏神经元计算模型id,必须 'activationFunction':{ # dict 可选 'name' : 'sigmod', # str 激活函数名称,必须 'a' :1.0,'b':1.0,'T':1.0 # float 激活函数参数,可选 }, 'bias':'uniform[-3.0:3.0]', # str 隐藏神经元的偏置变量,均匀分布,必须,可以是uniform[begin,end]或者normal(u,sigma) }, 'synapse':{ 'name':'synapse', # str 突触计算模型配置名称,可选 'modelid':'synapse', # str 突触计算模型Id,必须 'weight':'uniform[-3.0:3.0]' # str 突触学习变量,均匀分布,必须 } } } return Properties(netdef)
def execute(self,runParam): ''' 任务执行 任务执行过程中会显示命令行创建和执行进度界面,可以输入命令来显示更多内容,输入help显示所有命令 :param runParam: 运行参数 :return: ''' runParam = Properties(runParam) self.runParam = runParam self.monitor = Monitor(self,callback = self.callback) self.monitor.recordTaskBegin() for i in range(self.count): session = Session(self.popParam,self.runParam,self,i,self.monitor) self.curSession = session #self.monitor = session.run() session.run() #self.monitor.command() self.sessions.append(session) self.monitor.recordTaskEnd()
def __init__(self, propFolder=""): try: path = getPropertiesAtFolder(propFolder, "test.properties") except: print("Path not found in local folder. Going to resources!") path = getPathAtFolder("resources", "test.properties") prop = Properties() prop.load(open(path)) # path variables # try: self.HAAR_PATH = self.tryCatch(prop, 'haar_dir', 's', '') self.VIDEO_PATH = self.tryCatch(prop, 'vid_path', 's', 'device(0)') # except: # self.HAAR_PATH = '' # self.VIDEO_PATH = 'device(0)' # CNN Model training # self.EPOCHS_EYE = converter(prop.getProperty('epochs_eye'),'i') # self.EPOCHS_YAWN = converter(prop.getProperty('epochs_yawn'),'i') self.EPOCHS_EYE = self.tryCatch(prop, 'epochs_eye', 'i', 5) self.EPOCHS_YAWN = self.tryCatch(prop, 'epochs_yawn', 'i', 5) # Probability Cutoffs for Blink and Yawn # try: self.PROB_EYE = self.tryCatch(prop, 'prob_eye', 'f', 0.1) self.PROB_YAWN = self.tryCatch(prop, 'prob_yawn', 'f', 0.1) # except: # self.PROB_EYE = 0.1 # self.PROB_YAWN = 0.1 # Wait time for Evaluation self.WAIT_TIME = self.tryCatch(prop, 'wait_time', 'i', 200) self.INTER_WAIT_TIME = self.tryCatch(prop, 'inter_wait_time', 'i', 1000) # Drowsiness criterion # try: self.SECONDS_TO_BLINK = self.tryCatch(prop, 'seconds_to_blink', 'f', 0.1) self.SECONDS_TO_YAWN = self.tryCatch(prop, 'seconds_to_yawn', 'f', 1.2) # except: # self.SECONDS_TO_BLINK = 0.1 # self.SECONDS_TO_YAWN = 1.2 # try: self.BLINK_COUNTER_WINDOW = self.tryCatch(prop, 'blink_counter_window', 'i', 30) self.PERCLOS_COUNTER_WINDOW = self.tryCatch(prop, 'perclos_counter_window', 'i', 180) self.YAWN_COUNTER_WINDOW = self.tryCatch(prop, 'yawn_counter_window', 'i', 120) self.COUNTER_INITIAL_VALUE = self.tryCatch(prop, 'counter_initial_value', 'i', 0) # except: # self.BLINK_COUNTER_WINDOW = 30 # self.PERCLOS_COUNTER_WINDOW = 180 # self.YAWN_COUNTER_WINDOW = 120 # self.COUNTER_INITIAL_VALUE = 0 # # cross validation and splitting options # try: # self.CROSS_VAL = converter(prop.getProperty('cross_validation'),"b") # self.VALIDATE = self.tryCatch(prop,'validation'),"b") # except: # self.CROSS_VAL =False # self.VALIDATE=False # # if self.CROSS_VAL: # try: # self.CROSS_VAL_FOLDS=converter(prop.getProperty('cross_val_folds'),"i") # self.CROSS_VAL_TYPE=converter(prop.getProperty('shuffle_cross_val'),"b") # except: # self.CROSS_VAL_FOLDS=10 # self.CROSS_VAL_TYPE=False # # elif self.VALIDATE: # try: # self.VALIDATE_FRAC=converter(prop.getProperty('validation_fraction'),"f") # except: # self.VALIDATE_FRAC=0.2 # # # preprocessor and ensemble options # try: # self.ALLOW_PROCESSING=converter(prop.getProperty('allow_processing'),"b") # self.DO_ENSEMBLE=converter(prop.getProperty('do_ensemble'),"b") # except: # self.ALLOW_PROCESSING=self.DO_ENSEMBLE=False # # if self.DO_ENSEMBLE: # try: # self.ENSEMBLE_TYPE=converter(prop.getProperty('ensemble_type')) # except: # self.ENSEMBLE_TYPE="nn" # # # Defining Evaluation metrics # try: # self.EVAL_METRIC=converter(prop.getProperty('evaluation_metric')) # except: # self.EVAL_METRIC="none" # # # Defining whether hyper parameter tuning is active or not # try: # self.ALLOW_HYPERTUNING=converter(prop.getProperty('allow_tuning'),"b") # except: # self.ALLOW_HYPERTUNING=False # # # script generation option # try: # self.ALLOW_SCRIPT_GEN=converter(prop.getProperty('allow_script_gen'),"b") # except: # self.ALLOW_SCRIPT_GEN=False # Logging options try: self.ALLOW_LOGGING = converter(prop.getProperty('allow_logging'), "b") except: self.ALLOW_LOGGING = False if self.ALLOW_LOGGING: try: self.LOGGER_LEVEL = converter( prop.getProperty('logging_level')) except: self.LOGGER_LEVEL = "INFO"
def __init__(self, obs, robot): ''' :param obs: 四足机器人的观测数据, 四足机器人的输入维度是8,分别是四个腿上下两个关节的输入扭矩 注:这四个关节的顺序总是'front_left_foot', 'front_right_foot', 'left_back_foot', 'right_back_foot‘ 四足机器人的输出维度是28,是四足机器人的姿态数据,包括 # 0:z轴方向距离初始z的距离, # 1-2:面向行动目标的角度的sin值和cos值(啥是‘面向’,暂时我也不知道) # 3-5:相对于身体视点的三个方向的运动速度 # 6-7:身体的body_rpy中的r和p # 8-23:8个关节,按照顺序的位置和速度,归一化到-1和+1之间(位置怎么理解?不知道) # 24-27:4个脚是否着地,1着地,0未着地 ''' self.pos = robot.body_xyz self.parts_xyz = np.array( [p.pose().xyz() for p in robot.parts.values()]).flatten() body_pose = robot.robot_body.pose() self.body_rpy = body_pose.rpy() # r, p, yaw #self.orientation = robot.current_orientation() self.speed = obs[3:6] self.front_left_foot = Properties() self.front_left_foot.name = 'front_left' self.front_left_foot.up = Properties() self.front_left_foot.up.pos = obs[8] self.front_left_foot.up.angle = obs[9] self.front_left_foot.down = Properties() self.front_left_foot.down.pos = obs[10] self.front_left_foot.down.angle = obs[11] self.front_left_foot.ground = obs[24] self.front_right_foot = Properties() self.front_right_foot.name = 'front_right' self.front_right_foot.up = Properties() self.front_right_foot.up.pos = obs[12] self.front_right_foot.up.angle = obs[13] self.front_right_foot.down = Properties() self.front_right_foot.down.pos = obs[14] self.front_right_foot.down.angle = obs[15] self.front_left_foot.ground = obs[25] self.left_back_foot = Properties() self.left_back_foot.name = 'back_left' self.left_back_foot.up = Properties() self.left_back_foot.up.pos = obs[16] self.left_back_foot.up.angle = obs[17] self.left_back_foot.down = Properties() self.left_back_foot.down.pos = obs[18] self.left_back_foot.down.angle = obs[19] self.left_back_foot.ground = obs[26] self.right_back_foot = Properties() self.right_back_foot.name = 'back_right' self.right_back_foot.up = Properties() self.right_back_foot.up.pos = obs[20] self.right_back_foot.up.angle = obs[21] self.right_back_foot.down = Properties() self.right_back_foot.down.pos = obs[22] self.right_back_foot.down.angle = obs[23] self.right_back_foot.ground = obs[27] self.foots = [ self.front_left_foot, self.front_right_foot, self.left_back_foot, self.right_back_foot ]
def createNetDef(**kwargs): return Properties.create_from_dict(netdef_info, **kwargs)
def __init__(self): self.prop = Properties()
catalog='popparam.species.iter', required='optional', default=50, desc='物种算法迭代次数'), 'features': PropertyInfo(11, 'features', dict, catalog='popparam.features', required='optional', default={}, desc='适应度评估器,如果评估器只包含一个函数,也可以写成Evaluator(' 'fitness' ',fitness)'), } pop_param_info = Properties(pop_param_info) def print_popparam(): ''' 打印所有种群参数元信息 :return: None ''' for name, pi in pop_param_info.items(): print(str(pi)) def set_default_popparam(name, defaultvalue): ''' 设置种群参数缺省值 :param name: str 种群参数名或者别名
def unzip(source_file_path, target_path): index = target_path.rfind("/") target_real_path = target_path[:index] unzip_command = "unzip " + source_file_path + " -d " + target_real_path exec_shell_command(unzip_command) def del_dir(dir_path): if dir_path is None or dir_path == "": return command = "rm -rf " + dir_path exec_shell_command(command) property = Properties(sys.path[0] + "/config.properties").getProperties() arg_list = sys.argv arg_list_len = len(arg_list) if arg_list_len == 2: sub_command = arg_list[1] if sub_command == "stop": print "stop command run !" target_stop_command = property['target']['stop']['command'] if target_stop_command is None: print "not stop command in the config !" sys.exit() exec_shell_command(target_stop_command)
#!/usr/bin/env python # -*- coding: utf-8 -*- # ---------------------------------------------------------------------------------------------------------------------- # file: commons # author: eva # date: 2018/1/12 # version: # description: # ---------------------------------------------------------------------------------------------------------------------- import logging.config import logging from utils.mysqldb_helper import MysqlHelper from utils.properties import Properties import os file_path = os.path.dirname(__file__) logging.config.fileConfig(file_path + '/../../config/logger.conf') logger = logging.getLogger('logger01') mysql_properties = Properties( file_path + '/../../config/mysql.properties').get_properties() mysql = MysqlHelper(mysql_properties['host'], user=mysql_properties['user'], password=mysql_properties['password'], db=mysql_properties['db'])