Archive for February, 2007

Group theory and Unit testing

Posted in Computing 5 years, 3 months ago

While an advanced math degree isn’t absolutely required to be a programmer, it definitely helps one in designing smart unit tests. Here are two examples where I used mathematical properties to design unit tests. Most of my functions that take one of these objects as an argument runs these tests as a pre-condition. Of course, this is switched off in release builds.

SPD Matrices

A type of MRI modality known as Diffusion Tensor MRI can be used to measure the diffusion properties of molecules in tissues. The diffusion is because of the Brownian motion of the molecules. There is a direct connection between the diffusion constant and the local structure in tissues. DT-MRI is pretty much the only non-invasive imaging system for the white matter in the brain.

By making measurements of the diffusion in different directions, we can represent the local diffusion at a voxel by a tensor. This rank-2 tensor is a symmetric positive definite (SPD) matrix. Normal matrices can be thought of as points in a nine dimensional space, but symmetric matrices only have six degrees of freedom. So, instead of being a linear space, the manifold is that of a hyperboloid.

Therefore, it makes sense that any operation done on these matrices should also be a SPD matrix. For example, the group is not closed under the subtraction operation. Literature has many examples of distance definitions for SPD matrices. The log-Euclidean metric for example will fail if your matrix is not a SPD (log of a negative real number is undefined.)

Some properties of SPD matrices:

  • Eigenvalues are positive
  • Determinant is positive
  • Matrix inverse is positive definite

Special Orthogonal/Euclidean

The class of purely rotational matrices fall under Special Orthogonal, while matrices that combine rotations and translations fall under Special Euclidean. They’re both subclasses of general linear transformations. Almost every physics engine will have routines to generate transformations given an angle and a translation vector. Arbitrary transformations can be generated by the composition of transformations along the basis vectors for that space.

Some important properties of these groups:

  • Rows are orthogonal to each other
  • Columns are orthogonal to each other
  • Matrix transpose equals matrix inverse
  • Matrix times its inverse/transpose returns the identity matrix
  • Determinant is equal to +1
  • Columns and rows are normalized

These tests are particularly useful in making sure a multi-disciplinary group is on the same page. Physicists and almost everybody else uses a right hand coordinate system, while Chemists are trained to use the left hand coordinate system. The confusion possibly arises from the definitions of cis- and trans-, I’m not exactly sure. In fact, a quick look at the bible Computer Simulation of Liquids defines rotation matrices as the inverse of the “standard.”

Fast-slow dynamics

Posted in Physics 5 years, 3 months ago

In my non-linear physics class, we are covering topics that I find very interesting: Fast-slow dynamics.

fast-slow.jpg

Consider the system of coupled differential equations above. If the parameter r is extremely small, the equations exhibit two time-scales. From the perspective of the fast equation, the slow equation is almost constant and from the perspective of the slow equation, the fast equation has already reached steady-state. Thus, by appropriately re-scaling time, you can make approximations about the final behavior of the system. I’m still trying to understand the rigorous mathematical analysis that has gone into these equations. If you want to learn more about this re-scaling trick: search for “adiabatic elimination” and “center manifold.”

These techniques are often used in the field of weather prediction. You have dynamics that can act either locally or globally. By making robust approximations, you can get away with weak assumptions about the local effects. This lets you use a bigger timestep that can give you more relevant results.

From my own experience, I can draw parallels to the simulation of chemical systems. In protein simulations, you have solvent effects that are high frequency actions. This forces you to use a small timestep. Some concrete numbers: water molecules have motions in the picosecond range, while we really are only interested in the motion of the proteins on the nano/micro second range. But the action of the solvent is crucial to the dynamics of the protein, so we really cannot get away with ignoring solvent effects. I wonder if I can use a similar analysis to enable the use of a bigger timestep? Probably not, as somebody would have done this already.

Exhausted

Posted in Physics 5 years, 3 months ago

statmech.jpg

I’m pretty exhausted from the talk/discussion that I led at the MIAL today. I spent a lot of time getting the slides to look right, specially the equations. I did this by keying LaTeX equations into emacs, compiling them and importing the resulting PostScript into the Gimp. I imported them at a resolution of 500, which gave me an image of about 4000×4000 pixels (that should be enough for anyone.) From there I cut the equations and pasted them into Powerpoint. I scaled them down keeping the aspect ratio fixed.

There’s got to be a better way.