Election Web Service

First draft of the Election Web Service is up and running. I’ve implemented Plurality, IRV, Ranked Pairs, the Schulze Method, Plurality at Large, and STV.

The source code is up on GitHub for anyone interested in implementing additional voting systems or using them as Python libraries. For those that just want to send requests to a server, I have one responding to posts at vote.cognitivesandbox.com (note that the server only response to HTTP POSTs and works solely on JSON encoded requests).

Hopefully this takes some of the burden out of implementing polls and whatnot. You take care of storing the ballots, I’ll show you who won (and why).

Example Request

{
  "votingSystem": "stv",
  "ballots": [
    {"count": 4, "ballot": ["orange"]},
    {"count": 2, "ballot": ["pear", "orange"]},
    {"count": 8, "ballot": ["chocolate", "strawberry"]},
    {"count": 4, "ballot": ["chocolate", "sweets"]},
    {"count": 1, "ballot": ["strawberry"]},
    {"count": 1, "ballot": ["sweets"]}
  ],
  "winners": 3
}

Example Response

{
  "rounds": [
    {
      "tallies": {
        "orange": 4.0,
        "strawberry": 1.0,
        "chocolate": 12.0,
        "pear": 2.0,
        "sweets": 1.0
      },
      "quota": 6,
      "winners": ["chocolate"],
    },
    {
      "tallies": {
        "orange": 4.0,
        "strawberry": 5.0,
        "pear": 2.0,
        "sweets": 3.0
      },
      "quota": 5,
      "winners": ["strawberry"],
    },
    {
      "tallies": {
        "orange": 4.0,
        "sweets": 3.0,
        "pear": 2.0
      },
      "quota": 5,
      "loser": "pear"
    },
    {
      "tallies": {
        "orange": 6.0,
        "sweets": 3.0
      },
      "quota": 5,
      "winners": ["orange"],
    }
  ],
  "winners": ["orange", "strawberry", "chocolate"]
}

Spinning a clocklet disc

Imagine an infinitely small particle that keeps perfect time. Let’s call this particle a clocklet. We don’t have such particles, but they’re useful for considering the following.

clocklet-disc

Make a disc of clocklets about and start it spinning. Clocklet C0 is at the centre of the disc, C2 is on the edge, and C1 is half way in between. When the disc is spinning slowly, all three clocks agree on the time. C2 moves at twice the speed of C1. C0 spins, but does not otherwise move.

As we spin our disc faster and faster, the clocklets begin to differ due to an effect known as time dilation. Furthermore, C2 can never go faster than the speed of light even if C1 is moving faster than half the speed of light.

So what happens if it does? Assume that the disc spins fast enough such that C1 moves at 51% the speed of light. If the disc stops spinning, would C1 still be half way in between C0 and C2? Furthermore, does C0 differ at all from an independent clocklet outside of this disc?

I don’t have the background to answer these questions, but it’s certainly entertaining to think about.

Chained matching

Sometimes you want to find references to “foo bar” or things like that, but regex won’t cut it. Maybe “foo” is on a different line from “bar”. It can get a little hairy when you want to chain that together even further.

grep -ilR 'foo' * | xargs grep -il 'bar' | etc...

Chocolate oatmeal cups

Sometimes a recipe doesn’t turn out the way you’d expect. I have this one for oatmeal cookies that’s always turned out much flatter than I’d like. Instead of putting them on a cookie sheet, I tried using a muffin sheet such that they might hold their shape a little better. Little did I know that they’d puff up and collapse, creating chocolate oatmeal cups. Fantastic.

Ingredients

  • ½ cup margarine
  • 1 cup dry sweetener
  • 1½ tsp vanilla extract
  • 1 “egg” (I’m using Ener-G)
  • 1 tsp baking soda
  • ½ tsp salt
  • 1 cup rolled oats
  • ¼ cup cocoa
  • ½ cup flour

Method

  1. Like with all cookie recipes, mix the wet, sift together the dry, combine.
  2. Bake in a muffin tray at 350°F for 10 minutes.
  3. Let them cool down before putting them in the freezer for at least an hour.
  4. Fill with anything: jam, ice cream, peanut butter, etc.

Election API prototype

The project sputtered a few times before it really got going, but it seems well on its way. My first elections calculator was built to demonstrate the flaws of voting systems. This new one, however, is intended for the development community.

Most voting systems are plain Plurality (aka first past the post) and is prone to a great many flaws. Instead of implementing better voting systems libraries in each language, why not provide a general web service API?

The tool speaks JSON and provides and is completely stateless. You send your full request (ballots, desired voting system, etc) and it returns the winner (or winners) and an explanation as to how it reached that conclusion. All data is stored locally in cookies; The only server communication is for the result calculation.

I’m only about half-way done: four more algorithms to go (Schulze, STV, CPO-STV and Schulze STV) and a fair bit of polishing on the UI. Late December? Early January? Something like that.

French Onion Soup

I don’t think I’ve ever had onion soup before, so I’m kind of winging it on this one. The first attempt turned out tasty enough to share, as inauthentic as it may be.

Ingredients

  • ¼ cup margarine
  • 4 onions, sliced
  • 1 tsp sugar
  • 1 tbsp flour
  • 2½ cups water
  • 2½ cups onion broth
  • ½ cup red wine
  • croutons
  • vegan cheese, sliced (Earth Island Mozzarella works well, but I’m looking forward to trying Daiya’s)

Method

  1. Melt the margarine in a soup pot. Stir in the sugar. Add the onions and cook until caramelized (about 10 minutes).
  2. Stir in the flour until the mix thickens.
  3. Add the water, broth and wine. Bring to a boil, then simmer covered for 10 minutes.
  4. Ladle the soup into ramekins, placing a single layer or croutons on top, then multiple layers of the sliced cheese
  5. Bake at for 10 minutes at 220°C.

Sesame ginger cookies

The following recipe comes from The Veganomicon, my newest of cookbooks.

IMG_8672

Dry ingredients

  • 2¼ cups flour
  • ½ tsp baking powder
  • ½ tsp baking soda
  • ½ tsp salt
  • ½ tsp ground ginger
  • ½ tsp ground cinnamon

Wet ingredients

  • ½ cup vegetable shortening
  • ½ cup chunky peanut butter
  • ¼ cup brown rice syrup
  • 1¼ cups sugar
  • ½ cup soy milk
  • 1 tsp vanilla extract
  • ½ tsp almond extract

Additional ingredients

  • 5 oz. candied ginger, diced finely
  • ⅓ cup sesame seeds

Method

  1. Sift together the dry ingredients in one bowl.
  2. Beat the wet ingredients in another until smooth.
  3. Add the dry to the wet.
  4. Mix in the candied ginger.
  5. Roll small balls of batter first in the sesame seeds, then in some extra sugar before placing on a cookie sheet.
  6. Bake at 350°F for 13 minutes.

Pumpkin cheesecake cupcake

Cheesecupcake? Cupcheesecake? Whatever. Delicious. The recipe is loosely based off of the pumpkin tofu cheesecake from La Dolce Vegan, but with necessary substitutions based on ingredient scarcity.

Ingredients

  • 425g firm tofu and 300g silken tofu (I was short and used 350g firm tofu and an 8oz tub of Tofutti creamcheese)
  • 1¼ cups sugar
  • 1 cup pumpkin purée
  • ¼ cup flour
  • 1 tsp vanilla extract
  • ½ tsp maple extract (I used about 2 tbsp maple syrup)
  • 1 tsp cinnamon
  • ½ tsp salt
  • ¼ tsp ground ginger (I doubled this as I love ginger)
  • ¼ tsp ground cloves
  • 1 tbsp maple syrup (Omitted as per above)

The crust was just graham cracker crumbs with a bit of melted margarine and sugar.

Method

  1. In a set of about 8 ramekins, crumble the crust into the corners, forming a thin bottom and a reasonable ring around the outside.
  2. Blend the above ingredients (wet first, then dry) and pour the smooth mixture into the ramekins, on top of the crumble crust
  3. If desired, sprinkle some crumbled pecans, sugar and cinnamon on top. Drizzle some maple syrup if you’d like too. It’s not necessary, but they spice up an otherwise bland surface.
  4. Bake for 75 minutes at 150°C then let cool overnight in the fridge.

A conflict of interests

Exhibit A: The Canadian Charter of Rights and Freedoms, Fundamental Freedoms section

2. Everyone has the following fundamental freedoms:
(a) freedom of conscience and religion;
(b) freedom of thought, belief, opinion and expression, including freedom of the press and other media of communication;
(c) freedom of peaceful assembly; and
(d) freedom of association.

Exhibit B: Bill 13 — Miscellaneous Statutes Amendment Act, 2009

“specified municipality” means any of the following:
(a) the City of Richmond;
(b) the City of Vancouver;
(c) the Resort Municipality of Whistler.

32 (1) Subject to this section and section 34, an officer or employee of a specified municipality or a person authorized by the council of a specified municipality has the authority to enter on property, and to enter into property, without the consent of the owner or occupier for the purpose of enforcing, in accordance with subsection (4), the specified municipality’s bylaws in relation to signs.

(1) Subject to subsection (2), the Council may make by-laws for the purposes of enforcing its by-laws, including establishing one or more of the following penalties to which a person convicted of an offence in a prosecution under the Offence Act is liable:

(a) a minimum fine;
(b) a maximum fine of up to $10 000;
(c) in the case of a continuing offence, for each day that the offence continues either or both of
(i) a minimum fine under paragraph (a), or
(ii) a maximum fine under paragraph (b);
(d) imprisonment for not more than 6 months.

The timing of this and the location constraint suggest that this is motivated by the coming Olympics. The short of it is if you have a sign they don’t like, they can fine you $10,000 and put you in jail for 6 months. I’d think that the Charter of Rights and Freedoms would trump this. How is it even being discussed then?

If this concerns you, please contact your MLA. If you don’t know who your MLA is, find out.

Partitioning control of electoral reform from vested interests

Fox and Henhouse by Marj Joly

One of the key problems in electoral reform is that those who hold the power to change it benefit from the current system; It got them into office, right? Maybe there’s a way we can move that power out of those most disinclined to seriously consider it.

Just a thought. Every 10 years (5? 15?) hold a guaranteed referendum on what electoral system we should be using and switch to the preferred alternative. If the current system is FPTP, use FPTP as the referendum mechanism (likewise if it’s IRV, Schulze, etc).

Furthermore, the first referendum would occur in 10 years from now. Often candidates will run on platforms that include democratic reform, but abandon it once elected. By putting the first election far enough in the future, it can be ratified without directly threatening the power base of the current representative.

We don’t want the fox guarding the henhouse, right?