def test_prediction_long_term_hard_brake(self): config = TestConfig() config.n_global_steps = 20000 config.env_id = 'HeuristicRiskEnv-v0' config.discount = 0. # 599. / 600 config.max_timesteps = 10000 config.prime_timesteps = 50 config.learning_rate = 1e-3 config.adam_beta1 = .995 config.adam_beta2 = .999 config.dropout_keep_prob = 1. config.l2_reg = 0. config.local_steps_per_update = 20 config.hidden_layer_sizes = [32, 16] config.hard_brake_threshold = -3. config.hard_brake_n_past_frames = 1 config.target_loss_index = 3 config.loss_type = 'mse' env = build_envs.create_env(config) test_state = env.reset() summary_writer = tf.summary.FileWriter('/tmp/test') with tf.Session() as sess: trainer = async_td.AsyncTD(env, 0, config) sess.run(tf.global_variables_initializer()) sess.run(trainer.sync) trainer.start(sess, summary_writer) global_step = sess.run(trainer.global_step) c, h = trainer.network.get_initial_features() while global_step < config.n_global_steps: trainer.process(sess) global_step = sess.run(trainer.global_step) value = trainer.network.value(test_state, c, h) print(value)
def test_heuristic_deterministic_case(self): config = TestConfig() config.n_global_steps = 50000 config.max_timesteps = 50 config.env_id = 'BayesNetRiskEnv-v0' config.discount = 1. # 49. / 50 config.value_dim = 5 config.adam_beta1 = .9 config.local_steps_per_update = 100 config.hidden_layer_sizes = [128] config.learning_rate = 1e-3 config.learning_rate_end = 5e-6 config.loss_type = 'mse' config.target_loss_index = 1 config.validation_dataset_filepath = '/Users/wulfebw/Dropbox/School/Stanford/research/risk/risk_prediction/data/experiments/heuristic_determinstic_1_lane_5_sec/data/subselect_proposal_prediction_data.h5' config.max_validation_samples = 1 config.validate_every = 1000 config.visualize_every = 10000 config.summarize_features = True validation.transfer_dataset_settings_to_config( config.validation_dataset_filepath, config) config.base_bn_filepath = '/Users/wulfebw/Dropbox/School/Stanford/research/risk/risk_prediction/data/experiments/heuristic_determinstic_1_lane_5_sec/data/base_bn_filepath.h5' config.base_prop_filepath = '/Users/wulfebw/Dropbox/School/Stanford/research/risk/risk_prediction/data/experiments/heuristic_determinstic_1_lane_5_sec/data/prop_bn_filepath.h5' config.max_validation_samples = 1000 # config.roadway_radius = 400. # config.roadway_length = 100. # config.lon_accel_std_dev = 0. # config.lat_accel_std_dev = 0. # config.overall_response_time = .2 # config.lon_response_time = .0 # config.err_p_a_to_i = .15 # config.err_p_i_to_a = .3 # config.max_num_vehicles = 50 # config.min_num_vehicles = 50 # config.hard_brake_threshold = -3. # config.hard_brake_n_past_frames = 2 # config.min_base_speed = 30. # config.max_base_speed = 30. # config.min_vehicle_length = 5. # config.max_vehicle_length = 5. # config.min_vehicle_width = 2.5 # config.max_vehicle_width = 2.5 # config.min_init_dist = 10. # config.heuristic_behavior_type = "normal" # build env env = build_envs.create_env(config) dataset = validation.build_dataset(config, env) print('mean validation targets: {}'.format(np.mean(dataset.y, axis=0))) # run it summary_writer = tf.summary.FileWriter('/tmp/test') avg_loss = -1 last_global_step_val = 0 with tf.Session() as sess: trainer = async_td.AsyncTD(env, 0, config) sess.run(tf.global_variables_initializer()) sess.run(trainer.sync) trainer.start(sess, summary_writer) global_step = sess.run(trainer.global_step) while global_step < config.n_global_steps: trainer.process(sess) if (global_step - last_global_step_val) > config.validate_every: avg_loss = trainer.validate(sess, dataset) last_global_step_val = global_step global_step = sess.run(trainer.global_step)