def get_correction_factor(trial, conf, client): rnd.seed(conf['pyseedlist'][trial]) with tables.openFile('tmp', 'w') as fileh: tbl = fileh.createVLArray( '/', 'conf', tables.ObjectAtom(), title='Configuration used to generate the stored data.') tbl.append(conf) fileh.createArray( '/', 'repeat', [trial], title='Number of repeat run.') num_steps = conf['duration_in_steps'] kernel = instantiate(*conf['kernel']) predictor = instantiate(*conf['predictor'], prefix_args=(kernel,)) if 'bounds' in conf: predictor.bounds = conf['bounds'] if 'priors' in conf: for i in range(len(conf['priors'])): predictor.priors[i] = instantiate(*conf['priors'][i]) recorder = TaskPlumeRecorder(fileh, client, predictor, 1) err_recorder = ErrorRecorder(fileh, client, predictor, 1) target_chooser = behaviors.ChainTargetChoosers([ behaviors.SurroundArea(conf['area'], conf['margin']), behaviors.AcquisitionFnTargetChooser( instantiate(*conf['acquisition_fn'], predictor=predictor), conf['area'], conf['margin'], conf['grid_resolution'])]) controller = behaviors.FollowWaypoints( target_chooser, conf['target_precision']) updater = instantiate( *conf['updater'], predictor=predictor, plume_recorder=recorder) controller.observers.append(updater) behavior = controller.velocity_controller if conf['full_record']: client = ControlsRecorder(fileh, client, num_steps) sim_controller = Controller(client, controller, behavior) sim_controller.init_new_sim(conf['seedlist'][trial]) recorder.init(conf) err_recorder.init(conf) volume = np.product(np.diff(conf['area'], axis=1)) print volume test_x = err_recorder.test_x.T return np.sqrt(len(test_x) / np.sum( 1.0 / gaussian_kde(test_x)(test_x) ** 2) / volume)
def do_simulation_run(trial, output_filename, conf, client): rnd.seed(conf['pyseedlist'][trial]) with tables.openFile(output_filename, 'w') as fileh: tbl = fileh.createVLArray( '/', 'conf', tables.ObjectAtom(), title='Configuration used to generate the stored data.') tbl.append(conf) fileh.createArray( '/', 'repeat', [trial], title='Number of repeat run.') num_steps = conf['duration_in_steps'] kernel = instantiate(*conf['kernel']) predictor = instantiate(*conf['predictor'], prefix_args=(kernel,)) if 'bounds' in conf: predictor.bounds = conf['bounds'] if 'priors' in conf: for i in range(len(conf['priors'])): predictor.priors[i] = instantiate(*conf['priors'][i]) recorder = TaskPlumeRecorder(fileh, client, predictor, num_steps) err_recorder = ErrorRecorder(fileh, client, predictor, num_steps) updater = instantiate( *conf['updater'], predictor=predictor, plume_recorder=recorder) acq_behavior = behaviors.AcquisitionFnTargetChooser( instantiate(*conf['acquisition_fn'], predictor=predictor), conf['area'], conf['margin'], conf['grid_resolution']) if 'noise_search' in conf: if conf['noise_search'] == 'wind': tc_factory = behaviors.WindBasedPartialSurroundFactory( client, conf['area'], conf['margin']) else: tc_factory = behaviors.SurroundAreaFactory( conf['area'], conf['margin']) surrounder = behaviors.SurroundUntilFound(updater, tc_factory) surrounder.observers.append(recorder) target_chooser = behaviors.ChainTargetChoosers( [surrounder, acq_behavior]) maxv = 4 else: target_chooser = behaviors.ChainTargetChoosers([ behaviors.SurroundArea(conf['area'], conf['margin']), acq_behavior]) maxv = 6 controller = behaviors.FollowWaypoints( target_chooser, conf['target_precision'], behaviors.VelocityTowardsWaypointController( maxv, maxv, target_chooser.get_effective_area())) controller.observers.append(updater) behavior = controller.velocity_controller if conf['full_record']: client = ControlsRecorder(fileh, client, num_steps) sim_controller = Controller(client, controller, behavior) sim_controller.init_new_sim(conf['seedlist'][trial]) recorder.init(conf) err_recorder.init(conf) sim_controller.add_recorder(recorder) sim_controller.add_recorder(err_recorder) if hasattr(behavior, 'targets') and conf['full_record']: targets_recorder = TargetsRecorder( fileh, behavior, client.numUAVs, num_steps) targets_recorder.init() sim_controller.add_recorder(targets_recorder) try: sim_controller.run(num_steps) except Exception as err: err_tbl = fileh.createVLArray( '/', 'exception', tables.ObjectAtom(), title='Exception which was raised.') err_tbl.append(err) raise finally: try: if conf['full_record']: store_obj(fileh, fileh.createGroup('/', 'gp'), predictor) else: recorder.prune() except: pass