Skip to content

Commit 61f0228

Browse files
refactor: rename EloLogistic and EloNormalized classes into EloWDL and EloPentanomial (#232)
* Rename elo_logistic.cpp to elo_wdl.cpp * Rename elo_logistic.hpp to elo_wdl.hpp * Rename elo_norm.cpp to elo_pentanomial.cpp * Rename elo_norm.hpp to elo_pentanomial.hpp * Update elo_wdl.cpp * Update elo_wdl.hpp * Update elo_pentanomial.cpp * Update elo_pentanomial.hpp * Update output_cutechess.hpp * Update output_cutechess.hpp * Update output_fastchess.hpp * Update elo_test.cpp * Update cli.cpp * Update sprt.cpp * Update sprt.cpp * Update sprt.hpp * Update roundrobin.cpp * Update tournament_options.hpp * Update sprt.cpp * Update sprt.hpp * Update cli.cpp * Update roundrobin.cpp
1 parent 336d275 commit 61f0228

File tree

12 files changed

+51
-51
lines changed

12 files changed

+51
-51
lines changed

src/cli/cli.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,11 @@ void parseSprt(int &i, int argc, char const *argv[], ArgumentData &argument_data
249249
argument_data.tournament_options.sprt.alpha = std::stod(value);
250250
} else if (key == "beta") {
251251
argument_data.tournament_options.sprt.beta = std::stod(value);
252-
} else if (key == "bounds") {
252+
} else if (key == "model") {
253253
if (value == "logistic") {
254-
argument_data.tournament_options.sprt.bounds = true;
254+
argument_data.tournament_options.sprt.logistic_bounds = true;
255255
} else if (value == "normalized") {
256-
argument_data.tournament_options.sprt.bounds = false;
256+
argument_data.tournament_options.sprt.logistic_bounds = false;
257257
} else {
258258
OptionsParser::throwMissing("sprt", key, value);
259259
}

src/matchmaking/elo/elo_norm.cpp renamed to src/matchmaking/elo/elo_pentanomial.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#include <matchmaking/elo/elo_norm.hpp>
1+
#include <matchmaking/elo/elo_pentanomial.hpp>
22

33
#include <cmath>
44
#include <iomanip>
55
#include <sstream>
66

77
namespace fast_chess {
88

9-
EloNormalized::EloNormalized(const Stats& stats) {
9+
EloPentanomial::EloPentanomial(const Stats& stats) {
1010
diff_ = diff(stats);
1111
error_ = error(stats);
1212
nelodiff_ = nEloDiff(stats);
1313
neloerror_ = nEloError(stats);
1414
}
1515

16-
double EloNormalized::percToEloDiff(double percentage) noexcept {
16+
double EloPentanomial::percToEloDiff(double percentage) noexcept {
1717
return -400.0 * std::log10(1.0 / percentage - 1.0);
1818
}
1919

20-
double EloNormalized::percToNeloDiff(double percentage, double stdev) noexcept {
20+
double EloPentanomial::percToNeloDiff(double percentage, double stdev) noexcept {
2121
return (percentage - 0.5) / (std::sqrt(2) * stdev) * (800 / std::log(10));
2222
}
2323

24-
double EloNormalized::percToNeloDiffWDL(double percentage, double stdev) noexcept {
24+
double EloPentanomial::percToNeloDiffWDL(double percentage, double stdev) noexcept {
2525
return (percentage - 0.5) / stdev * (800 / std::log(10));
2626
}
2727

28-
double EloNormalized::error(const Stats& stats) noexcept {
28+
double EloPentanomial::error(const Stats& stats) noexcept {
2929
const double pairs = total(stats);
3030
const double WW = double(stats.penta_WW) / pairs;
3131
const double WD = double(stats.penta_WD) / pairs;
@@ -46,7 +46,7 @@ double EloNormalized::error(const Stats& stats) noexcept {
4646
return (percToEloDiff(devMax) - percToEloDiff(devMin)) / 2.0;
4747
}
4848

49-
double EloNormalized::nEloError(const Stats& stats) noexcept {
49+
double EloPentanomial::nEloError(const Stats& stats) noexcept {
5050
const double pairs = total(stats);
5151
const double WW = double(stats.penta_WW) / pairs;
5252
const double WD = double(stats.penta_WD) / pairs;
@@ -69,7 +69,7 @@ double EloNormalized::nEloError(const Stats& stats) noexcept {
6969
2.0;
7070
}
7171

72-
double EloNormalized::diff(const Stats& stats) noexcept {
72+
double EloPentanomial::diff(const Stats& stats) noexcept {
7373
const double pairs = total(stats);
7474
const double WW = double(stats.penta_WW) / pairs;
7575
const double WD = double(stats.penta_WD) / pairs;
@@ -81,7 +81,7 @@ double EloNormalized::diff(const Stats& stats) noexcept {
8181
return percToEloDiff(percentage);
8282
}
8383

84-
double EloNormalized::nEloDiff(const Stats& stats) noexcept {
84+
double EloPentanomial::nEloDiff(const Stats& stats) noexcept {
8585
const double pairs = total(stats);
8686
const double WW = double(stats.penta_WW) / pairs;
8787
const double WD = double(stats.penta_WD) / pairs;
@@ -100,7 +100,7 @@ double EloNormalized::nEloDiff(const Stats& stats) noexcept {
100100
return percToNeloDiff(a, stdev * std::sqrt(pairs));
101101
}
102102

103-
std::string EloNormalized::nElo() const noexcept {
103+
std::string EloPentanomial::nElo() const noexcept {
104104
std::stringstream ss;
105105

106106
ss << std::fixed << std::setprecision(2) << nelodiff_;
@@ -109,7 +109,7 @@ std::string EloNormalized::nElo() const noexcept {
109109
return ss.str();
110110
}
111111

112-
std::string EloNormalized::los(const Stats& stats) const noexcept {
112+
std::string EloPentanomial::los(const Stats& stats) const noexcept {
113113
const double pairs = total(stats);
114114
const double WW = double(stats.penta_WW) / pairs;
115115
const double WD = double(stats.penta_WD) / pairs;
@@ -131,15 +131,15 @@ std::string EloNormalized::los(const Stats& stats) const noexcept {
131131
return ss.str();
132132
}
133133

134-
std::string EloNormalized::drawRatio(const Stats& stats) const noexcept {
134+
std::string EloPentanomial::drawRatio(const Stats& stats) const noexcept {
135135
const double pairs = total(stats);
136136
std::stringstream ss;
137137
ss << std::fixed << std::setprecision(2) << ((stats.penta_WL + stats.penta_DD) / pairs) * 100.0
138138
<< " %";
139139
return ss.str();
140140
}
141141

142-
std::string EloNormalized::scoreRatio(const Stats& stats) const noexcept {
142+
std::string EloPentanomial::scoreRatio(const Stats& stats) const noexcept {
143143
const double pairs = total(stats);
144144
const double WW = double(stats.penta_WW) / pairs;
145145
const double WD = double(stats.penta_WD) / pairs;
@@ -153,7 +153,7 @@ std::string EloNormalized::scoreRatio(const Stats& stats) const noexcept {
153153
return ss.str();
154154
}
155155

156-
std::size_t EloNormalized::total(const Stats& stats) noexcept {
156+
std::size_t EloPentanomial::total(const Stats& stats) noexcept {
157157
return stats.penta_WW + stats.penta_WD + stats.penta_WL + stats.penta_DD + stats.penta_LD +
158158
stats.penta_LL;
159159
}

src/matchmaking/elo/elo_norm.hpp renamed to src/matchmaking/elo/elo_pentanomial.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace fast_chess {
99

10-
class EloNormalized : public EloBase {
10+
class EloPentanomial : public EloBase {
1111
public:
12-
EloNormalized(const Stats& stats);
12+
EloPentanomial(const Stats& stats);
1313

1414
[[nodiscard]] std::string los(const Stats& stats) const noexcept override;
1515
[[nodiscard]] std::string drawRatio(const Stats& stats) const noexcept override;

src/matchmaking/elo/elo_logistic.cpp renamed to src/matchmaking/elo/elo_wdl.cpp

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <matchmaking/elo/elo_logistic.hpp>
1+
#include <matchmaking/elo/elo_wdl.hpp>
22

33
#include <cmath>
44
#include <iomanip>
@@ -15,26 +15,26 @@ std::string EloBase::getElo() const noexcept {
1515
return ss.str();
1616
}
1717

18-
EloLogistic::EloLogistic(const Stats& stats) {
18+
EloWDL::EloWDL(const Stats& stats) {
1919
diff_ = diff(stats);
2020
error_ = error(stats);
2121
nelodiff_ = nEloDiff(stats);
2222
neloerror_ = nEloError(stats);
2323
}
2424

25-
double EloLogistic::percToEloDiff(double percentage) noexcept {
25+
double EloWDL::percToEloDiff(double percentage) noexcept {
2626
return -400.0 * std::log10(1.0 / percentage - 1.0);
2727
}
2828

29-
double EloLogistic::percToNeloDiff(double percentage, double stdev) noexcept {
29+
double EloWDL::percToNeloDiff(double percentage, double stdev) noexcept {
3030
return (percentage - 0.5) / (std::sqrt(2) * stdev) * (800 / std::log(10));
3131
}
3232

33-
double EloLogistic::percToNeloDiffWDL(double percentage, double stdev) noexcept {
33+
double EloWDL::percToNeloDiffWDL(double percentage, double stdev) noexcept {
3434
return (percentage - 0.5) / stdev * (800 / std::log(10));
3535
}
3636

37-
double EloLogistic::error(const Stats& stats) noexcept {
37+
double EloWDL::error(const Stats& stats) noexcept {
3838
const double n = total(stats);
3939
const double w = stats.wins / n;
4040
const double l = stats.losses / n;
@@ -51,7 +51,7 @@ double EloLogistic::error(const Stats& stats) noexcept {
5151
return (percToEloDiff(devMax) - percToEloDiff(devMin)) / 2.0;
5252
}
5353

54-
double EloLogistic::nEloError(const Stats& stats) noexcept {
54+
double EloWDL::nEloError(const Stats& stats) noexcept {
5555
const double n = total(stats);
5656
const double w = stats.wins / n;
5757
const double l = stats.losses / n;
@@ -70,15 +70,15 @@ double EloLogistic::nEloError(const Stats& stats) noexcept {
7070
2.0;
7171
}
7272

73-
double EloLogistic::diff(const Stats& stats) noexcept {
73+
double EloWDL::diff(const Stats& stats) noexcept {
7474
const double n = total(stats);
7575
const double score = stats.wins + stats.draws / 2.0;
7676
const double percentage = (score / n);
7777

7878
return percToEloDiff(percentage);
7979
}
8080

81-
double EloLogistic::nEloDiff(const Stats& stats) noexcept {
81+
double EloWDL::nEloDiff(const Stats& stats) noexcept {
8282
const double n = total(stats);
8383
const double w = stats.wins / n;
8484
const double l = stats.losses / n;
@@ -92,7 +92,7 @@ double EloLogistic::nEloDiff(const Stats& stats) noexcept {
9292
return percToNeloDiffWDL(perc, stdev * std::sqrt(n));
9393
}
9494

95-
std::string EloLogistic::nElo() const noexcept {
95+
std::string EloWDL::nElo() const noexcept {
9696
std::stringstream ss;
9797

9898
ss << std::fixed << std::setprecision(2) << nelodiff_;
@@ -101,7 +101,7 @@ std::string EloLogistic::nElo() const noexcept {
101101
return ss.str();
102102
}
103103

104-
std::string EloLogistic::los(const Stats& stats) const noexcept {
104+
std::string EloWDL::los(const Stats& stats) const noexcept {
105105
const double games = total(stats);
106106
const double W = double(stats.wins) / games;
107107
const double D = double(stats.draws) / games;
@@ -118,14 +118,14 @@ std::string EloLogistic::los(const Stats& stats) const noexcept {
118118
return ss.str();
119119
}
120120

121-
std::string EloLogistic::drawRatio(const Stats& stats) const noexcept {
121+
std::string EloWDL::drawRatio(const Stats& stats) const noexcept {
122122
const double n = total(stats);
123123
std::stringstream ss;
124124
ss << std::fixed << std::setprecision(2) << (stats.draws / n) * 100.0 << " %";
125125
return ss.str();
126126
}
127127

128-
std::string EloLogistic::scoreRatio(const Stats& stats) const noexcept {
128+
std::string EloWDL::scoreRatio(const Stats& stats) const noexcept {
129129
const double n = total(stats);
130130
const auto scoreRatio = double(stats.wins * 2 + stats.draws) / (n * 2);
131131

@@ -134,7 +134,7 @@ std::string EloLogistic::scoreRatio(const Stats& stats) const noexcept {
134134
return ss.str();
135135
}
136136

137-
std::size_t EloLogistic::total(const Stats& stats) noexcept {
137+
std::size_t EloWDL::total(const Stats& stats) noexcept {
138138
return stats.wins + stats.losses + stats.draws;
139139
}
140140
} // namespace fast_chess

src/matchmaking/elo/elo_logistic.hpp renamed to src/matchmaking/elo/elo_wdl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace fast_chess {
99

10-
class EloLogistic : public EloBase {
10+
class EloWDL : public EloBase {
1111
public:
12-
EloLogistic(const Stats& stats);
12+
EloWDL(const Stats& stats);
1313

1414
[[nodiscard]] std::string los(const Stats& stats) const noexcept override;
1515
[[nodiscard]] std::string drawRatio(const Stats& stats) const noexcept override;

src/matchmaking/output/output_cutechess.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include <matchmaking/elo/elo_logistic.hpp>
3+
#include <matchmaking/elo/elo_wdl.hpp>
44
#include <matchmaking/output/output.hpp>
55
#include <util/logger/logger.hpp>
66

@@ -16,7 +16,7 @@ class Cutechess : public IOutput {
1616

1717
void printElo(const Stats& stats, const std::string& first, const std::string& second,
1818
std::size_t current_game_count) override {
19-
const EloLogistic elo(stats);
19+
const EloWDL elo(stats);
2020

2121
std::stringstream ss;
2222
ss << "Score of " //

src/matchmaking/output/output_fastchess.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include <matchmaking/elo/elo_logistic.hpp>
4-
#include <matchmaking/elo/elo_norm.hpp>
3+
#include <matchmaking/elo/elo_wdl.hpp>
4+
#include <matchmaking/elo/elo_pentanomial.hpp>
55
#include <matchmaking/output/output.hpp>
66
#include <util/logger/logger.hpp>
77

@@ -27,9 +27,9 @@ class Fastchess : public IOutput {
2727
std::unique_ptr<EloBase> elo;
2828

2929
if (report_penta_) {
30-
elo = std::make_unique<EloNormalized>(stats);
30+
elo = std::make_unique<EloPentanomial>(stats);
3131
} else {
32-
elo = std::make_unique<EloLogistic>(stats);
32+
elo = std::make_unique<EloWDL>(stats);
3333
}
3434

3535
std::stringstream ss;

src/matchmaking/sprt/sprt.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace fast_chess {
1010

11-
SPRT::SPRT(double alpha, double beta, double elo0, double elo1, bool bounds) {
11+
SPRT::SPRT(double alpha, double beta, double elo0, double elo1, bool logistic_bounds) {
1212
valid_ = alpha != 0.0 && beta != 0.0 && elo0 < elo1;
1313
if (isValid()) {
1414
lower_ = std::log(beta / (1 - alpha));
@@ -17,7 +17,7 @@ SPRT::SPRT(double alpha, double beta, double elo0, double elo1, bool bounds) {
1717
elo0_ = elo0;
1818
elo1_ = elo1;
1919

20-
logisticBounds_ = bounds;
20+
logisticBounds_ = logistic_bounds;
2121

2222
Logger::log<Logger::Level::INFO>("Initialized valid SPRT configuration.");
2323
} else if (!(alpha == 0.0 && beta == 0.0 && elo0 == 0.0 && elo1 == 0.0)) {

src/matchmaking/sprt/sprt.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SPRT {
1010
public:
1111
SPRT() = default;
1212

13-
SPRT(double alpha, double beta, double elo0, double elo1, bool bounds);
13+
SPRT(double alpha, double beta, double elo0, double elo1, bool logistic_bounds);
1414

1515
[[nodiscard]] bool isValid() const noexcept;
1616

src/matchmaking/tournament/roundrobin/roundrobin.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RoundRobin::RoundRobin(const options::Tournament& tournament_config,
1616
// Initialize the SPRT test
1717
sprt_ = SPRT(tournament_options_.sprt.alpha, tournament_options_.sprt.beta,
1818
tournament_options_.sprt.elo0, tournament_options_.sprt.elo1,
19-
tournament_options_.sprt.bounds);
19+
tournament_options_.sprt.logistic_bounds);
2020
}
2121

2222
void RoundRobin::start() {

src/types/tournament_options.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ struct Sprt {
3131
double beta = 0.0;
3232
double elo0 = 0.0;
3333
double elo1 = 0.0;
34-
bool bounds = false;
34+
bool logistic_bounds = false;
3535
};
36-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ORDERED_JSON(Sprt, alpha, beta, elo0, elo1, bounds)
36+
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_ORDERED_JSON(Sprt, alpha, beta, elo0, elo1, logistic_bounds)
3737

3838
struct DrawAdjudication {
3939
int move_number = 0;

tests/elo_test.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <matchmaking/elo/elo_logistic.hpp>
1+
#include <matchmaking/elo/elo_wdl.hpp>
22

33
#include "doctest/doctest.hpp"
44

@@ -9,23 +9,23 @@ using namespace fast_chess;
99
TEST_SUITE("Elo Calculation Tests") {
1010
TEST_CASE("Elo calculation") {
1111
Stats stats(0, 36, 14);
12-
EloLogistic elo(stats);
12+
EloWDL elo(stats);
1313

1414
// CHECK(elo.diff(stats) == doctest::Approx(-315.34).epsilon(0.01));
1515
// CHECK(elo.error(stats) == doctest::Approx(95.43).epsilon(0.01));
1616
}
1717

1818
TEST_CASE("Elo calculation 2") {
1919
Stats stats(859, 772, 1329);
20-
EloLogistic elo(stats);
20+
EloWDL elo(stats);
2121

2222
// CHECK(elo.diff(stats) == doctest::Approx(10.21).epsilon(0.01));
2323
// CHECK(elo.error(stats) == doctest::Approx(9.28).epsilon(0.01));
2424
}
2525

2626
TEST_CASE("Elo calculation 3") {
2727
Stats stats(1164, 1267, 3049);
28-
EloLogistic elo(stats);
28+
EloWDL elo(stats);
2929

3030
// CHECK(elo.diff(stats) == doctest::Approx(-6.53).epsilon(0.01));
3131
// CHECK(elo.error(stats) == doctest::Approx(6.12).epsilon(0.01));

0 commit comments

Comments
 (0)