Feed john-d-cook John D. Cook

Favorite IconJohn D. Cook

Link https://www.johndcook.com/blog
Feed http://feeds.feedburner.com/TheEndeavour?format=xml
Updated 2026-01-30 15:32
Insertion sort as a fold
I’ve written several posts lately about various algorithms that can be expressed as functional folds: updating conjugate Bayesian models solving differential equations computing sample statistics These have all been numerical algorithms. Insertion sort is an example of a non-numerical algorithm that could be implemented as a fold. Insertion sort is not the fastest sorting algorithm. […]
Prime remainders too evenly distributed
First Brian Hayes wrote an excellent post about the remainders when primes are divided by other primes. Then I wrote a follow-on just focusing on the first part of his post. He mostly looked at pairs of primes, but I wanted to look in more detail at the first part of his post, simulating dice […]
Computing higher moments with a fold
Folds in functional programming are often introduced as a way to find the sum or product of items in a list. In this case the fold state has the same type as the list items. But more generally the fold state could have a different type, and this allows more interesting applications of folds. Previous […]
Chi-square goodness of fit test example with primes
Yesterday Brian Hayes wrote a post about the distribution of primes. He showed how you could take the remainder when primes are divided by 7 and produce something that looks like rolls of six-sided dice. Here we apply the chi-square goodness of fit test to show that the rolls are too evenly distributed to mimic […]
Grateful for failures
I’ve been thinking lately about different things I’ve tried that didn’t work out and how grateful I am that they did not. The first one that comes to mind is my academic career. If I’d been more successful with grants and publications as a postdoc, it would have been harder to decide to leave academia. […]
Ten spectral graph theory posts
Here are 10 blog posts I wrote earlier this year about spectral graph theory, studying graphs via the eigenvalues of matrices associated with the graphs. Measuring graph connectivity with eigenvalues Graph regularity and Laplacian eigenvalues Adding an edge increases eigenvalues Spectral coordinates in Python Bipartite graphs and the signless Lapacian Spectra of random graphs Can […]
ODE solver as a functional fold
One of the most widely used numerical algorithms for solving differential equation is the 4th order Runge-Kutta method. This post shows how the Runge-Kutta method can be written naturally as a fold over the set of points where the solution is needed. These points do not need to be evenly spaced. Given a differential equation […]
Functional folds and conjugate models
Bayesian calculations are intrinsically recursive: The posterior distribution from one step becomes the prior for the next step. With conjugate models, the prior and posterior belong to the same family of distributions. If a distribution from this family is determined by a fixed set of parameters, we only need to update these parameters at each step. This updating process is […]
Retronyms and Backronyms
A retronym is a new name created for an old thing, often made necessary by technological changes. For example, we have terms like “postal mail” or “snail mail” for what used to simply be “mail” because email has become the default. What was once called a “transmission” is now called a “manual transmission” since most […]
Flood control parks
The park in the photo above flooded. And that’s a good thing. It’s designed to flood so that homes don’t. It’s not really a park that flooded. It’s a flood control project that most of the time doubles as a park. Ordinarily the park has a lake, but a few days a year the park is […]
Kalman filters and bottom-up learning
Kalman filtering is a mixture of differential equations and statistics. Kalman filters are commonly used in tracking applications, such as tracking the location of a space probe or tracking the amount of charge left in a cell phone battery. Kalman filters provide a way to synthesize theoretical predictions and actual measurements, accounting for error in […]
Cepstral alanysis vocabulary
An earlier post defined cepstrum and quefrency. This post explains some of the other quirky terms introduced in the same paper by Bogert, Healy, and Tukey. (Given Tukey’s delight in coining words, we can assume he was the member of the trio responsible for the new terms.) The paper [1] explains why the new twists on […]
Selecting clients
One of the themes in David Ogilvy’s memoir Confessions of an Advertising Man is the importance of selecting good clients. For example, he advises “never take associations as clients” because they have “too many masters, too many objectives, too little money.” He also recommends not taking on clients that are so large that you would lose your independence […]
How about one good one?
I’m no fan of tobacco companies or their advertising tactics, but I liked the following story. When the head of a mammoth [advertising] agency solicited the Camel Cigarette account, he promised to assign thirty copywriters to it, but the canny head of R. J. Reynolds replied, “How about one good one?” Then he gave his account to […]
Cepstrum, quefrency, and pitch
John Tukey coined many terms that have passed into common use, such as bit (a shortening of binary digit) and software. Other terms he coined are well known within their niche: boxplot, ANOVA, rootogram, etc. Some of his terms, such as jackknife and vacuum cleaner, were not new words per se but common words he […]
Bring out your equations!
Nice discussion from Fundamentals of Kalman Filtering: A Practical Approach by Paul Zarchan and Howard Musoff: Often the hardest part in Kalman filtering is the subject that no one talks about—setting up the problem. This is analogous to the quote from the recent engineering graduate who, upon arriving in industry, enthusiastically says, “Here I am, […]
Top tweets
I had a couple tweets this week that were fairly popular. The first was a pun on the musical Hamilton and the Hamiltonian from physics. The former is about Alexander Hamilton (1755–1804) and the latter is named after William Rowan Hamilton (1805–1865). Hamiltonian: The new Broadway hit about the sum of potential and kinetic energy. pic.twitter.com/PCJk3imDsq […]
Tonal prominence in a leaf blower
This afternoon I was working on a project involving tonal prominence. I stepped away from the computer to think and was interrupted by the sound of a leaf blower. I was annoyed for a second, then I thought “Hey, a leaf blower!” and went out to record it. A leaf blower is a great example of […]
Loudness and sharpness
This post looks at loudness and sharpness, two important psychoacoustic metrics. Because they have to do with human perception, these factors are by definition subjective. And yet they’re not entirely subjective. People tend to agree on when, for example, one sound is twice as loud as another, or when one sound is sharper than another. Loudness Loudness […]
Electric guitar distortion
The other day I asked on Google+ if someone could make an audio clip for me and Dave Jacoby graciously volunteered. I wanted a simple chord on an electric guitar played with varying levels of distortion. Dave describes the process of making the recording as Fender Telecaster -> EHX LPB clean boost -> Washburn Soloist […]
Demystifying artificial intelligence
Computers do what we tell them to do. Period. Any talk of computers doing things they weren’t programmed to do is only a way of speaking. It’s a convenient shorthand when used properly, misleading mysticism when used improperly. When you write a program print(24*7) you could say that the computer isn’t programmed to print the number […]
Optimistic about humans in aggregate
Russ Roberts from his most recent podcast: I’m a very optimistic person, and I have a lot of faith in the human enterprise writ large—not so much in any one human. I have very little faith in any one human, which is why I’m suspicious of experts and power that is centralized.
Converting between Hz, Barks, and music notation
I’ve written before about how to convert between frequency and pitch and scientific pitch notation. I’ve also written about the Bark scale. Here’s a little online calculator to convert between Hz, Bark, and music notation. You can enter one of the three and it will compute the other two.
Spectral flatness
White noise has a flat power spectrum. So a reasonable way to measure how close a sound is to being pure noise is to measure how flat its spectrum is. Spectral flatness is defined as the ratio of the geometric mean to the arithmetic mean of a power spectrum. The arithmetic mean of a sequence […]
Family tree numbering
When you draw a tree of your ancestors, things quickly get out of hand. There are twice as many nodes each time you go back a generation, and so the size of paper you need grows exponentially. Things also get messy because typically you know much more about some lines than others. If you know […]
The acoustics of kettledrums
Kettledrums (a.k.a. tympani) produce a definite pitch, but in theory they should not. At least the simplest mathematical model of a kettledrum would not have a definite pitch. Of course there are more accurate theories that align with reality. Unlike many things that work in theory but not in practice, kettledrums work in practice but not in theory. […]
How to create Green noise in Python
This is a follow-on to my previous post on green noise. Here we create green noise with Python by passing white noise through a Butterworth filter. Green noise is in the middle of the audible spectrum (on the Bark scale), just where our hearing is most sensitive, analogous to the green light, the frequency where […]
Green noise and Barks
Colors of noise In a previous post I explained the rationale behind using names of colors to refer to different kinds of noise. The basis is an analogy between the spectra of sounds and the spectra of light. Red noise is biased toward the low end of the audio spectrum just as red light is […]
Consecutive pair magic square
The following magic square has a couple unusual properties. For one, numbers appear in consecutive pairs. Also, you can connect the numbers 1 through 32 in a continuous path. I found this in Before Sudoku. The authors attribute it to William Mannke, “A Magic Square.” Journal of Recreational Mathematics. 1 (3) page 139, July 1968. […]
How to digitize a graph
Suppose you have a graph of a function, but you don’t have an equation for it or the data that produced it. How can you reconstruction the function? There are a lot of software packages to digitize images. For example, Web Plot Digitizer is one you can use online. Once you have digitized the graph […]
Linear or not, random or not, at different levels
Linear vs nonlinear I’ve run across a lot of ambiguity lately regarding systems described as “nonlinear.” Systems typically have several layers, and are linear at one level and nonlinear at another, and authors are not always clear about which level they’re talking about. For example, I recently ran across something called a “nonlinear trapezoid filter.” My first instinct […]
The intersection of genomes is empty
From this story in Quanta Magazine: In fact, there’s no single set of genes that all living things need in order to exist. When scientists first began searching for such a thing 20 years ago, they hoped that simply comparing the genome sequences from a bunch of different species would reveal an essential core shared […]
Magic hexagon
The following figure is a magic hexagon: the numbers in any straight path through the figure add to 38, even though paths may have length three, four, or five. I found this in Before Sudoku. The authors attribute it to Madachy’s Mathematical Recreations. This is essentially the only magic hexagon filled with consecutive integers starting with one. The […]
Personal growth and discrete harmonic functions
“You are the average of the five people you spend the most time with.” A Google search says this quote is by Jim Rohn. I think other people have said similar things. I’ve heard it quoted many times. The implication is usually that you can improve your life by hanging around better people. Here are three things […]
Technical memento mori
The Latin phrase memento mori means “remember that you must die.” It has been adopted into English to refer to an object that serves as a reminder of death, especially a skull. This is a common theme in art, such as Albrecht Dürer’s engraving St. Jerome in His Study. I keep a copy of the book Inside […]
Well, F = ma.
Three or four very short stories on the difficulty of learning to use simple things. Depends whether you count the last section as a story. * * * When I was taking freshman physics and we were stuck on a problem, the professor would say “Well, F = ma.” True, but absolutely useless. Yes, we know that F = […]
Magic square rows and columns as numbers
Take any 3 by 3 magic square. For example, here’s the ancient Lo Shu square: If you read the rows as numbers and sum their squares, you get the same thing whether you read left to right or right to left. In this case 4922 + 3572 + 8162 = 2942 + 7532 + 6182. […]
Alphamagic squares in French
In earlier blog posts I give examples of alphamagic squares in English and in Spanish. This post looks at French. The Wikipedia article on alphamagic squares, quoting The Universal Book of Mathematics, says French allows just one 3 × 3 alphamagic square involving numbers up to 200, but a further 255 squares if the size of the […]
Alphamagic square in Spanish
In a previous post I gave an example of an alphamagic square in English. This is a magic square such that if you replace each number with the letter count when spelling out the word, you get another magic square. I wondered whether I could find an alphamagic square in Spanish, so I wrote a […]
Roughness of amplitude modulated tones
A recent post pointed out that two pure tones that are fairly close in pitch create a rough sound. The roughness increases with the frequency difference, up to a point, then decreases. This post will look at a roughness in a different setting, amplitude modulation. Several psychoacoustics researchers have suggested that perceived roughness increases as […]
An alphamagic square
British engineer Lee Sallows came up with the following unusual magic square. If you spell out the English name of each number then replace the contents of each cell with the number of letters inside you get another magic square! Update: Here are a couple alphamagic squares in Spanish and more in French.
Acoustic roughness
When two pure tones are nearly in tune, you hear beats. The perceived pitch is the average of the two pitches, and you hear it fluctuate as many times per second as the difference in frequencies. For example, an A 438 and an A 442 together sound like an A 440 that beats four times […]
Bayesian adaptive clinical trials: promise and pitfalls
This afternoon I’m giving a talk at the Houston INFORMS chapter entitled “Bayesian adaptive clinical trials: promise and pitfalls.” When I started working in adaptive clinical trials, I was very excited about the potential of such methods. The clinical trial methods most commonly used are very crude, and there’s plenty of room for improvement. Over […]
Paying for doughnuts with a phone
At a doughnut shop today, I noticed the people at the head of each line were using their phones, either to pay for an order or to use a coupon. I thought how ridiculous it would sound if I were to go back twenty or thirty years and tell my mother about this. Me: Some day […]
Cornu’s spiral
Cornu’s spiral is the curve parameterized by where C and S are the Fresnel functions, sometimes called the Fresnel cosine integral and Fresnel sine integral. Here’s a plot of the spiral. Both Fresnel functions approach ½ as t → ∞ and so the curve slowly spirals toward (½, ½) in the first quadrant. And by symmetry, […]
Categorical products
Introduction There’s an odd sort of partisan spirit to discussions of category theory. They often have the flavor of “Category theory is great!” or “Category theory is a horrible waste of time!” You don’t see this sort of partisanship around, say, probability. Probability theory is what it is, and if you need it, you use […]
New Twitter logos
I’ve updated the icons of all my daily tip Twitter accounts. My goal was to simplify some the icons and make them all more consistent. Here’s a page giving links and short descriptions for each account.
Science fiction recommendations
I like science fiction as a genre, but I dislike most science fiction books I’ve tried. I start with books that come highly recommended and give up on most of them. But here are a few I’ve read and enjoyed.
Beats: amplitude modulation in radios and musical instruments
What do tuning a guitar and tuning a radio have in common? Both are examples of beats or amplitude modulation. Examples In an earlier post I wrote about how beats come up in vibrating systems, such as a mass and spring combination or an electric circuit. Here I look at examples from music and radio. Music When two […]
Creating police siren sounds with frequency modulation
Yesterday I was looking into calculating fluctuation strength and playing around with some examples. Along the way I discovered how to create files that sound like police sirens. These are sounds with high fluctuation strength. The Python code below starts with a carrier wave at fc = 1500 Hz. Not surprisingly, this frequency is near where […]
...54555657585960616263