Recent Entries »

Java and Soft References

In a previous post, I described what weak references were and how the JVM interacted with them and how they contrasted with strong references. In summary, a strong reference is what we typically think of as a reference in Java; that is, when we instantiate an object and assign its reference to a variable, that is a strong reference. Obviously, these objects will not be cleared by the garbage collector (GC) until the reference is removed.

By contrast, a weak reference doesn’t prevent the garbage collector from clearing the referred object. That is, if the only references that remain to an object are weak references, that object will be treated as if there are no strong references to it, and thus it will be cleared by the GC on its next run. Weak references are implemented mainly by the WeakReference “wrapper” and WeakHashMap, the latter of which only maintains weak references to the keys, so that once the keys are inaccessible (i.e. no strong references exist), the WeakHashMap will automatically drop/remove the corresponding entries, which can also make the value objects eligible for GC so as long as there are no other references to them.

But how do these references contrast with a soft reference?


Analysis of the 2011-2015 Boston Marathon results

I recently analyzed the 2011-2015 Boston Marathon results. You can see the results in this GitHub Repo, or go straight to the IPython/Jupyter Notebook for the details.

Boston’s getting competitive

One of the more interesting observations is that with the tighter qualifying standards the race is much more competitive. Runners have apparently responded by stepping up their game, or perhaps, the race is now limited to faster runners.

The combination of a -5 minute adjustment across the board combined with the “fastest get in first” rule has created a much more competitive environment. This can be seen by comparing the distribution of finishing times for the M18-39 age group from 2011 (before the changes) to 2015 (the most recent year). (Both years generally were “fast”, as measured the mean and median finishing times)



You can see that the mode (most frequent bin) has been pushed from sub-3:10 to sub-3:00. This is very impressive for such a large race.

Check out the full results for more details!

Converting an IPython Notebook to PDF

If you have an IPython Notebook (*.ipynb file), you may want to convert to PDF for distribution. If you read the documentation for ipython nbconvert, it seems fairly straightforward:

$ ipython nbconvert --to PDF <your notebook>.ipynb

However, if you run that, you’re likely to run into an error asking to you install Pandoc; this is because nbconvert relies on an intermediate conversion to LaTeX first, and then to the final PDF output. Pandoc is used for this. To install on OS X:

$ brew install pandoc

Running the conversion again yields another error, suggesting you need the pdflatex command; Pandoc doesn’t include any built-in support for LaTeX->PDF, so you’ll need a LaTeX install. The Pandoc documentation suggests BasicTeX:

$ brew cask install basictex

Trying conversion results in another failure. Turns out, you need to install some more LaTeX packages:

$ sudo tlmgr update --self
$ sudo tlmgr install adjustbox
$ sudo tlmgr install collectbox
$ sudo tlmgr install ucs

After this, you should be able to do your conversion and have a fairly-decent PDF output based on your IPython Notebook:

$ ipython nbconvert --to PDF <your notebook>.ipynb