diff options
Diffstat (limited to 'analysis')
-rw-r--r-- | analysis/vis.livemd | 132 |
1 files changed, 57 insertions, 75 deletions
diff --git a/analysis/vis.livemd b/analysis/vis.livemd index 30401ca..33e0b54 100644 --- a/analysis/vis.livemd +++ b/analysis/vis.livemd @@ -14,6 +14,7 @@ Mix.install([ ```elixir require Explorer.DataFrame +require Explorer.Series alias Explorer.DataFrame, as: DF alias Explorer.Series, as: SE job_id = "1147" @@ -35,31 +36,13 @@ cost_model_files = cost_model_files ``` -```elixir -defmodule CostModel do - defstruct impl: nil, ops: [] -end - -defmodule OpCostModel do - defstruct op: nil, x0: nil, x1: nil, x2: nil, x3: nil, nmrse: nil -end - -defmodule Parse do - def cost_model_row(row) do - [name, x0, x1, x2, x3, nmrse] = String.split(row, " & ") - [nmrse | _] = String.split(nmrse) - - %OpCostModel{ - op: name, - x0: String.to_float(x0), - x1: String.to_float(x1), - x2: String.to_float(x2), - x3: String.to_float(x3), - nmrse: String.to_float(nmrse) - } - end +<!-- livebook:{"reevaluate_automatically":true} --> - def cost_model_output(fname) do +```elixir +# Parse cost model information +cost_models = + cost_model_files + |> Enum.map(fn fname -> {:ok, contents} = File.read(fname) [_, table | _] = String.split(contents, "line\n") [rows | _] = String.split(table, "\n\\end") @@ -68,73 +51,72 @@ defmodule Parse do [_, impl] = String.split(fname, "cost-model-") impl = String.replace(impl, "-", ":") - %CostModel{ - impl: impl, - ops: rows |> Enum.map(&cost_model_row/1) - } - end -end + rows + |> Enum.map(fn row -> + [name, x0, x1, x2, x3, nmrse] = String.split(row, " & ") + [nmrse | _] = String.split(nmrse) + + %{ + op: name, + x0: String.to_float(x0), + x1: String.to_float(x1), + x2: String.to_float(x2), + x3: String.to_float(x3), + nmrse: String.to_float(nmrse) + } + end) + |> Enum.map(fn d -> d |> Map.put(:impl, impl) end) + |> DF.new() + end) + |> DF.concat_rows() ``` -<!-- livebook:{"reevaluate_automatically":true} --> +```elixir +Tucan.histogram(cost_models, "nmrse") +``` ```elixir -cost_models = cost_model_files |> Enum.map(&Parse.cost_model_output/1) +cost_models +|> DF.filter(op == "contains") ``` ## Cost model exploratory plots ```elixir -defmodule PlotCostModel do - @startn 0 - @endn 20000 - @resolution 100 - def gen_ts(ns, %OpCostModel{x0: x0, x1: x1, x2: x2, x3: x3}) do - Enum.map(ns, fn n -> %{n: n, t: x0 + n * x1 + n * n * x2 + n * n * n * x3} end) - end - - def points_op(op) do - ns = @startn..@endn//@resolution - - gen_ts(ns, op) - |> Enum.map(fn data -> Map.put(data, :name, op.op) end) - end - - def points_model(model) do - model.ops - |> Enum.map(fn op -> - points_op(op) - |> Enum.map(fn point -> Map.put(point, :impl, model.impl) end) - end) - |> List.flatten() - end - - def points(models) do - models - |> Enum.map(&points_model/1) - |> List.flatten() - end - - def plot_op(op) do - points = points_op(op) - Tucan.lineplot(points, "n", "t", title: op.op) - end - - def plot_all_ops(%CostModel{impl: impl, ops: ops}) do - ops - |> Enum.map(&plot_op/1) - |> Tucan.concat(columns: 3) - |> Tucan.set_title(impl) - end +startn = 0 +endn = 200_000 +resolution = 100 + +points_for = fn impl, op -> + %{"x0" => [x0], "x1" => [x1], "x2" => [x2], "x3" => [x3]} = + DF.filter(cost_models, impl == ^impl and op == ^op) + |> DF.to_columns() + + Enum.map(startn..endn//resolution, fn n -> + %{ + impl: String.split(impl, "::") |> List.last(), + op: op, + n: n, + t: x0 + n * x1 + n * n * x2 + n * n * n * x3 + } + end) + |> DF.new() end ``` <!-- livebook:{"reevaluate_automatically":true} --> ```elixir +inspect_op = "contains" + cost_models -|> Enum.map(&PlotCostModel.plot_all_ops/1) -|> Tucan.vconcat() +|> DF.filter(op == ^inspect_op) +|> DF.distinct(["impl"]) +|> DF.to_rows() +|> Enum.map(fn %{"impl" => impl} -> points_for.(impl, inspect_op) end) +|> DF.concat_rows() +|> Tucan.lineplot("n", "t", color_by: "impl", clip: true) +|> Tucan.Scale.set_y_domain(0, 200) ``` ## Read benchmark data |