Skip to content

Commit

Permalink
Merge pull request #1 from Nightcrab/main
Browse files Browse the repository at this point in the history
reduce learning rates
  • Loading branch information
shakkar23 authored Feb 17, 2025
2 parents 05ff88d + f70ca3a commit c2fdc9d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 5 additions & 5 deletions mElo/mElo/update_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ std::tuple<Numeric, Numeric, Column, Column> update_melo(Numeric rA, Numeric rB,

Numeric error = observed_score - predicted_score;

Numeric K = 16;
Numeric K = 1;

rA += K * error;
rB += -K * error;


for (int i = 0; i < k; i++) {
cA[0+i*2] += std::clamp( error * cB[1 + i*2], (Numeric)-1, (Numeric)1);
cA[1+i*2] += std::clamp(-error * cA[1 + i*2], (Numeric)-1, (Numeric)1);
cB[0+i*2] += std::clamp(-error * cB[0 + i*2], (Numeric)-1, (Numeric)1);
cB[1+i*2] += std::clamp( error * cA[0 + i*2], (Numeric)-1, (Numeric)1);
cA[0+i*2] += 0.01 * std::clamp( error * cB[1 + i*2], (Numeric)-1, (Numeric)1);
cA[1+i*2] += 0.01 * std::clamp(-error * cA[1 + i*2], (Numeric)-1, (Numeric)1);
cB[0+i*2] += 0.01 * std::clamp(-error * cB[0 + i*2], (Numeric)-1, (Numeric)1);
cB[1+i*2] += 0.01 * std::clamp( error * cA[0 + i*2], (Numeric)-1, (Numeric)1);
}

return { rA, rB, cA, cB };
Expand Down
26 changes: 24 additions & 2 deletions mElo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int tetrio_trainer() {

constexpr int batch_period = 10'000;

for (int batch_n = 0; batch_n < 1; batch_n++) {
for (int batch_n = 0; batch_n < 50; batch_n++) {

Matrix MELO_copy = MELO;
// elo copy
Expand Down Expand Up @@ -99,6 +99,20 @@ int tetrio_trainer() {
save_elo(ELO);
save_melo(MELO);
save_player_map();

const auto example_player = "5f708143ea3d3a2b3abdfe23";

Column prediction(player_map.size());
for (auto&& [name, index] : player_map) {
auto jth = MELO.get_col(index);
auto ith = MELO.get_col(player_map[example_player]);
prediction[index] = predict(ELO(0, player_map[example_player]), ELO(0, index), ith, jth);
}
// print prediction
for (auto&& [name, index] : player_map) {
std::cout << name << ": " << prediction[index] << std::endl;
}

}

return 0;
Expand Down Expand Up @@ -224,6 +238,7 @@ int rps() {
int batch_counter = batch_period;

std::ranges::shuffle(games_list, LCG);

for (auto&& [i, j, outcome] : games_list) {
Column cA = MELO_copy.get_col(i);
Column cB = MELO_copy.get_col(j);
Expand Down Expand Up @@ -280,7 +295,7 @@ int rps() {
}

int main() {
return tetrio_viewer_total();
return tetrio_trainer();
}

std::vector<game> init_game_list() {
Expand All @@ -289,7 +304,14 @@ std::vector<game> init_game_list() {
// read the csv file
csv::CSVReader reader("assets/games.csv");

int i = 0;
const int data_limit = 1000'000'000;

for (auto&& row : reader) {
i++;
if (i > data_limit) {
break;
}
std::string player1 = row[0].get<std::string>();
std::string player2 = row[1].get<std::string>();

Expand Down

0 comments on commit c2fdc9d

Please sign in to comment.