From dbad9d96e0fc2923edfdbef37162ecd5b0645d50 Mon Sep 17 00:00:00 2001 From: nodchip Date: Wed, 9 Sep 2020 00:17:02 +0900 Subject: [PATCH] Removed LOSS_FUNCTION_IS_ELMO_METHOD macro. --- src/learn/learn.h | 19 --------------- src/learn/learner.cpp | 54 +------------------------------------------ 2 files changed, 1 insertion(+), 72 deletions(-) diff --git a/src/learn/learn.h b/src/learn/learn.h index d2477277..2ee2f8d6 100644 --- a/src/learn/learn.h +++ b/src/learn/learn.h @@ -5,21 +5,6 @@ #include -// ---------------------- -// Select the objective function -// ---------------------- - -// elmo (WCSC27) method -// #define LOSS_FUNCTION_IS_ELMO_METHOD - -// ※ Other things may be added. - - -// ---------------------- -// debug settings for learning -// ---------------------- - - // ---------------------- // learning from zero vector // ---------------------- @@ -111,11 +96,7 @@ typedef float LearnFloatType; // Learning with the method of elmo (WCSC27) // ---------------------- -#define LOSS_FUNCTION_IS_ELMO_METHOD - -#if defined(LOSS_FUNCTION_IS_ELMO_METHOD) #define LOSS_FUNCTION "ELMO_METHOD(WCSC27)" -#endif // ---------------------- // Definition of struct used in Learner diff --git a/src/learn/learner.cpp b/src/learn/learner.cpp index 82bcfa09..84cade5c 100644 --- a/src/learn/learner.cpp +++ b/src/learn/learner.cpp @@ -163,8 +163,6 @@ namespace Learner return ((y2 - y1) / epsilon) / winning_probability_coefficient; } -#if defined ( LOSS_FUNCTION_IS_ELMO_METHOD ) - // A constant used in elmo (WCSC27). Adjustment required. // Since elmo does not internally divide the expression, the value is different. // You can set this value with the learn command. @@ -293,7 +291,6 @@ namespace Learner (-m * std::log(m + epsilon) - (1.0 - m) * std::log(1.0 - m + epsilon)); } -#endif // Other objective functions may be considered in the future... double calc_grad(Value shallow, const PackedSfenValue& psv) { @@ -629,14 +626,12 @@ namespace Learner stop_flag(false), save_only_once(false) { -#if defined ( LOSS_FUNCTION_IS_ELMO_METHOD ) learn_sum_cross_entropy_eval = 0.0; learn_sum_cross_entropy_win = 0.0; learn_sum_cross_entropy = 0.0; learn_sum_entropy_eval = 0.0; learn_sum_entropy_win = 0.0; learn_sum_entropy = 0.0; -#endif newbob_scale = 1.0; newbob_decay = 1.0; @@ -689,15 +684,13 @@ namespace Learner // --- loss calculation -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) - // For calculation of learning data loss + // For calculation of learning data loss atomic learn_sum_cross_entropy_eval; atomic learn_sum_cross_entropy_win; atomic learn_sum_cross_entropy; atomic learn_sum_entropy_eval; atomic learn_sum_entropy_win; atomic learn_sum_entropy; -#endif shared_timed_mutex nn_mutex; double newbob_scale; @@ -759,13 +752,6 @@ namespace Learner std::cout << ", iteration " << epoch; std::cout << ", eta = " << Eval::get_eta() << ", "; -#if !defined(LOSS_FUNCTION_IS_ELMO_METHOD) - double sum_error = 0; - double sum_error2 = 0; - double sum_error3 = 0; -#endif - -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) // For calculation of verification data loss atomic test_sum_cross_entropy_eval, test_sum_cross_entropy_win, test_sum_cross_entropy; atomic test_sum_entropy_eval, test_sum_entropy_win, test_sum_entropy; @@ -779,7 +765,6 @@ namespace Learner // norm for learning atomic sum_norm; sum_norm = 0; -#endif // The number of times the pv first move of deep // search matches the pv first move of search(1). @@ -841,25 +826,11 @@ namespace Learner // Note) This code does not consider when // eval_limit is specified in the learn command. - // --- error calculation - -#if !defined(LOSS_FUNCTION_IS_ELMO_METHOD) - auto grad = calc_grad(deep_value, shallow_value, ps); - - // something like rmse - sum_error += grad * grad; - // Add the absolute value of the gradient - sum_error2 += abs(grad); - // Add the absolute value of the difference between the evaluation values - sum_error3 += abs(shallow_value - deep_value); -#endif - // --- calculation of cross entropy // For the time being, regarding the win rate and loss terms only in the elmo method // Calculate and display the cross entropy. -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) double test_cross_entropy_eval, test_cross_entropy_win, test_cross_entropy; double test_entropy_eval, test_entropy_win, test_entropy; calc_cross_entropy( @@ -881,7 +852,6 @@ namespace Learner test_sum_entropy_win += test_entropy_win; test_sum_entropy += test_entropy; sum_norm += (double)abs(shallow_value); -#endif // Determine if the teacher's move and the score of the shallow search match { @@ -905,17 +875,6 @@ namespace Learner while (task_count) sleep(1); -#if !defined(LOSS_FUNCTION_IS_ELMO_METHOD) - // rmse = root mean square error: mean square error - // mae = mean absolute error: mean absolute error - auto dsig_rmse = std::sqrt(sum_error / (sfen_for_mse.size() + epsilon)); - auto dsig_mae = sum_error2 / (sfen_for_mse.size() + epsilon); - auto eval_mae = sum_error3 / (sfen_for_mse.size() + epsilon); - cout << " , dsig rmse = " << dsig_rmse << " , dsig mae = " << dsig_mae - << " , eval mae = " << eval_mae; -#endif - -#if defined(LOSS_FUNCTION_IS_ELMO_METHOD) latest_loss_sum += test_sum_cross_entropy - test_sum_entropy; latest_loss_count += sr.sfen_for_mse.size(); @@ -960,9 +919,6 @@ namespace Learner learn_sum_entropy_eval = 0.0; learn_sum_entropy_win = 0.0; learn_sum_entropy = 0.0; -#else - << endl; -#endif } void LearnerThink::thread_worker(size_t thread_id) @@ -1144,7 +1100,6 @@ namespace Learner ? Eval::evaluate(pos) : -Eval::evaluate(pos); -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) // Calculate loss for training data double learn_cross_entropy_eval, learn_cross_entropy_win, learn_cross_entropy; double learn_entropy_eval, learn_entropy_win, learn_entropy; @@ -1165,7 +1120,6 @@ namespace Learner learn_sum_entropy_eval += learn_entropy_eval; learn_sum_entropy_win += learn_entropy_win; learn_sum_entropy += learn_entropy; -#endif const double example_weight = (discount_rate != 0 && ply != (int)pv.size()) ? discount_rate : 1.0; @@ -1600,12 +1554,10 @@ namespace Learner // Turn on if you want to pass a pre-shuffled file. bool no_shuffle = false; -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) // elmo lambda ELMO_LAMBDA = 0.33; ELMO_LAMBDA2 = 0.33; ELMO_LAMBDA_LIMIT = 32000; -#endif // Discount rate. If this is set to a value other than 0, // the slope will be added even at other than the PV termination. @@ -1703,13 +1655,11 @@ namespace Learner else if (option == "freeze_kkpp") is >> freeze[3]; #endif -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) // LAMBDA else if (option == "lambda") is >> ELMO_LAMBDA; else if (option == "lambda2") is >> ELMO_LAMBDA2; else if (option == "lambda_limit") is >> ELMO_LAMBDA_LIMIT; -#endif else if (option == "reduction_gameply") is >> reduction_gameply; // shuffle related @@ -1900,11 +1850,9 @@ namespace Learner reduction_gameply = max(reduction_gameply, 1); cout << "reduction_gameply : " << reduction_gameply << endl; -#if defined (LOSS_FUNCTION_IS_ELMO_METHOD) cout << "LAMBDA : " << ELMO_LAMBDA << endl; cout << "LAMBDA2 : " << ELMO_LAMBDA2 << endl; cout << "LAMBDA_LIMIT : " << ELMO_LAMBDA_LIMIT << endl; -#endif cout << "mirror_percentage : " << mirror_percentage << endl; cout << "eval_save_interval : " << eval_save_interval << " sfens" << endl;