<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
        <title>~traviscj/</title>
        <description>feed for traviscj.com/blog</description>
        <link>http://traviscj.com/blog</link>
        <lastBuildDate>Sun, 15 Apr 2012 22:40:45 +0000</lastBuildDate>
        <pubDate>Fri, 13 Apr 2012 00:00:00 +0000</pubDate>
        <item>
                <title>Integrating Sparrow and Aperture/iPhoto</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;In my recent quest to take on digital photography, I've been using Apple's Aperture to store download my pictures and do basic manipulation on them. It's been working great, except that emailing is a pain because Apple hardcoded the email clients to:&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;p&gt;Apple Mail.app&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Eudora (really!?)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;America Online(!?!)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Microsoft Entourage&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Microsoft Outlook

while I'd prefer to use Sparrow, a lightweight client that Sharvil got me hooked on a while back. Rather than continue to use Mail.app to send pictures via email, I found out that Aperture actually uses some AppleScripts to do the actual sending of the email. That got me thinking: I just need to change the script to mail using Sparrow, instead of Mail.&lt;/p&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;So all I needed to do is replace /Applications/Aperture.app/Content/PlugIns/Mail.applescript with the following script:&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

-- Mail from Sparrow.app instead of Mail.app

-- Travis Johnson (traviscj@traviscj.com)

on mail_images(email_subject, default_address, image_count, new_files, new_captions, new_comments, cancel_string)

	try

		tell application "Sparrow"

			activate

			set theMessage to make new outgoing message with properties {subject:email_subject, content:"Check out my sweet pictures!"}

			tell theMessage

				repeat with image_idx from 1 to image_count

					set this_imagefile to item image_idx of new_files

					set attachmentfilename to POSIX file this_imagefile

					make new mail attachment with properties {filename:attachmentfilename as alias}

				end repeat

				compose

			end tell



		end tell

	on error error_message number error_number

		log error_message &amp;amp; " " &amp;amp; error_number

		if the error_number is not -128 then

			tell application "Finder"

				beep

				display dialog error_message buttons {cancel_string} default button 1

			end tell

		end if

	end try

end mail_images

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, magically, I can press the 'Email&amp;rsquo; button in Aperture, and Sparrow pops up with a new email, and the proper file attached! Hooray!&lt;/p&gt;

&lt;p&gt;I looked into doing the same thing with iPhoto; a slightly different proceedure is needed here. I opened /Applications/iPhoto.app/Contents/Resources/Scripts/Mail.scpt with Script Editor via the terminal:&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

$ open /Applications/iPhoto.app/Contents/Resources/Scripts/Mail.scpt

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;then pasted in the above code, clicked 'Compile&amp;rsquo;, then 'Save&amp;rsquo;. iPhoto then worked as expected, opening a new Sparrow message with the files attached.&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:46 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/integrating_sparrow_and_apertureiphoto.html</link>
                <guid>integrating_sparrow_and_apertureiphoto</guid>
                <pubDate>Fri, 13 Apr 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>chicago 2012 marathon</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;I've signed up for the &lt;a href="http://www.chicagomarathon.com/cms400min/chicago_marathon/"&gt;Chicago 2012 Marathon&lt;/a&gt; with Team To End AIDS(&lt;a href="https://afc.aidschicago.org/netcommunity/page.aspx?pid=1458"&gt;full site&lt;/a&gt; or &lt;a href="https://afc.aidschicago.org/netcommunity/traviscj"&gt;my donation page&lt;/a&gt;&amp;ndash;PLEASE! every bit helps!). It's a bit of an unusual choice, probably, to not run for the American Lung Association(I have asthma) or the American Cancer Society(my dad is a survivor.) But it's actually been a good opportunity to learn a bit more about the current state of AIDS, AIDS policy, and what it's like to live with it. I've also had some really good discussions about it with people it would not have come up, so it has been nice all around. &lt;/p&gt;

&lt;p&gt;P.S.: I will beat Oprah's time or die trying. (Post-dated entry so you know I'm not kidding.&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:46 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/chicago_2012_marathon.html</link>
                <guid>chicago_2012_marathon</guid>
                <pubDate>Mon, 02 Apr 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>fibonacci miles and kilometers</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;In my running, I have been trying to keep track in kilometers. This presents a couple problems: Somehow, my mind still thinks in miles, which is weird because I do not really have &lt;i&gt;that&lt;/i&gt; good of an idea exactly how far a mile is, either.

Or someone wants to know how far a 5k is. Or, when I was running the 2011 Chicago Marathon, there would be kilometer postings between the mile markers. Anyway, it is handy to convert between them, but a bit of a pain.&lt;/p&gt;

&lt;p&gt;It turns out that the ratio of adjacent Fibonacci numbers are a decent approximation to the unit conversion between miles and kilometers. I decided to look into it a bit.&lt;/p&gt;

&lt;p&gt;First, in case you have never seen or do not remember what Fibonacci numbers are, they are a sequence of numbers where the first two fibonacci numbers are &lt;img class="eq" src="eqs/6144018481-130.png" alt="0" style="vertical-align: -1px" /&gt; and &lt;img class="eq" src="eqs/6272018864-130.png" alt="1" style="vertical-align: -0px" /&gt;, and then each number after that is the sum of the immediately prior two.

Mathematically, this is written as&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/6792254290460316966-130.png" alt=" f_0 = 0, f_1 = 1, f_n = f_{n-1} + f_{n-2}, " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;which gives rise to the sequence&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/1993993090070398999-130.png" alt=" 0,1,1,2,3,5,8,13,21,34,55,89,... " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;You can actually come up with a closed form solution for Fibonacci numbers, which is borderline incredible, using the recursion relationship given above. If you assume that &lt;img class="eq" src="eqs/7038944504527740626-130.png" alt="f_n=lambda^n" style="vertical-align: -4px" /&gt;, then you get&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/6910209986744733391-130.png" alt=" f_{n+2} = f_{n+1} + f_n implies lambda^{n+2} = lambda^{n+1} + lambda^n " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Then canceling a &lt;img class="eq" src="eqs/2768874965526883060-130.png" alt="lambda^n" style="vertical-align: -1px" /&gt; from both sides, and rearranging you get that&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/3216966367831414393-130.png" alt=" lambda^2 - lambda - 1 = 0 " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;You can use the trusty quadratic formula to solve this, it gives&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/5190923965880238753-130.png" alt=" lambda^*_{pm} = frac{-(-1)pm sqrt{(-1)^2 - 4(+1)(-1)}}{2(1)} = frac{1pmsqrt{5}}{2} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Clearly the &lt;img class="eq" src="eqs/8680299316192824474-130.png" alt="n^{th}" style="vertical-align: -1px" /&gt; Fibonacci number is not just this messy looking irrational fraction to the &lt;img class="eq" src="eqs/8680299316192824474-130.png" alt="n^{th}" style="vertical-align: -1px" /&gt; power, so we need one more trick. Introduce a couple of constants &lt;img class="eq" src="eqs/799031295774617328-130.png" alt="c_1" style="vertical-align: -3px" /&gt; and &lt;img class="eq" src="eqs/799031295774617325-130.png" alt="c_2" style="vertical-align: -3px" /&gt;, and let&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/4373476486787520123-130.png" alt=" f_n = c_1(frac{1+sqrt{5}}{2})^n + c_2(frac{1-sqrt{5}}{2})^n " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Now, since we want &lt;img class="eq" src="eqs/2606343998917836349-130.png" alt="f_0=0" style="vertical-align: -4px" /&gt; and any number to the zeroth power is 1, we have that &lt;img class="eq" src="eqs/8473532579904666164-130.png" alt="f_0=c_1+c_2=0" style="vertical-align: -4px" /&gt;, or that &lt;img class="eq" src="eqs/5816154655401865191-130.png" alt="c_1=-c_2" style="vertical-align: -3px" /&gt;. Then &lt;img class="eq" src="eqs/6521417518585524889-130.png" alt="f_n = c_1((frac{1+sqrt{5}}{2})^n - (frac{1-sqrt{5}}{2})^n)" style="vertical-align: -7px" /&gt;.

The final step is requiring that &lt;img class="eq" src="eqs/2606342998921836329-130.png" alt="f_1=1" style="vertical-align: -4px" /&gt;. This gives that&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/5888667212511203342-130.png" alt=" f_1 = c_1(frac{1+sqrt{5} - 1 + sqrt{5}}{2}) = c_1 (frac{2sqrt{5}}{2})equiv 1 implies c_1 = frac{1}{sqrt{5}} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Now, finally, we have that&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/4367085267240577464-130.png" alt=" f_n = frac{1}{sqrt{5}} left( left(frac{1+sqrt{5}}{2}right)^n + c_2left(frac{1-sqrt{5}}{2} right) right) " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;It seems I have run a little off track. What does all of this have to do with running? Well, the Fibonacci numbers eventually approach this fancy &lt;img class="eq" src="eqs/2768874965527882998-130.png" alt="lambda_+" style="vertical-align: -5px" /&gt; we came up with earlier, and it turns out that &lt;img class="eq" src="eqs/3955170786733374107-130.png" alt="lambda_+ = 1.618" style="vertical-align: -5px" /&gt;. It also turns out that one mile is about 1.609 kilometers. That is just 0.56% error! Sweet!&lt;/p&gt;

&lt;p&gt;There is a catch though. Some Fibonacci ratios are better than others:&lt;/p&gt;

&lt;table id="TABLENAME"&gt;

&lt;tr class="r1"&gt;&lt;td class="c1"&gt;&lt;img class="eq" src="eqs/3531076114242782242-130.png" alt="f_n/f_{n-1}" style="vertical-align: -5px" /&gt;  &lt;/td&gt;&lt;td class="c2"&gt; approximation &lt;/td&gt;&lt;td class="c3"&gt; error &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r2"&gt;&lt;td class="c1"&gt;1/1 &lt;/td&gt;&lt;td class="c2"&gt; 1   &lt;/td&gt;&lt;td class="c3"&gt; 37.8% &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r3"&gt;&lt;td class="c1"&gt;2/1   &lt;/td&gt;&lt;td class="c2"&gt; 2 &lt;/td&gt;&lt;td class="c3"&gt; 24.2%  &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r4"&gt;&lt;td class="c1"&gt;3/2	  &lt;/td&gt;&lt;td class="c2"&gt; 1.5			&lt;/td&gt;&lt;td class="c3"&gt;6.7% &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r5"&gt;&lt;td class="c1"&gt;5/3	  &lt;/td&gt;&lt;td class="c2"&gt;	1.666	&lt;/td&gt;&lt;td class="c3"&gt;3.5% &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r6"&gt;&lt;td class="c1"&gt;8/5	  &lt;/td&gt;&lt;td class="c2"&gt;	1.6			&lt;/td&gt;&lt;td class="c3"&gt;.58% &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r7"&gt;&lt;td class="c1"&gt;13/8  &lt;/td&gt;&lt;td class="c2"&gt;	1.625			&lt;/td&gt;&lt;td class="c3"&gt;.97% &lt;/td&gt;&lt;/tr&gt;

&lt;tr class="r8"&gt;&lt;td class="c1"&gt;21/13 &lt;/td&gt;&lt;td class="c2"&gt;	1.615			&lt;/td&gt;&lt;td class="c3"&gt;.37%

&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;It looks to me like a sweet spot is at the 8 kilometer/5 mile mark.

So now you can see that 25 miles is 40 kilometers, or whatever distance you wanted to know about in the first place.&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:56 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/fibonacci_miles_and_kilometers.html</link>
                <guid>fibonacci_miles_and_kilometers</guid>
                <pubDate>Thu, 29 Mar 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>digital photography</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;Recently I've decided to dedicate a slight bit of time to get a bit better at taking pictures.

I'd always wanted to get a truly nice camera, and the opportunity presented itself, so I decided to go for it and bought a Nikon D5100 DSLR.

I also ended up getting a complete steal on the Nikon 55-200mm DX VR lens, which was pretty awesome.

&lt;a href="http://content.photojojo.com/tutorials/project-365-take-a-photo-a-day/"&gt;Project 365&lt;/a&gt; would be a great move from here, since I'm certainly no photographer, but it's been fun just learning about it all the ins and outs and how it all works together.

In any case, I did start a &lt;a href="http://www.flickr.com/photos/drtraviscj/"&gt;Flickr: drtraviscj&lt;/a&gt; account which I'll be posting stuff.&lt;/p&gt;

&lt;p&gt;More later&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:56 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/digital_photography.html</link>
                <guid>digital_photography</guid>
                <pubDate>Thu, 29 Mar 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>tjtestharness - a language-agnostic DVCS unit-test/continuous integration tool</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;I've been wanting to have a way to visualize which unit tests(or sets of them) passed for a given commit, if for no other reason than the sense of accomplishment from watching boxes turn yellow, then green, as they pass tests.

The trouble is, I write code in a lot of different languages for a lot of different projects.

I also don't want to bother with running unit tests individually&amp;ndash;I want them to run as I perform commits.&lt;/p&gt;

&lt;p&gt;My main project right now is working on a fast quadratic programming(QP) solver for series of related QPs, and in turn using that QP solver as the basis for a sequential quadratic programming method with a penalty globalization. 

It's working okay, but there's a lot of levels to the project, and it's easy to make a change in one place in the code that has far-reaching effects on other parts.

It's also got a very complicated structure for testing, because of the nature of nonlinear programming.

Testing runs something like&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;p&gt;First, need to check the most basic version of the QP solver itself, and how robustly it solves the most basic QPs.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Next we start adding in bells and whistles: We use a couple different types of numerical algorithm approaches.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;There are also two functionally identical but yet distinct approaches to actually formulating the QP.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A layer up from all of the QP solver, we're simultaneously building onto a nice penalty SQP method&amp;ndash;which itself has many options and tweakable parameters.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A layer up from that, we're testing the penalty SQP method on many different nonlinear programs. They might require different settings in terms of tolerance parameters(standard tolerance might be difficult to reach in a given problem, for example.)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;A layer up from &lt;b&gt;that&lt;/b&gt;, we're also testing the penalty SQP method on mixed integer nonlinear programs. This involves solving many, many NLPs. &lt;/p&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;So there's a lot of levels and layers and levers and settings. What was happening is that I would change some parameter and eventually it'd get checked into the repository, and that wouldn't play nice with other codes.&lt;/p&gt;

&lt;p&gt;I realized that I wanted some unit testing to automate this testing process, and document how it should be run, and soforth. But I also wanted the video game-style insta-rewards vibe to it, along the lines of the &lt;a href="http://www.panic.com/blog/2010/03/the-panic-status-board/"&gt;Panic Status Board&lt;/a&gt;(albeit less professional.) I also didn't want to spend a ton of time on it. I planned out the interface and databases over some beers with my roommate one night and wrote the entire thing in Django the next evening. I wanted it to run automatically on every repository commit. I also wanted it to try to make some sense out of Python, MATLAB, and C&lt;tt&gt;&lt;/tt&gt;, since I use all three extensively. It should also actually be able to build a project from scratch, and every build should run from nothing&amp;ndash;this enforces the rule that the repository is self as self-contained as possible. Finally, I also wanted to be able to look back at the actual run log of that unit test and see how or why it failed(and also have instructions on which repo/commit to checkout to see the bug in action).&lt;/p&gt;

&lt;p&gt;My basic idea was that I wanted some program that kept a database of projects I'm working on, displayed some commits from those projects, showed the status of any test_*.{exe,mat,py} commands it could run. Okay, so I need a table of projects, one of commits, and another of tests. Originally I built it that way, but I wasn't sure how to get columns uniformly figured out. So I decided to split the 'test&amp;rsquo; table into 'Tests&amp;rsquo; and 'TestResults&amp;rsquo;, which worked out nicely.&lt;/p&gt;

&lt;p&gt;The other tricky part was figuring out how I should add commits to the database, and how tests should get run. I ended up writing a fairly nice script for the commits to put in .git&lt;i&gt;hooks&lt;/i&gt;post-commit, though it requires the kludgy 'git push origin master&amp;rsquo; in the post-commit as well. This is causing a bit of trouble with modifying commits(ie, it breaks the other script and causes extra merges/commits.) The not-so-interesting side was the one that peeks into the database, grabs the 'test&amp;rsquo; (which is basically just a shell-script to run), and runs it. It also pushes the data back to the database when it's done.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.djangoproject.com/"&gt;Django&lt;/a&gt; is a really amazing framework. The entire coding part of the project went together in &lt;a href="http://traviscj.com/pictures/tjtestharness/"&gt;about 8 hours&lt;/a&gt;. I'm still not happy with it. I've got a laundry list of stuff to add here:&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;p&gt;check for executable test_&lt;b&gt;.&lt;/b&gt; (this is basically done, along with subdirectory test checking)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;it'd be nice to move the actual unit testing to a server instead of my laptop. But maybe it's safer to not have the interface EVER web-pointing.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Big one: time/datestamp in the commit rows, to tell when you did it.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;button to undisplay old commits, or a limit of how many commits show on the main page. This could get out of hand REALLY fast.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;collapse commit sha1 (did this, should add: re-expand commit sha1's)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;button to rerun tests(did this).&lt;/p&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;If you're interested, check it out at &lt;a href="http://code.traviscj.com/p/tjtestharness/"&gt;code.traviscj.com's tjtestharness&lt;/a&gt;&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:56 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/tjtestharness_-_a_language-agnostic_dvcs_unit-testcontinuous_integration_tool.html</link>
                <guid>tjtestharness_-_a_language-agnostic_dvcs_unit-testcontinuous_integration_tool</guid>
                <pubDate>Mon, 26 Mar 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>cplex matlab interface</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;Just for my own reference, I'm documenting the interface to CPLEX.&lt;/p&gt;

&lt;p&gt;CPLEX expects a problem in the form&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/8345748758283935426-130.png" alt=" begin{split} min qquad &amp;amp; g^Td + frac12 d^TWd text{subject to} qquad &amp;amp; c_L leq Ad leq c_U 						 &amp;amp; d_L leq d leq d_U end{split} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;and is called by&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

cplex = Cplex('test');

cplex.Param.feasopt.tolerance.Cur = 1e-8;

if params.printLevel &amp;lt; 8

    cplex.DisplayFunc = [];

end

cplex.Model.sense = 'minimize';

cplex.Param.qpmethod.Cur = 1;

cplex.addCols(gk,[],bl-xk,bu-xk);

cplex.addRows(-ck, A0, -ck);

cplex.Model.Q = W;

cplex.Model.obj = g;

cplex.Model.lb = d_L;

cplex.Model.ub = d_U;

cplex.Model.lhs= c_L;

cplex.Model.rhs= c_U;

cplex.solve();

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:40:57 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/cplex_matlab_interface.html</link>
                <guid>cplex_matlab_interface</guid>
                <pubDate>Wed, 01 Feb 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>a trig problem solved in MATLAB</title>
                <description>&lt;div id="layout-content"&gt;

&lt;table class="imgtable"&gt;&lt;tr&gt;&lt;td&gt;

&lt;a href="http://www.reddit.com/r/matlab/comments/p4b4s/nothing_feels_as_good_as_getting_a_somewhat/"&gt;&lt;img src="http://i.imgur.com/yOswe.jpg" alt="diagram" height="209px" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/td&gt;

&lt;td align="left"&gt;&lt;p&gt;I came across &lt;a href="http://www.reddit.com/r/matlab/comments/p4b4s/nothing_feels_as_good_as_getting_a_somewhat/"&gt;this&lt;/a&gt; post. The basic idea is the guy wants to maximize &lt;img class="eq" src="eqs/2070911567435834787-130.png" alt="L_1+L_2" style="vertical-align: -3px" /&gt; 

constrained to this box, where &lt;img class="eq" src="eqs/6653501418137561499-130.png" alt="L_i" style="vertical-align: -4px" /&gt; is the length of beam &lt;img class="eq" src="eqs/13440040424-130.png" alt="i" style="vertical-align: -1px" /&gt;. It's constrained

to be a 61 cmx61 cm box, but one beam must start from 10cm up from the bottom 

right corner and the beams must meet at a point along the top of the box.

I added the further assumption that the other beam must end in the bottom left 

corner.&lt;/p&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/6875492102792034284-130.png" alt=" begin{split} 	T_1 =&amp;amp; L_1sintheta_1 	51 =&amp;amp; L_2costheta_1 	T_2 =&amp;amp; L_2sintheta_2 	61 =&amp;amp; L_2costheta_2 end{split} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;which fall from simple trig. There's one more equation, which constrains the side length to 61 cm:&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/7569030847154539588-130.png" alt=" T_1 + T_2 = 61 " /&gt;

&lt;br /&gt;&lt;/div&gt;



Next, I squared each pair of equations to get



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/7606720134884816401-130.png" alt=" begin{split} 	T_1^2 =&amp;amp; L_1^2sin^2theta_1 	51^2 =&amp;amp; L_1^2cos^2theta_1 	end{split}implies 	L_1^2 = T_1^2 + 51^2 " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;and similarly &lt;img class="eq" src="eqs/7140644357327633665-130.png" alt="L_2^2=61^2+T_2^2" style="vertical-align: -5px" /&gt;. &lt;/p&gt;

&lt;p&gt;I'm planning on using MATLAB's FMINCON, which means I need to formulate this as a minimization problem. This is accomplished by observing&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/7458785666452681016-130.png" alt=" 	max f(x) iff min -f(x). " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;Therefore, the final nonlinear program that I want to solve is&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/6976589928226967925-130.png" alt=" begin{split} 	min qquad &amp;amp; -L_1 - L_2 	text{subject to} qquad &amp;amp; L_1^2 -T_1^2 - 51^2 = 0 							 &amp;amp; L_2^2 -T_2^2 - 61^2 = 0 							 &amp;amp; T_1 + T_2 - 61 = 0 end{split} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;which can be solved with the matlab program&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

function xsol = solveproblem()

f = @(x) -x(1)-x(2);

x0 = [0;0;0;0]; LB=[0;0;0;0];

settings = optimset('TolFun',1e-8,'Algorithm','interior-point');

xsol = fmincon(f,x0,[],[],[],[],LB,[],@nonlincon,settings);



function [c,ceq]=nonlincon(x)

l1=x(1);l2=x(2);t1=x(3);t2=x(4);

c=[];

ceq = [l1^2-t1^2-51^2;

        l2^2-t2^2-61^2;

        t1 + t2 - 61];

end

end

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When run, this produces a length 140.5 pair of beams. Hooray&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:41:01 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/a_trig_problem_solved_in_matlab.html</link>
                <guid>a_trig_problem_solved_in_matlab</guid>
                <pubDate>Wed, 01 Feb 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>spamfunc for optimization in matlab</title>
                <description>&lt;div id="layout-content"&gt;

&lt;div id="toptitle"&gt;

&lt;h1&gt;what spamfunc is&lt;/h1&gt;

&lt;div id="subtitle"&gt;In developing optimization algorithms, one of the most tedious parts is trying different examples, each of which might have its own starting points or upper or lower bounds or other information.

The tedium really starts when your algorithm requires first or second order information, which might be tricky to calculate correctly.

These bugs can be pernicious, because it might be difficult to differentiate between a bug in your algorithm and a bug in your objective or constraint evaluation.

Handily, Northwestern Professor &lt;a href="http://users.iems.northwestern.edu/~4er/"&gt;Robert Fourer&lt;/a&gt; wrote a language called &lt;a href="http://www.ampl.com/"&gt;AMPL&lt;/a&gt;, which takes a programming-language specification of objective and constraints and calculates derivatives as needed.

The official amplfunc/spamfunc reference is contained in &lt;a href="http://ampl.com/REFS/HOOKING/#UsewithMATLAB"&gt;Hooking Your Solver to AMPL&lt;/a&gt;, but I'm shooting for a more low-key introduction.&lt;/div&gt;

&lt;/div&gt;

&lt;p&gt;You'll need to compile spamfunc before using it, but I'm saving that for last&amp;ndash;until after I've shown off it's power a little bit.

You'll also need a .nl file for spamfunc; these are generated by AMPL's command line program from an AMPL .mod source file.

I'll be using rosenb.nl as my example here, for the Rosenbrock function.&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

&amp;gt;&amp;gt; [x0,bl,bu,lam,cl,cu]=spamfunc('rosenb.nl');

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This serves as the initialization. It's worth noting the mathematical form AMPL bends your problem into.

In particular, AMPL's spamfunc returns your problem in the form&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/979121563542324325-130.png" alt=" begin{split} 	min qquad 		&amp;amp; f(x) 	text{s.t.}qquad 	&amp;amp; c_L leq c(x) leq c_U 						&amp;amp;	 x_L leq x leq x_U. 						end{split} " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;So we've initialized 6 variables for our environment: the initial &lt;img class="eq" src="eqs/5999452984665080490-130.png" alt="x_0" style="vertical-align: -4px" /&gt; we specified in the mod file, lower(&lt;img class="eq" src="eqs/5999452984665080534-130.png" alt="x_L" style="vertical-align: -3px" /&gt;) and upper bounds on those variables, the initial Lagrange multipler(lam, short for &lt;img class="eq" src="eqs/9213219682577124982-130.png" alt="lambda" style="vertical-align: -1px" /&gt;), and the lower(&lt;img class="eq" src="eqs/799031295774617235-130.png" alt="c_L" style="vertical-align: -3px" /&gt;) and upper(&lt;img class="eq" src="eqs/799031295774617228-130.png" alt="c_U" style="vertical-align: -4px" /&gt;) bounds on the constraints.

To get zeroth order information(that is, &lt;img class="eq" src="eqs/509596383745784049-130.png" alt="f(x)" style="vertical-align: -5px" /&gt; and &lt;img class="eq" src="eqs/5473439298489947164-130.png" alt="c(x)" style="vertical-align: -5px" /&gt;) for a particular point &lt;img class="eq" src="eqs/15360046201-130.png" alt="x" style="vertical-align: -1px" /&gt;, just call spamfunc again with the the &lt;img class="eq" src="eqs/15360046201-130.png" alt="x" style="vertical-align: -1px" /&gt; you'd like to evaluate at, as in&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

&amp;gt;&amp;gt; [f,c] = spamfunc(x,0);

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To get first order information(the gradient of the objective and Jacobian of constraints), call spamfunc as&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

&amp;gt;&amp;gt; [g,A]=spamfunc(x,1);

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;so that the gradient &lt;img class="eq" src="eqs/2963955257387299826-130.png" alt="nabla f(x)" style="vertical-align: -5px" /&gt; is stored in g, and the &lt;img class="eq" src="eqs/5826031279503259477-130.png" alt="i^{th}" style="vertical-align: -1px" /&gt; row of A is the transposed-gradient &lt;img class="eq" src="eqs/447010879752046272-130.png" alt="(nabla c_i(x))^T" style="vertical-align: -5px" /&gt;.

That is, the entry &lt;img class="eq" src="eqs/4385172453074458281-130.png" alt="A_{ij}" style="vertical-align: -6px" /&gt; of the matrix &lt;img class="eq" src="eqs/8320025024-130.png" alt="A" style="vertical-align: -0px" /&gt; is the derivative &lt;img class="eq" src="eqs/4962808113126072433-130.png" alt="frac{partial c_i(x)}{partial x_j}" style="vertical-align: -11px" /&gt;.&lt;/p&gt;

&lt;p&gt;Finally, to get the Hessian of the Lagrangian, call spamfunc with just the multipliers &lt;img class="eq" src="eqs/9213219682577124982-130.png" alt="lambda" style="vertical-align: -1px" /&gt;, as in&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

&amp;gt;&amp;gt; WL = spamfunc(lam);

&amp;gt;&amp;gt; WF = spamfunc(0*lam); % if you just want \nabla^2 f(x).

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here, spamfunc reuses the last &lt;img class="eq" src="eqs/15360046201-130.png" alt="x" style="vertical-align: -1px" /&gt; at which spamfunc(x,1) was evaluated at.&lt;/p&gt;

&lt;h3&gt;how to use spamfunc in your own code&lt;/h3&gt;

&lt;p&gt;Fine and good, but how do you use this in your code?

I'll consider a very simple unconstrained optimization problem(and finally define the Rosenbrock function, if you've been waiting with bated breath).

The &lt;a href="http://en.wikipedia.org/wiki/Rosenbrock_function"&gt;Rosenbrock function&lt;/a&gt;&amp;ndash;or, Rosenbrock's banana function, as I'll be calling it from now on, is defined as&lt;/p&gt;



&lt;div class="eqwl"&gt;&lt;img class="eqwl" src="eqs/3857563474723003589-130.png" alt=" 	f(x_1, x_2) = 100(x_2 - x_1^2)^2 + (1-x_1)^2 " /&gt;

&lt;br /&gt;&lt;/div&gt;&lt;p&gt;If we wanted to use our spamfunc interface to solve this, we'd generate the .nl file as described below, then do a standard Newton method iteration.

Since Newton steps are defined as &lt;img class="eq" src="eqs/6981674424188171082-130.png" alt="p_k = -nabla^2 f(x_k) nabla f(x_k)" style="vertical-align: -5px" /&gt; and then the iterate is updated as &lt;img class="eq" src="eqs/1144455162036380271-130.png" alt="x_{k+1}=x_k + p_k" style="vertical-align: -5px" /&gt;, the most basic possible form of the algorithm is&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

[x,bl,bu,lam,cl,cu]=spamfunc('rosenb.nl');



grad = inf;

while norm(grad) &amp;gt; 1e-6

	    [grad,A] = spamfunc(x,1);

	    W = spamfunc(lam);

	    pk = -W\grad;

	    x = x + pk

end

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: This is a terrible algorithm; there're no bells and whistles like line search, Hessian modification, etc. But it demonstrates calling at least a couple of spamfunc options.&lt;/p&gt;

&lt;h3&gt;how to compile spamfunc&lt;/h3&gt;

&lt;p&gt;I recovered an outline for building spamfunc and amplfunc from a project I've worked on; it should get you a compiled spamfunc binary.

You need to make sure to have mex (MATLAB's compiler wrapper) in your path and properly configured.&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

&lt;span class="builtin"&gt;wget&lt;/span&gt; --ftp-user anonymous --ftp-password traviscj@traviscj.com ftp://netlib.org/ampl.tar

&lt;span class="builtin"&gt;tar&lt;/span&gt; xf ampl.tar

&lt;span class="statement"&gt;cd&lt;/span&gt; ampl/solvers

sh configurehere

mv makefile makefile.dist

&lt;span class="builtin"&gt;sed&lt;/span&gt; &lt;span class="string"&gt;"s/CFLAGS = -O/CFLAGS = -fPIC -O/g"&lt;/span&gt; makefile.dist &lt;span class="operator"&gt;&amp;gt;&lt;/span&gt; Makefile

make

&lt;span class="statement"&gt;cd&lt;/span&gt; examples

&lt;span class="comment"&gt;# following line should reflect where mex(1) is.&lt;/span&gt;

export PATH=/meas/bin:$PATH

mv makefile makefile.dist

&lt;span class="builtin"&gt;sed&lt;/span&gt; &lt;span class="string"&gt;"s/- o/-o/g"&lt;/span&gt; makefile.dist &lt;span class="operator"&gt;|&lt;/span&gt; &lt;span class="builtin"&gt;sed&lt;/span&gt; &lt;span class="string"&gt;"s/mex -I/mex -ldl -I/g"&lt;/span&gt; &lt;span class="operator"&gt;&amp;gt;&lt;/span&gt; Makefile

make spamfunc.mex amplfunc.mex

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It's worth noting the difference between amplfunc and spamfunc; amplfunc returns dense matrices while spamfunc returns them in sparse format.

MATLAB can do linear algebra on sparse format matrices much more efficiently than dense format matrices(as long as the matrices themselves are sparse enough!)&lt;/p&gt;

&lt;h3&gt;how to generate nl files&lt;/h3&gt;

&lt;p&gt;In the above examples, I started with an AMPL source file, rosen.mod.&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blocktitle"&gt;rosenb.mod&lt;/div&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

var x {1..2};



minimize obj: 100*(x[2] - x[1]^2)^2 + (1-x[1])^2;



let x[1] := 1.2;

let x[2] := 1.2;

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This file tells AMPL what how many variables you need, how you'd like to name them, what objective function you're minimizing, and what initial values they should take.

To compile it to a .nl file, use&lt;/p&gt;

&lt;div class="codeblock"&gt;

&lt;div class="blockcontent"&gt;&lt;pre&gt;

$ ampl -P -ogrosenb rosenb.mod

&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Congratulations! You now have a .nl file to feed into your super sweet solver!&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:41:09 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/spamfunc_for_optimization_in_matlab.html</link>
                <guid>spamfunc_for_optimization_in_matlab</guid>
                <pubDate>Mon, 30 Jan 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>VirtualBox and HRD/JT65</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;One of the semi-frustrating aspects of the state of computing and ham radio is the unavailability of some software packages on OSX.

In particular, I've been interested in experimenting with JT65 and also wanted to use my Yaesu FT-857d's CAT cable to program memories and also try out HRD.

(I should add&amp;ndash;I've tried the JT65 stuff and some Yaesu memory programmers, but wasn't satisfied with the Linux setup for those.

I'll probably look into getting them working more later, but for now, this article.)&lt;/p&gt;

&lt;p&gt;In any case, I use VirtualBox with a Windows install to get support for these packages.

The difficulty, though, is getting the Signalink interfaced with Windows programs.

I've been unable to get them to interface directly, but one workaround is to:





&lt;/p&gt;

&lt;p&gt;This works, but there's another difficulty now: Your windows sounds will be broadcast over the air, which is a bit of a &amp;rsquo;'lid&amp;rsquo;&amp;rsquo; mistake. So probably turn off oyur Windows sound effects as well.&lt;/p&gt;

&lt;p&gt;Congratulations! You have an OSX box running Windows running ham radio software!&lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:41:09 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/virtualbox_and_hrdjt65.html</link>
                <guid>virtualbox_and_hrdjt65</guid>
                <pubDate>Tue, 10 Jan 2012 00:00:00 +0000 </pubDate>
        </item>
	
        <item>
                <title>tcjblog.py</title>
                <description>&lt;div id="layout-content"&gt;

&lt;p&gt;I've now (for the most part) finished a working version of some software I've

wanted to tackle for a while. I call it tcjblog.py. It's a blog platform built

using &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc.py&lt;/a&gt; to format simple text files into

nice looking HTML. What're the benefits of this, and features of tcjblog.py in 

general?&lt;/p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;p&gt;Simple, text file management of blog posts. (I control these with git.)&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Ability to include LaTeX markup.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Static HTML for all blog-related pages&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Entries show up on an index of all posts, the category associated with the post, and the month the post was made.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;An RSS feed displays the formatted entries nicely for RSS readers.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Indexes split posts 10 per page.&lt;/p&gt;

&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Entry URLs are a sanitized version of the page title, so they're auto-perma-links, at least once you're happy with a title.&lt;/p&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;There's still a fair bit of work for it, but probably it's time to focus a bit

on the content and less on the software, at least until it seems more pressing.

This has been a great couple-afternoon project for me&amp;ndash;a nice break from the

almost 5000 lines of numerical/algorithms stuff in C&lt;tt&gt;&lt;/tt&gt; I've done in the last couple of weeks.&lt;/p&gt;

&lt;p&gt;It's worth noting that the static approach generates a fair number of files for this approach: one for each entry, one for each category, and one for each month, plus a tenth of the total number again for the index pages. So I use a makefile to manage all of it. &lt;/p&gt;

&lt;div id="footer"&gt;

&lt;div id="footer-text"&gt;

Page generated 2012-04-15 17:41:09 CDT, by &lt;a href="http://jemdoc.jaboc.net/"&gt;jemdoc&lt;/a&gt;.

&lt;/div&gt;

&lt;/div&gt;

&lt;/div&gt;
</description>
                <link>http://traviscj.com/blog/tcjblogpy.html</link>
                <guid>tcjblogpy</guid>
                <pubDate>Fri, 09 Sep 2011 00:00:00 +0000 </pubDate>
        </item>
	
</channel>
</rss>
