Friday, July 31, 2015

Gaussians, Gasses, and Spices.

Today I learned:
1) High-dimensional multivariate gaussians have almost all of their probability in a thin hypersphere shell of standard deviation 1. That’s not as complex as it sounds, so let me try to break it down.

Gaussian: A normal distribution. A bell curve. Basically a function (probability distribution) that looks like a hill, with each of the tails dropping off quite quickly.

Multivariate Gaussian: A normal distribution in more than one dimension. In 2D, that’s a circular hill with a big bulge at the center. In 3D that’s… a spherical blob with a bunch of mass at the center, I guess? A higher-dimensional version is… the same, but in more dimensions!

“Almost all of their probability”: By this, I’m talking about what a statistician might call a “typical set” — that is, there’s some relatively small subregion of the distribution that contains almost all of the mass/probability/weight of the function.

hypersphere shell of standard deviation 1: In the case of a high-dimensional multivariate Gaussian, the typical set is a hypersphere around the center with radius 1 standard deviation — that means that if you take a random sample from, say, a 10,000 dimensional gaussian (this is equivalent to taking 10,000 independent random samples from 10,000 gaussians) and you calculate the distance from the very center of the gaussian to the sample you just took, that distance will almost always be very close to 1. Weird, eh?

Edit: To demonstrate #1, I've put together a quick script, which you can find here: https://github.com/sclamons/QuickDemos (it's MultivariateGaussianTypicalSet.py). Usage:

python MultivariateGaussianTypicalSet.py n_samples n_dimensions

where "n_samples" and "n_dimensions" are the number of samples and the number of dimensions per sample, respectively. Written and tested for Python 2.7. If you have matplotlib installed, it will display a nice histogram of the sample radii; otherwise it will just print the mean radius.

2) There were international treaties in place before World War I banning the use of various kinds of chemical warfare, including “asphyxiating gasses” and various kinds of poisoned weapons, including the use of bullets or artillery containing toxic chemicals. I had always assumed that chemical weapons were *banned* after the war in response to wartime atrocities. Apparently someone foresaw it.

3) It’s harder to tell spices apart by smell than I thought it would be.

Thursday, July 30, 2015

A Quirk of C, Bad Vinegar, and An Old Creation

Today I learned:
1) In C, variables have variable scope by default. Sort of. They can be modified by statements with more interior scope, but aren’t by default made accessible by outer scopes. What I mean is that if you do the following:

int x = 0;
int foo()
{
  x = 1;
}
foo();
printf(“%d”, x);

it will print “1”, because x was modified by foo (!!!!), while if you do

int foo()
{
  int x = 1;
}
foo();
printf(“%d”, x);

you will get a compilation error because x doesn’t exist. The second thing makes total sense. The first thing disturbs me in some mild-but-deep way.

2) Fruit vinegars can, in fact, go bad. Surprisingly bad.

3) I still have a copy of our old custom planechase cards (@Chris Lennox, @Lady Jade Beacham). I also happen to know that Caution has a copy. Did we duplicate them at some point?

Wednesday, July 29, 2015

Hydra Cancer, Putting Stuff in Orbit, and A Book by Bill Bryson

 Today I learned:
1) A bit of a puzzle regarding cancer. See, the genes for cancer, used by cancer and probably required for cancer emerged around the time that multicellularity evolved. This is probably not a coincidence — cancer can’t really be said to happen until there’s a multicellular organism, after all. So we expect cancer to go back to the first multicellular organisms, including sponges and jellyfish. Here’s the puzzle — as far as I know, we’ve never observed a tumor in a sponge. I’m not sure about jellyfish, though hydra *have* been observed with tumors. How do you identify a tumor in a hydra? It could be difficult to tell a tumor from a natural and beneficial but rare growth, after all. In this case, the alleged “tumors” were a) unusual growths b) displaying phenotypes of reproductive structures far from where they usually occur c) with unusual gene expression profiles similar to (though distinct from) tumors in mammals d) capable of being transplanted to other parts of the hydra and spreading throughout the body that e) reduced the fitness of the host. Sounds like cancer to me.

2) It costs somewhere around $25,000 to put a kilogram of material into geosynchronous orbit, and about half as much to put a kilogram of material into low earth orbit. (that’s the market marginal cost per kilogram, not the total cost.)

3) The word “seafood” and the term “dirt road” were invented in America, and spread from there to England and other English-speaking countries. In fact, I’ve been learning about dozens and dozens of such word-spreadings from Bill Bryson’s “The Mother Tongue: English and how it got to be that way”, but those two really stuck with me for some reason. Other little tidbits from that book — the crossword was called a word-cross by its inventor, and crossword puzzles were spurned by major publishers as crass for many decades after their invention (eventually they gave in because they were super-popular).

Jeffreys Prior, Buffalo Sauce, and Skype

Today I learned:
1) If you need to assign a prior probability to a standard deviation parameter (as I mentioned in a TIL a couple days ago), you should use the Jeffreys prior, which is basically p(sigma) = 1/sigma. I know, kind of oddly simple... but that's the only prior probability distribution that's "fair" in the sense that if you'd chosen to make a prior over 1/sigma^2 instead of sigma (which is a totally arbitrary choice), you'd use exactly the same prior. Also, it has the maximum entropy under certain conditions, which is another way to say it's maximally uninformative.

2) It's not known for sure how buffalo sauce got that name, but the most likely reason is that it was invented by a bar in Buffalo.

3) xbox one has a skype app. And it's pretty good.

Monday, July 27, 2015

An Idiom, A Weather Phenomena, and A Fact about Booking Agencies

Today I learned:
1) The idiom "ride 'em hard and put 'em away wet." It refers to horse riding, when you ride a horse hard and then put it away without grooming or taking care of it, and basically means adding insult to injury.

2) Fog that forms in the central valley of California between November 1st and March 31st is called "Tule fog", and it's pretty intense fog.

3) Online hotel reservations have massive profit margins. In fact, one of the primary goals of airline booking agencies is to get you to book hotels, as a booked hotel makes something like 10 times the amount of money as a booked flight. So next time you're booking a flight, watch for hotel advertisements and see just how much they want you to buy that hotel.

Sunday, July 26, 2015

Smelly Chemistry, Beautiful Chemistry, and a new Magic Format

1) Possibly the smelliest chemical in the world is thioacetate. It's the kind of chemical which causes coworkers in a building 200 yards away to complain about if it's accidentally left uncapped. An accidental release of the stuff was responsible for forcing an evacuation of the town of Friedberg, Germany because the scent was making residents ill.

2) How to make bismuth crystals in your kitchen! Basically, you a) melt some relatively high-grade bismuth in a steel (or, less optimally, aluminum) cup on medium-high heat, b) pour the liquid bismuth into a second steel cup, leaving behind any impurities that scum to the surface, c) let the second cup of bismuth cool slowly, then d) once the second cup starts to solidify, pour off some of the liquid bismuth back into the first cup. The remaining bismuth will be crystallized. If they aren't satisfactory, melt it down and try again. If you don't know what bismuth looks like, I recommend checking it out (it's my favorite crystal!)

3) How you cross Dominion with Magic the Gathering. Lady Ŀady Jade Beacham and I playtested some Dominion Magic until we got a balance that worked pretty well. The rules, as succinctly as possible:
-- Open two booster packs, lay them face up. This, plus an infinite number of each basic land type, is the draft pool.
-- Each player starts with a deck of two of each basic land.
-- Players draw 3 cards each draw step (except on the first and second players' first turns, where they draw 2 and 4 cards instead, respectively). If you would draw a card with no cards in your library, you shuffle your graveyard into your library first.
-- At sorcery speed, players may discard any number of lands to draft a card from the draft pool if the lands could produce the mana cost of the card (for instance, discarding two islands and a plains could draft a cancel or an oblivion ring). Drafted cards go to the graveyard.
-- You may cast nonland cards without paying their mana costs.
-- You may play one land per turn (as per usual magic) which you can use to pay for activated abilities.
-- Maximum hand size is equal to the largest converted mana cost of any card in the draft pool (this is to avoid degenerate strategies where you hold all of the lands in your deck in your hand).

This format worked really well with two Return to Ravnica booster packs, and decently well with a pair of Dragons of Tarkir boosters. The RtR packs, in particular, were fun enough to play several games with before we really cracked the format.

Friday, July 24, 2015

Administrative Test

Pardon the dust

Six Things Learned and One Thing Taught

Today is a special guest post of Today I Learned with Lady Jade Beacham.

Lady Jade 1) Stanford built a RNA design video game called EteRNA that asks people to design RNA strands that fold in particular ways.  The community of players discovered some design guidelines that outperformed the best RNA design algorithm (NUPack).

Sam 1) Beavers eat wood. At least, some parts of wood -- branches and bark, in particular. That's pretty unusual for a mammal. Beavers apparently have some kind of microorganisms in their guts that break down the wood, allowing them to digest around a third of the cellulose in it.

Also, it may be that beavers cut down species of tree they don't like (pine, for example) to make room for the species of tree they do like. I'm skeptical of this -- it could alternatively be that they just cut down lots of trees, and leave the ones they don't like alone.

Lady Jade 2) Caltech has a department that is designed to incubate any startups that are gonna start from Caltech grad students and their research - they help them bridge from academia to industry and deal with intellectual property issues and seed capital, and in return, get a chunk of the company.

Sam 2) Apparently reverse engineering is used as a way to get around patents. The idea is that you can have one team of engineers take apart a competitor's product and design spec sheets based on what they find. Then you give the specs sheets to a separate team of engineers and have them design a new product, from scratch, to fit the specs. If you have a nice clean paper trail documenting the whole-cloth design of your product from a spec sheet, you aren't necessarily liable for breaking patent.

Lady Jade 3) You can't pick a lock by pressing all of the pins all the way up and out of the lock cylinder, because the lock cylinder is too short for that.  Lucky because that would be a very easy way to pick any lock.

Sam 3) For most web apps, and some other applications, database lookups are really really bad for code performance. Often a database has to serve many different servers, which makes them very limited resources for the app. In general, don't put lookups in a loop. Instead, do as much precalculation as you can to figure out all the things you need from the database, then retrieve them all in one big query.

Bonus teaching moment: Today we taught that rocks are not alive. We spoke to a waitress today who, as it turned out, believed that rocks were alive ("they must be, because crystals evolve, right?") We informed her otherwise, and explained a bit about how crystals grow, which she seemed very pleased to learn about. Is this what being a professor feels like?

Thursday, July 23, 2015

Bouldering (not Boulders or Boulder), Exoplanets, and the Thermodynamics of Ice Cream

1) How to boulder! The lab went bouldering* today, which reminded me just how much fun climbing stuff is, and also *exactly* how out of shape I am (pretty out of shape, but not hopelessly so). 

* Bouldering is like gym-style rock climbing, but less tall and without the safety lines. Instead, they just have super plushy mats that you fall onto. Falling and rolling out is the most fun part, imho.

2) NASA is holding a press conference tomorrow detailing the latest results from the Kepler Space Telescope, which searches for Earth-like planets in other star systems. The fact that they're having a press announcement, and not just publishing their results like normal scientists, may be a sign of very juicy details about to come to light. Stay tuned!

3) How *not* to make ice cream by hand. The usual method is to put your cream into essentially a thermos with the vacuum part replaced by a slurry of ice and salt, which rapidly cools the interior. Then you turn a crank that scrapes ice crystals off the sides. What you might be tempted to do is to add your ice and salt to the thermus bit, then fill the rest with water to increase thermal conductivity between the ice and the inside container. That would be wrong. It turns out that the cooling is mostly from the enthalpy of fusion of the ice, which is a technical term for the heat that is absorbed by ice as it melts, which it does very quickly because of the salt. The enthalpy of fusion absorbed (is this the right term? Chemists help me out) from melting is much stronger than the effect of conduction from ice-cold water, and adding water just gives you a huge heat source to draw from instead of the interior container, ergo slower cooling of the interior and longer crank times.

Now, this begs the question in my eyes -- what if you fill the thermos bit with saltwater, freeze it (using a -20 freezer, presumably), let it warm until it starts to melt, then add ice cream and start cranking? It seems like that would give you the benefits of both enthalpy of fusion of ice and maximal thermal conductivity.

...or you could just use liquid nitrogen. (http://tinyurl.com/plk5n53 -- note the last step)

Wednesday, July 22, 2015

Curves, Chocolate, and Unconstrained Nonlinear Optimization Without Gradient Information

1) A *roulette*, in geometry, is a planar curve described by a point on a shape (usually a smooth shape like a circle, line, ellipse, or parabola) as it rolls smoothly, without slipping, across, around, or inside another shape. Spirographs are one example. Another quite beautiful example can be found on the Wiki page for "Interpolation" (https://en.wikipedia.org/wiki/Interpolation).

2) There is such a thing as vegan chocolate sorbet. And it is delicious.

3) A couple of different algorithms for nonlinear optimization without gradient information. See, imagine you have a really complicated function of a bunch of variables (say, the function that takes the number of hours you spend on different activities and gives your grade in a class as an output) and you want to find the parameters that minimize (or, in this case, maximize) the value of the function. In general, this is a pretty difficult problem, but there are a bunch of nifty algorithms for figuring it out. Most of the ones I'd been familiar with involve starting with a guess and then iteratively moving some distance in the direction with the steepest slope -- imagine finding the lowest point in a valley by starting somewhere random, then turning in the direction with the steepest downward slope and taking ten steps in that direction over and over and over (warning: do NOT try this at home).

The problem is, that kind of technique requires knowing what the direction of steepest descent is. Usually that's done by calculating the derivative (or in multiple dimensions, the gradient -- it's conceptually the same thing) of the function at that point. Sometimes, though, as in the example above, you *can't* take the derivative of the function.

There are a number of popular solutions to this problem that don't require explicit calculations of the gradient. You could sample the space around you in every direction to try to approximate the derivative, but that's pretty inefficient.

There's another method called simulated annealing where you take a bunch of guesses, then let them jiggle around with some "temperature" (a probability of accepting worse values of the function) which you then slowly turn down. The idea is that the points initially scatter about randomly, then settle down into local minima. When you compare the values of the local minima at the end, you find the global minimum.

Then there are the simplex methods (not to be confused with the completely unrelated simplex method of *linear* optimization), where you start with a simplex (basically a bunch of points scattered evenly around a point -- a triangle in two dimensions or a triangular pyramid in 3D) centered on an initial guess. You check the values of the function at every vertex, pick the *worst* vertex, draw a line from that vertex through the opposite face of the simplex and some distance out the other side, and search very coarsely along that line for a better function value. You do this a bunch of times, and the simplex will ooze its way around the function landscape until it shrinks down to what it thinks is a good point. You can visualize this by laying out a triangle (your simplex) on a 2D landscape (heavily crumpled blankets are pretty good for this), then applying the algorithm described above. Alternatively you can ogle this graphic from wiki's page on the Nelder-Mead Simplex algorithm: http://tinyurl.com/o9sa5h4.

Monday, July 20, 2015

p53, Genomes, and Teflon

1) A bit of background -- p53 is an extremely famous protein that's primarily responsible for preventing cancer via a variety of mechanisms involving detecting DNA damage, repairing DNA damage, and killing the cell if there's too much DNA damage. Given p53's importance in preventing cancer, it's not surprising that p53 is mutated in more than half of cancers -- breaking p53 makes cancer much more likely to happen. So I got this hairbrained idea for preventing (some incidents of) cancer -- basically, put in a backup copy of p53 that's repressed by transcription of the primary copy (for instance, by putting a nuclease-null cas9 gRNA targeted to the backup p53 inside an intron in the primary). If anything stops the primary from being made, the backup switches on, probably along with a marker of some sort telling you that something's gone wrong with the primary.

...except today I learned that most p53 mutations are point mutations, not frameshifts or big deletions or regulatory knockdown like I expected. In fact, something like 3/4 of p53 mutations are *gain of function* mutations, not knockouts at all! So much for that. (If you have Nature Cell Biology accesssee http://www.nature.com/ncb/journal/v15/n1/full/ncb2641.html for more.)

2) Question: How many species' genomes do you have to sequence to detect conservation of a single nucleotide, assuming realistic mutaiton rates and about a 1% error rate? What about an 8 nucleotide conserved region (as in a transcription factor binding site)? What about a 50 bp exon? Think about this for a minute and see what number you come up with.

The answers, according to Harvard professor (and, more impressively to me, former HHMI Investigator), are about 28 genomes, 4 genomes, and 2 genomes, respectively. See http://tinyurl.com/nvnu2e6 (open access!) for details.

3)  Teflon (polytetrafluoroethylene) is damned tough stuff. Among other things, it can "safely" contain dioxygen difluoride. To quote HyperLuminal from chemistry.stackexchange.com: "Known as the gas of Lucifer,[...] It ignites stuff at temperatures that most of the stuff that we breathe in would be in liquid form. No one really knows about its atomic structure (obviously)." Yet Teflon can hold it just fine. Go teflon.

Sunday, July 19, 2015

Planaria, Window ACs, and Color Pairs

1) A bit on how planaria (https://en.wikipedia.org/wiki/Planarian) regenerate. Planaria are tiny little flatworms tens of thousands to hundreds of thousands of cells in size. They're some of the most common creatures on the planet, and if you cut an average planarian in half, it regenerates into two planarians. If you cut it in fourths, it regenerates into four. In fact, you can cut a planarian into any number of pieces and they will all regenerate, provided each piece contains a neoblast. What's a neoblast? A neoblast is sort of a super stem cell for planarians. They have active telomerase and don't, as far as I know, age, and they can regenerate any cell type. They're found diffused throughout the body of a planarian and make up about a quarter of its cell count.

Here's a little (published) anecdote to give you an idea of how powerful neoblasts are. Some scientists (named Wagner et al) exposed a sexual strain of planaria to lethal doses of radiation (some planaria strains reproduce sexually, some asexually, I believe by splitting in half). Some of these were implanted with a single neoblast from a related asexual strain of planaria. Not all of the implantees survived, but the ones that did regenerated their lost body parts, grew up normally, and started reproducing asexually. As the authors of the review where I ran across this put it, "[i]magine if a very old and sick person could inject a single stem cell, frozen away since youth, under his/her skin and rejuvenate their body -- youthful and disease-free!" In some sense, though, this is even weirder -- it's like an old and sick dying person injected a single stem cell from someone else and transformed into that person -- youthful and disease free!

2) How to install a window AC unit. To whit, http://www.lowes.com/projects/build-and-remodel/install-a-window-air-conditioner/project. Thanks Lowe's!

(Sadly, I also learned that window AC units are not allowed where I live. Oh well.)

3) Good color pairs for the color blind -- check out about 4/5ths of the way through this article for a set of 8 colors that are pretty well distinguishable even under the three most common forms of color blindness: http://jfly.iam.u-tokyo.ac.jp/color/

Saturday, July 18, 2015

Pluto, Haskell, and Star Trek

1) There are mountains on Pluto. Mountains of ice. Young ones. Where did they come from? We still have much to learn.

2) How to code in Haskell! Ok, not really -- I'd actually read a bunch on Haskell over the years, and even coded up a few snippets. Today, though, I put together a Haskell program that's actually useful for something useful. Not very useful, mind you, but at 100-ish lines it's by far the most I've done in Haskell (and 100 Haskell lines does more than you'd think it would). Haskell is an unusual language... I once asked a friend of mine why he'd done a project in Haskell, and his answer was "It's fairly difficult to write a program in Haskell that will compile and still not do what you want." The flip side to this is that it's one of the more difficult languages in which to get things to compile. It's quite common to get errors like:

"Couldn't match expected type ‘Color -> [(Card, Int)] -> b’
                with actual type ‘[Char]’
    Relevant bindings include
      output :: [b] (bound at process_cube.hs:28:9)
    The function ‘unlines’ is applied to three arguments,
    but its type ‘[String] -> String’ has only one
    In the expression: unlines list_cards_with_color c merged_cards
    In the first argument of ‘map’, namely
      ‘(\ c -> unlines list_cards_with_color c merged_cards)’"

*sigh*. Not the most helpful, eh? One thing I've discovered is that a heck of a lot of errors in Haskell are because either a) the order of operations somewhere isn't what you expect, or b) you tried to treat a list of Foo as thought it were a Foo, or a Foo as though it were a list of Foo.

Another tip for Haskell programming, at least for beginners -- forget efficiency. It will just hold you back. Let Haskell handle the "efficiency" stuff and it will work out fine.

3) ...about Star Trek: Axanar. It's a studio-independent, crowd-funded Star Trek movie of much higher quality than most. It's a monologue-driven (fictional) historical documentary about the Four-Years War, an early conflict between the Federation and the Klingon Empire. It's got some real talent in its cast, including Richard Hatch and Kate Vernon from Battlestar Galactica (Tom Zarek and Ellen Tigh, respectively), and J. G. Hertzler (Martok from Star Trek: DS9). Axanar is still in production, but there's a 20-minute short prelude up on Youtube, which I encourage any Star Trek fans out there to go check out (https://www.youtube.com/watch?t=1112&v=1W1_8IV8uhA). 

Friday, July 17, 2015

The Very First "Today I Learned"

Yes, The Caps Are Necessary

As of now, my "Today I Learned" series will be hosted via Blogger here: http://positivederivative.blogspot.com/. Posts will automatically be pushed to Facebook (odds are, that's where you're reading it right now, so you don't need a link) and to my new Tumblr: http://positivederivative.tumblr.com/. I'm new to both of these mediums, so I'm open to any advice aesthetic or functional. 

Now, for the things I learned today:

1) I learned how to blog! And how to tumblr! This feels kind of like cheating, but I'm excited about it.

2) There is a remarkable variety of lifespans and ageing styles among the basal metazoans (animals). Among the hydras, for example, there are species which appear be healthy and fertile for decades or centuries, but other species that stop producing offspring and die within a few weeks. Similar variety can be found among cnidaria (jellyfish and anemones). Two notable cases are the hydra Campanularia flexuosa (http://www.sciencephoto.com/media/365594/view) and the sponge  Acropora cytherea (http://www.arkive.org/staghorn-coral/acropora-cytherea/#src=portletV3api), two not-particularly-related species that both live in large colonies of many polyps, all integrated into a single organism with continuous connective tissue. In both species, individual polyps show signs of aging (lower ATP production in the hydra, reproductive dropoff and defects in the sponge), but the overall colonial organism remains healthy. 

3) Use caution when stir-frying with wood-ear mushrooms (https://en.wikipedia.org/wiki/Auricularia_auricula-judae). If you put them into a hot, oil-lined pan, they quickly start to pop violently, spewing little bits of hot oil over surprising distances. They seem to behave better with other vegetables around them, or in water-based cooking methods. 


Test II

Simple test (19:55)

Some kind of title here?

(small subtitle)

This post is a test of the (non)emergency posting system and of formatting across media