Bigger On The Inside http://blog.chewxy.com Straight from my brain, mostly unfiltered. Thu, 23 Jul 2015 01:03:33 +0000 en-US hourly 1 http://wordpress.org/?v=4.2.3 Operator Overloading With Right Associativity In Python http://blog.chewxy.com/2015/07/23/operator-overloading-with-right-associativity-in-python/ http://blog.chewxy.com/2015/07/23/operator-overloading-with-right-associativity-in-python/#comments Thu, 23 Jul 2015 01:03:33 +0000 http://blog.chewxy.com/?p=2935 Continue reading ]]> It’s actually quite fun that after years of using something, you still find a new way to do something. So at the last Sydney Python meet up, there were showings of how Python interfaces objects.

Consider this for example:

class Blah(object):
    ''' skipping the __init__ and stuff '''
    def __add__(self, other):
        # skips checks and stuff
        return self.value + other

>>> b = Blah(2)
>>> b + 2 
4

However, it was pointed out by my friend Julian, that the other way wouldn’t work – that operator overloading was only left associative:

>>> b = Blah(2)
>>> 2 + b

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'Blah'

Last night as I was preparing my slides and code for my PyConAU talk, I accidentally found this. More specifically, I found out about the __radd__, __rmul__ etc methods.

So, if you implement both __add__ and __radd__ interface methods, you can have right associativity:

class Blah(object):
    ''' skipping the __init__ and others '''
    def __add__(self, other):
        # skips checks and stuff
        return self.value + other
    def __radd__(self, other):
        return self.__add__(other)

>>> b = Blah(2)
>>> b + 2 
4
>>> 2 + b
4

.

Here’s Julian’s proof of concept to show that ambiguities don’t matter:

class Multiplier(object):
    def __init__(self, description):
        self.description = description
 
    def __mul__(self, b):
        print ("__mul__ was called on {0}".format(self.description))
 
    def __rmul__(self, b):
        print ("__rmul__ was called on {0}".format(self.description))
 
    def __int__(self):
        return 43
 
 
 
a = Multiplier("a")
b = Multiplier("b")
 
# Confirm Chew's finding still works.
a*5
5*a

# Which gets priority in this ambiguous situation? Turns out __mul__ does.
a*b

# But, we can force it.
int(a)*b

So, there you go… kinda cool, eh?

]]>
http://blog.chewxy.com/2015/07/23/operator-overloading-with-right-associativity-in-python/feed/ 0
Writing… Again http://blog.chewxy.com/2015/07/20/writing-again/ http://blog.chewxy.com/2015/07/20/writing-again/#comments Mon, 20 Jul 2015 07:41:24 +0000 http://blog.chewxy.com/?p=2933 This blog has been awfully silent the past year. I guess now that my job has been made redundant, I’m going to return to writing more.

Hah! Here’s to hoping!

]]>
http://blog.chewxy.com/2015/07/20/writing-again/feed/ 0
Designing SquatCoach http://blog.chewxy.com/2015/07/07/designing-squatcoach/ http://blog.chewxy.com/2015/07/07/designing-squatcoach/#comments Tue, 07 Jul 2015 04:06:23 +0000 http://blog.chewxy.com/?p=2895 Continue reading ]]> A few months ago, I blogged about my frustrations with logarithmic progressions with weightlifting. I highly enjoy linear progressions – who doesn’t enjoy work that is easy? But I was wrong about one thing: I hadn’t hit the logarithmic progression part. In fact as at the time of writing of this blog post, I am still firmly in the linear progression phase.

So what went wrong? The answer is form. I was basically squatting with exceedingly poor form. I was using all kinds of stabilizer muscles in an unbalanced way that left me injured often. I took notes and noticed that it was at around 55 to 60kg that I kept getting injured about and hence the weights I squatted lingered around there. There is an old saying goes: “Practice Makes Perfect”. That is wrong. The phrase that should really be passed around is “Perfect Practice Makes Perfect”.

The breakthrough came when I got got my partner to record me squatting for the first time. I had religiously read /r/fitness and /r/formcheck, so I had a fairly good idea of what good form is. I thought I had good form – I didn’t. One of the first things I noticed was that I wasn’t squatting anywhere near deep enough, despite the fact that I had all along thought that I was doing an ass-to-grass squat.

After years spending seated in front of the computer, I had no spatial awareness of how deep I was squatting. I had to learn what a deep squat was (learning the flexibility to do that is a tale on its own). I taught her how to check for correct form: the hip crease must go lower than the top of the kneecap to be counted as a good squat. And so she began to spot me. But this wasn’t fair for her as it was eating into her training time. So after a couple of sessions, I went about developing an app that used computer vision to determine if I was squatting with good form.

The thing about computer vision is while it’s easy to start, accuracy is a Difficult goal with a capital D. One indeed can spend a lot of effort to boost the accuracy a very miniscule amount. I cut down a lot of that by using various hacks like coloured sticker dots on the hip crease, knee and barbell tip to increase the accuracy of the app. By and large, I got it working, for me. But it wasn’t working for my partner, or a colleague who had begun to be interested about the app (he had separately approached me about the feasibility of an idea similar to SmartSpot, whose idea I love). The killing blow, I think was that I had irritated some fellow gym-goers by my wrapping of a gorillapod around their racks or bars in order to set up a static filming point.

And so it transpired I would need a new app. The app would have to do these things in order to teach me to have a better squat form:

  • Monitor my form as I squat
  • Inform me when I have hit a good form
  • Only one person involved – no interfering with anyone else in the gym

Introducing SquatCoach

After a bit of imaginative thinking, I wrote the prototype of what is released today as SquatCoach (Android | iOS). The idea was simple – strap a device full of sensors (read: any modern phone) to the legs, and use the sensors to detect whether I had good form or not. It was kinda obvious.

At first I wrote the app for myself. The app did one thing very simple – play a sound when I had hit good depth. Gradually, the app got a bit more complex – I started tracking if my knees were caving in, and whether or not I was putting excess force on the knees (easily tracked by checking if the knees extend forwards on the downward motion).

About a week after I built my first prototype app, I showed it to a few friends. I still recall the first question one of my friends asked after I told him about the app and how I am using it to improve my form: “Can I play music while using the app?”. The more I asked around, the more it transpired that that the idea of having an app that teaches you how to squat properly was a popular one. And so I decided to commercialize the idea.

From Personal To Production

The first version of the app looked something like this (which I used for myself):

Squat Coach v1

There was no UI, save for a button. I had tinkered around with a few other ways the app could work – I’m really a fan of UI-less applications. One version I had was just a background service that played a sound when the correct squat depth was reached. That wouldn’t fly. I went around asking if people would use the app, and after showing them, they’d ask, “where’s the app?”

I had to have a UI. At around the same time, I had a gym acquaintence who gave me this tip: keep your head neutral when squatting – pick a spot, and stare at it for the duration of the squat. The gym I train at has a mirror behind of the power rack, so you could watch yourself squatting. I put two and two together, and decided to add a feature to count reps as you squat. This gave the app more “meat”. Alongside that I updated the app to vibrate instead of play a sound (so people who use their phones to play music while they work out can use it without distraction).

An app that just vibrates when a good depth is reached isn’t of much value. No. The app needs to actually track good form. And so we did some research and collected data. The app collected data from day 1. I mainly used the data to plot my form. But what is good form, really? There are a few videos on the internet explaining what good form is. I personally wasn’t able to reliably replicate those good form as I had at that point in time, yet to be flexible enough, so I had to enlist outside help.

I enlisted the help of several other more experienced squatters (who all squat with perfect form), and recorded their data. I aggregated the data from the 7 people I had initially testing, and formed the “model” of what a good squat is. It is this model which the squat data are compared and scored against. The set up for the gathering of data itself was a challenge and worthy of another story, perhaps another day. Currently the model is “baked in” as 20 or so constants and a few functions. Future versions will contain a on-line machine learning system. Our team is still debating if we should have a upload data-to-server component.

The most important lesson learned from the process of gathering data was that both iOS and Android versions of the app had to be developed. I had discovered that many people were disdainful that the app would be exclusive to Android (as I am a daily Android user). So at Pressyo we serially-parallel developed both Android and iOS versions.

Designing the SquatCoach App

SquatCoach was a learning experience for us – while we had written many production quality web apps before, a production quality Android and iOS app was new for us (our experience with mobile apps had been mostly personal and internal apps, where polish wasn’t as important). We ran into a few interesting design challenges along the way.

Interaction Design

We designed this app to be as simple as possible. The idea was that you’re just supposed to strap the phone to your legs, and squat. The app is supposed to figure out the rest. This way, you can focus on performing the squat without having to worry or constantly check the app to see what is happening.

We had initially collected data on all sorts of different kinds of squats (well, 3 – back squats, front squats, and bodyweight squats). We discovered that having to specify which exercise you would be doing was involving too many steps for the user. Later on, we differentiated the back squats into high-bar and low-bar squats, which added to the user confusion.

It’s often easy to get carried away by adding features when writing programs. Over the course of iterating on this app, we went overboard with features. One feature we added was social media sharing –

It was buggy, as it was supposed to screenshot the screen, and then crop to an appropriate size, then shared on Twitter. Granted, it was a bad idea to do it that way, and there are better ways of doing it. But a lot of time was spent dicking around with things that aren’t related to the core duties of the app: teach the users how to squat.

Some other features that we started to implement, before they were ultimately canned were cloud based storage of historical records (useful, but not really useful in the context of learning how to squat, other than to see progress) and tracking various other activities like benchpress. The project was becoming runaway.

Eventually we scaled back down and focused on the core thing: tracking squat forms. We doubled down on figuring out better algorithms for detecting good squat forms. We figured that reinforcement learning would be the best way to teach squat form. The vibration feedback when squatting was one way, but there would have to be a repeated reinforcement at the end of a set, to remind the user that he/she did well, and showed where to improve.

Score Design

The app itself tracks a lot of other things to determine if a squat form is good (limited of course, to what it is able to detect). We needed a way to display that information without cluttering the screen.

The first few ideas we had were to do with scoring. It was easy, and something we have a lot of experience doing: take a bunch of numbers, and merge them down to a singular score. But one number is not informative enough. Eventually we settled for what is in the current version of SquatCoach

The display of the score was inspired by the periodic table. The elements of the periodic table are frequently displayed as letters in a square box with numbers around them. Here’s an example of a chemical I cannot live without:

carbon

The periodic table box is a good way to show quite a bit of information in a small area without having to resort to a table. It’s information visualization by convention. By convention, every periodic table box would have the element symbol, the atomic mass and atomic number listed.

The beauty of the periodic table box is that depending on advancedness, you get more information per box. I’ve seen periodic tables where the valence shell numbers are shown, while some other periodic tables might have first ionization energies listed.

The downside to a visualization like this is while it can pack quite a bit of information in a small space, it’s also quite contextless if you don’t know what they numbers stand for, and hence a learning curve is required. This will be addressed in upcoming versions of the app.

We debated using the Wilks Score instead of weight ratio, but that required us asking for more information about the user than what our test group said they were comfortable giving up – namely their gender. It also interfered with our idea that it should ask for as little information from the user as possible (both from a privacy perspective and from a usability perspective).

Forms

By design, SquatCoach is exceedingly simple to use. However, in order to calculate the score, we had to have some information from the user that we wouldn’t have had prior: the weight the user was squatting and the user’s body weight. This required a form for data entry – this is simple on a web page, but an app has a lot more subtleties:

  • Do we put everything in a table?
  • Do we restrict input?
  • If we do, how is input entered? On a keypad? On a multi-part selector?
  • Can the field be seen once the onscreen keyboard pops up?

On iOS, restricting the keyboard to the decimal one came with its own interesting problem – the decimal keyboard does not have a dismiss or done button. Yep, that done button we’ve grown so accustomed to seeing is actually a customisation – not default. It made sense now why a lot of applications didn’t update to resize to the iPhone 6 and 6 Plus sizes. We chose the simplest solution – instead of having a fixed Done button above the keyboard, we had it dismiss when you tapped anywhere except the keyboard.

On Android, we didn’t have the above problems, however, after a few attempts at trying have a uniform interface between both platforms, we decided that it would be wisest to follow each platform’s conventions. The result was that the user interface for each platform is slightly different. I will have to say though, the iOS form does indeed look better than the Android version. Upcoming versions aim to fix that.

For example, in the Android version, there is a big visible button to start and stop squats. This was a problem for the iOS version as buttons on iOS are small! In iOS 7 onwards, they only encompass the words on screen, unless you customise it. We grappled with this for while, since we didn’t want to have gigantic text just to have a larger touch target. In the end we chose to make the button a little larger on Weight screen; and we allowed the entire screen to press the button for us on the Squats screen. (After all, that’s when you want to be fumbling less with your phone.)

Interesting Things Learned

We had an iPhone 6 Plus user, so we were very keen on ensuring that our app scaled to all sizes. Storyboards have proven to be an amazing tool for ensuring everything was in the intended place. There is a slight learning curve – like realising that constraints weren’t automatically added for you, so we had some amusing moments trying to figure out why elements decided it belonged in on iPad-sized screen while running on an iPhone 5S.

A slightly interesting thing that we learned was that managing the parallel development of two app on different was easier than expected. It was also a lot more serial and linear than expected. Often, a feature would be developed on one platform first, and then the work would have to slow down until the other platform catches up to feature parity before we would continue.

Perhaps the most interesting thing about this exercise, is that I couldn’t find any app on either app stores that did what I wanted – an app that teaches you how to squat. The apps that are out there are variations of workout tracking. I seriously wonder why. This could either mean that this is such a terrible idea that this project is going to fail, or this is new ground that is being explored, opening a path for people to copy.

Another interesting thing that we learned was that app store deployments took a lot more paperwork than we expected. And way many more questionaires than ever imagined.

Lastly, I was quite amused to find out how hacker-y my test group was. A good number of people in the test group couldn’t wear a phone band around their thighs (they were too developed), so they put the phones in their shorts (and the app still worked!). One guy even extended an existing arm band to make it longer (though to be fair, he is quite handy with a sewing machine, being a cosplay veteran) so that his thigh could fit. This also led to us focusing more on making the app work when the phone is in the pocket. Upcoming versions aim to fix a few issues on that end.

The experience of writing this app has been an interesting one. While we’ve written apps before, we’ve never written one that was meant to be out in an app store. For that, my experience has been to cut, cut and cut. Most features aren’t necessary, and I felt that we wasted a lot of time trying to add features that weren’t necessary. On the other hand, I’m quite glad for just launching the app. I think you should check it out.

]]>
http://blog.chewxy.com/2015/07/07/designing-squatcoach/feed/ 0
The Bane of Communicating Succinctly http://blog.chewxy.com/2015/04/23/the-bane-of-communicating-succinctly/ http://blog.chewxy.com/2015/04/23/the-bane-of-communicating-succinctly/#comments Thu, 23 Apr 2015 11:46:55 +0000 http://blog.chewxy.com/?p=2857 Continue reading ]]> You may have noticed I have not blogged for a while. And if you do follow me on twitter you’ll note that my tweet rate has also dropped.

Ever increasingly, I find the need to share some ideas, but the ideas cannot be succinctly communicated in a pithy sentence or two. I have a lot of what I consider to be “dangerous” ideas (in the vein of the Festival of Dangerous Ideas), and I think it is imperative to be clear about the ideas.

And so I would sit down and write a blog post about it, only for it to derail into some mega long essay that is at best reads like mindless rambling (for example, see my previous post). It is in these cases that I sometimes feel I’m better off not writing. But sometimes I get passionate about a topic, and start writing a lot

Then midway through, I’d lose steam. Here are the example of titles that I have in my archive that went nowhere:

  • Why Do Ceramics Heat Up in Microwave Ovens (3997 words and I lost steam) – this article began life exactly a year ago today
  • Making Friends – A Rant (1301 words, and still incomplete, as I’m still gathering data, though I’m quite sure I’ll lose steam on that too)
  • Scrambled Eggs, The Guide (1514 words, lost steam already)
  • Logarithmic (A musing on non linear progression of things)
  • Track (A musing on being on track for a plan, and why sometimes it’s ok to let go)
  • Graveyard of Sideprojects (originally written when there was a craze over having side projects. I have 200+ side projects that I have not touched for years)
  • The Virtuous Molecule (a blog post about the fallacies of natural products)
  • Reviews: I have 3 book reviews, 2 movie reviews in my drafts, and they are nowhere

I have since concluded that it’s the length that makes me lose steam.

Yesterday I read Evan Miller’s Four Days of Go. The takeaway is that I wish I could write like him. I actually felt envious that he was able to get his point across straight, and still not be dry.

I have a problem with communicating succinctly. I look at all the work emails that I sent out – most explanation type emails have graphs, definitions and all sorts of background things. Even when I highlight the key takeaway points, written in normal English, sometimes they are missed.

…[P]erfection is attained not when there is nothing more to add, but when there is nothing more to remove

So says the oft-quoted Antoine de Saint Exupery.

The problem is I don’t know what to take away. I don’t know what to remove. The typical advice of how to improve writing is to “write more”. I’ve written this blog for more than 10 years in one form or another. I actually need to know how to improve, not just write more.

Argh.

]]>
http://blog.chewxy.com/2015/04/23/the-bane-of-communicating-succinctly/feed/ 1
Just Fair http://blog.chewxy.com/2015/03/11/just-fair/ http://blog.chewxy.com/2015/03/11/just-fair/#comments Tue, 10 Mar 2015 17:50:25 +0000 http://blog.chewxy.com/?p=2746 Continue reading ]]> Preamble: I have not blogged in a while. I have quite a few things to say, and have started at least 7 blog posts but never found the steam to complete them. Last Friday, I was having a rather interesting conversation with my colleagues, and that was cut short by a prior dinner arrangement. Having left the conversation topic unended, I decided that it’s a good point to jump off and continue blogging.

I lean slightly left towards Marxism, and I made it clear what it is that appeals to me. What appeals to me about Marxism is that it is most sci-fi in nature. “From each according to his ability, to each according to his need” is probably one of the most Star Trek-esque thing you can say. Indeed, I dream about a future where society functions like this, and I am actively working towards making such a change in society.

Of course there are other bits of Marxism that are I think outdated – the concept of class warfare, and proleteriats needing to seize control of Das Kapital[1] is in my opinion, a very 19th century view. I do however, note a similarity between today’s society and the society that Marx lived in, one on the verge of a technological revolution[2]. Just as I note that the philosophy of Marx’s time was that people find meaning of life through work, we are similarly in a period where the same has happened. Think of how you would introduce yourself to other people – it’s your name, followed by what you do.

And there we were, seated at the table. Me, J and P were discussing my Marxist leanings. J posited a very interesting question, which I have paraphrased to omit the amount of obscenities that are wont to come about around groups of male humans speaking:

Imagine if there were two students, A and B. A is super hardworking, and does all the work during the semester. A even does extra work to understand the subject deeply. B on the other hand is a party animal, preferring to skip classes and not study, and would rather spend his time partying.

Then comes exam time. Obviously A does better than B. But here’s the twist. The lecturer for whatever reason, approaches A and proposes that A averages out his grade with B.

If you were A would you do that?

This is obviously a variant of the legendary socialism classroom experiment story that has been floating around the Internet for some time now.

Putting aside obvious flaws with the analogy (which I will expand on in the later part of this post), I answered with an affirmative – that I would indeed be okay to average out the grades.

After cries of indignation and disbelief, and logical reasonings why my decision is abnormal, I laid out an alternative view:

Imagine if there were two students, A and B. Both A and B are extremely interested in the subject, and are motivated enough to study hard for the knowledge.

B however, has a string of rotten luck and poor health, which causes her to skip classes and study time as B has to go to the hospital quite a bit.

Come exam time, and the teacher makes the same offer. Would you average out your grades if you were A?

Both scenarios are the same, mechanically speaking, even if the motivations are different. Both J and P said that they would at least think about averaging the grades. Incidentally, during the dinner I adjourned to, I posited the both situations and the guests at the dinner too had similar responses as J and P – that it would not be fair (and that they would not agree to average grades in the first scenario and that they would consider in the second scenario).

This harks to a concepts of justice, equity and fairness – concepts not commonly seen in academic economic literature[3].

Definitions

But to further discuss this issue, let’s first define the concepts of justice, equity and fairness in the context that I wish to discuss. The main context is that the concepts are to be discussed in terms of distribution of resources, which economics is mainly concerned about.

Justice is the idea that the distribution of resources is done in such a way that the receiver deserves the goods received. This makes it an extremely prickly subject, because justice means different things to different people, and it comprises a wide range of ethics and philosophies, as I shall try to paint in broad strokes here. To religious nutbags, the words of the deity in question is just. If the deity says to allocate resources in a certain manner, it is just. Anything else is unjust and blasphemous. To capitalists[4], it’s only just that people get what they work for. Any other way of gaining resources is unjust. To legal theorists like John Rawls, justice is a form of fairness[5].

Equity and equality refers to the idea that all participants within a transaction should be treated the same (or similarly), without a party being unfairly preferenced. Of the three concepts, this is the simplest concept. There is a subtle difference in the terms equality and equity. In recent years, equality has taken to mean equality of opportunity – it means that all people participating within a certain social situation should be afforded the same opportunity. For the sake of this article, we’ll call this equity. Equality is concerned with the distribution of resource, not the distribution of opportunity[6]. If everyone had an equal share of the goods, then equality is achieved. Note that an equal share does not mean that it is fair, and by extension, just.

Fairness is a concept that is related to both the concepts above. Usually when discussing economic concepts, fairness is not well defined. It’s quite hard indeed to define fairness. For the sake of simplicity, let’s say that fairness is defined as the prospensity to avert inequity and maximize justice. And I believe that this is innate in all humans (and chimps too). Given a game like the Dictator Game, it’s been shown in multiple experiments, across all cultures, that people playing the role of the dictator tend to split the earnings evenly (I believe a 50-50 split is the most common split). It’s still one of the most interesting game theory experiments to be run on the ideas of altruism and reciprocity and fairness.

fairness

Fairness, in my opinion, is a complex value[7] that has components in justice and equality. Obviously it has components in other values like reciprocity, compassion and debtedness, but for the sake of simplicity in this article, we’ll just say it’s comprised of justice and equality. We spend a lot of time thinking things in life are either fair or unfair, creating the red line and the dotted borders above. However, if we think depeer, there are other quadrants which can be filled, as I will explain in an example below.

Coincidentally, in the field of psychology, fairness can also be defined in three components – sameness, deservedness and need. The definitions of which sound pretty close to the three concepts I have defined above. However, since I have no expertise in psychology, I shall say no further.

Back to last Friday. What J and P and my dinner guests felt for the first situation was that it was unjust to average the grades in the first scenario above, while it’s at least just to average the grades in the second scenario. It is equal, for sure, but it’s clear that most people feel that in Situation 1, the averaging of grades would be unjust (Student A does NOT deserve it), but it is unarguable that it is equal. Likewise with Situation 2, where it’s somewhat just (student A may deserve it), and equal.

The talk of justice opens up all sorts of cans of worms. But the one I want to talk about is the arbitrator problem.

The Arbitrator Problem

The arbitrator problem can be illustrated with a third scenario:

A, B and C are students in a class. A is the aforementioned party dude in the class in Scenario 1. B is the aforementioned hardworking one in both Scenarios. And C is the aforementioned ill-lucked one.

You play the role of the teacher. Do you average marks between A and B? or B and C? or C and A? Or between all three?

In this scenario, the teacher/lecturer is playing the judge – the arbitrator who will solve the problem of justice and equality. The problem is then the system is reliant upon the arbitrator to make good judgment calls. You’d be lucky if in a situation the arbiter is Superman. But even Superman can fail. In a very clear cut scenario like the one above, it’s easy to make good judgment calls. If A is the nephew of the teacher, and the teacher decides to average the grades for the benefit of A, we can clearly see that it’s unjust. We call this corruption in real life. Real life isn’t clear cut like the above. Real life is murky, with twists and turns.

Which brings me to the main objection of the whole analogy to begin with. There exists an arbitrator in all of the scenarios above. It’s clearly meant to be the analogue of the government (or dictator), where the students are the citizenry of the country. The scenarios above are very shallow analogues of central governments (the teachers) distributing resources (grades) to the people (students). Except, reality doesn’t work like that. There has been experiments on central government directly distributing resources, but none has worked well so far. The problem with this analogy is that it ignores the fact that the citizenry interact amongst themselves.

Of course there will come a day when the hypothetical optimal distributor viable – say a super computer who knows everyone’s indifference and utility curves over a basket of every possible item – I’d be willing to let such a computer distrubute resources and forego the marketplace dynamics if such a supercomputer were possible. But that’s a story for another day, probably one involving star dates.

Games

Let’s say we accept that the only form of information transfer is between the teacher and each student. How would a situation like the scenarios be represented as a game?

It turns out there is indeed a game theory experiment that is similar to the scenarios above – the Public Goods Game. The main difference between the scenarios above (let’s call it the Averaged Grades Game) and the Public Goods Game is that the Averaged Grades Game requires work as an input and some other form of utility as a reward.

This is a important distinction. Firstly, I believe the concept of justice can only be measured if the player has to work (i.e. put through some minor discomfort) for it, and some form of equality has to be factored in as well. The usual design tricks of giving participants some initializing tokens that can be exchanged for money does not fully capture the injustice that is felt if real work were done. A variant of the Public Goods Game where the initial play money is “earned” (or with different levels of “income”) approximates this. Having work unit fuzzies the connection between how much is invested and how much is returned.

Secondly, the Averaged Grades Game has no multiplier (or, has a multiplier set to 1). Again, this is a distinct difference. It’s been shown that without a multiplier, the Public Goods Game doesn’t work. I believe it will work for the Averaged Grades Game, because information is leaked to the player through the averaged grade, as opposed to told to the player.

Thirdly, the rewards the participants get is solely through the “exam results”. In the Public Goods Game, the rewards the players get is the sum of what they kept for themselves, and the the multiplied returns from the public pool.

Lastly the analogue for the Public Goods Game is a public good, which may or may not feature in a participant’s preference set. Whereas in analogue for the Averaged Grades Game is the results of an exam, of which preference for is a strictly increasing monotonic function[8].

Description

Here’s a more formal description of the Averaged Grades Game:

Players are given a task to solve puzzles, where a puzzle is a work unit. The more puzzles players can solve, the more reward (a monetary unit) the player earns. However, at the end of the game, all the players’ rewards are pooled together, and the averaged reward is returned to the player. The player is told at the end of the round, how much he/she has earned, and what he/she will be getting.

Variations can include a surprise rounds of not averaging the results, announced only after the round has ended. The amount of leaked information can also be used to test for justice. For example, at the end of every round, the proportion of students who score more than 50% is broadcast (this will make those who have done extra work feel “vengeful” and “punish” those who haven’t pulled their weight).

Equilibria

Depending on how the game is framed, there may be two Nash equilibria. The first Nash equilibrium of this game is the same as the Public Goods Game – zero work units will be expended. Not contributing any work is the only move a player can make in which other players’ decisions will not make the player worse off. However, just like real life experiments with the Public Goods Game, I expect reality to not converge towards 0. Instead, I believe it will converge on a level that is just above 0.

The second Nash equilibrium is the maximum work units being produced. This would happen if the game were expressed as a modified Public Goods Game where the players only get rewarded after contributing to the pool, and don’t get to keep their initial tokens. I don’t see this happening in real life situations either. People tend to punish, and feel guilt, especially with successive rounds.

Simulations

Given that I don’t have access to a behavioural economics lab, I decided I would replace human participants with some silicon ones, so I wrote some simulations[9], simulating a few things:

  • Each student has some baseline “intelligence”[10] that does not change.
  • Each student puts in work. The amount of work put in is a function of the intrinsic motivation of the student[11].
  • Results are a function of both intelligence and work
  • After each round, the student receives both a score, and an averaged score
  • The student chooses to make adjustments on the work put in for his/her next exam
  • The adjustment is subject to two other factors: motivation, and locus of identity of the student

The key metric we’d be looking at is the trend of the averaged scores over time, as well as the effort put in by each student over time. Here are the results of a hundred runs. Here’s the code in 200 lines of Python (skip to results and discussions):

Results

And here’s the result:

100 runs of Average Results over time, overlaid with each other

100 runs of Average Results over time, overlaid with each other

Here we note that as expected the average result does indeed drop after an initial spike. This is how it looks like when it’s smoothed and averaged across all the runs:

100 runs smoothed

We’d also have to consider the distribution of scores for each time period. To do that, I have plotted a box plot of the scores of a particular run (Run 47).

run 47 boxplot scores

Discussion

The simulation is obviously a very very very simple simulation. If you hadn’t understood the code, here’s a general gist of what it does: The study period is drawn from a normal distribution with a mean and standard deviation that is the same for everyone in the first period. When the second period starts, the motivations of the students affect the mean of which the study period is drawn from. The locus of identity of the student affects the standard deviation from which the study period is drawn.

The exam scores are a linear function of the study period and intelligence (of which is only a small component), and noise drawn from a normal distribution with constant mean and standard deviation across all time periods.

It should hence be clear why the average scores converge around the mean of the initial study period. This is a reasonable assumption. Nobody goes to university with a goal of not putting a single ounce of effort into studying.

Another part of the code that I don’t particularly like is the amount of clamp() that is used. This was necessary to clamp down on extreme values, but it may turn out that I don’t quite have a feel for drawing from normal distributions, so instead of tweaking the starting mean and standard deviations, I decided to just cheat by using clamp().

If anyone is willing to make a better program, please, do by all means fork the code and write me your results. I am keen to know.

On Socialism and Equality and Equity

I had mentioned briefly that I would say yes to the first scenario – that I would be willing to average my grades with the scumbag who doesn’t study. Furthermore, I too mentioned that the classroom example is a poor analogue for a central authority distributing resources to the public. Saying this appears to make me go from Oliver Queen to Lonnie Machin.

The issue is one of semantics. I’m not saying the government has no role in distributing resources, but rather, I think the government has a role as a player in the same game. In fact, I would say the government is an entity that it charged with the moral role of ensuring equity amongst other players by using the rules of the game.

What this means is that things like affirmative actions, specifically quota-based ones, are in my opinion, not good, while things like universal living wage is a good thing. The difference between them is universal minimum wage plays by the rules of the game – transactions, etc – while things like affirmative action justly creates equal opportunity by making providing unequal distribution.

Consider a scenario where a university has places for 100 students. Let’s say the university has a 20% quota for peoples of [your choice of disadvantaged demographic]. It just happens that there are 120 students who are equally qualified to enter. Out of that 120 students, 20 of them are from [your choice of disadvantaged demographic] families, so they’re instantly accepted. This means that only 80% of the others would be accepted. While the intention is noble and just (I fully agree with equal opportunity), it is not difficult to reframe the statistics in such a way that it’s unfair. Observe:

100% of students of [insert disadvantaged demographic] gets accepted to the university, while 80% of the students of higher socioeconomics status gets accepted. Does that mean that if I’m a [insert disadvantaged demographic] student, I can still get into this university without good grades?

I grew up in a country where racial quota plays a role in everything, from education to buying houses. I can tell you from first hand experience it is not fun. Even when you logically convince yourself that it’s for the betterment of society, one can’t help but feel that there is some level of unfairness at play. Obviously there is no just basis for having racial quotas, but even if the quotas were based on socioeconomic status (which I feel is most just), I’m quite sure that the feelings will remain.

And yes, I am aware in the the reframing above, I am also conflating entrances from quota with entrances from ability. It doesn’t mean that if a person is accepted as part of a disadvantaged group, the person does not have the ability to be accepted if they’re not part of the disadvantaged group.

Quota-based affirmative action almost always guarantees that a proportion of people of higher skills will not be accepted. That’s rather the whole point of quota-based affirmative actions: There exists a group that is disadvantaged in some way, and do not have the same opportunity as someone who is not in the disadvantaged group. Chances are high that the main opportunity gap is one of skill. That is to say the average skill of the disadvantaged group that is lower than the non-disadvantaged group, mainly due to pre-existing life conditions. If both groups are of the same average skill, then the opportunity gap must lie elsewhere. If the opportunity gap lies elsewhere, a quota based system will not help.

Another issue is that the disadvantaged demographic definition is subject to the arbitrator problem. Someone has to decide that X, Y, Z features are features of the disadvantaged demographic. There is a distinction of feature quality too. For example, socialeconomic status is a much better feature than say, race or ethnicity. One is easily defined and verified, the other is too fuzzy – everyone knows about the ridiculous one drop rules, for example.

This in part is why I am more in favour of softer affirmative action (such as targeted advertising[12]). Or even things like universal living wage all sound like fairly good ideas to me. These are actions in which an arbitrator does not have absolute power. Yes, I am aware that the free market is flawed, and needs to be somewhat reigned in (by said arbitrator/government/state), but the power is not as absolute as in enforcing quotas. I have digressed too much though. I may actually spend another blog post writing about that.

And Yet…

And yet, if you recall earlier in the blog post, I said I would be willing to average the grades with the scumbag who doesn’t study. Considering it as a solely one-off event, I would likely say no. However, when the situation was posited to me, I instantly started thinking about other variations in which the ill-scoring student was subject to other conditions[13]. It is from this thinking that a sense of fairness rooted in higher weightage of equality which prompted me to say yes.

Further Work

This is just a brain dump that arose from Friday Night Drinks at work. However I have a feeling that this is actually a good econs experiment that can be carried out. If anyone would like to carry it out, please do, and also keep me informed. I’d be delighted to read your papers[14].

TL;DR

Congratulations for making it so far through my ramblings. I’m not sure what you gained from it. My views on political systems is abysmal and pessimistic at best, so please don’t follow what I say.

I posited a situation, based on a popular story online. I then defined the concepts of justice, equality and fairness. From there, I digressed slightly to a problem with using a classroom setting as an analogy for government, and tried to define the classroom interaction as a game. I pointed out the similarities with a already known game, and then discussed the possible equilibrium states. I then continued with a simple simulation of the game, and discuss the results. I then end with a rant on socialism and equality and equity.

Also, I tried to hide multiple Justice League related puns and/or references. I think I failed in that aspect.

Reading Material

If you’re interested in this topic, here are some reading material on the topic:

  • Gary Bolton and Alex Ockenfels’ A Theory of Equity, Reciprocity and Competition
  • Erns Fehr and Klaus Schmidt’s A Theory of Fairness, Competition, and Cooperation
  • Matthew Rabin’s Introducing Fairness into Game Theory and Economics
  • John Rawls’ A Theory of Justice[15]
  • Amartya Sen’s Collective Choice and Social Welfare
  • Ken Binmore’s Game Theory and Social Contracts
  • Most of Al Roth’s works
  • Most microeconomic literature
  1. [1] by that I mean, means of production. I think this is a very good pun
  2. [2] Das Kapital was published just as the dust of the Industrial Revolution was settling. Its observations of course, were made by Marx DURING what we call now the Industrial Revolution
  3. [3] OK, I lied. There is an entire field of economics dedicated to this topic – it’s just very new – about fewer than 20 years. Matthew Rabin invented a whole new way of looking at utility based on fairness as a preference in the utility curve. Fehr and Schmidt came up with ways to encode guilt and compassion when looking at games. The past 10 years have been pretty much replicating experiments across cultures, with not much new or groundbreaking
  4. [4] meant in the broadest sense of the word, i.e. if you are Ayn Rand
  5. [5] wait, what? circular reference detected
  6. [6] For the purposes of this article, let’s say that opportunity is distinct from being a resource
  7. [7] think of it as a vector/complex number if you will
  8. [8] Think about it, name me a sane person who would prefer lower grades to higher grades
  9. [9] Yes, I am aware that I can use matrices and linalg, but I wrote it this way to be clear about what is happening, but hey, Python 3.4 features are actually useful!
  10. [10] This is a prickly one too. I use “intelligence” as a term as a catchall. Think of it as confounding variables that are encapsulated into one, if you will.
  11. [11] Again, this encodes things that are not directly measurable
  12. [12] Of course bear in mind that my past work with advertising has coloured my view
  13. [13] I blame alcohol
  14. [14] HAH! As if anyone would be inspired by this blog post enough to write a paper…
  15. [15] It’s a book. A very hard and dry book to get through. I didn’t bother finishing it – just skimmed through
]]>
http://blog.chewxy.com/2015/03/11/just-fair/feed/ 0
Logarithmic http://blog.chewxy.com/2015/02/24/logarithmic/ http://blog.chewxy.com/2015/02/24/logarithmic/#comments Tue, 24 Feb 2015 10:17:29 +0000 http://blog.chewxy.com/?p=2733 Continue reading ]]> I started lifting weights a few months ago after a bit of health awakening. At first, it was a lot of fuckaround. Eventually I got into a program, and a routine. I started seeing progress in my strength, and I kept a record of how much I can lift – I’ve got nice charts to show my strength progressions. It’s not much but I can bench press about 60% of my body mass now. Slowly but surely I’m getting there.

When you are a newbie to lifting weights, there is a phase you go through what is colloquially called ‘n00b gainz’ online. It’s where an untrained/novice lifter will gain strength faster than a trained lifter. In other words, you will see strength increase (as measured by the weight lifted) linearly as a function of time, until a certain point, where you no longer see that increase.

I’ve been riding the n00b gainz wave since I started, until the last couple of weeks, where I have stalled on my squats and benchpress. The weights I can lift no longer increase linearly with time. And this is frustrating.

It’s mostly psychological, really. There is something nice about linearity. It’s easy work – put in X amount of work, get out Y amount of result. Conversely, we can also say that things get “harder” when the results are logarithmic in response to the effort put in – where you have to put in a lot more work for less result each successive time.

It is said that the n00b gainz phase is determined by one’s genetic potential. The logarithmic progression that comes after is hard work. Some people are more genetically gifted in the strength department, and so spend longer time in the n00b gains phase. By the time they get out into the logarithmic progression bit, they are way ahead.

Thinking about this is kinda stressing. But then I think back on the things I did in life so far. Let’s say everything in life with some sort of progression will follow this form: linear until a certain point, then it becomes logarithmic. It can be studying, understanding of mathematics, or weightlifting. We’ll call this the “easy” and the “hard” parts.

All my life I have coasted on the “easy” parts. Exams? Didn’t have to study much for it, because a lot of things were intuitively understood. Startup? Writing the programs were the easy parts. Initial marketing and press handling was the easy part. Then the going gets tough, and I bail, or abandon the project. It would appear that I have ran from logarithmic progressions all my life.

This isn’t a good thing. How would one be able to persevere? I need to be learning that.

]]>
http://blog.chewxy.com/2015/02/24/logarithmic/feed/ 0
Naming Things (They’re All Named Lucy) http://blog.chewxy.com/2014/09/28/naming-things/ http://blog.chewxy.com/2014/09/28/naming-things/#comments Sun, 28 Sep 2014 11:56:21 +0000 http://blog.chewxy.com/?p=2682 Continue reading ]]> Have you had an experience you couldn’t quite put to words? Or understood some things that cannot be described well, and everything you tried to describe it in feel like poor analogies of it? Or that you even have to resort to using analogies to begin with?

And then someone mentions a word that sounds familiar, and suddenly, the connection makes sense. It made sense for the word to mean the experience/series-of-events/phenomena that you had experienced/understood.

Earlier this afternoon I had that experience. I had experienced something that is really difficult to describe, and put to words. I took a lot of notes about it, but I wasn’t able to accurately or satisfactorily explain it with words. What the experience was and the topics it surrounded is not of much importance, nor is it profound because I spent the rest of the afternoon obssessing about the fact there are no names to describe exactly what I had experienced.

In fact, the whole meta-ness about names makes even writing this blog post a little difficult, but I hope I am able to express what I mean quite clearly.

Names are pretty important, because without them, we do not understand the world. In fact, when you name a colour, you actually start perceiving the colour as a separate colour, as did the Chinese and Japanese discovered when they named the colour blue.

Given that names are pretty important, there are a lot of problems with names.

The Problem With Names

MagrittePipe

To talk about names clearly and unambiguously, some definitions are in order. Magritte’s Treachery of Images would be best used to illustrate my case of what a name is. A name, by my definition for the purpose of this blog post, is simply a reference. Just as the painting of the pipe is referring to the “idea” of a pipe (such ideas may be concrete or abstract, but I am getting ahead of myself), a name simply refers to something else. What this “something” is, can be concrete (keys, car, house), of it can be abstract (Einstein’s Mass Energy equivalence).

Both nouns and verbs are names, for different things. Nouns are typically names for real-life objects and abstract ideas, while verbs are names for actions and activities. For this part, I’m going to mainly concentrate on using nouns as an example, but you can easily extrapolate my arguments for verbs.

Ambiguity, Part I

The first problem with names is this: The thing that the name refers to is ambiguous in most situatons.

Arguably, (in-situ) context helps. For example, if I were in a completely empty room with you with a pipe in the middle of the room, if you mentioned “pipe” or “the pipe”, it would occur to me that it refers to the pipe in the room. Otherwise, a “pipe” simply refers to the my idea of what a pipe is, which could be any one of these:

"The shell". Via Wikipedia.

The shell“. Via Wikipedia.

or these:

"Mechanical room" by Original uploader was P199 at en.wikipedia - Originally from en.wikipedia; description page is/was here.. Licensed under CC BY 2.5 via Wikimedia Commons.

Mechanical room” by Original uploader was P199 at en.wikipedia – Originally from en.wikipedia; description page is/was here.. Licensed under CC BY 2.5 via Wikimedia Commons.

Or a whole other lot of things and ideas.

And that brings to conclusion part I of Ambiguity – a name can refer to a lot of very different things.

Ambiguity – Part II

Even if we add a lot of context to a piece of communication (for example, you may refer to smoking certain herbs that activate the cannabinoid receptors in the brain[1]), the name could still be highly ambiguous.

Imagine if you will, you encountered a tribe, C whose language has no name for the word “pipe”. But yet they clearly do have a device they smoke pot out of. Imagine this tribe has to regularly build and dispose of such pipes on the fly, as such they have no need to give it a name (let’s say they use apples to make the pipes). They have a name for apples, and despite using apples as pipes, they have no words for a pipe. They instead, call it by either what it is (an apple), or by its function (i.e. “giver of smoke” or “smoke gift” [2])

The key idea is that people of Tribe C knows what it is, but have no specific name for it.

If on your first contact with tribe C, you pointed out that the thing they use to smoke out of is not only called an apple, it’s also called a pipe, they may not recognize it as a distinct noun. Afterall, it is in their culture to consume the pipe after combustion[3], and they never needed a name for it because it’s a throwaway thing.

Even so, there has to be a shared understanding of what a “pipe” refers to. If you were making first contact with the tribe, and showed them your pipe, and called it a “pipe”, they may think that only that is a pipe.

This exactly is the problem that artificial intelligence faces – a “pipe” does not only refer to one thing. It refers to a set of things that share certain features with each other (the basic pipe is simple: 1 hole for the herb, 1 hole for the smoke to get out of, and optionally one carb). It’s the idea, or concept of a pipe that is shared.

A “pipe” can essentially mean any of these and more:

Here we see Google outperforming humans. I'd never have expected some of these to be pipes

Here we see Google outperforming humans. I’d never have expected some of these to be pipes (mainly due to the sheer stupidity of using lightbulbs or drink cans seemed a bit extreme to me)

The above ambiguity can of course be cleared up further, using deictic demonstratives like this or that; or definite articles like the. But not all languages have them.

My Issues With Naming

Often when I am explaining things, I will slip into jargon. Friends have often told me that I’m always arguing semantics. And this is exactly the problem I have with naming things.

Most things are poorly defined. To the point that at the beginning of each discussion I have, I tend to actually lay out the definitions clearly and unambiguously (which, try as I can, isn’t as easily achievable as it seems). This makes me sound rather pedantic and nitpicky.

It also makes me look rather inconsistent. The definition of things change from discussion to discussion – sometimes the scope of definition is wider, and sometimes it is narrower, depending on the context of the discussion. And yet, they share the same name.

One of the most interesting development in computer science is content addressable storage. Every file has a unique hash to it (made from the contents of the file obviously), and the file’s name is its hash, which is its contents. If the file changes, a copy is made with a new hash. For all intents and purposes (barring strange collisions), the hash is the content, and the hash is the name of the file.

This of course, cannot work in real life. There is no hashing function in real life that can describe an action, or even an object. And it would be laborious if we were to call everything by the contents of the object (content can be features of the object, or even the action of the object). But let’s imagine it can. Instead of a hash, the name of a thing in the real world is called by its features and properties. This leads to one of two possibilities: Nounless languages, and verbless languages[4].

A nounless language would be quite hard to imagine. But apparently they do exist. The Salishan group of languages are apparently nounless (it’s a debatable feature), as are the language of Riau in Indonesia. In those languages, a duck is “one that exhibits duck like behaviour”. Think off it as duck-typing of human languages.

A verbless language is even harder to imagine. I don’t think there are any in real life. But let’s imagine how some of the language would occur. Instead of saying “I eat food”, you’d probably say something along the lines of “I mouth food”.

What To Do About Naming

To be honest, I don’t think there is a good solution at all. Creating a language that is precise and unambiguous is nearly impossible. Programming languages come closest to being precise and unambiguous, but communicating in code would be a nightmare.

Everything I wrote so far can actually be applied to programming languages. Nounless languages are essentially functional languages (well, kind of. The analogy breaks down upon a lot of further thought). Verbless languages are essentially object oriented programming languages. But these are mere analogies. There things that are yet to be named, that we do not know of.

TL;DR – Names are a pain in the ass, especially when you think about it. Now, tell me what you think

  1. [1] because let’s face it, who uses tobacco pipes nowadays?
  2. [2] You’ll see later that these two are essentially the same, and not a noun at all
  3. [3] mmm, munchies
  4. [4] There has to be some level of abstraction. I think humans are comfortable with the abstraction at the physical layer of life
]]>
http://blog.chewxy.com/2014/09/28/naming-things/feed/ 0
Small Languages http://blog.chewxy.com/2014/09/03/small-languages/ http://blog.chewxy.com/2014/09/03/small-languages/#comments Wed, 03 Sep 2014 05:24:10 +0000 http://blog.chewxy.com/?p=2642 Continue reading ]]> “I like small languages,” said a friend of mine.

“Yeah, me too. Wait. What do you mean by small languages?” I replied

“You know, small. JavaScript. Lisp. Small, stuff… Not big,” he faltered as he struggled with the rest of his sentence.

That led to a series of discussions about what a small language is. We eventually enumerated a list of languages which we knew and could classify. Languages which we mutually agree are small are listed in small fonts; languages which we mutually agree are large are listed in large fonts:

  • C
  • Scheme
  • Lua
  • Python
  • Go
  • JavaScript
  • Haskell
  • Java
  • C#

Comparing Keywords

So what exactly is a “small language”, and why do people clamour for it? One metric discussed is the number of reserved keywords a language has. We quickly (and I must add, roughly) looked up and tabulated the results:

Language Reserved Words Count Sources
C 32(C99); 37(C11) Wikipedia
Scheme 20(R4RS); 0(R5RS) R4RS (PDF); R5RS
Lua 21 Lua Reference Manual(§2.1)
Python 31 (2.7.8); 33 (3.4) Python 2.7.8 reference; Python 3.4 reference (§2.3.1)
Go 25 Go Specification
JavaScript 41 (5.1); 43 (6) ECMAScript 5.1 Specification; ECMAScript 6 in MDN
Haskell 55 Haskell wiki
Java 50 Wikipedia
C# 79 MSDN

Okay, so C doesn’t fit into the (limited) picture of what a small language is. It’s also obvious that there are non-functional reserved words in JavaScript which I have included (i.e. the stupid weird shit known as future reserved words). The Haskell keywords wiki itself counts certain operators and lexemes as keywords (like comments).

A big problem with using keyword count is clearly that it’s not really representative of the language, though it is indicative of what we’re looking for. C# and Java have a large number of keywords (the word “enterprise” and “bureaucracy” also comes to mind when these two languages are mentioned), and are often thought of as large languages.

The use of keywords count also shed some light on the question of “what is a small language”. For such a short phrase, it’s surprisingly ambiguous. What could a small language mean? Is it small in terms of its built in functions? Is it small in terms of the standard library that comes with the language? These two do not seem to be likely what people are most often talking about when it comes to small languages. A small grammar could conceivably be what people mean when they talk about “small languages”.

So I thought to myself: why not compare grammars?

Comparing Grammars

Fortunately most programming languages have a well-defined grammar and they can be usually be expressed in (Extended) Backus-Naur Form. And fortunately too, most language specifications actually do specify the grammars of the language in some vague EBNF-like form.

So the solution is to count the number of production rules in the official language specifications. I’m going to ignore C# (because if there are 79 keywords, imagine how long the EBNF is going to be – Here’s where to find the C# 4.0 EBNF), and Java (the Java 8 specification has 17 pages worth of EBNFs.)

Some grammar specifications were embedded in long web pages, which I have extracted. Most of these grammars are not proper EBNF, but they resemble closely enough in the sense they follow this pattern Production Rule [separator] Nonterminals (some language spec has terminals in them). I also transformed all the grammars so that 1 line contained 1 production rule. Counting the number of production rules is simply counting the lines in a file.

Here’s what the languages I considered looked like:

Language Production Rules Source
C 68 Source
Scheme 122 R5RS Grammar
Lisp [1] < 10
Lua 22 Lua 5.1 Reference Manual
Python 82 Python 3.4.1 Complete Grammar
Go 153 Go specification; Extraction Script
JavaScript[2] 157 ECMAScript 5.1 Specification; Extraction script
Haskell 78 Haskell 2010 report

So there you have it. A comparison of grammars based on how many rules there are. These are the “lightweight” languages. Needless to say C# and Java will have a lot more rules.

Caveat

As always (in most of my blog posts I have one of these), there is a caveat. For each language there can be multiple EBNFs – it depends on how you want to specify your grammar. The EBNFs I used are mostly official grammars from the language specifications themselves (some like C are printed on dead tree paper, so I’m not going to type that out, so I shortcutted and used someone else’s).

Perhaps another way to think of “small languages” is what kind of parser could be built for those languages. If a LL(1) parser could be built for the grammar, that implies it’s a simple grammar, and that means it’s a small language (yes, I am aware that I am conflating the concepts of simplicity with size). That pretty much also means that in the list above, only Python could be parsed (and even so it does with a lot of crutches).

Small Languages, A Conclusion

I can definitely see the appeal of small languages. A small grammar implies a smaller cognitive load. This leaves more space for the structure of the program that you’re writing itself. Of course small languages can be complex too – I often had to look up where to put the * during the course of whatever little C programming I have done (can’t remember the spiral rule for the life of me).

I think this also highlights how important the stdlib of a language is. Out of these languages, I love and use Go and Python the most simply because they have fantastic stdlibs. Small core, but great stdlibs, that’s what I look for in a language.

But surely this is not the only appeal of small languages? Tell me why you like small languages below.

  1. [1] that you built in a day
  2. [2] I only extracted a portion, since ECMA also specifies the JSON grammar, which is what I consider to be outside the programming language, as well as the regex grammar
]]>
http://blog.chewxy.com/2014/09/03/small-languages/feed/ 11
The Dinner Party Around the World http://blog.chewxy.com/2014/07/30/the-dinner-party-around-the-world/ http://blog.chewxy.com/2014/07/30/the-dinner-party-around-the-world/#comments Wed, 30 Jul 2014 00:37:37 +0000 http://blog.chewxy.com/?p=2605 Continue reading ]]> TL;DR Last saturday I held a dinner party at my house. This is the recap, with the recipes.

For the last 3-4 months, I had been thinking a lot about holding a dinner party. I had been playing with several ideas in my head. And you know how ideas are like – they are screaming to come out of one’s head and into reality. So last month I decided to send out invites to 6 people, for a dinner party around the world.

For the dinner party I knew there had to be a theme. I originally started with the theme of “Layers”, but as time went on, I convinced myself that the theme would be too subtle. So I changed it to “Travelling Around Planet Earth”. But I still was very enamoured with the idea of layers in my dinner party. So I made a compromise. By the time the invites were sent out, the dinner party was called “A Trip Around Planet Earth”, with the theme of “Layers”

The Initial Plan

The initial plan was to serve different courses of meals that correspond to different continents of Planet Earth. The menu on the invite was this:

The Menu

  • Apéritif and Amuse-bouche*
  • Entrée: A Garden Salad
  • Main Course: Chilli con Carne and Corn Bread
  • Dénouement: A Glass of Milk
  • Dessert: A Secret (for now)
  • Digestif: Coffee

* Tentative, depending on availability on the day itself.

Not very useful information. But of course by the time I had sent out the invite, I had a very solid idea of what I had wanted to do. My invitees on the other hand, didn’t expect much.

There were a few things I had in mind that were vital in this dinner party. Each course (save the amuse-bouche) corresponded to a continent, and the food would correspond to foods found in that continent. I had to make my guests feel as though as they had been transported to those places. The amuse-bouche was to be the launchpad for the imaginative journey that were to begin.

I am a big believer that we eat with ALL our senses. That meant everything needed to be controlled, from the music in the background, to the scent in the air, to the ambient temperatures. Thankfully it was winter, so it was easier to control the latter with heaters.

Amuse-bouche: Lemongrass Prawn with Carrot and Ginger “Caviar”

The amuse-bouche was a last minute idea. My original plan didn’t actually include an amuse-bouche nor an apéritif. However, upon tallying up the the dishes I had, it didn’t feel balanced. So I added the amuse-bouche just before I had sent out the invites. Hence the asterisk – in case I wasn’t able to come up with an idea, I’d not have an amuse-bouche.

Nonetheless, I did come up with an idea for the amuse-bouche. Many years ago, I had lamented anonymously on a gastronomy forum that there weren’t many particularly interesting uses of popping candy in a savoury dish. The problem was that popping candy reacts to water. So the choices of things that work with popping candy was limited.

I was very insistent on using popping candy as an ingredient in the amuse-bouche because as the first dish, it would signal the tone of the dishes that would come. I wanted it to be magical. I wanted my guests to get excited and find that child-like wonder when encountering this dish.

I had always figured that popping candy works well with highly intense flavours because when the candy pops, it sends extra gases into one’s nose retronasally.

Hence the idea was to have a highly fragrant dish that would have its flavours accentuated by the popping candy popping in the mouth. Lemongrass immediately came to mind – it is exteremly fragrant, and it works well with a number of things. I have had successes matching lemongrass with carrots and ginger in the past, so I thought why not do something with carrots and ginger – the flavours go very well together.

But how to present carrots and ginger in a nice single-serve? My thoughts immediately jumped to fancy hors d’oeuvres that I’ve had. A lot of them featured fish roe. So why not make carrots and ginger into a “caviar”[1]? I have a spherification kit, and so I jumped to it.

Lastly the dish needed something to carry it. I jumped into the typical solution of scallops. But on the day itself, we couldn’t find scallops, and had to settle for some dodgy looking prawns.

To figure out the optimum amount of popping candy, my partner and I did a large amounts of tests – and we settled on the solution literally minutes before my guests arrived. The solution was to place 2-3 pieces of popping candy at the top of the spoon so that the candy goes in last, and creates the popping effect with the rest of the dish in the mouth.

Recipe

Playing It Out in Real Life

To start things off, the music in the background was Hedwig’s Theme from the Harry Potter’s OST, which I had always associated with magic and wonderment. I had also considered When You Wish Upon A Star, but I decided that lyrics were too confusing. The main point was to impart a magical moment as if my guests had entered a different world.

And so we started. I had the reaction I was looking for. My guests were doubtful at the dish in the beginning, but when the popping started, everyone visibly got a lot more animated. I’m quite glad to see that popping candy still holds some magical effect over people.

As for the flavours, it worked quite as expected – it was the ginger that was accentuated though, with the lemongrass forming a background hum in the mouth. One of my guests actually thought the piece of fried ginger. There was a obvious textural layering from the flesh of the prawn to the pop of the “caviar” to the crunch of the popping candy. There too were layers of flavour difference – the salty prawn followed by spiciness and sharpness from the “caviar” and finally a burst of sweetness from the popping candy.

After an initial round, I showed my guests how the dish and flavour was built, layer by layer, and then they helped themselves to future buildings of the dish. This interactivity was unplanned, and I liked it, so I decided to follow up with a guide on how to build the dish after each dish was presented.

Entrée: A Garden Salad

For a number of years now I had wanted to re-create Heston Blumenthal’s Garden Salad, but never had the opportunity. I had made the salad before, but never had the opportunity or need to dress it up. This was my chance at it.

With the sauce gribiche, it was the perfect first location – Europe – to land in. To me the dish really did embody everything European – classic French recipe, emboldened by mediterranean flavours. The acidity in the dish would make it a good entrée, preparing the audience’s palate for the upcoming dish, which was bolder.

In my original plan, I had wanted to make olive oil gummy worms to bury in the soil, and edible baby potato rocks. I then considered the psychology of my guests – a couple of them are quite squirmish, and won’t touch anything “weird” – and realized that had I put those in, I’d be teetering a very fine line between an enjoyable night and an awkward night.

Recipe

Playing It Out in Real Life

The music was changed to Mozart’s Concerto No. 21. When I think of Europe as a whole, I have a romantic image of classical musicians ruling the courts of the day, and I wanted to impart that. The intended scent of the meal was geosmin, to impart a ground-like/earthy/mossy smell as the guests dug into the salad. That didn’t turn out because I couldn’t acquire geosmin oil in Australia. I tried soaking cucumber in water and spraying it into the air but that didn’t do much.

I think the surprise was when the dish was brought out. Many comments were about how much of a shame it would be to dig into the dish. I think the acidity of the dish surprised my guests, as they didn’t expect it from a white-looking sauce.

This dish was layers in the sense that it was literally built in layers. The dehydrated olives and roasted pecans worked together to give the dish a meaty taste that cuts away the acidity. The vegetables were blanched and were deep green, but yet still were hard enough to be slightly crunchy. There was a good variety of texture in the dish, and I quote one of my guests, “it’s growing on me”.

Main Course: Chilli con Carne with Corn Bread

I’ve made this chilli con carne many many times. I feel like it’s one of the best dishes I have made. I also didn’t have many opportunities to cook this, since the minimum amount of people this recipe works for is 8, and it’s quite hard to scale the recipe down[2].

Another consideration I had in mind when designing the menu was that almost all the food had to be cooked before hand. I had held a number of dinner parties in the past to know that I don’t want to be in the kitchen when my guests are in the dining room. A food that is cooked for the masses would be great.

Chilli con carne was chosen because it would also form part of the narrative – leaving the Old World (Europe) and entering the Americas. And really, I DO think that there isn’t a better dish to represent BOTH Americas. The dish was invented in the United States, but clearly with influences from down south.

Corn bread was also chosen because it pretty much originated from there. My corn bread was a little different from most. You see, I love mozarella cheese with my chilli con carne. It’s just fantastic. So when making my corn bread, I stuffed a bocconcini ball into the middle just before baking. This led to an eruption of cheese as it bakes.

Recipe

Playing It Out in Real Life

The music I had chosen was Con Mi Guaguanco (from Dexter’s OST). I didn’t have much exposure to South American music, so I hooked on to the closest thing I knew – OST from Dexter, which featured a lot of Cuban-esque music without lyrics. The playlist eventually steered into creepy Dexter music, which led to some hilarious comments about serial killers and Hannibal.

I had originally wanted to heat up the room as we entered this phase of the dinner party. Nature was plotting against me. It turned out if I used multiple heaters, the circuit breaker would trip. So that plan was abandoned. The scent was smoke (from burning some bamboo sticks in the kitchen).

The crowning glory of this dish was when one of my guests leaned in and told me “I know where you’re going with this dish, Chewxy”. I probed a bit further and he told me that the dish, with its smokiness, Jack Daniels sweetness and hot chilli evoked emotions of what America was. In particular, he said, it evoked images of cowboys. Mission accomplished. I was happy.

The dish itself tasted good. The beans, when they finally break open in the mouth, tasted of colas. There were many layers to the flavours of this dish – starting from the immediate hit of chilli, then the acidity of the tomatoes, and followed by the bittersweetness of the JD. It is then completed with a smoky aftertaste. I liked it quite a lot, though my partner found it more bitter than bittersweet. The majority of the comments about the dish was that it was kinda mild. I had actually decided to tone down the heat of the dish because I knew one of my guests didn’t do well with spicy food.

Dénouement: A Glass Of Milk

I had expected the heat to get the better of my guests, so I designed this dish as a conclusion of sorts to the main course. Of course, from the Americas, specifically the United States, the next destination can only be something really cold – outer space.

The theme was travelling around Planet Earth, as well as layers. The dish had to satisfy both themes AND be functional enough to conclude the main course. The answer was to cool the palate, making outer space an obvious choice (the other choice was antarctica, but eh, it’s hard to make penguins). We know that milk cools the mouth really well after spicy food because capsaicin dissolves in fats. Other things that evokes emotion of cooling are cucumbers and melons – cold fruits and vegetables.

So why not a cucumber flavoured milk? But what of the layers? Cucumber flavoured milk is all that, but it’s just a single layer. Then I put two and two together.

Mention milk in outer space, and you’ll almost immediately get “Aunt Beru’s Blue Milk” as a response. Indeed, that’s kinda the line of thought. Aunt Beru’s blue milk is highly associative with outer space adventures (Star Wars for those who didn’t get the reference). And the best part is, nobody knows what Aunt Beru’s blue milk tasted like, and so I was free to imagine how it would taste like.

What if Aunt Beru’s Blue Milk had changing flavours? One minute it was cucumber, and the next minute it would taste like bubblegum, or hamburgers, or something.

Aunt Beru's Blue Milk

Playing It Out in Real Life

For this portion of the meal, the music was changed to the Binary Sunset theme from the Star Wars: Episode IV OST. In my mind, that’s one of the most powerful music I have associated with outer space and adventure and magic [3]. I also opened the windows and doors to air the house to cool everything down, though that didn’t have much of an effect.

I think the best part of the meal for me was when one of my guest expressed surprise when the flavours changed. This dish had been nearly a failure. I had originally wanted to impart the flavours of my favourite sandwich – a cucumber sandwich – the layers would be: cucumber, butter, toast. However, a series of mishaps happened and I had only the cucumber portion set out. A last minute change was instead of fancier (and weirder) flavours like hamburger, or roast pork, I’d go with cucumber, followed by melon. And even that was a bit of a failure. I had accidentally left the rind of the melon into the milk to infuse, and it made the milk a little bitter. The last stuff up was I messed up my ratios, and instead of the cucumber infused milk being the denser milk, it turned out to be the less dense milk.

Which was why I was absolutely delighted when my guests slowly, one by one realized that the blue milk had changed flavours. I loved the magic. It was amazing to watch as their eyes widen and realized it went from one green flavour to another. Of course in retrospect, the more drastic the flavours were, the better the effect would have been.

Dessert: Thai Sticky Rice with Mango (Khao Niao Ma Muang)

The dessert came next. And it had to top the magic from the previous dish. One of the best things to do would be to disguise a dish as another dish. And this dish in fact is also one that I’ve been dying to do – it’s Thai sticky rice with mango, except the plan was to make it look like a fried egg on rice.

Fried egg on white rice is amazing, especially if you pour a small amount of soy sauce on the egg. That was the concept I had in mind – the egg white would be made of coconut milk, the yolk made out of mango, and the soy sauce would actually be a gula Melaka syrup or caramel.

This dish also ties together a locale – Australasia. And also, it fits the layers theme – in more than one way. The perceptive layering was my main objective – I wanted my guests to perceive this dish as one thing, and realize it’s another.

It was the last proper dish, and had to set a memory. Unfortunately it didn’t go so well.

Recipe

Playing It Out in Real Life

If I had to do it again, I’d play Only For Love from The Banquet, a 2006 Chinese movie. There is a haunting beauty and sadness about that piece. But I had too, a rule about music without lyrics. Add to that the hustle of actually having to cook the “egg whites” for each dish individually, I didn’t actually manage to change the music that was playing.

Encouraged by the success of the amuse bouche, I tried to get my guests to make their own “egg yolks”. That didn’t go too well. When the ugly secrets are revealed, the magic is lost. There wasn’t as much magic or amazement when I completed the dish.

The dish itself too had some problems. It was under salted (salting the dish was part of the theatrics originally), and the mango wasn’t very sweet (I had been on a no-sugar diet for months before this, and I had thought it was very sweet).

Nonetheless, I think the reaction to the dish was still one of general (albeit muted) surprise – I think my guests had some difficulties wrapping their heads around the idea of coconut milk that was solid when it was hot, but liquid when cooled.

It was a very muted affair, my dessert. The recipe above has been updated with additional salt and sugar. Indeed, the backup cake was much better than this dish. :(

Digestif: Coffee and Dates

And so we enter the last parts of the dinner party. The plan was to serve them a glass of cold-dripped coffee, and dates. It would be the Africa portion of the night – the last continent we had yet to touch. The original coffee I had planned to serve was an Ethiopian Yirgacheffe. But a week before the dinner party, I stumbled onto some Colombian Geisha, which were rare beans with immense amounts of flavour.

Here’s how the cold drip tower I hacked up looked like (this was taken from a practice run I was doing a few days before the dinner party):

coffeedriphack

For me, I really loved the Geisha. It was a complex coffee, and bursting with flavours. And the best part was after eating a date, and taking a sip of the coffee again, the taste completely changes. The dates definitely do complement the coffee.

There wasn’t really any more changes to the environment because this is a wind-down course. We wound down over good tasty coffee and eventually moved on to Baileys on the rocks to wash everything down.

Summary

For the table loving types, here’s a quick summary:

Course Geographical Theme Aural Olfactory Environment
Amuse Bouche: Lemongrass Prawn with Carrot and Ginger Caviar Hedgwig’s Theme Fireworks/Gunpowder*† Room Temperature
Entrée: A Garden Salad with Sauce Gribiche Europe Mozart’s Concerto No. 21 Geosmin*† Room Temperature
Main Course: Chilli con Carne and Corn Bread The Americas Con Mi Guaguanco Smoke Heated room
Dénouement: A Glass of Milk Outer Space Binary Sunset Green Notes Freezing Cold
Dessert: Fried Egg with Rice (Thai Sticky Rice with Mango) Australasia Only for Love*† Lemon myrtle/Bush spice and red dust/rust*† Warm
Wind-down: Coffee and Dates Africa

Notes: * indicates the ideal choice from my point of view. † indicates that it was poorly executed on during the dinner party (when paired with *, it means it wasn’t done at all).

The Aftermath

As with all dinner parties, it’s the social interaction that was most interesting. I had went into this dinner party expecting an exchange of ideas – afterall, my guests comprise of a digital advertising account manager, an adops expert , a marketing manager, a web developer, and a googler. Almost all of us had attempted a startup at one point or another. There was bound to be some interesting things that go on.

After the dinner party, we sat down and caught up with each others’ latest news. It was interesting. I had expected the night to be rather mind expanding, but it didn’t really turn out that way. It ended up mostly being a catchup of things that happened in our lives. I was okay with the way it turned out though, because it was actually rather fun. There were a lot of things to be shared and I definitely enjoyed myself. I hope my guests did too.

Key Learnings

Things I learned from running this dinner party:

  • Do as little cooking as possible during the duration of the dinner party
  • For complex dishes, starting 2 days ahead of time is NOT ENOUGH
  • Perform more dry runs
  • Don’t prepare food when intoxicated – math skills are impaired and you’d most likely get the ratios wrong.
  • Don’t reveal the secret of the magic too early – if the audience knows the secret, the magic is lost.
  • I’ll never run a restaurant.
  • I’ll definitely host another dinner party (been hosting them fairly often since 2011 anyway)
  • I’ll probably include more alcohol in future dinner parties
  1. [1] At around the same time the idea formed, I found Erin’s blogpost which solidified the idea
  2. [2] Scaling recipes can be quite difficult. I tend to use a weighted percentage-weight scaling for recipes
  3. [3] the others are Also Spracht Zarathustra, the Alien main theme and the Star Trek opening themes, but this one is most obvious
]]>
http://blog.chewxy.com/2014/07/30/the-dinner-party-around-the-world/feed/ 0
Alternate Names For TV Shows http://blog.chewxy.com/2014/06/23/alternate-names-for-tv-shows/ http://blog.chewxy.com/2014/06/23/alternate-names-for-tv-shows/#comments Mon, 23 Jun 2014 10:55:46 +0000 http://blog.chewxy.com/?p=2524 Continue reading ]]> Earlier this afternoon I mentioned to my partner that we should watch an episode of The Adventure of WASP Girl in the Land of Systemically Biased Sampled Population. Which was of course, Orange is the New Black. She got what show that was immediately though, but I don’t think most people would get it. I then recalled a time when my housemate couldn’t find House of Cards on my home media server because I had named the folder “Derps of Capitol Hill”.

So here’s a list of funny names for TV shows I had over the years:

Show Name Nickname
Arrow drop :: Int -> [a] -> [a]
Arrow Woe is Laurel
Castle Beckett, Beckett, Beckett
Castle Caskett
Hannibal Best Cooking Show on TV
House of Cards Derps of Capitol Hill
Marvel’s Agents of SHIELD Agents of Nothing
Orange is the New Black The Adventures of WASP Girl in the Land of Systemically Biased Sampled Population
Person of Interest Adventures of Batman and Brother Eye in a Post-Snowden World
Young Justice Not The Teen Titans
]]>
http://blog.chewxy.com/2014/06/23/alternate-names-for-tv-shows/feed/ 0