Skip to content

Commit 00bee13

Browse files
committed
Little fixes, stats
1 parent d3dbe26 commit 00bee13

2 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/engine/server/NN/ModelManager.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,7 @@ size_t ModelManager::GetCountEpisodes()
843843
}
844844

845845
void ModelManager::Update(double avg_reward, bool cache_model, bool &updated,
846-
double &avg_training_loss, double &avg_actor_loss, double &avg_critic_loss,
847-
double &avg_entropy,
848-
double &avg_actor_grad_norm, double &avg_critic_grad_norm,
849-
double &avg_actor_weight_norm, double &avg_critic_weight_norm,
850-
double &avg_actor_activation_mean, double &avg_actor_activation_std,
851-
double &critic_mean_absolute_error, double &critic_correlation_coefficient,
852-
double &avg_angle_entropy, double &avg_hook_entropy, double &avg_hammer_entropy, double &avg_direction_entropy)
846+
NNStats& stats)
853847
{
854848
// Update.
855849
if(!ac_work->is_training())
@@ -887,13 +881,7 @@ void ModelManager::Update(double avg_reward, bool cache_model, bool &updated,
887881
{
888882
PPO::update(ac_update, ac_work, opt, rewards.size(), ppo_epochs,
889883
mini_batch_size, count_mini_batches, ent_coef, gamma, lambda, device,
890-
avg_training_loss, avg_actor_loss, avg_critic_loss,
891-
avg_entropy,
892-
avg_actor_grad_norm, avg_critic_grad_norm,
893-
avg_actor_weight_norm, avg_critic_weight_norm,
894-
avg_actor_activation_mean, avg_actor_activation_std,
895-
critic_mean_absolute_error, critic_correlation_coefficient,
896-
avg_angle_entropy, avg_hook_entropy, avg_hammer_entropy, avg_direction_entropy,
884+
stats,
897885
clip_param);
898886
}
899887
catch(const std::exception &e)

src/engine/server/NN/NeuralNetwork.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ void CNeuralNetwork::OnInit()
378378

379379
load_model = false;
380380
load_previous = true;
381-
load_folder_path = "train\\1769268227386";
381+
load_folder_path = "train\\1769318571446";
382382
load_main_model_name = "last";
383383

384384
bool record_initial_demo = false;
@@ -422,7 +422,7 @@ void CNeuralNetwork::OnInit()
422422
dbg_msg("neuralnetwork", "Can't make demos directory");
423423
exit(1);
424424
}
425-
dbg_msg("neuralnetwork", "Train directory with folders created.");
425+
dbg_msg("neuralnetwork", "Train directory with folders created: %s.", ("train\\" + dir_name).c_str());
426426

427427
dbg_msg("neuralnetwork", "Adding bots...");
428428
if(count_teams)
@@ -563,6 +563,8 @@ void CNeuralNetwork::OnInit()
563563
"Maximal Hook entropy",
564564
"Maximal Hammer entropy",
565565
"Maximal Direction entropy",
566+
"Count ticks with current",
567+
"Count ticks with old",
566568
};
567569

568570
// Write the CSV header
@@ -981,6 +983,10 @@ void CNeuralNetwork::PostTick(float time_to_tick)
981983
static float first_bot_cumulative_reward = 0;
982984
static float second_bot_cumulative_reward = 0;
983985

986+
// Collect ticks with current/old models for statistics
987+
static float count_ticks_with_current = 0;
988+
static float count_ticks_with_old = 0;
989+
984990
// Score goaled
985991
static float first_bot_cumulative_score = 0;
986992
static float second_bot_cumulative_score = 0;
@@ -1025,7 +1031,7 @@ void CNeuralNetwork::PostTick(float time_to_tick)
10251031
static float step_reward = -0.02f; // -0.001f Applies every tick
10261032
static float divide_reward_by = 10.f;
10271033

1028-
static int force_stop_tick = 2000; // 2000 INT_MAX
1034+
static int force_stop_tick = 2000; // 2000 20 minutes to play. If more than this - force stop.
10291035

10301036
static int current_old_shuffle_counter = 0; // Save 1 old per 4 current
10311037

@@ -1172,21 +1178,27 @@ void CNeuralNetwork::PostTick(float time_to_tick)
11721178
if (first_bot_character->GetCore().m_HookedPlayer && first_bot_character->GetCore().m_HookedPlayer % 3 == 2)
11731179
{
11741180
first_bot_reward += bot_is_holding_ball_reward;
1175-
if(vLastTouchedBall[team_id] != 1 && !(second_bot_character->GetCore().m_HookedPlayer % 3 == 2))
1181+
if(!(second_bot_character->GetCore().m_HookedPlayer % 3 == 2))
11761182
{
1177-
first_bot_reward += bot_hooked_ball_reward;
1183+
if(vLastTouchedBall[team_id] != 1)
1184+
{
1185+
first_bot_reward += bot_hooked_ball_reward;
1186+
}
1187+
vLastTouchedBall[team_id] = 1;
11781188
}
1179-
vLastTouchedBall[team_id] = 1;
11801189
}
11811190

11821191
if (second_bot_character->GetCore().m_HookedPlayer && second_bot_character->GetCore().m_HookedPlayer % 3 == 2)
11831192
{
11841193
second_bot_reward += bot_is_holding_ball_reward;
1185-
if(vLastTouchedBall[team_id] != 2 && !(first_bot_character->GetCore().m_HookedPlayer % 3 == 2))
1194+
if(!(first_bot_character->GetCore().m_HookedPlayer % 3 == 2))
11861195
{
1187-
second_bot_reward += bot_hooked_ball_reward;
1196+
if(vLastTouchedBall[team_id] != 2)
1197+
{
1198+
second_bot_reward += bot_hooked_ball_reward;
1199+
}
1200+
vLastTouchedBall[team_id] = 2;
11881201
}
1189-
vLastTouchedBall[team_id] = 2;
11901202
}
11911203

11921204
first_bot_reward += first_bot_character->m_FreezeTime ? being_in_freeze_reward : 0;
@@ -1198,7 +1210,14 @@ void CNeuralNetwork::PostTick(float time_to_tick)
11981210
match_is_done = true;
11991211

12001212
if (team_with_old)
1213+
{
12011214
count_episodes_with_old += 1;
1215+
count_ticks_with_old += vTeamTickCounter[team_id];
1216+
}
1217+
else
1218+
{
1219+
count_ticks_with_current += vTeamTickCounter[team_id];
1220+
}
12021221

12031222
if (current_old_shuffle_counter == 0 || team_with_old)
12041223
current_old_shuffle_counter = 4;
@@ -1440,6 +1459,9 @@ void CNeuralNetwork::PostTick(float time_to_tick)
14401459
<< "," << stats.max_hook_entropy
14411460
<< "," << stats.max_hammer_entropy
14421461
<< "," << stats.max_direction_entropy
1462+
// Print count ticks with new/old
1463+
<< "," << count_ticks_with_current
1464+
<< "," << count_ticks_with_old
14431465
<< endl;
14441466
dbg_msg("neuralnetwork",\
14451467
"Avg. first/second bot score: %f/%f "\
@@ -1490,6 +1512,8 @@ void CNeuralNetwork::PostTick(float time_to_tick)
14901512
= current_bot_cumulative_score \
14911513
= old_bot_cumulative_score \
14921514
= count_episodes_with_old \
1515+
= count_ticks_with_current \
1516+
= count_ticks_with_old \
14931517
= count_every_update = 0;
14941518
}
14951519
respawn_all = true;

0 commit comments

Comments
 (0)