interpolation with estimated llr and peak locking
This commit is contained in:
1 parent
2884a7ccf8
commit
4e8c6c9423
4 files changed
+92
-17
No files matched your search
@@ -211,9 +211,9 @@ def llr_history_graph(test, width=320, height=112):
|
|||||||
|
|
||||||
history = list(OpenBench.utils.get_llr_history(test))
|
history = list(OpenBench.utils.get_llr_history(test))
|
||||||
if not history:
|
if not history:
|
||||||
history = [[0, 0.0], [max(test.games, 1), test.currentllr]]
|
history = [[0, 0.0, False], [max(test.games, 1), test.currentllr, False]]
|
||||||
elif history[-1][0] != test.games or history[-1][1] != test.currentllr:
|
elif history[-1][0] != test.games or history[-1][1] != test.currentllr:
|
||||||
history.append([test.games, test.currentllr])
|
history.append([test.games, test.currentllr, False])
|
||||||
|
|
||||||
x_max = max(max(point[0] for point in history), 1)
|
x_max = max(max(point[0] for point in history), 1)
|
||||||
observed = [point[1] for point in history] + [0.0]
|
observed = [point[1] for point in history] + [0.0]
|
||||||
@@ -247,10 +247,11 @@ def llr_history_graph(test, width=320, height=112):
|
|||||||
{
|
{
|
||||||
'games': x,
|
'games': x,
|
||||||
'llr': round(y, 4),
|
'llr': round(y, 4),
|
||||||
|
'estimated': estimated,
|
||||||
'x': round(scale_x(x), 2),
|
'x': round(scale_x(x), 2),
|
||||||
'y': round(scale_y(y), 2),
|
'y': round(scale_y(y), 2),
|
||||||
}
|
}
|
||||||
for x, y in history
|
for x, y, estimated in history
|
||||||
]
|
]
|
||||||
y_mid = (y_min + y_max) / 2.0
|
y_mid = (y_min + y_max) / 2.0
|
||||||
x_mid = x_max / 2.0
|
x_mid = x_max / 2.0
|
||||||
|
|||||||
+60
-11
@@ -136,7 +136,7 @@ def path_join(*args):
|
|||||||
def llr_history_path(test_id):
|
def llr_history_path(test_id):
|
||||||
return os.path.join(MEDIA_ROOT, 'llr_history', '%d.json' % (test_id))
|
return os.path.join(MEDIA_ROOT, 'llr_history', '%d.json' % (test_id))
|
||||||
|
|
||||||
def get_llr_history(test):
|
def load_llr_history(test):
|
||||||
|
|
||||||
path = llr_history_path(test.id)
|
path = llr_history_path(test.id)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
@@ -149,6 +149,63 @@ def get_llr_history(test):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return [[0, 0.0]]
|
return [[0, 0.0]]
|
||||||
|
|
||||||
|
def interpolate_llr_history(history, max_points=120):
|
||||||
|
|
||||||
|
if not history:
|
||||||
|
return []
|
||||||
|
|
||||||
|
normalized = []
|
||||||
|
for games, llr in sorted(history, key=lambda point: point[0]):
|
||||||
|
point = [int(games), float(llr), False]
|
||||||
|
if normalized and normalized[-1][0] == point[0]:
|
||||||
|
normalized[-1] = point
|
||||||
|
else:
|
||||||
|
normalized.append(point)
|
||||||
|
|
||||||
|
if not normalized or normalized[0][0] != 0:
|
||||||
|
normalized.insert(0, [0, 0.0, False])
|
||||||
|
|
||||||
|
if len(normalized) == 1:
|
||||||
|
return normalized
|
||||||
|
|
||||||
|
final_games = max(normalized[-1][0], 1)
|
||||||
|
desired_points = min(max_points, max(2, final_games + 1))
|
||||||
|
step = final_games / float(desired_points - 1)
|
||||||
|
source_index = 0
|
||||||
|
estimated = []
|
||||||
|
|
||||||
|
for index in range(desired_points):
|
||||||
|
target_games = final_games if index == desired_points - 1 else index * step
|
||||||
|
|
||||||
|
while source_index + 1 < len(normalized) and normalized[source_index + 1][0] < target_games:
|
||||||
|
source_index += 1
|
||||||
|
|
||||||
|
left = normalized[source_index]
|
||||||
|
if source_index + 1 >= len(normalized):
|
||||||
|
llr = left[1]
|
||||||
|
else:
|
||||||
|
right = normalized[source_index + 1]
|
||||||
|
game_span = right[0] - left[0]
|
||||||
|
if game_span <= 0:
|
||||||
|
llr = right[1]
|
||||||
|
else:
|
||||||
|
ratio = (target_games - left[0]) / float(game_span)
|
||||||
|
llr = left[1] + ratio * (right[1] - left[1])
|
||||||
|
|
||||||
|
display_games = int(round(target_games))
|
||||||
|
estimated.append([display_games, round(llr, 4), True])
|
||||||
|
|
||||||
|
merged = {}
|
||||||
|
for games, llr, is_estimated in estimated + normalized:
|
||||||
|
existing = merged.get(games)
|
||||||
|
if existing is None or (existing[2] and not is_estimated):
|
||||||
|
merged[games] = [games, llr, is_estimated]
|
||||||
|
|
||||||
|
return [merged[key] for key in sorted(merged.keys())]
|
||||||
|
|
||||||
|
def get_llr_history(test, max_points=120):
|
||||||
|
return interpolate_llr_history(load_llr_history(test), max_points=max_points)
|
||||||
|
|
||||||
def extract_option(options, option):
|
def extract_option(options, option):
|
||||||
|
|
||||||
match = re.search(r'(?<={0}=")[^"]*'.format(option), options)
|
match = re.search(r'(?<={0}=")[^"]*'.format(option), options)
|
||||||
@@ -526,9 +583,9 @@ def update_test(request, machine):
|
|||||||
|
|
||||||
return [{}, { 'stop' : True }][test.finished]
|
return [{}, { 'stop' : True }][test.finished]
|
||||||
|
|
||||||
def record_llr_history(test, max_points=120):
|
def record_llr_history(test):
|
||||||
|
|
||||||
history = get_llr_history(test)
|
history = load_llr_history(test)
|
||||||
point = [test.games, round(test.currentllr, 4)]
|
point = [test.games, round(test.currentllr, 4)]
|
||||||
|
|
||||||
if history and history[-1][0] == point[0]:
|
if history and history[-1][0] == point[0]:
|
||||||
@@ -539,14 +596,6 @@ def record_llr_history(test, max_points=120):
|
|||||||
if not history or history[0][0] != 0:
|
if not history or history[0][0] != 0:
|
||||||
history.insert(0, [0, 0.0])
|
history.insert(0, [0, 0.0])
|
||||||
|
|
||||||
if len(history) > max_points:
|
|
||||||
keep = [history[0]]
|
|
||||||
interior = history[1:-1:2]
|
|
||||||
history = keep + interior + [history[-1]]
|
|
||||||
|
|
||||||
while len(history) > max_points:
|
|
||||||
history = [history[0]] + history[1:-1:2] + [history[-1]]
|
|
||||||
|
|
||||||
path = llr_history_path(test.id)
|
path = llr_history_path(test.id)
|
||||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||||
with open(path, 'w') as fout:
|
with open(path, 'w') as fout:
|
||||||
|
|||||||
+1
-1
@@ -951,4 +951,4 @@ def api_pgns(request, pgn_id):
|
|||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
|
|
||||||
def buyEthereal(request):
|
def buyEthereal(request):
|
||||||
return render(request, 'buyEthereal.html')
|
return render(request, 'buyEthereal.html')
|
||||||
@@ -10,6 +10,20 @@
|
|||||||
document.querySelectorAll('.llr-history-widget').forEach(function(widget) {
|
document.querySelectorAll('.llr-history-widget').forEach(function(widget) {
|
||||||
var history = JSON.parse(widget.dataset.history || '[]');
|
var history = JSON.parse(widget.dataset.history || '[]');
|
||||||
if (!history.length) return;
|
if (!history.length) return;
|
||||||
|
var realPoints = history.filter(function(point) { return !point.estimated; });
|
||||||
|
var peakGames = {};
|
||||||
|
|
||||||
|
for (var r = 1; r < realPoints.length - 1; r++) {
|
||||||
|
var prev = realPoints[r - 1];
|
||||||
|
var curr = realPoints[r];
|
||||||
|
var next = realPoints[r + 1];
|
||||||
|
var isPeak = curr.llr > prev.llr && curr.llr > next.llr;
|
||||||
|
var isValley = curr.llr < prev.llr && curr.llr < next.llr;
|
||||||
|
|
||||||
|
if (isPeak || isValley) {
|
||||||
|
peakGames[curr.games] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var svg = widget.querySelector('.llr-history-graph');
|
var svg = widget.querySelector('.llr-history-graph');
|
||||||
var plot = widget.querySelector('.llr-history-plot');
|
var plot = widget.querySelector('.llr-history-plot');
|
||||||
@@ -30,7 +44,7 @@
|
|||||||
hoverPoint.classList.toggle('llr-hover-point-positive', point.llr >= 0);
|
hoverPoint.classList.toggle('llr-hover-point-positive', point.llr >= 0);
|
||||||
hoverPoint.classList.toggle('llr-hover-point-negative', point.llr < 0);
|
hoverPoint.classList.toggle('llr-hover-point-negative', point.llr < 0);
|
||||||
|
|
||||||
tooltip.textContent = point.games + ' games | LLR ' + point.llr.toFixed(2);
|
tooltip.textContent = point.games + ' games | LLR ' + (point.estimated ? '≈' : '') + point.llr.toFixed(2);
|
||||||
tooltip.classList.add('active');
|
tooltip.classList.add('active');
|
||||||
|
|
||||||
var left = clamp((point.x / viewBox.width) * plot.clientWidth + 8, 8, plot.clientWidth - tooltip.offsetWidth - 8);
|
var left = clamp((point.x / viewBox.width) * plot.clientWidth + 8, 8, plot.clientWidth - tooltip.offsetWidth - 8);
|
||||||
@@ -50,13 +64,24 @@
|
|||||||
var localX = ((clientX - rect.left) / rect.width) * viewBox.width;
|
var localX = ((clientX - rect.left) / rect.width) * viewBox.width;
|
||||||
var best = history[0];
|
var best = history[0];
|
||||||
var bestDistance = Math.abs(best.x - localX);
|
var bestDistance = Math.abs(best.x - localX);
|
||||||
|
var bestPeak = null;
|
||||||
|
var bestPeakDistance = Infinity;
|
||||||
|
|
||||||
for (var i = 1; i < history.length; i++) {
|
for (var i = 0; i < history.length; i++) {
|
||||||
var distance = Math.abs(history[i].x - localX);
|
var distance = Math.abs(history[i].x - localX);
|
||||||
if (distance < bestDistance) {
|
if (distance < bestDistance) {
|
||||||
best = history[i];
|
best = history[i];
|
||||||
bestDistance = distance;
|
bestDistance = distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!history[i].estimated && peakGames[history[i].games] && distance < bestPeakDistance) {
|
||||||
|
bestPeak = history[i];
|
||||||
|
bestPeakDistance = distance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestPeak && bestPeakDistance <= 5) {
|
||||||
|
return bestPeak;
|
||||||
}
|
}
|
||||||
|
|
||||||
return best;
|
return best;
|
||||||
|
|||||||
Reference in new issue
Block a user