Skip to content
Jul 15 10

Microsoft Solver Foundation for Quadratic Programming

by Dan

The Microsoft Solver Foundation provides some excellent APIs for solving optimization problems in C# .NET. Getting to documentation about the Quadratic Programming facilities can be a bit tricky though. I’ve added below some sample code to help out with this.

In the following example I’m solving an example of the lagrangian dual form used for classification in an SVM.

// Classify using solver
InteriorPointSolver solver = new InteriorPointSolver();

// Langrangian Dual
int dual = 0;
solver.AddRow("L", out dual);

// Sum Constraint
int linearConstraint = 0;
solver.AddRow("SumConstraint", out linearConstraint);

// Add variables and Lagrangian linear terms
int[] vars = new int[n];
for (int i = 0; i < n; i++)
{
	// Add the variable
	solver.AddVariable("a" + i, out vars[i]);

	// Factor in C upper bounds
	solver.SetBounds(vars[i], 0, C);
}

// Linear constraint must equal 0
solver.SetBounds(linearConstraint, 0, 0);

// Lagrangian Quadratic Terms
for (int i = 0; i < n; i++) { 	solver.SetCoefficient(linearConstraint, vars[i], trainingData[i].output()); 	solver.SetCoefficient(dual, vars[i], 1); 	Parallel.For(0, n, o, (int j) =>
	{
		double coef = trainingData[i].output() * trainingData[j].output() *
			kernel.evaluate(trainingData[i].point(), trainingData[j].point());

		solver.SetCoefficient(dual, -0.5 * coef, vars[i], vars[j]);
	});
}

solver.AddGoal(dual, 0, false);

InteriorPointSolverParams param = new InteriorPointSolverParams();

Essentially all we are doing here is adding all the variables to our constraint optimization problem and asking the solver to minimize. The vars array simply expressing a list of identifier for variables in the constraint problem. You should fire up the Solver Foundation library and give it a shot yourself.

Here are some resources that should make understanding this a bit easier as well. Its the official blog of one of the key developers on the project, specifically the links to tutorial on the quadratic programming solver.

Nathan Brixius’ QP Solver Tutorial

Jun 29 10

Hiking Trip – Bake Oven Knob

by Dan

A bunch of my friends took a trip to Bake Oven Knob in Lehighton, Pa this past Sunday. It was the first chance I’ve had to go hiking in a long time. It also presented a great opportunity to test out the camera and video chat features on my new iPhone 4. I also found this great free app for the iPhone called RunKeeper which let me track out progress, time, and pace via GPS. It even lets you automatically share it through Facebook or embed it in your blog.

Interact With This

Overall we did about 7 miles, which amounts to going a little less than half way of the entire Bake Oven Knob trail, then turning back. I got some great shots I thought I’d share to anyone interested. The Bake Oven Knob privates a great view at its peak which is only about half a mile from the trail entrance.


Created with Admarket’s flickrSLiDR.

Jun 24 10

Iphone post

by Dan

Goodbye EVO. Hello iPhone.

May 28 10

HowTo Fix: Roomba Clicking Noise

by Dan

A while back the vacuum in our apartment stopped working so I decided to do something I always wanted: Get a roomba. So far its been great and it keeps the carpet clean with minimum effort.

However, we have encountered some problems where the Roomba occasionally makes a repeated clicking noise and then shuts off. It then repeats “Please Clean Roomba’s Brushes”. It got to the point where it was making the clicking noise EVERY time it was run and would shut down after about 2 minutes. I tried reseting the battery, cleaning the brushes…everything. Finally I realized what was wrong. I wasn’t cleaning the brushes properly. If you have a lot of dirt in your carpet or pets (we have cats), it’s easy for fibers to get wrapped around some of the moving parts of the roomba brush.

So to fix the problem simply remove the brushes from the Roomba as your normally would to clean them. However, check under the yellow cap at the end of both brushes (by that I mean the brush and the rubber roller). Don’t worry, they are designed to come off, so you can pull on them. Afterwards you may see something like this:

What you may see if your roomba is making a clicking noise

Just pull out all the hair and fibers with a pencil or paper clip and replace the yellow cap. Afterwards your roomba will be good as new! Be aware though, that this is likely to happen again so make sure you periodically clean under the cap of both brush attachments.

Apr 4 10

Quick Fix: iPhone Microphone and Headset Buttons don’t work

by Dan

I recently had a problem with my iPhone headphones where neither the built in mic nor the headphone answer (or start/stop) button would work. I attributed the failure to a recent tumble which also crack my front glass along the bezel.

Now, thanks to a helpful blog post I was able to correct the problem. Seems like a rather large piece lint had made it’s way into the headphone jack and was blocking the plug. I would have never figured it out if it wasn’t for this helpful blog post. So I’ve linked it below and will leave the explanation to him:

http://www.iphoneincanada.ca/tips-tricks/how-to-fix-your-iphone-headphones-mic-if-its-not-working/