mathjax

Tuesday, June 25, 2019

Somevideos

physics thing list:PL7aXC0jU4Qk7K778c5nmgQImd6VKKFMYu video:heYshgHFBJA
impa elliptic regularity list:PLo4jXE-LdDTQfW_IQ-umx660Plg9NX-nC video:p2V4hPZn8C'

Tuesday, June 5, 2018

A Nice Table of Set Algebras

I was studying Probability today, I found this interesting table in Oliver Knill's book on probability



I thought this was a nice summary of different set algebras collected in one place. I had never thought of typologies and Borel sigma algebras as other type of set algebras!

I tried to make sense of when and why each was used, but I could not really find a good reason to prefer some systems over another. They appear to be more or less useful depending on contexts.

Importantly, it reminds me that as much as I find the structure of mathematics elegant, somehow the foundations are specified so that things are built to work.

Wednesday, February 26, 2014

File Locking in MATLAB

File locking in MATLAB becomes a problem if you're running a parallel computation -- amongst other things. Say you're running a parameter sweep that requires some files to be loaded into memory. If all your processes are trying to load the same file into their memories at the same time, your program will crash. I couldn't find a nice function in MATLAB that would lock files. But I found a nice hack online used mkdir in shell scripts and incorporated it into my MATLAB scripts using system.

mkdir is a nice function because its atomic, i.e., it creates a folder if one doesn't exist and returns an error if one already exists with the same name. You can leverage this to implement a hacky file lock & release function. Create a directory somewhere and use the system command in MATLAB to mkdir. The name of the created directory will be the name of the file you loaded. If the file already exists, mkdir will throw an error. system returns the exit status of bash scripts as an integer: 0 if successful and 1 if failed.

With all this in mind check out the code below.

function getLock(lockPath,fName)
  d = strcat('mkdir',{' '},lockPath,fName,{' '},'2>/dev/null');
  while system(d{1})
    e = strcat(fName,{' '},'is locked...waiting 10 seconds');
    disp(e{1})
    pause(10)
  end
end

function releaseLock(lockPath,fName)
  d = strcat('rmdir',{' '},lockPath,fName,{' '},'2>/dev/null');
  system(d{1});
end

So this would be implemented in the following way:

dirStruct = dir('/path/to/data/myData.mat')
getLock(lockPath,dirStrcut.name)
load(myData.mat)
releaseLock(lockPath,dirStruct.name)

Thursday, August 22, 2013

Setting up MATLAB on EC2 Cluster

So at this time of this writing, when you search this in google -- you get directed to a bunch of websites with dead links to the MathWorks pdf. Which was kind of annoying. So for the sake of my future-self who might use this and the e-universe that might find this useful, I'm writing this. It's not too bad to figure out using google foo, but its still annoying to trouble shoot.

When I was looking up how to do this, I found a really cool set of directions that sent compiled MATLAB directives from a licensed computer to your EC2 instance. It seemed like a lot of work though and unlike that poor fellow, I was fortunate enough to have a access to a designated machine license key (so no connecting to license server BS).

These directions are to install MATLAB on an Ubuntu EC2 cluster. I don't imagine the instructions are much different for another *nix machine.

  1. Start an EC2 instance -- make sure you have SSH access, login
  2. Obtain a copy of the MATLAB install files
    1. Take your activation key (which you got from an administrator or something) & go the the matlab website and sign up for an account
    2. With your activation key create your license. You'll need to associate the license with the mac address of the EC2 instance you're using. You can obtain that with the following command:
      /sbin/ifconfig eth0 | grep HWaddr
    3. Email the license file & number to yourself (there should be an option to do this in the dialogue box)
  3. SCP the MATLAB installer files to your EC2 instance
    scp -ri /path/to/*.pem /path/to/folderToTransfer ubuntu@ec2-*.compute.amazonaws.com:/path/to/destination
    r - recursive copy, so copy all folders and subfolders in filepath
  4. Create a folder where you want the install to go (in the previous step, you transfered the installer -- when you make this folder, you're making the folder where MATLAB will actually go). Use chmod 777 to change the permissions on the new folder, so that the installer can write to it.
  5. Unzip the installer (you'll need to apt-get unzip). Make a copy of installer_input.txt and open the copy. In the copy, scroll down and set the appropriate variables. I set: destinationFolder, fileInstallationKey (which you emailed to yourself in step 2), agreeToLicense, and mode.
  6. In the same folder run: ./install -inputfile [nameOfEditedInputFile]
  7. The install should start running now. After its done navigate to path where you created your folder. Create a directory called: licenses. Navigate into it.
  8. Go back to your email from step 2 -- there should be an attachment to it. It contains all the toolboxes you're licensed for. Start nano (or whatever text editor you use), and copy and paste its content into the terminal. Save as license.lic
  9. I got stuck at this point for a while. You can't start matlab yet because it will complain that it's missing some libraries. After some google foo, I realized that it's looking for some window management display libraries. They don't come preinstalled with the EC2 instance because you're running everything on command line. So just install the libraries.
    sudo apt-get install libxt6
    sudo apt-get install libxmu6
  10. Navigate to MATLABROOT/bin (where MATLABROOT is where you installed MATLAB). Run ./matlab
  11. Add to .profile: alias matlab="MATLABROOT/bin/matlab"
  12. If you want the compiler to, run mbuild -setup.

    fin

Monday, January 7, 2013

Bing Wallpaper Changer

Check out this script that take the bing.com picture of the day and posts it as your wallpaper. I run Ubuntu 12.04 -- but even if you run this OS, you'll need to modify the script a little bit. Make sure to read the README -- getting it to work with cron was painful, but the solution (for me) was easy.

Sunday, October 7, 2012

Anatomy of a Fire

I currently stay with a chemistry grad student. He occasionally starts a fire pit in the back. Somehow, we got to pontificating on why fire looks the way it does. I thought to synthesize his hunches because: 1. they sounded right 2. i have no reason to doubt a phd chemist 3. it sounded cool

Basically wood is a solid fuel. It's packed densely with cellulose (amongst other sugar chains and other long chain molecules). Heat liberates these sugars (along with other molecules). As the heat increases, the sugars themselves decompose into alcohols. The liberated decomposed sugars and other molecules become a gas. What we observe as the flames of the fire is oxidation of this heated gas. The escaping gas ignites under heat and oxygen, giving the fire its characteristic flicker. The light and heat we feel from a fire is actually the radiation from this oxidation reaction. Some of liberated radiation in the visual spectrum (the light of the fire). A lot of the heat we feel from the fire is radiation released in the IR spectrum.

The flame persists for a while because the fire is a self-catalyzing reaction. The radiation released from the oxidation reaction becomes the heat that's used to liberate more molecules from the wood. This creates more gas. New oxygen diffuses in and reacts with the heated gas -- releasing even more energy that's again used to liberate more gas. This is why fanning flames sometimes help fires catch. When you fan, you blow away the gas and replace it with a bunch of oxygen. So when you stop fanning, there's a lot of oxygen for the gas to react with. But it's also important not to fan too much. You run the risk of decreasing the temperature of the reaction zone above the wood.

The embers of charcoal that are left glowing is actually extremely hot carbon remnants of the wood. The heat and light we see from charcoal is actually blackbody radiation. You'll notice if you pick up what's left from a fire, the wood is considerably less dense. Basically, the solid sugar fuel for the fire burned up, leaving the carbon shell of what held the fuel. This carbon shell itself glows when its hot. The charcoal you buy in a store is basically this stuff ground down to a dust and pressed together with clay.