Skip to content

Commit

Permalink
Change plotting of mttkrp to use previous results
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmul1114 committed Oct 31, 2023
1 parent e0c692b commit 6b99aba
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
28 changes: 23 additions & 5 deletions benchmark/gcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ using Distributions

const SUITE = BenchmarkGroup()

bench = SUITE["gcp"] = BenchmarkGroup()
BenchmarkTools.DEFAULT_PARAMETERS.seconds = 1

bench_gcp = SUITE["gcp"] = BenchmarkGroup()

# Benchmark least squares loss
for sz in [(15, 20, 25), (30, 40, 50)], r in 1:2
Random.seed!(0)
M = CPD(ones(r), rand.(sz, r))
X = [M[I] for I in CartesianIndices(size(M))]
bench["least-squares-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, LeastSquaresLoss())
bench_gcp["least-squares-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, LeastSquaresLoss())
end

# Benchmark Poisson loss
for sz in [(15, 20, 25), (30, 40, 50)], r in 1:2
Random.seed!(0)
M = CPD(fill(10.0, r), rand.(sz, r))
X = [rand(Poisson(M[I])) for I in CartesianIndices(size(M))]
bench["poisson-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, PoissonLoss())
bench_gcp["poisson-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, PoissonLoss())
end

# Benchmark Gamma loss
Expand All @@ -30,13 +32,29 @@ for sz in [(15, 20, 25), (30, 40, 50)], r in 1:2
M = CPD(ones(r), rand.(sz, r))
k = 1.5
X = [rand(Gamma(k, M[I]/k)) for I in CartesianIndices(size(M))]
bench["gamma-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, GammaLoss())
bench_gcp["gamma-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, GammaLoss())
end

# Benchmark BernoulliOdds Loss
for sz in [(15, 20, 25), (30, 40, 50)], r in 1:2
Random.seed!(0)
M = CPD(ones(r), rand.(sz, r))
X = [rand(Bernoulli(M[I]/(M[I] + 1))) for I in CartesianIndices(size(M))]
bench["bernoulliOdds-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, BernoulliOddsLoss())
bench_gcp["bernoulliOdds-size(X)=$sz, rank(X)=$r"] = @benchmarkable gcp($X, $r, BernoulliOddsLoss())
end


# MTTKRP benchmarks
bench_mttkrp = SUITE["mttkrp"] = BenchmarkGroup()

szs = [10,30,50,80,120,200]
shapes = [(sz, sz, sz) for sz in szs]
n = 1
rs = 20:20:200

for sz in shapes, r in rs
Random.seed!(0)
X = randn(sz)
U = [randn(Ik,r) for Ik in sz]
bench_mttkrp["mttkrp-size(X)=$sz, rank(X)=$r"] = @benchmarkable GCPDecompositions.mttkrp($X, $U, $n)
end
19 changes: 0 additions & 19 deletions benchmark/mttkrp.jl

This file was deleted.

24 changes: 13 additions & 11 deletions benchmark/plot_mttkrp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ using GCPDecompositions
using BenchmarkTools
using UnicodePlots

BenchmarkTools.DEFAULT_PARAMETERS.seconds = 1
# Load benchmark results from benchmark_results.txt
benchmark_results = readresults("benchmark_results.txt")
mttkrp_results = benchmark_results.benchmarkgroup["mttkrp"]

szs = [15, 30, 45, 60, 75, 90]
szs = [10,30,50,80,120,200]
shapes = [(sz, sz, sz) for sz in szs]
n = 1
rs = 1:5
rs = 20:20:200
results = zeros((size(szs)[1], size(rs)[1]))

for (idx, r) in enumerate(rs)
Random.seed!(0)
Xs = [randn(sz) for sz in shapes];
Us = [[randn(Ik,r) for Ik in sz] for sz in shapes];
times = [@belapsed GCPDecompositions.mttkrp($X, $U, $n) for (X,U) in zip(Xs, Us)]
results[:, idx] = times
# Collect results in array where columns are ranks and rows are sizes
for (col_idx, r) in enumerate(rs)
for (row_idx, sz) in enumerate(szs)
# Get median runtime (in milliseconds)
median_time = median(mttkrp_results["mttkrp-size(X)=($sz, $sz, $sz), rank(X)=$r"]).time / 10^6
results[row_idx, col_idx] = median_time
end
end

first_r = rs[1]
plt = lineplot(szs, results[:, 1], title="MTTKRP runtime vs. size",
xlabel="Size", ylabel="Runtime(s)", name="r = $first_r");
xlabel="Size", ylabel="Runtime(ms)", name="r = $first_r")
for (idx, r) in enumerate(rs[2:end])
lineplot!(plt, szs, results[:, idx + 1], name="r = $r")
end
Expand Down

0 comments on commit 6b99aba

Please sign in to comment.