From 7e1d30669f5a2406798c121aa39563394d9bceed Mon Sep 17 00:00:00 2001 From: axch <233710+axch@users.noreply.github.com> Date: Tue, 1 Aug 2023 19:14:46 +0000 Subject: [PATCH] Updating gh-pages from 3cbde4c396a029873d7fd0a8b6aa0a65465b96d1 --- examples/bfgs.html | 8 ++--- examples/levenshtein-distance.html | 16 ++++----- examples/md.html | 52 +++++++++++++++--------------- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/examples/bfgs.html b/examples/bfgs.html index c698b90d9..0b0bfe7c8 100644 --- a/examples/bfgs.html +++ b/examples/bfgs.html @@ -508,8 +508,8 @@
%time bfgs_minimize rosenbrock [10., 10.] eye (\f. backtracking_line_search 15 f) 0.001 100
BFGSresults(1.741236e-11, [0.9999971, 0.9999939], 0.0001280856, 46)
-Compile time: 1.222 s -Run time: 190.600 us
+Compile time: 1.501 s +Run time: 239.000 us
@noinline def multiclass_logistic_loss(xs: n=>d=>Float, ys: n=>m, w: (d, m)=>Float) -> Float given (n|Ix, d|Ix, m|Ix) = w_arr = for i:d. for j:m. w[(i, j)] @@ -554,5 +554,5 @@
%time multiclass_logreg xs ys maxiter maxls tol
1.609437
-Compile time: 6.142 s -Run time: 483.800 us
\ No newline at end of file +Compile time: 7.656 s +Run time: 835.600 us \ No newline at end of file diff --git a/examples/levenshtein-distance.html b/examples/levenshtein-distance.html index 2666a866f..023b3258f 100644 --- a/examples/levenshtein-distance.html +++ b/examples/levenshtein-distance.html @@ -373,8 +373,8 @@
%time levenshtein_table ['k', 'i', 't', 't', 'e', 'n'] ['s', 'i', 't', 't', 'i', 'n', 'g']
[[0, 1, 2, 3, 4, 5, 6, 7], [1, 1, 2, 3, 4, 5, 6, 7], [2, 2, 1, 2, 3, 4, 5, 6], [3, 3, 2, 1, 2, 3, 4, 5], [4, 4, 3, 2, 1, 2, 3, 4], [5, 5, 4, 3, 2, 2, 3, 4], [6, 6, 5, 4, 3, 3, 2, 3]]
-Compile time: 523.207 ms -Run time: 179.500 us
+Compile time: 619.673 ms +Run time: 309.000 us

The actual distance is of course just the last element of the table.

def levenshtein(xs: n=>a, ys: m=>a) -> Nat given (n|Ix, m|Ix, a|Eq) = levenshtein_table(xs, ys)[last_ix, last_ix] @@ -382,8 +382,8 @@
%time levenshtein (iota $ Fin 100) (iota $ Fin 100)
0
-Compile time: 230.942 ms -Run time: 132.500 us
+Compile time: 294.183 ms +Run time: 163.000 us

Speed

To check that we don't embarrass ourselves on performance, let's run the Sountsov benchmark: Compute Levenshtein distances for all pairs of @@ -396,8 +396,8 @@ levenshtein (iota $ Fin iint) (iota $ Fin jint)

Sountsov Benchmark -Compile time: 120.568 ms -Run time: 53.165 ms (based on 38 runs)
sum(sum(answer)) +Compile time: 142.499 ms +Run time: 78.456 ms (based on 26 runs)
sum(sum(answer))
333300

The straightforward C++ program for this takes about 35ms on my workstation, so Dex performance is in the right ballpark. (And we @@ -418,8 +418,8 @@

%time closest_word "hello"
"hello"
-Compile time: 264.952 ms -Run time: 122.652 ms
+Compile time: 325.490 ms +Run time: 165.681 ms
closest_word "kitttens"
"kittens"
closest_word "functor"
"function"
closest_word "applicative" diff --git a/examples/md.html b/examples/md.html index d3b2e5c3a..fa390295e 100644 --- a/examples/md.html +++ b/examples/md.html @@ -522,8 +522,8 @@
%time :html render_svg (draw_system 0.5 R_init_small) (Point(0.0, 0.0), Point(L_small, L_small))
-Compile time: 240.282 ms -Run time: 23.112 ms
+Compile time: 286.090 ms +Run time: 38.842 ms

Define energy function. Note the preiodic_displacement, which means our system will be evolving on a torus.

def energy(pos: n=>d=>Float) -> Float given (n|Ix, d|Ix) @@ -548,20 +548,20 @@ s' = fire_descent_step (periodic_shift L_small) energy s (s', energy $ s'.R)
-Compile time: 604.760 ms -Run time: 806.584 ms
+Compile time: 742.346 ms +Run time: 1.046 s

Here's how the energy decreases over time.

%time :html show_plot $ y_plot energies
-Compile time: 396.694 ms -Run time: 4.135 ms
+Compile time: 469.335 ms +Run time: 5.864 ms

Here's what the system looks like after minimization.

%time :html render_svg (draw_system 0.5 (state_small'.R)) (Point(0.0, 0.0), Point(L_small, L_small))
-Compile time: 232.721 ms -Run time: 21.518 ms
+Compile time: 276.094 ms +Run time: 31.315 ms

Neighbors optimization

The above pair_energy function will compute the influence of every atom on every other atom, regardless of how far apart they are.

@@ -670,8 +670,8 @@
%time tbl = cell_table grid_size bucket_size cell_size $ state_small'.R
-Compile time: 210.708 ms -Run time: 27.600 us
+Compile time: 137.284 ms +Run time: 69.900 us

We have a table of cells with atoms in them

:t tbl
(((Fin 2) => Fin 20) => BoundedList (Fin 10) (Fin 500))
@@ -751,8 +751,8 @@ res = (neighbor_list 4000 tbl (periodic_near 1.0 L_small $ state_small'.R) $ state_small'.R)
-Compile time: 122.818 ms -Run time: 935.700 us
+Compile time: 136.718 ms +Run time: 1.677 ms

In that configuration, we find this many pairs of neighbors:

AsList(k, _) = as_list res
k @@ -858,18 +858,18 @@ (state_nl', energies_nl) = unsafe_io \. simulate (periodic_displacement L_small) 0.5 L_small (Fin 100) state_small
4568 initial neighbor list size
4614 new neighbor list size
4564 new neighbor list size
4376 new neighbor list size
4346 new neighbor list size
4266 new neighbor list size
4178 new neighbor list size
4140 new neighbor list size
4100 new neighbor list size
4028 new neighbor list size
4006 new neighbor list size
3922 new neighbor list size
3868 new neighbor list size
3810 new neighbor list size
3762 new neighbor list size
3720 new neighbor list size
3656 new neighbor list size
3640 new neighbor list size
3602 new neighbor list size
3572 new neighbor list size
3552 new neighbor list size
-Compile time: 1.755 s -Run time: 49.137 ms
+Compile time: 2.200 s +Run time: 67.111 ms
%time :html show_plot $ y_plot energies_nl
-Compile time: 398.377 ms -Run time: 4.108 ms
+Compile time: 493.134 ms +Run time: 6.327 ms
%time :html render_svg (draw_system 0.5 state_nl'.R) (Point(0.0, 0.0), Point(L_small, L_small))
-Compile time: 232.975 ms -Run time: 21.874 ms
+Compile time: 303.606 ms +Run time: 29.258 ms

But of course the point of the exercise is that this now scales up to larger systems because it avoids the quadratic energy computation.

N_large = if not (dex_test_mode()) then 50000 else 500 @@ -882,8 +882,8 @@
%time :html render_svg (draw_system 0.2 R_init_large) (Point(0.0, 0.0), Point(L_large, L_large))
-Compile time: 615.106 ms -Run time: 2.260 s
+Compile time: 795.001 ms +Run time: 2.947 s
state_large = energy_func = (energy_nl L_large $ just_neighbor_list 1.0 L_large R_init_large) fire_descent_init 0.1 0.1 energy_func R_init_large @@ -892,18 +892,18 @@ (state_large_nl', energies_large_nl) = unsafe_io \. simulate (periodic_displacement L_large) 0.5 L_large (Fin 100) state_large
474778 initial neighbor list size
474090 new neighbor list size
471628 new neighbor list size
465540 new neighbor list size
453724 new neighbor list size
442298 new neighbor list size
434298 new neighbor list size
428432 new neighbor list size
421932 new neighbor list size
418256 new neighbor list size
414656 new neighbor list size
411276 new neighbor list size
404290 new neighbor list size
398562 new neighbor list size
393958 new neighbor list size
390030 new neighbor list size
386782 new neighbor list size
382868 new neighbor list size
379510 new neighbor list size
376428 new neighbor list size
374024 new neighbor list size
371272 new neighbor list size
368946 new neighbor list size
366958 new neighbor list size
365340 new neighbor list size
363842 new neighbor list size
362166 new neighbor list size
360926 new neighbor list size
360118 new neighbor list size
359558 new neighbor list size
358906 new neighbor list size
358038 new neighbor list size
357402 new neighbor list size
357078 new neighbor list size
-Compile time: 1.593 s -Run time: 9.979 s
+Compile time: 1.877 s +Run time: 14.094 s

Energy decrease

%time :html show_plot $ y_plot energies_large_nl
-Compile time: 739.060 ms -Run time: 3.234 ms
+Compile time: 944.445 ms +Run time: 4.893 ms

System state after minimization.

%time :html render_svg (draw_system 0.2 state_large_nl'.R) (Point(0.0, 0.0), Point(L_large, L_large))
-Compile time: 421.518 ms -Run time: 2.247 s
+Compile time: 530.145 ms +Run time: 3.016 s
\ No newline at end of file