Square roots (Part VI)

20/02/2018

I’ve discussed algorithms for computing square roots a couple of times already, and then some. While sorting notes, I’ve came across something interesting: Archytas’ method for computing square roots.

Archytas’ method is basically the old Babylonian method, where you first set

a=1,

b=n,

and iterate

\displaystyle a'=\frac{a+b}{2},

\displaystyle b'=\frac{n}{a'}=\frac{2n}{a+b},

until desired precision is achieved (or the scribe is exhausted).

Read the rest of this entry »


Elementary Automata (Generating Random Sequences XI)

06/02/2018

So 3-cells context elementary automata seem too “self-correcting” to be useful pseudo-random generators. What if we fixed that boundary problem and have the automaton run on a cylinder (with both end joined)? What if we augment the context from 3 to 5 cells?

Read the rest of this entry »


Elementary Automata (Generating Random Sequences X)

30/01/2018

I was rather discontented with last week’s post results. Most automata seemed to produce self-correcting patterns, even when seeded randomly—one could argue that rand() isn’t the strongest random generator, but that wasn’t the problem. No, indeed, most automata exhibit self-correcting behavior, forming the same self-similar pattern, or worse, the same periodic pattern.

So I made a few more experiments with random seeds and larger images. The code isn’t very complicated and isn’t of interest in itself, but it reveals a couple of interesting things.

Read the rest of this entry »


Elementary Automata (Generating Random Sequences IX)

23/01/2018

A while ago, Wolfram (re)introduced elementary cellular automata, a special case of cellular automata that lives in one dimension. One cutesy aspect of these automata is that the rules are easy to describe and number. As any automata, it is given a context, a region of interest, and gives an output depending on the context. For example, we can have the rules:

Context output
000 1
001 0
010 1
011 0
100 1
101 0
110 1
111 1

The output column can be viewed as a number, in this case 11010101, 0xd5, or 213. This is rule 213.

It may be tempting to use those to generate chaos, noise, and random numbers. But is it that a good idea?

Read the rest of this entry »


Fast Recurrences

02/01/2018

Quite a while ago, I wrote a post on how to compute an arbitrarily large Fibonacci number F_n in essentially O(\log n) steps. Turns out, that technique generalizes to other recurrence relations, and of any order.

Read the rest of this entry »


Derivatives and matrix-vector products (part I)

26/12/2017

We don’t usually think of linear algebra being compatible with derivatives, but it very useful to be able to know the derivative of certain elements in order to adjust them—basically using gradient-descent.

We might therefore ask ourselves questions like, how do I compute the derivative of a scalar product relative to one of the vector elements? Of a matrix-vector product? Through a matrix inverse? Through a product of matrices? Let’s answer the first two questions for now.

Read the rest of this entry »


Taylor Series

19/12/2017

A Taylor series for a function f(x) around x_0 that is n times differentiable is given by

\displaystyle f(x) \approx f(x_0)+f'(x_0)(x-x_0)+\frac{f''(x_0)}{2}(x-x_0)^2+\frac{f'''(x_0)}{6}(x-x_0)^3+\cdots

or

\displaystyle f(x) \approx \sum_{i=0}^{n} \frac{f^{(i)}(x_0)}{i!}(x-x_0)^i,

where f^{(i)}(x) is the ith derivative of f at x.

Have you ever wondered where the coefficients in a Taylor series come from? Well, let’s see!

Read the rest of this entry »


Building a large text corpus (Part I)

12/12/2017

Getting good text data for language-model training isn’t as easy as it sounds. First, you have to find a large corpus. Second, you must clean it up!

Read the rest of this entry »


The Middle Square Method (Generating Random Sequences VIII)

21/11/2017

Von Neumann proposed the middle square method of generating pseudo-random numbers in 1949, in a paper published a bit later. The method is simple: you take a seed, say 4 digits long, you square it, and extract the middle 4 digits, which become the next seed. For example:

4373\to{}19123129\to{}1231.

While it seems random enough, is it?

Read the rest of this entry »


Rational Approximations (Part II)

10/10/2017

Last week, we noticed a fun connection between lattices and fractions, which helped us get rational approximations to real numbers. Since only points close to the (real-sloped) line are of interests, only those points representing fractions are candidates for rational approximation, and the closer to the line they are, the better.

But what if we find a point real close to the line? What information can we use to refine our guess?

Read the rest of this entry »