All posts by Douglas Blank

Associate professor in Computer Science at Bryn Mawr College interested in computer science education and Developmental Robotics.

Psychology could inform Programming Language Syntax

Last weekend I attended a fascinating lecture by Rob Goldstone that reviewed much work that he has done over the course of a few decades. His talk was part of a workshop on Perceptual Learning and Expertise, co-organized by my colleague at Bryn Mawr College, Adrienne Prettyman:

Screenshot from 2017-02-28 08-43-18

Screenshot from 2017-02-28 08-43-31

One bit of research that Professor Goldstone described was the effect of spacing on interpreting mathematical equations. You can read a couple of research papers on the topic here:

  1. How Space Guides Interpretation of a Novel Mathematical System
  2. The Alignment of Ordering and Space in Arithmetic Computation

Basically, the findings show that spacing between symbols and numbers in a mathematical equation effect how people interpret the equation. So:

5 + 6*7

is interpreted correctly (i.e., perform the multiplication before the addition). However:

5+6 * 7

is interpreted incorrectly.

This suggests (at least to me) that programming languages could help prevent these kinds of errors by making such spacing as compile-time errors. Thus, if one tried to compile the second example above, you’d get an error. Python is already sensitive to indentation spacing, so paying attention to spacing does have some precedence. Programming languages could also require parentheses so that humans don’t have to apply their own PEMDAS, another source of mistakes.

Understanding Election Data

I am not a political scientist, historian, nor a social scientist. I am a computer scientist and cognitive scientist. And, like most of the country, I was surprised by the election results.

One thing that computer scientists study is process, and I have been looking at the election process. As a cognitive scientist, I am also interested in patterns of behavior, motivations, and decision making.

I see many different theories attempting to explain what happened (some theories from friends, some from the media), and what to adjust (in oneself and the system) going forward. I have been thinking about these stories.

First, there is a discussion of the accuracy of the data. Was the data was right or wrong? Of course, polling people ask them to introspect and report back who they will vote for. For a large segment of the population, this is a no-brainer. But there are some people that voted for Barack Hussein Obama and also voted for Donald J. Trump.

Was the polling data wrong for these people? Perhaps, but maybe the pollsters were just asking the wrong questions. We definitely need to make some changes to the poll-predict loop to get a better handle on what is happening. Is Nate Silver one of those elite scientists that is always wrong? Should we throw the science out with the bathwater? We should continue to try to understand how people make decisions. But perhaps thinking of the outcome as a “probability” with a real-value number with a decimal place of accuracy is very wrong headed. What did it mean when Clinton had a 75.2% chance of winning? In the end, it meant nothing. But I think we can make better predictors.

But how can we predict people that can vote for Obama one election, and Trump the next? How does race play into this question? Could Hillary have done something different? Why did nothing Trump did seem to matter? Should we get rid of the electoral college? Should we protest in the street? Should we help President Trump be successful on any program?

All good questions. In thinking about how I would answer these, I was reminded about a professor that claimed that he had a model that predicted that Trump would win the election. In fact, he made his prediction even before March 2016. He calls his system the Primary Model because it is based information from presidential primaries. Since the election, the professor (Helmut Norpoth of Stony Brook University) has cleaned up his website, and now has a nice page at

I read his paper back in March. I dismissed it fairly quickly. It didn’t have any data. It wasn’t peer reviewed. It didn’t have any equations. The “Prediction Formula” for the model was expressed in a very odd manner, sort of half spreadsheet, half something else. I tried to make a stab of turning it into a reproducible Python program in a Jupyter notebook.

Screenshot from 2016-11-10 12-48-55

Professor Norpoth claims that his “model” has predicted the last 5 out of 5 elections, and is accurate for all those prior to 1996 (and for which we have primary data). I didn’t play with the code much. It wasn’t really a model, but an equation that separates winners from losers in past elections. There are many ad hoc values, but I did find it interesting that such a line could be drawn between winners and losers. (This is often the task for machine learning algorithms.)

But I believe that there is something for Nate Silver to learn from this model: it takes into account the past election cycle. There is a built-in “backlash” from the previous election cycle. Van Jones called it a “whitelash” this time around. But it doesn’t matter about the details of who is running, their race, their gender, or how tall they are. It just matters who one the last election.

This is what some would call an emergent pattern. Each voter appears to be making independent choices each selection cycle, presumably based on policy, or some criteria. But that can’t be if there are higher level patterns. We need to take such long term data into account. We don’t understand emergent phenomena very well. Consider “life” and “consciousness”. Both emergent phenomena. For election predictions, we need to acknowledge that this pattern exists, and needs to be added to the models.

Where to go from here? This information makes be feel somewhat better. Trump really could do just about anything, and it wouldn’t have mattered at one level. Clinton was swimming against the tide. Did race play a part? Most certainly yes, but we need to understand the long term election voting patterns too.

Should we help President Trump where we agree with him? Should we let him tweak Obamacare and let him call it Trumpcare? I say “yes” because we can still help people. And, it doesn’t really matter if we help him (and the Republicans) be successful. He’ll be swept away in the next backlash.

I agree with Michael Moore on a good many things. But sometimes he is just wrong. Consider his 5 Things To Do Now. Here are mine:

  1. We need to work with the Democratic Party. This isn’t anyone’s fault.
  2. Don’t fire the pundits, researchers, etc. Science works by making mistakes, and making better models. Moore sounds anti-scientific sometimes.
  3. Don’t fight like the Republicans fought Obama. That doesn’t hurt anyone except the people. Take the high road.
  4. Acknowledge that there will always be a backlash
  5. You can say that Clinton won the popular vote, if only to prevent anyone from saying “mandate”.

This doesn’t mean that nothing matters, nor that we should do nothing. We can still make a difference! Tim Burke has written on how to organize to make a difference. To address these emergent swings, the next time we elect a Democratic President, we should immediately start working on which candidate will be the “backlash” candidate. It might be a Democrat, or it might be a Republican. We just need to make sure that it isn’t another Trump.

An evening with Taylor Swift

Parents with daughters and Taylor Swift

Parents with daughters and Taylor Swift

My daughter was invited to spend an evening with Taylor Swift at her house, and I was allowed to tag along (actually I was required as my daughter is only 15 years old and she had to have an adult with her). How did this happen? My daughter runs a tumblr blog with two of her best friends, and over the last year it has evolved into a blog mostly about Taylor Swift. They don’t have a huge following… in fact, it is quite small compared to many other blogs.

To make a longer story shorter, Taylor was searching (“stalking” in her words) the internets for dedicated fans. She found many, of course. But it appears that she was looking for those fans who were also kind and caring souls. That she did, indeed, find on their blog. She also said to my daughter: “you all are so funny and cute!” The three girls do mix humor and even a bit of psychological counselling into their posts. They are always positive to the other fans; you can tell that they really enjoy the conversations.

The three bloggers.

The three bloggers with Taylor.

So, Taylor picked them from the oceans of fans on twitter, tumblr, instagram, and the www. We got a call last Thursday evening asking details about our daughter. It was very secretive, and lacking in details. As one of the other parents asked, “is this a front for a human trafficking scheme?” We were to be in Rhode Island in a parking lot between 4 and 4:30pm on Saturday. Weird! But we were in. We’d just have to risk it that it wasn’t human trafficking… a risk that my daughter was willing to take.

We left the next day, and had a relaxed brunch on Saturday morning. I was hoping to keep the stress level down on my daughter (“I hope I don’t throw-up on Taylor!” she was thinking all day). We arrived in the parking lot as instructed. After a two-hour wait, I started to think that maybe this was an elaborate hoax. But, no, we were soon after scanned for electronic recording equipment, and all of our personal items were collected. We were then shuttled over to Taylor’s home. As we entered, music was playing through the house (the house seemed to be carefully engineered for sound). But this wasn’t my daughter’s music playing… it was the Kingston Trio singing “Tom Dooley”… this was music I grew up to. Apparently, Taylor has eclectic tastes.

We had a nice finger-food dinner, although my daughter didn’t eat much—still worrying about projectile food flowing onto Taylor’s stylish shoes. Turns out that I was the only male/father of all of the chaperons. Interesting, but I was made to feel at home. Soon, Taylor came down to where we were, and played her complete unreleased album (it will be released later this month) to about 80 girls and young women (and their chaperons)  who were crammed into her living room. Between each song, she provided details about how she wrote the songs—detailing motivations and process.

Both of Taylor’s parents were there, and freely spoke informally to everybody. (One young woman was mortified when her mother asked Taylor’s father: “which daughter is yours?”… all of the fans recognize Taylor’s entire entourage.) Yes, of course, Taylor’s parents are proud parents. But this child of their’s was no ordinary child.

Throughout the evening, it became very clear that Ms. Swift is not only a talented singer, song-writer, and performer, but she is really a genius. I don’t say that lightly, but she really is a brilliant mind. Combined with her hard-working work ethic and her kindness, it is not at all surprising that she is successful. But she is also a philosopher. She is intense, and focused, and considers lines of thought that often go against conventional wisdom. She was very willing to share her ideas with these young women in an honest, thoughtful conversation.

The blogger daughter.

The blogger daughter and Ms. Swift.

I have been very lucky in my life and work to be surrounded by strong, intelligent women; I am very proud of my daughter for her funny, caring posts on her Taylor Swift blog that she works so hard on. And I very much appreciate the care and thought given by Ms. Swift to help create another generation of strong, intelligent women.

Calico Myro Robot Simulation: faster than real-time

A few Myro users have wondered what it would take to make the Calico Myro simulator run faster than real time. This is possible in the current Myro (Calico version 2.4.4 and earlier). In addition, Calico 3.0.0 has a new method, called simulate:

Myro.Simulator.simulate(duration, stepTime)

This method will move the robot for duration (given in seconds), stepping stepTime units at a time, and then update the Simulation window.

Below you will find an example of using the simulator decoupled from real time. The following uses the new ICalico notebook interface.

In [1]:
import Myro
In [2]:
robot = Myro.getRobot()
You are using:
   Simulated Fluke, version 1.0.0
   Simulated Scribbler 2, version 1.0.0
Hello, my name is 'Scribby'!
In [4]:
robot.setOption("show-sensors", True)
In [5]:
In [6]:
Myro.getSimulation().stop() # stop the simulation loop
In [7]:
robot.forward(1) # queues request to move
In [8]:
robot.update() # fires waiting requests
In [9]:
robot.setPose(100, 250, 0) # manually position robot
In [10]:
Myro.getSimulation().simulate(.1) # simulate some time
In [11]:
Myro.robot._getLocation() # normal robot.getLocation() would fire in robot.update()
[151.19999694824219, 250.0]
In [12]:
In []:

The Future of Python

I am a big fan of the programming language Python, and was one of the first people (along with my colleagues) to write about using Python in computer science education. That year, 2003, was probably too early for many schools to even consider using Python as a language for the introductory CS courses (which we call CS1), because they were just switching from C++ to Java.

Since that time, we have fully embraced Python in our courses. Personally, I have worked for the past 8 years to make using Python easy and accessible for all students, especially those from non-traditional backgrounds and underrepresented groups. In the early years, we used the de facto standard editor for Python, called IDLE. IDLE has always had issues, but perhaps not more than the entire Python ecosystem itself. In the end, we ended up writing our own editor, and, in fact, creating our own entire “stack” of software—we package everything needed to do cool stuff, including graphics, music, text-to-speech, robotics, and more.

Python’s motto is “batteries included” because it has an extensive standard library that allows much functionality without having to download additional modules. But, if you stray from the standard library, then things get hairy quickly. Take, for example, text-to-speech. This is the functionality that allows you to take text and produce the sound waves on your speaker of a human-sounding voice. You know, like Siri or Her. Such functionality is often implemented as a low-level library, often written in C. These libraries often need to be compiled for each type of computer (Mac/Windows/Linux * 32bits/64bits  * version). On top of the low-level libraries there are often “wrappers” that allow them to be used from Python. Trying to make a simple Python interface for students to use on whatever computer they have turned into a impossible compatibility task—there were just too many variables changing too quickly.

In the end, we  created a system, called Calico, that contains all of the bits necessary, with very few dependencies on low-level libraries, and no wrappers. I’ll be writing more about Calico in the future.

In a recent post on the idle-dev mailing list, a link was posted to a video by Jessica McKellar on “The Future of Python“. Jessica points out many issues with Python, and makes many good suggestions, and I agree with most of her main points. But, I don’t think she goes far enough. For example, she says (around the 10 minute mark) that part of the problem with IDLE on Windows is that there aren’t enough developers that are invested in the problem. I would say that there aren’t enough IDLE (and Python) developers that actually have to wrestle with using Python in the classroom.

How do you install Python (say on the Mac or Windows), and run IDLE? How do you make Python say “hello, world” out of your speakers? How do you make a window and draw a shape? It is too complicated to get to the point where you can do these things.

My suggestions:

  • IDLE needs its own Guido. Someone needs to make hard decisions to make IDLE useful for beginners. IDLE should focus on doing intro CS (at all levels) well. It should have an easy-to-use stepper/debugger. This IDLE-Guido should be in the classroom everyday, and be a visionary.
  • There needs to be a complete Python environment (with easy access to graphics, audio, devices) ready for easy download and install, with IDLE (or a new editor) prominently visible.

Until we tackle these two issues, look for future “Future of Python” suggestions that aren’t that different from past ones.