Author Archives: Ben Nolting

Limitations of the negative binomial distribution in spatial models

Galaxies, trees, and influenza cases have something in common: they tend to occur in clusters. The issue of how to model clustered spatial patterns is thus of interest to a variety of scientific disciplines. For many people, the mention of spatial clumping brings to mind the negative binomial distribution. This is appropriate, because the negative binomial distribution is overdispersed, meaning its variance is greater than its mean (in contrast to the Poisson distribution, which has equal variance and mean). Unfortunately, there are some difficulties in using the negative binomial distribution in spatial modeling, which we attempt to explain in this post.

Suppose that you want to create a model that generates spatial locations of trees. You want the model to be stochastic, so that each time you generate a forest, you end up with a different configuration of trees. The relevant tool is a spatial point process; mathematical details are described in books such as Daley and Veres-Jones. Each forest that you generate is called a realization of the process.

Continue reading “Limitations of the negative binomial distribution in spatial models” »

Volume Rendering and Large Data Sets

Volume rendering, a new feature in Mathematica 9, provides an efficient way to visualize very large data sets. I first learned of this feature from reading Jeffery Bryant’s post on the Wolfram blog. Bryant’s post dealt with simulating galatical collisions. Galaxies have hundreds of billions of stars, so visualizing them as dynamically interacting clouds of points is computationally difficult. Volume rendering provides a solution.

In today’s post, we will use volume rendering for a more prosaic example: color analysis of a photo of puppies.
puppic

Continue reading “Volume Rendering and Large Data Sets” »

Custom interfaces in Mathematica using Dynamic Module

In our last post, we explored how Fourier transforms can be used in Mathematica to make a frequency filter for audio files. That post was primarily concerned with implementing the appropriate transforms (and, of course, paying homage to the amazing talent of Macklemore and Ryan Lewis). The accompanying interactive tool had an extremely cumbersome interface. Here is a slightly better attempt, featuring a more widely known piece of music:

Continue reading “Custom interfaces in Mathematica using Dynamic Module” »

Macklemore and Fourier

The Heist by Macklemore and Ryan Lewis is a masterpiece. It is clearly the best album of 2012, and I suspect it will go down alongside classics like IllmaticThe ChronicThe Marshall Mathers LP, and The College Dropout.

The lyric, symphonic, and emotional range of The Heist is impressive. You’ve probably heard the playful number one song “Thrift Shop”, but the heavier songs like “Same Love” (about gay marriage and civil rights) and “Starting Over” (about getting off the mat following relapse) show the Seattle duo at their most virtuosic.

In the video below, they are joined by Ray Dalton for a live radio performance of “Can’t Hold Us” on KEXP. Stay tuned until the end, when Dalton opens up his full register. I suggest you sit down before hitting play.

Continue reading “Macklemore and Fourier” »

New Year’s Resolution: Be more interactive

One of my New Year’s resolutions is to make this blog more interactive. To do this, I’ll be using Wolfram’s computable document format (cdf). You don’t need Mathematica to interact with .cdf files, but you do need a free plug-in. You can download the plug-in here.

Once you’ve downloaded the plug-in, you should be able to interact with .cdf files that are embedded in this blog.

A simple example is shown below. It is useful for teaching systems of linear equations in introductory algebra courses. By entering numbers into the input fields, students can experiment and try to find situations where there are no solutions, a unique solution, or an infinite number of solutions. The image can be rotated by dragging.

Continue reading “New Year’s Resolution: Be more interactive” »

Finite Difference Method (now with free code!)

A couple of months ago, we wrote a post on how to use finite difference methods to numerically solve partial differential equations in Mathematica. Several readers have asked for more details about the method. To help everyone out, we are posting a Mathematica notebook that contains explanations and code. Download the notebook by clicking here.

The notebook will implement a finite difference method on elliptic boundary value problems of the form:

The comments in the notebook will walk you through how to get a numerical solution. An example boundary value problem is solved, yielding a solution that looks like this:

Last week, Mathematica 9 was released. It has some awesome new features, including enhanced NDSolve capabilities. Sadly, there is no built-in finite difference method solver yet. We will have to continue to use workarounds like the notebook posted here for a while longer.

Comparing stolen paintings: Picasso and Matisse

Art Heist

Last week, burglars stole seven paintings from the Kunsthal museum in Rotterdam. The paintings included works by Picasso, Monet, Gauguin, and Matisse. The loot is likely worth hundreds of millions of dollars, but the loss of these great pieces surpasses anything that can be calculated as a monetary figure. Art is unquantifiable, right? Yes, but it is still fun to do data analysis on paintings. In today’s post, we will explore how Mathematica’s image processing capabilities can be used to compare two of the paintings stolen from the Kunsthal.

Let’s consider Matisse’s “Reading Girl in White and Yellow” (1919) and Picasso’s “Harlequin Head” (1971).

Continue reading “Comparing stolen paintings: Picasso and Matisse” »

Armchair mountaineering with Mathematica

In today’s blog post, we’ll show you how to use Mathematica’s plotting features to visualize geospatial data.

Baintha Brakk, aka The Ogre, is a mountain in the Karakoram range in northern Pakistan. It is “only” the 87th highest mountain on the planet (23,901 feet), but it’s among the technically most difficult to climb.

Chris Bonington and Doug Scott made the first ascent in 1977. Early in the descent, Scott broke both his legs in a repelling accident. The ensuing struggle to get down alive was epic.

The Ogre was not climbed again until 2001 (although there were many unsuccessful attempts in the intervening years). To my knowledge, the 1977 and 2001 expeditions are still the only successful ones.

Note: For another intense account of high altitude survival, check out the most recent episode of Family Guy, Into Fat Air.

Continue reading “Armchair mountaineering with Mathematica” »

Zing! Mathematica one-liners

I love the elegant simplicity of programming in Mathematica. There is something undeniably beautiful about accomplishing something complex in a concise chunk of code. A famous Mathematica mantra is, “if you are using a For loop, you are probably doing it wrong.” I encourage Mathematica programmers to keep that in mind.

To illustrate the efficiency of Mathematica code, I’d like to draw your attention to the recent results of Wolfram’s “One-Liner Competition”.  Each program in the competition is 140 characters or less. Yes, that’s right… tweetable programs. You can watch screencasts of the winner and honorable mentions here and download a notebook of the programs here.

For those who work in biological modelling, I recommend checking Yves Klett’s entry. It gives a new meaning to the old modelling punchline “assume all cows are spheres”.

A skeptical look at The Economist’s Sinodependency Index

In a recent blog postThe Economist discusses its “Sinodependency Index”, which measures the world’s economic dependence on China. This index was originally proposed in 2010. In today’s post, we will take a closer look at this index, and in the process, we will explore some of Mathematica’s finance-related capabilities.

The Economist’s Sinodependency Index (SI) is composed of S&P 500 firms, weighted according to their revenues from China. You can see how the SI has outperformed the S&P 500 over the past couple of years, with the implication that firms with more exposure to China are performing better than their less “Sinodependent” peers.
Continue reading “A skeptical look at The Economist’s Sinodependency Index” »

On Labor Day, make your computer’s job easier with Milstein’s method

In today’s post, we will explore numerical schemes for integrating stochastic differential equations in Mathematica. We will take an informal approach; for an in-depth treatment of stochastic differential equations, I recommend that you look at Stochastic Processes for Physicists by Kurt Jacobs and Modeling with Ito Stochastic Differential Equations by Edward Allen.

Continue reading “On Labor Day, make your computer’s job easier with Milstein’s method” »

Numerically solving PDEs in Mathematica using finite difference methods

Mathematica’s NDSolve command is great for numerically solving ordinary differential equations, differential algebraic equations, and many partial differential equations. Most of the integration details are handled automatically, out of the user’s sight. NDSolve switches between integration schemes based on the problem at hand, adapting step sizes and monitoring stiffness as it goes. Advanced users can override these options, customizing NDSolve to their needs.

Sadly, some types of PDEs are beyond NDSolve’s capabilities. Confronted with one of these PDEs, a user must resort to a more “manual” procedure to find a numerical solution. In this post, we’ll examine a few tricks that can make this process easier.

Continue reading “Numerically solving PDEs in Mathematica using finite difference methods” »

Gini Coefficients and the Olympic Medal Race

Today’s post will attempt to answer a provocative question: is the race for Olympic medal dominance getting more competitive? In the process of addressing this topic, we’ll learn how to directly import data from WolframAlpha into Mathematica.

If you watched any of the Olympics over the past two weeks, you likely became familiar with the medal count table. This table is a grossly reductionist metric of national achievement at the Olympics. Nonetheless, it provides a useful way to quantify the aggregate performance of different nations.

The United States took home 104 medals from the 2012 games, placing it at the top of the medal table. The race for the most medals was exciting, though, as China and Russia were not far behind.

Continue reading “Gini Coefficients and the Olympic Medal Race” »

Six little data points and one huge story

It has been an exciting summer in science news. In early July, CERN announced the probable discovery of a Higgs-like particle at the Large Hadron Collider, filling a long open hole in the standard model of physics. On Sunday, the Curiosity rover successfully executed a phenomenally difficult landing on Mars.

Sandwiched between these headline-grabbing events, a story of arguably equal significance has been overshadowed: evidence from the remote Amazon that unvaccinated humans can develop antibodies to rabies.

Rabies is a scary disease (jokes on The Office notwithstanding). It causes approximately 55,000 deaths annually. Victims suffer anxiety, hallucinations, delirium, paralysis and eventually death. It is hard to imagine a more horrific way to die.

Continue reading “Six little data points and one huge story” »

A Traveling Salesman on a Sphere: Pitbull’s Arctic Adventure

You’ve probably heard of the traveling salesman problem: given a set of cities, what is the shortest possible route that visits each city exactly once and returns to the origin city? This problem pops up in a huge number of applications.

For the purposes of this post, let’s focus on a concrete example: a musician is planning a tour and wants to travel as efficiently as possible. Suppose that concerts are to be held in the following cities (with an encore concert in the origin city): Anchorage, Athens, Barrow, Berlin, Brussels, Cairo, Copenhagen, Denver, Detroit, Dublin, Helsinki, Istanbul, Jerusalem, Kabul, Lagos, Lisbon, London, Los Angeles, Miami, Moscow, Murmansk, New York, Prague, Reykjavik, Rome, Seattle, Stockholm, and Toronto.

Perhaps you’ll object that this is an unlikely list, because it includes several high latitude cities with limited concert venues. Musicians can get sent to some pretty obscure locations, though. Take the rapper Pitbull’s recent trip to Kodiak, for example. Bear with me.

Fortunately, Mathematica has a built-in function, FindShortestTour to help compute the solution to our problem. Before we get too excited, though, we should remember that the world is not flat, and hence we won’t be able to use our usual Euclidean distance metric.

Continue reading “A Traveling Salesman on a Sphere: Pitbull’s Arctic Adventure” »

Voronoi Diagrams in Mathematica

Ecological models sometimes find very unexpected applications. Work on wolf territory modeling by Mark Lewis’s research group at the University of Alberta has been employed by researchers studying gang territories in Los Angeles. You can check out that paper by Smith, Bertozzi, Tita, and Valasik in the September 2012 issue of the Journal of Discrete and Continuous Dynamical Systems.

This Smith et al. paper uses Voronoi diagrams as a null model for territorial use. Voronoi diagrams pop up in modeling forest canopy structure, and a variety of other ecological applications. Given the their utility, I am devoting today’s post to an overview of computing and displaying them in Mathematica.

Continue reading “Voronoi Diagrams in Mathematica” »

Call it the decline and fall of popular music… maybe?

You’ve probably already experienced the agony that accompanies an infection of Carly Rae Jepsen’s inane earworm “Call Me Maybe”. You’ve probably also been subjected to the current number one song in America, Flo Rida’s “Whistle”, a ditty whose only creative merit is its ability to evade censorship despite its explicit subject material. These two songs are representative of a dismaying trend in popular music: songs are becoming symphonically simpler and more predictable.

Were Mr. Rida to read my pretentious lament over the state of popular music, he would undoubtedly counter that I lack data to support my claim. Do I have metrics to quantify a song’s banality? No. Fortunately, a group of researchers lead by Joan Serra of the Artificial Intelligence Research Institute in Spain does. In a recent Nature paper, “Measuring the Evolution of Contemporary Western Popular Music”, Serra’s team concludes that popular music is headed “towards less variety in pitch transitions, towards a consistent homogenization of the timbral palette, and towards louder and, in the end, potentially poorer volume dynamics.” So yes, Mr. Rida, there is science behind my assertion that popular music is becoming increasingly stupid.

Continue reading “Call it the decline and fall of popular music… maybe?” »