25 November 2008

Only in grad school...

Last night, the research group and I were up all night working on a paper. I was modifying some benchmarks to collect another kind of data, and I got to a point where the code didn't work, and I had no idea how to fix it.

The code boiled down to something like this:

int x = 0;

int f()
{
...
x++;
}


int main()
{
...
f();
...
printf("%d\n",x);
...
}

But every time, it would print out zero. I asked one of the other grad students, and after a few perplexed moments, he came up with the solution:

"Oh, Nick! You forgot that we loaded the kernel module which drastically changes the semantics of memory."

Ah... gradschool.

23 November 2008

Amused by SMLtoJs

I love Standard ML -- its excellent type system finds nearly all of my bugs before I run the code even once, and the idea of restricting side-effects to a small portion of my code makes the whole easier to reason about. Not to mention, disjoint union types seem to cover 99% of my previous use of object oriented programming. Runtime performance sucks, but honestly, how frequently does that even matter?

I hate javascript, even more than I hate perl. It is a language with no definition. It is a language with no reference implementation---and even individual implementations are self-inconsistent. It's a classic example: very little planning went into its beginnings, and the remaining planning only came about after every vendor had pushed their own solutions.

I recently discovered SMLtoJs -- a compiler that translates Standard ML into Javascript. I can't decide if I'm disgusted or pleased by this. I'm definitely amused...

10 November 2008

Cool Plot :: Gibbs Sampling and a (mostly) independant Bayes Network

Here's a cool plot that came up while I was doing a homework assignment. It is the result of the Gibbs Sampling algorithm approximating a 50-50% variable over a billion iterations on a probability space of dimensionality close to 2^25.

Imagine you have a random coin toss which we'll call the leader. Now imagine you have one or more followers who choose to agree with the leader x% of the time, or disagree otherwise. Suppose that you can't "see" what the leader chose, but only what the followers have chosen. Determine the probability distribution of the leader's coin. We'll call this the leader-follower problem.

In this particular instance of the problem, the leader's coin is unbiased (50-50%), followers agree with 90% probability, and we have 25 followers. Each of the followers depends only on the leader and not on each other, and so each follower represents a nearly independent dimension. I claim that the probability space P(Leader|Followers) is nearly 2^25 in size.

When we put a Gibbs Sampler to the task, it's performance kind of sucks. Effectively, it is running a Monte-Carlo simulation of the scenario, and attempting to count the probability distributions over the network. But, since the space is so large, it cannot effectively explore the whole space, and so there is a lot of error.

What I find so intriguing about this plot is its smooth upward or downward trends, with sharp turns.

You can think of any trend away from the solution (50-50%) as a situation in which more than half of the followers disagree with the leader, and any trend towards it as a situation in which more than half agree with the leader. Since Gibbs Sampling changes one variable at a time, we effectively have a "momentum" effect; once more than half disagree, each one needs to be independently fixed, on at a time, before we can turn around.

Also observe that the slope of these traces is proportional to the number of followers in disagreement. This is why the slope tends to flatten out as we reach the extrema.

Enjoy.

09 November 2008

Modding my minilathe :: Adding locks to the X-,Y-Axes

I posted before about a few modifications to my minilathe. These cheap lathes are fun and accessible to many, but they have a few weaknesses. Now that I'm taking the machine shop course at Princeton, and learning a lot more about machine work, I've realized a few more deficiencies.

In particular, since a lathe provides several degrees of freedom to the tool holder, it's possible for the tool holder to drift along these dimensions while cutting. Decent lathes provide a locking mechanism along each degree of freedom to prevent this, but for the most part, the minilathe does not.

My minilathe's tool holder has five degrees of freedom: left-to-right (X), forward-backward (Y), rotation (Theta), compound (Z), and tool orientation (Phi). The factory stock lathe provides locks for rotation and tool orientation, however the remaining three cannot be locked.

It turns out it's pretty easy to add locks for the X and Y dimensions.

Lathe Mod #9To add a lock to the X dimension, one needs only to drill and tap a hold along the X-carriage so that a bolt will press against the X-ways.

Lathe Mod #8A very similar approach will work for the Y dimension, though care should be taken to prevent this bolt interfering with the rotation of the tool holder, or from coming in contact with the work piece or chuck.

The Z dimension is trickier because of the shape of the tool post, and I don't have an answer yet for how to add a lock. In the best case, I can't figure out how to provide a lock over more than a small region of the Z-travel. Even then, there are two counterbored holes through the Z-ways (to lock the rotation) which would make this more difficult. If you have any suggestions, I'd like to hear them.

Also, I've been putting a lot of thought into rotation. With a stock minilathe, you have to half-remove the compound to unlock the rotation, adjust the rotation, and then replace the compound. This is really a pain in the butt, and I've been thinking about a way to add a dial to rotate the tool post. My plan is to cut threads along the perimeter of the rotation-clamp part, and then add another screw that will slowly rotate the tool holder. This is still in the works, and I'll let you know when I get it working.

05 November 2008

And now...

[warning: politics follow]

I'm excited about the results of the election, not because I'm glad that the Democrats won, but for the hope that an opposition party has taken control of the legislature and executive. The distinction is subtle, and all hinges on whether or not the Democrats will finally step up to the plate and offer a new direction.

Over the last eight years, I saw the Democratic party crippled. They were afraid to even speak against Bush for many years after September 11. More recently, they have felt more free to criticize the Republican Platform, but as far as I can tell, they didn't present any alternative. Anyone who is surprised that Bush won in 2004 should observe that it was a failing of the Democrats in 2004.

But now, the future is open. Obama has inherited a huge mess, and I don't know how well he will be able to deal with it---the war, the economy, and the nations energy policy at large. I hope they can accomplish something. I hope we don't just see four years of apologists.

04 November 2008

01 November 2008

I am very pissed at Acer right now

I recently purchased an Acer B203W widescreen flatpanel monitor. All I am trying to do is adjust the f*king stand to raise the monitor, but I can't figure it out. Worst of all, the instructions do not cover the locking mechanism for the monitor stand, and the Acer website claims there is no instruction manual for this product.

I called their customer support, but it's closed.

I read and reread the meager instructions supplied, and they don't mention this feature at all.

I googled, but mention Acer B203W and all you'll find is stores trying to sell the flatscreen.

So that's it. Screw you Acer. You have a bad rep in the blogomotron.