Skip to content

Commit

Permalink
All figure 3 graph for all buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
sethtroisi committed Jan 29, 2019
1 parent 5b9f3df commit d984ea8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 55 deletions.
78 changes: 36 additions & 42 deletions web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,6 @@ def model_thumb(name):
cache_timeout=60*60)


@app.route('/eval/<bucket>/<filename>')
def eval_image(bucket, filename):
filepath = os.path.join(LOCAL_EVAL_DIR, bucket, filename)
if is_naughty(filepath, LOCAL_EVAL_DIR, '.png'):
return ''

return send_from_directory(
LOCAL_EVAL_DIR,
os.path.join(bucket, filename),
cache_timeout=30*60)


def _fstat_dir(directory, top_dir):
if not os.path.isdir(directory):
return []
Expand Down Expand Up @@ -454,44 +442,50 @@ def pro_game_view(filename):
)


@app.route('/<bucket>/figure-three')
def figure_three(bucket):
eval_path = os.path.join(LOCAL_EVAL_DIR, bucket)
exists = os.path.exists(os.path.join(eval_path, 'move_acc.png'))
def parse_fig3_data(bucket):
fig3_json = '{"acc":{}, "mse":{}, "num":{}}'

json_file = os.path.join(LOCAL_EVAL_DIR, bucket, "fig3.json")
if os.path.exists(json_file):
with open(json_file, "r") as f:
fig3_json = f.read()

# This is a longtime request from andrew.
key = '{}/fig3-json'.format(bucket)
fig3_data = cache.get(key)
if fig3_data is None:
fig3_json = '{"acc":{"0":0.01}, "mse":{"0":0.25}, "num":{"0":1}}'
fig3_data = []
try:
fig3_json = json.loads(fig3_json)
for k, v in fig3_json["num"].items():
acc = fig3_json["acc"][k]
mse = fig3_json["mse"][k]
fig3_data.append((v, acc, mse))
except Exception as e:
print("Error parsing fig3 json:", e)

json_file = os.path.join(eval_path, "fig3.json")
if os.path.exists(json_file):
with open(json_file, "r") as f:
fig3_json = f.read()
return sorted(fig3_data)

fig3_data = []
try:
fig3_json = json.loads(fig3_json)
for k, v in fig3_json["num"].items():
acc = fig3_json["acc"][k]
mse = fig3_json["mse"][k]
fig3_data.append((v, acc, mse))
except Exception as e:
print("Error parsing fig3 json:", e)

fig3_data.sort()
@app.route('/<bucket>/figure-three')
def figure_three(bucket):
figure_data = None
figure_three_data = []

# This list is a reasonable proxy for 'all' minigo runs.
for other_bucket in CloudyGo.MINIGO_TS:
key = '{}/fig3-json'.format(other_bucket)
fig3_data = cache.get(key)
if fig3_data is None:
fig3_data = parse_fig3_data(other_bucket)
cache.set(key, fig3_data, timeout=5 * 60)

if other_bucket == bucket:
figure_data = fig3_data

cache.set(key, fig3_data, timeout=5 * 60)
for values in fig3_data:
figure_three_data.append((other_bucket,) + values)

return render_template('figure-three.html',
bucket=bucket,
exists=exists,
fig3_data=fig3_data,
eval_files=[
'move_acc.png', 'value_mse.png',
'move_acc2.png', 'value_mse2.png',
],
fig3_data=figure_data,
figure_three_data=figure_three_data,
)


Expand Down
47 changes: 34 additions & 13 deletions web/templates/figure-three.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!DOCTYPE html>
<html lang="en" xml:lang="en" xmlns= "http://www.w3.org/1999/xhtml">
{% from "macros.html" import models_link, bucket_name,
bootstrap_links, favicon_links, navbar with context %}
bootstrap_links, favicon_links, navbar, tip with context %}
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="Content-Language" content="en">
Expand All @@ -28,6 +28,7 @@
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='styles/general.css') }}">

<script src="https://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript" src="{{ url_for('static',filename='d3-tip.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static',filename='graphs.js') }}"></script>

<style>
Expand All @@ -44,7 +45,9 @@
<body>
{{ navbar('figure_three', 'Figure 3 Reproduction') }}

{% if exists %}
{% if not fig3_data %}
Unfortunately figure 3 is hard to reproduce and I haven't yet found the professional games or wrangled the outputs of the model for {{ bucket_name(bucket) }} yet, Sorry.
{% else %}
<hr>
These graphics are generated by sampled 1,000 games (no handicap, 7.5 Komi) from
<a href="http://badukmovies.com/pro_games">baduk movies pro game collection</a>
Expand All @@ -64,18 +67,11 @@
<br>
Much additional analysis has been done in <a href="https://colab.research.google.com/drive/1kfzXQh2oG4Fne47bcD-tyTOz8mdvDlFl#scrollTo=nyCr1p6XMaBL">Google Colab</a>.
<hr>
{% if fig3_data %}
<svg class="model-graph" id="fig3-acc"></svg>
<svg class="model-graph" id="fig3-mse"></svg>
{% endif %}
{% for eval_file in eval_files %}
{% if '2' in eval_file or not fig3_data %}
<img src="{{ url_for('eval_image', bucket=bucket, filename=eval_file) }}"
class="model-graph">
{% endif %}
{% endfor %}
{% else %}
Unfortunately figure 3 is hard to reproduce and I haven't yet found the professional games or wrangled the outputs of the model for {{ bucket_name(bucket) }} yet, Sorry.

<svg class="model-graph" id="fig3-acc-all"></svg>
<svg class="model-graph" id="fig3-mse-all"></svg>
{% endif %}
</body>
<script type="text/javascript">
Expand Down Expand Up @@ -103,7 +99,32 @@
"Value Error in Outcome of Game from Pro Dataset",
"Model Number",
"Value Error");
{% endif %}

var model_fn = function(d) { return d[1]; }
var figure_three_data = JSON.parse('{{ figure_three_data | tojson | safe}}');
var filtered = figure_three_data.filter(function(d) { return model_fn(d) % 10 == 0; });

rating_scatter_plot(
d3.select("#fig3-acc-all"),
filtered,
function(d) { return d[2]; },
function(d) { return 0.00; },
function(d) { return d[0]; },
model_fn,
"Accuracy in Prediction Moves from Pro Dataset",
"Model Number",
"Accuracy");

rating_scatter_plot(
d3.select("#fig3-mse-all"),
filtered,
function(d) { return d[3]; },
function(d) { return 0.00; },
function(d) { return d[0]; },
model_fn,
"Value Error in Outcome of Game from Pro Dataset",
"Model Number",
"Value Error");
{% endif %}
</script>
</html>

0 comments on commit d984ea8

Please sign in to comment.