Mon, 30 Mar 2020 16:46:47 -0500
Added README.md
11 | 1 | |
2 | # Algorithm tools for Julia | |
3 | ||
4 | Author: Tuomo Valkonen <tuomov@iki.fi> | |
5 | ||
6 | This repository contains some general utility routines and tools for doing | |
7 | iterative algorithms in Julia: | |
8 | ||
9 | * Tools to facilitate working with `Channel`s | |
10 | * Linked lists and writing them to log files. | |
11 | * Structs: iteration, field replacement | |
12 | * Calculation of norms, dot products, projections | |
13 | * Conditional thread execution macros | |
14 | * Template for conveniently writing iterative algorithms using `do`-block anonymous functions as algorithm steps, with visualisation/verbosity implemented generally in iterator. | |
15 | ||
16 | The code is used, for example, by <http://dx.doi.org/10.5281/zenodo.3659180>. | |
17 | ||
18 | ## Iterative algorithms example | |
19 | ||
20 | The package includes `simple_iterate` which helps separating the computational step of iterative algorithms for visualisation routines. It is merely intended to serve as a template, as different applications require different visualisation routines to be implemented in a replacement of `simple_iterate`. The computational step is implemented as a `do`-block anonymous function that gets passed another function is a parameter for doing the verbosity on request. Example: | |
21 | ||
22 | ```julia | |
23 | using AlgTools.Iterate | |
24 | ||
25 | params = (verbose_iter = 10, maxiter = 100,) | |
26 | ||
27 | begin | |
28 | local x = 1 | |
29 | simple_iterate(params) do verbose | |
30 | # This is our computational step, as an anonymous | |
31 | # `do`-block function. It has one parameter: `verbose`, | |
32 | # itself a function. | |
33 | x = x + √x | |
34 | verbose() do | |
35 | # This is another anonymous function that will | |
36 | # only get called when decided by `verbose`. | |
37 | # If we do get called, return current value | |
38 | return x, nothing | |
39 | end | |
40 | end | |
41 | end | |
42 | ``` | |
43 | This will output | |
44 | ``` | |
45 | 10/100 J=31.051164 | |
46 | 20/100 J=108.493699 | |
47 | 30/100 J=234.690039 | |
48 | 40/100 J=410.056327 | |
49 | 50/100 J=634.799262 | |
50 | 60/100 J=909.042928 | |
51 | 70/100 J=1232.870172 | |
52 | 80/100 J=1606.340254 | |
53 | 90/100 J=2029.497673 | |
54 | 100/100 J=2502.377071 | |
55 | ``` | |
56 |