29 November 2010

Shipping Packages

Popular Mechanics did an interesting article/experiment on how companies handle shipping packages.  Specifically, they used a set of sensors to record things like temperature and acceleration, to see how well the packages were handled (or mis-handled) during their voyage.

I think this is a really cool article because I once had an idea to do something similar for a start-up company.  The idea was for a customer to receive a small tracking device which he would then place inside his package before shipping.  This device would then be returned to the company to check if the package was handled correctly.  The target audience is for items that are fragile or require very special handling, such as scientific instruments.  Parameters I thought we could track would include acceleration (for drops/large bumps), water/humidity, temperature, magnetic field (for scientific instruments...?), and GPS location.  Most of these sensors are already available in many hand held smart phones nowadays.  It would also be interesting to couple this with some type of shipping insurance, since the data from a recorder would provide excellent, concerte evidence of mis-handeling.

That being said, while I find this to be an interesting article, to some extent the real question is "who cares?"  We all know that these shipping companies throw our stuff around.  But we also know that our orders are placed in lots of packaging to prevent damage.  I love buying stuff online... books, computers, electronics.  Lots of expensive and seemingly fragile stuff, yet I would say 99.9% of everything I have ever ordered has come in perfect, working condition.  Maybe we should just turn a blind eye to how things are handeld mid-transit if, in the end, the company can deliver on its promise to sucessfully deliver them un-damaged.  Sometimes, isn't it better just to not know what's going on?

22 November 2010

Matrix Inverse

Oh The Complexity!

I'm doing something that most numerical computing people would consider crazy -- I'm computing the analytical inverse of a square non-singular (although ill-conditioned) matrix. I'm doing this as a solution to a differential equation, which I need to be able to evaluate very quickly very very many times (100,000's of times), so naturally I am coding up the problem in C.

Its amazing how quickly the closed-form solution becomes complex as the order of the matrix increases. For example, the quite trivial case for the inverse of a 2x2 matrix can be written in just 5 lines:

    // inv(A)
    scalar = (1.00/ (A[0][0]*A[1][1] - A[1][0]*A[0][1]));
   
    invA[0][0] = scalar * A[1][1];
    invA[1][1] = scalar * A[0][0];
    invA[1][0] = scalar * -1.00*A[1][0];
    invA[0][1] = scalar * -1.00*A[0][1];

Ok, that was trivial!  The code for a 3x3 inverse is longer, but still quite manageable.

  double z;
  double invX[3][3];
 
  z = X[0][0] * (X[1][1]*X[2][2] - X[2][1]*X[1][2]) + X[1][0]*(X[2][1]*X[0][2] - X[2][2]*X[0][1]) + X[2][0]*(X[0][1]*X[1][2] - X[1][1]*X[0][2]);
  z = 1/z;
 
  invX[0][0] = z*(X[1][1]*X[2][2] - X[2][1]*X[1][2]);
  invX[0][1] = z*(X[2][1]*X[0][2] - X[0][1]*X[2][2]);
  invX[0][2] = z*(X[0][1]*X[1][2] - X[1][1]*X[0][2]);
 
  invX[1][0] = z*(X[2][0]*X[1][2] - X[1][0]*X[2][2]);
  invX[1][1] = z*(X[0][0]*X[2][2] - X[2][0]*X[0][2]);
  invX[1][2] = z*(X[1][0]*X[0][2] - X[0][0]*X[1][2]);
 
  invX[2][0] = z*(X[1][0]*X[2][1] - X[2][0]*X[1][1]);
  invX[2][1] = z*(X[2][0]*X[0][1] - X[0][0]*X[2][1]);
  invX[2][2] = z*(X[0][0]*X[1][1] - X[1][0]*X[0][1]);

Now consider the inverse of a 6x6... let me just say its messy.  Very messy.  Messy enough that its nearly impossible to be able to do it out by hand on a white board and sucessfully type it up into C. It was easier to find the solution using MATLAB's symbolic math toolbox, then reformat the result from MATLAB into C.

The next thing to ask -- why use an analytical solution at all?  If you asked about this on a forum post, most people would direct you to some other algorithm such as QR or LU decomposition, as implemented in LAPACK or some other free "off-the-shelf" numerical software package.  I have my reasons against this:

(1) Its true, most of the algorithms in LAPACK are highly optimal, however they are optomized for working with very HUGE systems of matricies (with dimensions in the 100's or even 1,000's).  Generally, doing this kind of math is "trivial" on small matricies (2x2, 3x3) is very easy to do by hand, and the focus of most numerical computing work has been on really large systems.

(2) Using LAPACK adds to the complexity of the code.  It requires that the correct libraries be installed.  It also means that the code can't easily be compiled on another platform, for example as a CUDA or other GPU-type program.  Again, it seems like overkill to make the whole program much harder to port onto different systems just to solve one little 6x6 matrix inverse.

I have also investigated 3rd party C implementations, such as Jordan Exchange or LU decomposition.  As I said before, however, this is a fairly ill-conditioned matrix for some cases, and these numerical methods tend to introduce a lot of error into the result which could affect the performance of the overall algorithm.  Its also true that most of these implementations require many conditional statements (e.g. for choosing columns for pivoting), and are therefore inefficient when implemented on a GPU.

In conclusion, there are a lot of great resources out there for solving large systems of equations; there are also fairly trivial solutions to simple systems.  What I'm struggling with is where my problem lies -- is it trivial enough to warrent a hommade analytical solution, or does it the use of some external software library, such as LAPACK (and all the associated headache of getting that to work)?

27 October 2010

Hard Drives, Etc

Been doing some work on my computer, as usual. I have really wanted an SSD (solid state hard drive) for a while now, as I've found that my user experience with Windows 7 is gradually slowing down (or maybe my expectations are just gradually increasing). A recent set of blog posts (Jeff Atwood & Linus Torvalds) suggest that an SSD may be the most cost-effective performance boost right now, and judging by the amount of clicking and grinding my hard drives are going through whenever I try to launch a program or interact with my computer, I think this may be a real issue which I have not previously addressed.

However, having recently spent a considerable amount of money on guitar equipment and a Halloween costume, I'm not really in the position to blow another $200+ on a hard drive that is only 80GB large! As an alternative, I decided that it was time to take a step back and look at the current resources I have to work with. My computer, in terms of hard disk arrangement, was a complete MESS. I have 4 hard drives, about ~2.5 TB worth of storage space, but chunked up into many medium-size partitions. The main reason I've gotten into such a mess when it comes to disks is:

(1) I tend not to really have an "upgrade roadmap" for disks, as I typically do for other components such as CPU/Mobo/RAM, and video card (for these, I have an idea of when they'll become obsolete, when the newer technology hits the price point I'm willing to pay, and what components I can buy knowing they'll last past several iterations of computer upgrades). And I never buy brand new disks when building a new system, nor factor them into the overall cost of a computer.

(2) I tend to buy disks as they come on special sales at SlickDeals (or if I have a BustBuy er.. BestBuy gift card to blow), so they all have mis-matched Manufacturer/Capacity/Performance/Cache Size.

(3) I tend to choose which disks to keep in my system based on their size, not performance. With a limited number of SATA ports (4 - 1 for CD-ROM), I just keep the 3 biggest disks around.

(4) Most of my important data has been historically spread across many different disks, partitions, and file system formats, and I always have too much to fit on one single disk. So when I want to install a new OS, I typically find a disk that has enough free space to throw on a partition and go from there. The result has been that the drive I choose for an install is more based on where data already is than the optimal configuration.

Recently I solved problem #4 by buying a relatively high-performance (WD 'Black' /w 32MB cache) 1TB drive and creating a "dump" of all my most precious data. Another way to go, of course, is to get a NAS or similar external drive enclosure. For the purposes of home computing, I think this is a really bad idea for a number of reasons:

(1) If you use an external hard drive, your performance suffers greatly! Most of these things are still USB or FireWire, and even if its the faster Firewire spec, its still nowhere near as good as a SATA drive. Yes, you can get ones that have eSATA, but there is a significant price penalty. Also, I have found some incompatibilities, such as certain drives only working at SATA-I with certain enclosures.

(2) External enclosures are usually louder than internal ones. You already have a perfectly good "enclosure" sitting at your desk: your computer case! Why add more junk? Yes, they're more portable, but in today's age of network & Internet file sharing, its doubtful you will want to physically lug around several Terabytes of your data (not to mention reliability and security issues!).
(2b) If you buy a pre-configured enclosure, the exact specs of the drives inside are often unclear. Its also often unclear if you can take it apart, put a bigger hard drive, or replace a failed hard drive.
(2c) If you buy a separate enclosure system and hard drives, it can be difficult to determine if the thermal transfer of that enclosure will be sufficient to cool your disks and not shorten their life span. It also adds yet another price overhead that can be completely avoided by sticking the drive in your computer.

(3) Using a NAS at home doesn't make sense: sure its great that you have all of your data easily network-accessible to all computers/devices in your home (and in some cases, on the Internet as well), but then you also have slow (NETWORK) access to all machines. If you have the disks inside your computer, its almost trivially easy to setup a Samba share in Windows that achieves the same level of data sharing AND have it be very FAST on at least one computer!


Coming off my rant on external drives & NAS, I decided to think about something I never did before: Performance. So I ran several HDD benchmarks, and here were the results:

(1) I had my OS installed, for "historical reasons" (i.e. this was the free disk I had laying around at the time) on a 0.5 TB drive which was actually my SLOWEST internal hard drive. I had backups running to a 0.75 TB drive which was significantly faster.

(2) As expected, my data-drive ('Home') was on the fastest drive, a 1TB Western Digital. However, because this was in an eSATA external enclosure, it was only running at SATA-I instead of SATA-II, so that was a significant area for improvement. It also produced a strange resonance with my desk so it made my system significantly louder.

(3) A good fraction (>25%) of my space was in "dead filesystems", i.e. Ext3 and Hfs+ partitions from Linux & OSX installs I had abandoned a while ago and did not care about the data.

So, in conclusion, I was able to streamline my system down to 2 disks, 4 partitions, and greatly improve performance. My OS disk has 2 80 GB partitions: 1 for Windows 7, 1 for Linux, and 1 500GB partition for a Home Backup. My Home disk continues to be 1TB with 1 partition, but now that its an internal drive it operates at a higher performance. For those hackers out there who ignore their file system and disk plans, take a second look before resorting to more expensive technologies.

Next Post: How I was blown away by the quality of both Win7 and Linux after my recent re-configuration.

20 October 2010

Safari 5 For Windows

I keep getting Apple Updater alerts every so often, because I unfortuantly have iTunes installed on most of my computers (mostly to make it easy to use my iPod, not because I particularly like having a 500MB MP3 player). But I always see under the 'optional updates' section: Safari 5. And so I ask myself, does anyone actually use Safari for Windows? Is it actually considered a real browser, or just some experiment gone horribly wrong? Maybe the only people who actually have it installed are those who are duped into doing so when updating their iTunes...

25 June 2010

Google CL Posting

Post from the command line! http://code.google.com/p/googlecl/

16 June 2010

Rent vs Buy

An interesting article on the relative investment and merits of renting vs. buying a home.

http://www.mint.com/blog/goals/rent-vs-buy/

10 February 2010

Updates, Photos, Etc

I finally sucked it up and fixed my desktop computer after suffering almost half a year of screwed up Windows XP (10 minute boot-up time, wouldn't hibernate anymore, random network drop outs, printer only worked half of the time, etc etc).

The results are quite impressive: Replaced the buzzing stock Intel CPU fan with an unnecessarily monsterous OCZ Vendetta cooler. I got Windows 7 up and running in under a day. Moved over everything important to a new 1 TB hard drive. I now have 3 TB of storage, all of my photos are now managed /w Picasa, and all of my music is (unfortunately) re-imported into iTunes. Most importantly for the first time in almost 3 years all of my data is finally backed up to a secondary hard drive *whew* talk about flirting with disaster!

As a result of the Picasa upgrade, I took down all the pics from the photos section of the website until I can find a better set of newer pics to put up there.

03 February 2010

News Section Moved

The 'Blog' or 'News' section of the site has been moved from http://paradime.net/news to http://blog.paradime.net, because Google no longer supports FTP uploading of blogs. FYI.