def higher_discount_rate(): quad_rotor_plant = QuadRotor2DPlant( 1. / FREQUENCY, blade_flapping=BLADE_FLAPPING, init_mean=DEFAULT_INIT_STATE_MEAN, ) actor_critic_args = ( Actor( FeatureSet([feature_z, feature_zdot]), FeatureSet([feature_u1]), quad_rotor_plant.get_feature_set(), K_ACTOR, STAGE_ONE_AC_MEMORY, ALPHA_ACTOR, TOLERANCE_ACTOR, ), Critic( FeatureSet([feature_z, feature_zdot]), quad_rotor_plant.get_feature_set(), K_CRITIC, STAGE_ONE_AC_MEMORY, LAMBDA_TRACE, ALPHA_CRITIC, 0.99, QuadraticErrorRewardFunction( ACTION_REWARDS, STATE_REWARDS, desired_state=DESIRED_STATE ), TOLERANCE_CRITIC, ), PlantModel( quad_rotor_plant.get_feature_set(), FeatureSet([feature_z, feature_zdot, feature_u1]), K_PLANT_MODEL, STAGE_ONE_PM_MEMORY, PREDICTION_TOLERANCE, ), quad_rotor_plant, DEFAULT_LENGTH, DEFAULT_ADD_METHOD, DEFAULT_PURGE_METHOD, ExplorationStrategy(EXPLORATION_DICT), ) print("Starting training of quad-rotor with higher discount rate.") trained_cs = ControllerSet( parallelize( parsed_args.j, train, [actor_critic_args + (SEED + i,) for i in range(parsed_args.p)], ) ) print("Finished higher discount rate with {:.2f} (id={})".format( SimulationResult( trained_cs.lookback_result(LOOK_BACK_WINDOW), metric=parsed_args.metric ).get_cum_state_error()[1:2].sum(), trained_cs.get_id(), )) trained_cs.notes = "Sensitivity analysis: higher discount rate" # trained_cs.dump() RewardSet(trained_cs).dump()
# ZERO EXPANSION zero_expansion = ControllerSet( parallelize( parsed_args.j, train_zero_expansion, [deepcopy(ac) for ac in first_stage_cs], )) print("Finished zero expansion (id={}) with {:.2f}".format( zero_expansion.get_id(), SimulationResult( zero_expansion.lookback_result(LOOK_BACK_WINDOW), metric=parsed_args.metric).get_cum_state_error()[1:2].sum())) zero_expansion.notes = "Test with zero expansion method" # zero_expansion.dump() RewardSet(zero_expansion).dump() # PERTURB-GAUSS EXPANSION perturb_gauss_expansion = ControllerSet( parallelize( parsed_args.j, train_perturb_expansion, [deepcopy(ac) for ac in first_stage_cs], )) print("Finished perturb Gauss expansion (id={}) with {:.2f}".format( perturb_gauss_expansion.get_id(), SimulationResult( perturb_gauss_expansion.lookback_result(LOOK_BACK_WINDOW), metric=parsed_args.metric).get_cum_state_error()[1:2].sum())) perturb_gauss_expansion.notes = "Test with perturb Gauss expansion method" # perturb_gauss_expansion.dump()
] targets = [ "sensitivity-analysis-alpha-lower", "sensitivity-analysis-alpha-higher", "sensitivity-analysis-gamma-lower", "sensitivity-analysis-gamma-higher", ] BASE_PATH = FIGURE_PATH file_format = "pdf" dpi = 300 for i, t in zip(ids, targets): try: rc = RewardSet.load(i) except IOError: rc = RewardSet(ControllerSet.load(i)) rc.dump() print("ID: {}".format(i)) vis = rc.plot( conf=68, bounds=False, metric="median", minimum=9000, ) vis.save( "report-3pp", target=os.path.join(BASE_PATH, t + "-{}.{}".format(len(rc), file_format)), format=file_format,
quad_rotor_plant, DEFAULT_LENGTH, DEFAULT_ADD_METHOD, DEFAULT_PURGE_METHOD, ExplorationStrategy(EXPLORATION_DICT), ) # STAGE ONE trained_cs = ControllerSet( parallelize( parsed_args.j, train, [ actor_critic_args + (SEED + i, ) for i in range(parsed_args.p) ], )) print("Finished Gaussian clone expansion (id={}) with {:.2f}".format( trained_cs.get_id(), SimulationResult( trained_cs.lookback_result(LOOK_BACK_WINDOW), metric=parsed_args.metric).get_cum_state_error()[1:2].sum())) trained_cs.dump() RewardSet(trained_cs).dump() except KeyboardInterrupt: print("Shutdown requested... exiting") finally: print("Stopped run!")