# Orienting

(You can download this post as a notebook here.)

## Orienting¶

We're in New Zealand for a semester. Recently, Ash Patea was telling us some Māori lore about local mountains. We're based in Whanganui, learning about the mountains Tongariro, Taranaki, and Ruapehu, all of which are to our north. Ash starts all of these sessions off by telling us that we're learning his iwi's stories, but that they're not the only stories. That other stories are different, and none is "right." We then get to the part where we learn that the name "Tongariro" tells you it's a mountain to the south, and Ash says that's how they know the story we're learning isn't their story, and all of a sudden I have to write a little math post.

I don't want to spoil the punchline too much (yes I do), but there's a really neat connection between Ash's language and mathematics, about how you orient yourself in the world, and about how things can't always be consistent.

# Chromebooks for the kids

## Chromebook for the kids

My oldest daughter is 9, and the twins are 6, so it's probably time to get them involved in computer things. I could have done this earlier, but I definitely screwed up with the kids by introducing tech/books/etc. before they were ready, so I decided to wait. The kids are definitely ready, so here are the goals:

• Programming
• Minecraft seems to be the best for this, but I want more than 2GB of RAM. Preferably 8GB.
• Scratch also seems to get a ton of great recs.
• Having an office suite around. The 9yo will be writing papers at school next year, etc.

My original thought was that I'd get a cheap desktop: either a Windows box or a refurbished Mac. I was leaning against Linux because I'm old and it seems like there's a big barrier to entry for Linux. I want this to just work for the kids. Then someone pointed out that we'll be traveling out of the country next year, so a desktop is a bad idea. The cheapo version of a laptop is a Chromebook, but I wanted one capable of running Minecraft. I find a really nice guide to setting up Minecraft on a Chromebook. Of all things, the answer is to install Linux via crouton. Who knew. So, I'll give that a try. The site also has a nice guide to Minecraft-capable Chromebooks. On the high end, the Pixel has all of the stats I could want ... but $1k seems like quite a bit to spend on a "cheapo" laptop. There were some nice$200 models, but I settled on the Asus Flip 2 (Intel Core m3, 4GB of RAM ... not quite the 8GB I wanted). I think the kids will really like the touchscreen and flipscreen. Hopefully they won't fight too much over the single computer.

So, as per the guide,

• Be prepared to Powerwash/revert to factory settings. (In fact, I had to do this because apparently I screwed up a root password in the next step.)
• Enable Developer Mode.
• Install crouton and the crouton Chrome extension (link on crouton page).
• Install Linux

• "Ctrl + Alt + T" gives you a command terminal in Chrome
• shell gives you a shell
• sudo sh -e ~/Downloads/crouton -t touch,kde-desktop
• Switch back to the Chromebook side (shift+ctrl+alt+left arrow at the top of the keyboard).

• Download the Linux Java version of Minecraft from minecraft.net
• Switch back to the linux side (shift+ctrl+alt+right arrow at the top of the keyboard).
• Put Minecraft in a stable place
• mkdir ~/Games
• mv ~/Downloads/Minecraft.jar ~/Games
• You can launch via the command line: java -jar ~/Games/Minecraft.jar
• You can make a KDE shortcut to launch it. It's very particular.
• Open up kmenuedit and make a new item under Games.
• Call it Minecraft.
• Make the command java -jar ./Minecraft.jar
• Under Advanced, make the Work path ~/Games and select Run in terminal
• You can also go into ~/Games, open it up in the file browser via xdg-open . then drag the Minecraft jar file onto the desktop. That gives you an icon which, when double-clicked, will launch Minecraft.

Be aware that exiting developer mode will erase all of the Linux setup from above. Reinstalling it takes about 5 minutes of typing and 45 minutes of letting the computer churn.

So far, the kids seem more than happy with this setup. The crouton Linux install seems to be shared no matter who logs in on the Chromebook, so they can all log in individually on the ChromeOS side, but share the same Linux side. They don't seem to have a problem opening up a command terminal and sudo-launching kde, which is either cool or disturbing. Not sure which :).

# Coin Flipping and Entropy

You can download this whole post as a Jupyter notebook here

## Some useful interactive bits for coin flipping and entropy.¶

I made this post for my 1st semester intro physics class, as a lead in to the standard discussion of entropy (sue me, I can't make myself dive into this without starting from stat mech).

### Say you're going to flip 4 coins. What's the most likely outcome? How likely is it?¶

How should we keep track of outcomes? One easy way is to ask "how many heads did we get?"

# Post-tenure job stress, part 1/N

I'm feeling a little down job-wise, and perhaps looking for some advice.

I got into this job for several reasons, and I can't shake the feeling that I'm set up never to be excellent at any of them. Some are below, not in order.

Super-brief context: I'm likely teaching a 3-3 load (none of these are likely to be research classes) and chairing my department for the foreseeable future. This is in addition to broader campus service, which becomes more relevant the more senior I become.

# Visualizing differential geometry in Jupyter notebooks

(you can download this post as a notebook here)

## Visualizing differential geometry in Jupyter notebooks¶

In [19]:


Out[19]:
In [30]:


Out[30]:

I taught a senior seminar on differential geometry last year. I'll be honest: it was a selfish course. Markus Deserno writes all of these cool papers about membranes, and I didn't know enough math to follow them. So, the goal of our course was basically to learn enough differential geometry to read several of his papers. It was fantastic. We used several of his papers, as well as Kreyszig's textbook, as our core materials.

Here's the thing: a lot of this was pretty foreign to my physics students. In particular, the discussion of surfaces and mappings was new. So, we wrote some tools in Jupyter Notebooks to help us visualize and solve problems. I particularly like the stuff we wrote to visualize a mapping, and I don't know of a comparable resource elsewhere.

As a teaser, the above movies show you how to interpolate between a surface and a curve in the first case, and how the Monge gauge works for a membrane in the second case.

Let's jump in.

# Switching to Nikloa for Jupyter Notebooks and a static site

I've been using WordPress for quite a while, almost entirely because it's an out-of-the-box blog setup that just works. But it kind of sucks for what I mostly want to do, which is stick some code into blog posts. In fact, what usually happens is that I do something in a Jupyter notebook, and want to stick it up as a blog post. That's a real pain in WordPress. The best I found was converting the notebooks to html and then including them as a static block, but those invariably are brittle and ugly.

So, smart people like Jake Vanderplas and themodernscientist switched over to something that deals natively with Jupyter notebooks a long time ago (so long ago they were called IPython Notebooks!). I'm a slow pony, but I'm switching to Nikola. It seems to be the easiest one at the moment. It's a static page generator, which is more than fine for my purposes, and it deals natively with Jupyter notebooks. Sweet. I thought it would be useful to document the process for future-me. I leaned heavily on the Nikola site (including the documentation for import_wordpress). The process wasn't completely trivial, but that's because I did some hacky stuff to get Jupyter Notebooks included in my WordPress posts anyway. This seems like a lot of work for like 13 posts, but nobody ever claimed I was wise.

[UPDATE: I ended up switching all of my old IPython/Jupyter posts over to notebooks rather than HTML. If you read an earlier version of this, basically everything else is the same]

# Can I be smarter about late policies?

Questions: Is my late policy reasonable? Are there diversity implications for smart late policies?

Robin DeRosa had an interesting tweet about late policies recently, and I posted my late policy in reply. Here’s a slightly expanded version:

In most of my classes, late work happens because students are really busy, not because they’re slackers. That means a late policy with percentage deductions kind of sucks, because my students will also be really busy the next week. Instead, I combine “no late work accepted” with dropping the equivalent of one week’s worth of each assignment time. E.g. in a class that meets three times a week, I throw out three of the daily assignments.

I make sure to frame this in a discussion with the students, where I explain that the policy is an explicit recognition of the fact that they’re busy. If you’re too busy to get the work done on time, JUST SKIP it, and get your life caught up.

So far, it has been working out really well. The students appreciate the extra lever for managing their schedules, and it’s clear from the beginning that there won’t need to be any exceptions. Note: every semester so far, students have managed to get confused early on … luckily, this comes up in terms of one of those low-weight daily assignments, so we clear it up before a high-stakes situation shows up).

# Using numba to speed up mean-squared displacement calculations

You can download this whole thing as a Jupyter notebook here

## Writing a faster mean-squared-displacement function¶

I'm trying to calculate the Mean Squared Displacement (MSD) of a particle trajectory. In reality, I have an array of positions for numtrj particles and numpts timepoints and dim dimensions: pos[numtrj, numpts, dim]. I think my question has the same answer if I just have the x trajectory of a single particle, though.

In case you haven't done MSD calculations before, there's one cute way in which you get extra information out of a trajectory. Say I have just five time points, and my positions are

In [83]: x

Out[83]: array([ 0.        ,  1.74528704,  1.59639865,  2.59976219,  3.70852457])


You could just get squared displacement by looking at x**2. However, you could also say that you have 4 different values for the displacement at one timestep:

x[1] - x[0], x[2] - x[1], x[3] - x[2], x[4] - x[3]


Similarly, three values for displacement at two timesteps: x[2:] - x[:-2]. Etc. So, the way I'm calculating MSD at the moment is:

def msd_1d(x):
result = np.zeros_like(x)
for i in range(1,len(x)):
result[i] = np.average((x[i:] - x[:-i])**2)
return result


or

def get_msd_traj(pos):
result = np.zeros_like(pos)
for i in range(1,pos.shape[1]):
result[:,i,:] = np.average((pos[:,i:,:] - pos[:,:-i,:])**2,axis=1)
return result


(side note: often the data comes indexed like pos[numpts, numtrj, dim] for molecular dynamics trajectories, but that doesn't change anything here)

So, I asked Joshua Adelman if he had any quick thoughts.

# More March Madness Monte Carlo style

You can download this post as a Juypter notebook here

## MMMC the 2015 update¶

See the original blog post for details and history. Here's the short story: in my Statistical and Thermal Physics class, we want to use Monte Carlo simulations to generate brackets for March Madness. There are at least two obvious ways to go about this:

1. Make some function that tells us the chance that team A beats team B, then flip coins for each matchup. That gets you one bracket. Repeat 100,000 times, collect statistics. This is the way Nate Silver's 538.com handles simulations for basketball, elections, etc, and I should probably implement it (note to self/motivated students: it's as easy as just generating 100,000 new brackets at a given temperature).

2. Generate one bracket, then do a Monte-Carlo walk through bracket space. This is tougher. We have to figure out how to make a move in bracket space, which is part of the fun of Monte Carlo simulations in general. To see how this is done, check out the code in Bracket.swap and Brackets.simulate.

As you can tell, we take option 2 above. I've made things a bit nicer from a user standpoint this year; here's a walkthrough. First, load up our standard IPython setup

One of my students wanted to speed up the calculation of exp(x) in a simulation. There are a few ways to do this, but a lookup table is often a huge win in situations like this. The basic idea is that, for an expensive function like exp(x), you pre-calculate exp(x) for a bunch of values that cover the range in which you're interested. You then look things up in the table at runtime. If the exact value you want isn't in the table, you use a cheap interpolation function. By tweaking the density of your pre-calculated values and the sophistication of your interpolation function, you can get results that are quite close to exact calculations for a fraction of the run-time cost.