From 9a1853ebdf17f2492af95cd6845b0be37ad1bb16 Mon Sep 17 00:00:00 2001 From: axch <233710+axch@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:17:51 +0000 Subject: [PATCH] Updating gh-pages from be6befd3127390d9b0505f9f3c906fb8d45b477b --- examples/bfgs.html | 8 ++--- examples/levenshtein-distance.html | 16 ++++----- examples/mandelbrot.html | 2 +- examples/md.html | 52 +++++++++++++++--------------- lib/complex.html | 3 +- 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/examples/bfgs.html b/examples/bfgs.html index 0b0bfe7c8..96ad59b91 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.501 s -Run time: 239.000 us
+Compile time: 863.250 ms +Run time: 120.400 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: 7.656 s -Run time: 835.600 us
\ No newline at end of file +Compile time: 2.779 s +Run time: 391.700 us \ No newline at end of file diff --git a/examples/levenshtein-distance.html b/examples/levenshtein-distance.html index 023b3258f..240fecd37 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: 619.673 ms -Run time: 309.000 us
+Compile time: 351.624 ms +Run time: 143.100 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: 294.183 ms -Run time: 163.000 us
+Compile time: 177.136 ms +Run time: 53.300 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: 142.499 ms -Run time: 78.456 ms (based on 26 runs)
sum(sum(answer)) +Compile time: 76.633 ms +Run time: 38.838 ms (based on 52 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: 325.490 ms -Run time: 165.681 ms
+Compile time: 194.843 ms +Run time: 74.451 ms
closest_word "kitttens"
"kittens"
closest_word "functor"
"function"
closest_word "applicative" diff --git a/examples/mandelbrot.html b/examples/mandelbrot.html index 9a60f1d2c..84ab6a8d8 100644 --- a/examples/mandelbrot.html +++ b/examples/mandelbrot.html @@ -366,4 +366,4 @@
escapeGrid = for j i. escapeTime (Complex xs[i] ys[j])
:html matshow (-escapeGrid) -
\ No newline at end of file + \ No newline at end of file diff --git a/examples/md.html b/examples/md.html index fa390295e..bec768167 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: 286.090 ms -Run time: 38.842 ms
+Compile time: 194.861 ms +Run time: 14.342 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: 742.346 ms -Run time: 1.046 s
+Compile time: 407.979 ms +Run time: 485.619 ms

Here's how the energy decreases over time.

%time :html show_plot $ y_plot energies
-Compile time: 469.335 ms -Run time: 5.864 ms
+Compile time: 324.766 ms +Run time: 2.608 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: 276.094 ms -Run time: 31.315 ms
+Compile time: 190.444 ms +Run time: 13.144 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: 137.284 ms -Run time: 69.900 us
+Compile time: 91.521 ms +Run time: 20.200 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: 136.718 ms -Run time: 1.677 ms
+Compile time: 87.310 ms +Run time: 746.600 us

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: 2.200 s -Run time: 67.111 ms
+Compile time: 1.228 s +Run time: 36.633 ms
%time :html show_plot $ y_plot energies_nl
-Compile time: 493.134 ms -Run time: 6.327 ms
+Compile time: 329.593 ms +Run time: 2.525 ms
%time :html render_svg (draw_system 0.5 state_nl'.R) (Point(0.0, 0.0), Point(L_small, L_small))
-Compile time: 303.606 ms -Run time: 29.258 ms
+Compile time: 193.301 ms +Run time: 13.552 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: 795.001 ms -Run time: 2.947 s
+Compile time: 490.417 ms +Run time: 1.390 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.877 s -Run time: 14.094 s
+Compile time: 1.138 s +Run time: 6.908 s

Energy decrease

%time :html show_plot $ y_plot energies_large_nl
-Compile time: 944.445 ms -Run time: 4.893 ms
+Compile time: 568.747 ms +Run time: 2.157 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: 530.145 ms -Run time: 3.016 s
+Compile time: 355.255 ms +Run time: 1.379 s
\ No newline at end of file diff --git a/lib/complex.html b/lib/complex.html index 03721f18b..aeff26bf3 100644 --- a/lib/complex.html +++ b/lib/complex.html @@ -402,7 +402,8 @@
def complex_sqrt(x:Complex) -> Complex = m = complex_mag x - Complex (sqrt ((x.re + m) / 2.0)) (sign x.im * sqrt ((m - x.re) / 2.0)) + sgn = if x.im >= 0 then 1.0 else -1.0 + Complex (sqrt ((x.re + m) / 2.0)) (sgn * sqrt ((m - x.re) / 2.0))
def complex_sin( x:Complex) -> Complex = Complex(sin x.re * cosh x.im, cos x.re * sinh x.im)
def complex_sinh(x:Complex) -> Complex = Complex(sinh x.re * cos x.im, cosh x.re * sin x.im)