Hi. My name is Alex Wiltschko.

This is my internet log.



14 March, 2012

From the Alan Lomax archives

(download)

Willie Washington - My Jack Don't Drink No Water

4 February, 2012

Sprucing up curves with B-splines in Python

First things first, by "in Python", I mean "using NumPy and SciPy, two fantastic scientific computing packages for Python that I don't know what I'd do without." I need them to do my job, every day I do it.

Second things second, what the heck is "parameterizing curves"? A lot of times, when poking around for things I want to do with data, I pick up terms here and there that give me the sense that they're just important. If you search around for "smoothing curves"  or "interpolating data", you're bound to end up reading a little about B-splines. 

I'm not going to go into the mathy stuff, but I'll instead give you a nice picture that explains what B-splines can do. 

Here's an extracted contour of a mouse. If you strain your eyes, you can see the head in the upper right, and the butt in the lower left, and the tail's been omitted. But, notice a couple things: 

- Our eyes pick out a clear contour
- The contour is not sampled at even intervals
- There's some noise and jitter in the contour

Pastedgraphic-3

Here's what points calculated from a B-spline fit to the above data look like:

Pastedgraphic-4

Proof in the puddin', as they say. So how do you do it? Again, not going to get into the principles behind it, just going to show you the code that does it:

Okay, let's break it down, using those numbers as indices.

1. The smoothing factor of a spline defines how tightly it'll fit to the points you provide it. Keep your smooth factors within the range [ numPointsIn - sqrt( 2 * numPointsIn ) , numPointsIn + sort( 2 * numPoints In ) ]. Where'd I get that range? The trusty documentation for the function in the next line.
2.Here we actually calculate the spline. We feed it our noisy, incomplete points, and two other parameters. One, the smoothing parameter we set before, and then a "per" parameter I'll 'splain down below. A couple things here we should talk about.
- What's "tck" stand for? "t" is for knots ( no idea why ), "c" is for coefficients, and k is for the degree of the polynomial ( k is often used for these things ). 
- What's that underscore doing there? Well, that's a handy way to say in Python that you don't give a hoot about any other variables returned from a function. Basically says "give me the first, toss the rest". Comes in handy when functions spit out varying numbers of outputs based on how you call them, but you rarely end up caring about most of them. 
- per = 1. What's that? Well, our contour array doesn't end where it starts, meaning it doesn't form a closed loop. When we set "per", standing for "periodic" to 1, we're asking the B-spline to close itself off. Useful for contours like this. Might not suit your needs, but it definitely does suit ours here.
3. Why a variable from 0 to 1? What a spline of the type we're making does is to map a set of points onto a new, synthetic  continuously varying variable. That's called "parameterization", and it gives us the neat ability to tell where we are in the curve, in the sense of beginning to end. I'll show you more about that in a bit. But, what we're basically saying is we want 100 evenly-spaced values all around our contour. 
4. Evaluate the spline, giving us our beautiful, smooth, even x and y values that are plotted in a rich blue above. 

If you want to start interpolating and smoothing, that's all you need to know! But here's an extra tidbit. 
So, what if you didn't add that underscore in #2? Well, the next variable you could get out of the spline evaluation function is "u", which we calculated separately ourselves. Why didn't we use the one they gave us? Let's plot the one they would give us (black), versus the one we made (blue).

Pastedgraphic-5

Ew, jaggedy, ugly black u. Beautiful straight blue u. Why's that? The "u" given back to us from interp.splprep will correspond to the points that go into fit the B-spline, which means the same unevenly sampled points you had in the first place. What's neat about this, though, is it provides you a measure of where your uneven sampling is. That can actually be a pretty useful metric sometimes, if you need a single-dimension metric to quantify data quality along a winding contour, like a coast line. 

There's another notion in B-splines called "control points", which I don't have fully figured out, but am digging into. If you, dear reader, know how to work with setting explicit control points in SciPy, please do let me know, I'm extremely interested. If I find out, or if somebody finds out and tells me, I'll add a little section about that here. Ciao, happy data wrangling!

2 February, 2012

Mountains on the mind

2 February, 2012

Five Year Old Analyzes Logos

(via daringfireball.net)

31 January, 2012

The misery that is now upon us is but the passing of greed

31 January, 2012

Advice from Freeman Dyson

1. I continue working because I agree with Sigmund Freud’s definition of mental health. To be healthy means to love and to work. Both activities are good for the soul, and one of them also helps to pay for the groceries.

2. In my younger days my work as a scientist was deep and narrow. Now, as I grow old, my work grows broader and shallower. As a young man, I solved technical problems of interest only to a few specialists. As an old man, I write books about human affairs of interest to a broad public. In both halves of my life, I tried to make the best use of my limited abilities.

3. (a). Advice to people at the beginning of their careers: do not imagine that you have to know everything before you can do anything. My own best work was done when I was most ignorant. Grab every opportunity to take responsibility and do things for which you are unqualified.

(b). Advice to people at the middle of their careers: do not be afraid to switch careers and try something new. As my friend the physicist Leo Szilard said (number nine in his list of ten commandments): “Do your work for six years; but in the seventh, go into solitude or among strangers, so that the memory of your friends does not hinder you from being what you have become.”

( source )

10 January, 2012

The Technology Always Comes Before the Artist

4 January, 2012

I just don't know what to do, and I don't know what will become of America

2 January, 2012

We are mortgaging tomorrow

1 December, 2011

Homemade Sous Vide Machine

Here are the pieces of my homemade sous vide machine, and some notes on what I used to put it together. 
First off, other folks have put together much nicer DIY posts, and I based my machine somewhat off their words. The main departure I take from other methods is to use a bucket deicer as the heating element, not tiny little heating coils. It's more expensive, but it works faster and can get much hotter.

Here's my bucket list:
A PID controller. $40. (that's not the exact one I used, which I can't find for sale anymore).  
K-type thermocouple. $4.
Bucket heater. $55. 
Solid-State Relay (SSR). $9.
Aquarium pump. $7.
Foodsaver Vacuum Sealer (optional, but it sure makes things convenient) $70.
( Plus, some stuff from your hardware store, or that you might have laying around )
- Wire to connect an outlet plug to the SSR ( speaker wire works just fine for me ).
- AC plug
- Beer cooler, or a bucket, or something that can hold enough water for you to cook what you want.

Alright, so let me break it down:
First off, the PID controller is the brains of the system. It stands for proportional-intrgral-derivative controller, and they cost about $30, and they take temperature information from a thermometer (well, technically a "thermocouple"), and decide when to turn on the heating element to keep the water bath at a stable temperature. My Uncle had a couple extra PIDs, and gave me one of his (he builds glassblowing furnaces, but this one still works in the non-glassblowing temperature range). I couldn't find the one I have for sale on Amazon, but just make sure that it's compatible with a "K-type thermocouple". They're cheap and good.

On the one I have, the top number is the current temperature detected by the thermocouple (see the next picture for what the thermocouple looks like), and the bottom number is the destination temperature. 

Sous_vide_6_of_10

 

Get a thermocouple. This little screw-looking thing is the thermometer that the PID uses when deciding to turn on or off the heat. The wire it's connected to is flexible, but holds its shape, so you can bend it over the lip of a cooler to bucket to keep it nicely suspended.

Sous_vide_8_of_10

 

I keep a separate digital thermometer handy to check that the whole contraption is working. I've had a couple instances where the thermocouple was positioned poorly, and it ruined a dish. This was before I started using larger water baths (moved from a 10 gallon bucket to an Igloo beer cooler) and before I got an aquarium pump to keep the water circulating constantly. It's still a nice precaution and sanity-check.

Sous_vide_9_of_10

 

A solid-state relay and an outlet. The PID directly controls the solid state relay, which controls whether or not electricity flows from the wall to the outlet plug. That black cord in the AC plug goes to the water heater, in the next picture.

Sous_vide_10_of_10

 

A bucket deicer. This is the best heating element for the money that I've been able to find. 

Sous_vide_7_of_10

 

And, if you hook everything up right, and vacuum pack some pork butt and cook it for three days at 155°F, this is what you get:

(download)

Sous_vide_1_of_10

I don't have pictures of the pork preparation process, but it's simple enough. Check it — 

- Cut pork butt into about 1.5" thick slices. 
- Cover each side liberally with salt, black pepper, rosemary and thyme.
- Vacuum pack the slices with a Foodsaver, or by dipping a ziploc bag into water until all the water is squeezed out, then sealing it. I've done it both ways, and it was delicious both times. 
- Cook the pork in the water bath for few days at 155°F.
- Take it out, of the bath, open up the bag, pull it apart.
- Strain the juices out to make a gravy. 
Search it. Browse it. Subscribe it. Get caught up in it.


Get the RSS feed! Go ahead.