Skip to content

Commit

Permalink
refactor; logging is broken a little maybe. still trains and beats 9 …
Browse files Browse the repository at this point in the history
…days on eval
  • Loading branch information
xinpw8 committed Jan 5, 2025
1 parent 82257fc commit bae3af2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
8 changes: 4 additions & 4 deletions pufferlib/ocean/enduro/enduro.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ int demo() {
// Weights* weights = load_weights("resources/enduro/enduro_weights.bin", 142218);
// LinearLSTM* net = make_linearlstm(weights, 1, 68, 9);

Weights* weights = load_weights("resources/enduro/enduro_w.bin", 10122);
Default* net = make_default(weights, 1, 68, 128, 9);
Weights* weights = load_weights("resources/enduro/0105enduro_weights.bin", 142218);
LinearLSTM* net = make_linearlstm(weights, 1, 68, 9);

Enduro env = {
.num_envs = 1,
Expand All @@ -55,14 +55,14 @@ int demo() {
if (IsKeyDown(KEY_LEFT_SHIFT)) {
get_input(&env);
} else {
forward_default(net, env.observations, env.actions);
forward_linearlstm(net, env.observations, env.actions);
}

c_step(&env);
c_render(client, &env);
}

free_default(net);
free_linearlstm(net);
free(weights);
close_client(client, &env);
free_allocated(&env);
Expand Down
33 changes: 18 additions & 15 deletions pufferlib/ocean/enduro/enduro.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,19 @@ Log aggregate_and_clear(LogBuffer* logs) {
return log;
}
for (int i = 0; i < logs->idx; i++) {
log.episode_return += logs->logs[i].episode_return / logs->idx;
log.episode_length += logs->logs[i].episode_length / logs->idx;
log.score += logs->logs[i].score / logs->idx;
log.reward += logs->logs[i].reward / logs->idx;
log.step_rew_car_passed_no_crash += logs->logs[i].step_rew_car_passed_no_crash / logs->idx;
log.crashed_penalty += logs->logs[i].crashed_penalty / logs->idx;
log.passed_cars += logs->logs[i].passed_cars / logs->idx;
log.passed_by_enemy += logs->logs[i].passed_by_enemy / logs->idx;
log.cars_to_pass += logs->logs[i].cars_to_pass / logs->idx;
log.days_completed += logs->logs[i].days_completed / logs->idx;
log.days_failed += logs->logs[i].days_failed / logs->idx;
log.collisions_player_vs_car += logs->logs[i].collisions_player_vs_car / logs->idx;
log.collisions_player_vs_road += logs->logs[i].collisions_player_vs_road / logs->idx;
log.episode_return += logs->logs[i].episode_return /= logs->idx;
log.episode_length += logs->logs[i].episode_length /= logs->idx;
log.score += logs->logs[i].score /= logs->idx;
log.reward += logs->logs[i].reward /= logs->idx;
log.step_rew_car_passed_no_crash += logs->logs[i].step_rew_car_passed_no_crash /= logs->idx;
log.crashed_penalty += logs->logs[i].crashed_penalty /= logs->idx;
log.passed_cars += logs->logs[i].passed_cars /= logs->idx;
log.passed_by_enemy += logs->logs[i].passed_by_enemy /= logs->idx;
log.cars_to_pass += logs->logs[i].cars_to_pass /= logs->idx;
log.days_completed += logs->logs[i].days_completed /= logs->idx;
log.days_failed += logs->logs[i].days_failed /= logs->idx;
log.collisions_player_vs_car += logs->logs[i].collisions_player_vs_car /= logs->idx;
log.collisions_player_vs_road += logs->logs[i].collisions_player_vs_road /= logs->idx;
}
logs->idx = 0;
return log;
Expand Down Expand Up @@ -714,12 +714,15 @@ void update_time_of_day(Enduro* env) {
elapsedTime -= totalDuration;
env->elapsedTimeEnv = elapsedTime;
}
env->previousDayTimeIndex = env->currentDayTimeIndex;
int time_idx = 0;
while (time_idx < 15 && elapsedTime >= BACKGROUND_TRANSITION_TIMES[time_idx]) {
time_idx++;
}
env->currentDayTimeIndex = time_idx % 16;
env->previousDayTimeIndex = env->currentDayTimeIndex;
env->currentDayTimeIndex = (env->reset_count < 2) ? (rand() % 16) : time_idx % 16;
if (env->previousDayTimeIndex != env->currentDayTimeIndex) {
add_log(env->log_buffer, &env->log);
}
}

void clamp_speed(Enduro* env) {
Expand Down
Binary file not shown.
Binary file removed pufferlib/resources/enduro/enduro_w.bin
Binary file not shown.
Binary file removed pufferlib/resources/enduro/old_enduro_weights.bin
Binary file not shown.

0 comments on commit bae3af2

Please sign in to comment.