spacer
{Arrest This Man, He Talks In Maths } spacer

Blog : Archives : Homepage

With your feet in the air, and your head on the ground . . .

spacer
spacer

{Thursday, December 16, 2004}

 
"So... in an HTML analogy, your code now has a "style sheet" instead of you typing in the modifiers for every individual tag you use, every time you use it? (You load the main program once, then switch the parameters without re-performing the vast majority of the task?)"

I don't really know CSS (:-p) so I'm not sure how apt the analogy is, but my guess is this is pretty different. The optimizations don't make my code "cleaner" in an aesthetic sense, and they don't reduce my effort in writing the code - the purpose is just to make the code run faster, i.e. reduce the computer's effort in executing the code.

The best metaphor I can think of for the memory allocation situation is this: let's say you're a professor, and before every lecture, you need a lot of material put up on a board, which you'll lecture from. Fortunately, you have a TA to help you with this task (the subfunction you call, metaphorically speaking.) Now, you would probably think the easiest thing to do would just be to give your TA the relevant info that needs to go up on the board each time. So you do that, and classes go fine, but at the end of the semester you notice you've gone way overbudget due to "TA expenses". It turns out the TA has been going out and BUYING A WHOLE NEW FREAKING BLACKBOARD for every lecture. Now, that's obviously not very efficient. But you don't think it would be very efficient to lug the blackboard over to the TA before each lecture, either. Fortunately, there's a simple solution: just tell the TA where the blackboard is, and ask them to just go write on it. In a language like "C", this is simple to do, with something called a "pointer" - you pass a pointer to a big chunk of memory into a function instead of sending the whole thing, and everything's groovy. Matlab, trying to be simpler and easier to use, doesn't want to confuse you with pointers, so you can't do this. What I did was figure out a trick to let me (effectively) pass a pointer . . . and thus, metaphorically, cut out the cost of the TA buying a new blackboard (allocating memory) for every lecture.

posted by Miles 8:55 AM

  (2) comments

{Wednesday, December 15, 2004}

 
Booyaka.

This morning, I had no code for my next planned experiment.

Tonight, I not only have working "demo" code, I've also cleaned up and massively optimized a lot of the underlying code. The optimization work was especially satisfying. Matlab is fruity enough that you kind of have to trick it into being efficient, and while the documentation is great for quickly learning how to make something that will work, it doesn't give you a lot of info on how to make things go fast. So I'm left to explore by trial & error.

Case in point:

I have a function (called repeatedly within a loop) which produces a dot-array image matrix from a set of {x,y} coordinates. Simple. But it was taking TONS of time. Making it a 'uint8' instead of a 'double' matrix helped, but it was still painfully slow. Solution? Instead of (implicitly) declaring the variable for the matrix inside the function (which requires memory allocation), I passed a 'template' matrix - declared once, on the "outside" - into the function. I wouldn't have guessed that this would work, actually, because my initial thinking was that it was costly to pass big variables in and out of functions. Not so; apparently, by using the same name for the argument TO and the output FROM a function, you can sort of create a "tunnel" in and out of the function, allowing it to avoid creating (and allocating memory for) a new variable. Neat, but not intuitive, at least to me. I wonder whether I'm thinking about that the right way, conceptually. I'm not totally sure.

In another function, which creates the coordinate sets, I figured out a way to eliminate two levels of nesting (which Matlab tends to stumble over), and turn an O(N^2) process into an O(N) process. The latter improvement was possible merely because my original algorithm was blindingly idiotic, but fixing it was still really satisfying. This is code that I've been using to create experimental stimuli for about the last 4 years, now. It worked, but it was always annoyingly slow. Now it blazes.

It serves to remind me how silly it is to be obsessed with hardware & CPU clockspeed, when comparing across platforms. If the software you're using is well-designed and optimized, it will run fast. If it's poorly-designed, it will drag.

As an aside, it's pretty sad that Pedro's not gonna' be pitching for the Sox next year. Yeah, he seemed to be getting old and tailing off a little, but he was a heck of a fun character.


posted by Miles 1:29 AM

  (2) comments

{Thursday, December 09, 2004}

 
Oh, man, this is hard.

I decided this morning (in the shower) that I spend way too much time reading news on the web, and I should quit. I don't really get that much out of it, you know, it's more of a compulsion, and overall I'd be happier if I spent the time (a) working, or (b) actually relaxing and enjoying myself - taking walks along the river, going to museums, watching movies, bowling, getting drunk, that kind of thing.

So I decided to go cold turkey. For 10 days. I'm gonna' ask Jess to go through my web-browser's "history" files over the weekend to check on me, and make sure I haven't slipped.

Oh, man, this is hard.

No cnn.com. No msnbc.com. No nytimes.com, or news.google.com, or finance.yahoo.com. And I had to type all those URLs in by hand, because I couldn't go to the sites and copy & paste, like I usually would.

But like Obi Wan Kenobi said, in Trainspotting (eh-heh) . . . with God's help I will conquer this terrible affliction.

(News: It's the new heroin. Any day now the War on Terror will be passe, and the administration will declare a new "war" to free us from the terrible scourge of news addiction.)


p.s. - Yes, I'm allowed to blog, and yes, it is just about exactly like methadone for me.

posted by Miles 5:28 PM

  (2) comments

{Monday, December 06, 2004}

 
Today, thanks to an applescript I found, I was able to do a calculation I've wanted to do for a long time. Here, in order, are the artists or bands I've listened to the most over the last ~2 years (total playcount > 200):

Liz Phair, Guster, Jump Little Children, The Beatles, Deb Talan, Mos Def, Aimee Mann, Coldplay, Radiohead, The Shins, Ben Folds, The Pixies, R.E.M., The Roots, Joni Mitchell, Evanescence, Elliott Smith, The Foo Fighters

There it is, in the cold light of day. :-)

Liz Phair? 743 listens, total, to the 72 songs in my library. Deb Talan has the highest "density", with 384 listens spread over just 13 songs, for an average of almost 30 plays per song. And yes, you've probably never heard of her. She plays acoustic guitar and sings . . . and writes some really addictive tunes.

Overall, my total iTunes playcount stands at about 24,500. That actually goes back to Nov. 17, 2002, a little more than 2 years ago, or just about 750 days ago . . . which means on average, I've listened to about 32 songs a day, on iTunes & my iPod, combined. Fascinating.

Anyway. Time to walk home through the snow . . .

posted by Miles 10:59 PM

  (0) comments

{Thursday, December 02, 2004}

 
I saw the Pixies last night, with Francis & Jordan. Today I can't speak and I'm half-deaf. God, that was good. They closed with "Gigantic", and as I stood, soaked in sweat, eyes closed and a hand in the air, I was hit by a constant rolling wave of endorphins. Listen to the resonance in their guitars in the minute-long closing instrumental to that song. I love the Pixies. And I love endorphins. I haven't moshed like that in years. Gah.

You know, there's something to be said for working hard. There's something to be said for relaxing. There's something to be said for the feeling of being respected. For gettin' paid. For feeling secure.

But fuck all, man, none compare to feeling ALIVE.


I think the Pixies are an acquired taste. To the untrained ear, they can sound too raw, maybe too punk, too angry, too fucked. And since they're frequently credited as the band whose innovations inspired grunge, you might think they're about darkness and pain and depression. But really . . . that's not what the screeching vocals or wailing, driving instrumentals are about. At all. The Pixies are great because they rock, and they rock you. They make your head implode. They make it feel fucking great to be young, and strong, and alive. Their music just embodies everything that Rock is about. In amazing, innovative, pounding, driving, emotive ways.

I don't know - I'm full of shit, I know. I give up. Let's just leave it that the Pixies are awesome.

posted by Miles 10:54 AM

  (1) comments
spacer