software development and consulting

For some time, I’ve been wanting to find some big data source to dig around in and make plots of. Yesterday, I realized that I have access to #lisp logs from IRC going back several years.

The first question that I wanted to look at was: How well does talkativeness on IRC follow a Power Law?

It looks pretty close when you’re looking at the raw data if you limit yourself to the top 100 to 300 people. Once you get up near the top 500 people, the best-fit curve really skyrockets way through the roof. There are just tons of speakers who have said one or two lines in the given time period. And, I made no effort to track lurkers so I have no zeros in my data set.

Here is a plot of the top 250 speakers (ranked by lines spoken). stassats is the leader, followed by pjb, then H4ns, then Xach. I made a best-effort to collate different handles for the same person (e.g. Xach_ vs. Xach). The least-squares, best-fit power-law curve here is . So, if we’re going to match the curve exactly, we’ll need stassats to talk more than twice as much. If you’d like to know how much more (or less) you should talk, drop me a note. 🙂

Click on the image above for the full-size version. I used optima.ppcre to read the log files and vecto to draw the graph. Here is the relevant source code: package.lisp, read.lisp, and power.lisp.

Introduction

SICP has a few sections devoted to using a general, damped fixed-point iteration to solve square roots and then nth-roots. The Functional Programming In Scala course that I did on Coursera did the same exercise (at least as far as square roots go).

The idea goes like this. Say that I want to find the square root of five. I am looking then for some number so that . This means that I’m looking for some number so that . So, if I had a function and I could find some point where , I’d be done. Such a point is called a fixed point of .

There is a general method by which one can find a fixed point of an arbitrary function. If you type some random number into a calculator and hit the “COS” button over and over, your calculator is eventually going to get stuck at 0.739085…. What happens is that you are doing a recurrence where . Eventually, you end up at a point where (to the limits of your calculator’s precision/display). After that, your stuck. You’ve found a fixed point. No matter how much you iterate, you’re going to be stuck in the same spot.

Now, there are some situations where you might end up in an oscillation where , but for some . To avoid that, one usually does the iteration for some averaging function . This “damps” the oscillation.

The Fixed Point higher-order function

In languages with first-class functions, it is easy to write a higher-order function called fixed-point that takes a function and iterates (with damping) to find a fixed point. In SICP and the Scala course mentioned above, the fixed-point function was written recursively.

Inverting functions

I found myself wanting to find inverses of various complicated functions. All that I knew about the functions was that if you restricted their domain to the unit interval, they were one-to-one and their domain was also the unit interval. What I needed was the inverse of the function.

For some functions (like ), the inverse is easy enough to calculate. For other functions (like ), the inverse seems possible but incredibly tedious to calculate.

Could I use fixed points to find inverses of general functions? We’ve already used them to find inverses for . Can we extend it further?

After flailing around Google for quite some time, I found this article by Chen, Lu, Chen, Ruchala, and Olivera about using fixed-point iteration to find inverses for deformation fields.

There, the approach to inverting was to formulate and let . Then, because

That leaves the relationship that . The goal then is to find a fixed point of .

I messed this up a few times by conflating and so I abandoned it in favor of the tinkering that follows in the next section. Here though, is a debugged version based on the cited paper:

A tinkering attempt when I couldn’t get the previous to work

When I had abandoned the above, I spent some time tinkering on paper. To find , I need to find so that . Multiplying both sides by and dividing by , I get . So, to find , I need to find a that is a fixed point for :

This version, however, has the disadvantage of using division. Division is more expensive and has obvious problems if you bump into zero on your way to your goal. Getting rid of the division also allows the above algorithms to be generalized for inverting endomorphisms of vector spaces (the function being the only slightly tricky part).

Denouement

I finally found a use of the fixed-point function that goes beyond -th roots. Wahoo!