Tuesday, June 14, 2016

Sorting Subjective Items With Software

Have you ever needed to sort a large number of items that don't have an easily defined order?  Maybe it's what TV to buy or where you're going for a holiday.  Some things only have a specific order to you. So ordering them with software isn't an easy option.  To simplify the process I wrote Sortamajig.  Watch it in action.


For a long time now I've know that the ballot paper for the 2016 Australian senate elections had a chance of being large, and because I'm a little pedantic/broken I like numbering all the boxes. The ballot paper for the Australian senate can get a little complicated.  You have the option of voting for at least 6 parties(sort of) above the line (which automatically selects the candidates under the line in order), or numbering at least 12 individual candidates under the line.  That might not seem hard, but in the 2016 election the ballot paper for Queensland will have about 40 columns and 122 candidates under the line.  This is where Sortamajig helps.

Ballot Paper
Australian Senate Ballot Paper

All I have to do is feed it a group of images and it will continue asking me to choose between two of them until they're sorted.  If I can't make a choice, there's a button to randomly make a choice for me.  If I make a mistake there are undo and redo buttons as well.  When the sort is complete, I click on generate output and an image grid and text file of the results is generated.
GUI
Sortamajig GUI

Now to test out the program I needed something I can sort that's subjective and easily comparable.  So I decided to go with Jelly Beans, particularly Jelly Belly brand.  I love them, and people's favourites vary just as much as their favourite politicians.
Jelly Beans
Test Jelly Beans - Barcode 07156798554
To generate some data I decided to do three trials on separate days and combine the data into a final result.  Some flavours can overpower the next flavour tasted, to prevent this the tasting order was randomised on each trial by shuffling a 50 numbered pieces of paper and placing them in the compartments on the box tray.  The jelly beans were tasted in this order.

Jelly Beans
Randomized Sampling Process
Below are the results of the three trials in image form.  The jelly beans are ordered from left to right and then top to bottom.  For instance, in the first image Strawberry Jam is first and Plum is second.
Jelly Beans
Trial 1
Jelly Beans
Trial 2
Jelly Beans
Trial 3
To combine the results I averaged the position of each flavour in the different trials and re-ranked them using the average.  The graph below shows the average position on the horizontal axis and the position and spread of the three trials on the vertical axis.

Graph
Aggregated Trial Results

An interesting thing I noticed when processing the results of the 3 trials is that I'm reasonably certain about the flavours I like the most and least.  In the middle of the rankings however, the positions of a particular flavour in each trial has a wider spread and is less certain.

The code is really rough and needs to be cleaned up.  If you have a look at the Github repo at some point in the future I may have improved it.
Get The Code!
Some of the groundwork for this tool can be found in these other posts.

Merge Sort... Sort Of 
Smart TkInter Image Manager for Labels
A Python Sorting Manager With a Human Comparison Operator
Visually Appealing Image Layout Algorithm

Now for the important part.  What were my results?

01.  Lemon Drop
02.  Pomegranate
03.  Tutti Fruitti
04.  Plum
05.  Orange
06.  Raspberry
07.  Lemon
08.  Lemon Lime
09.  Strawberry Jam
10.  Tangerine
11.  Bubble Gum
12.  Orange Sherbet
13.  Pink Grapefruit
14.  Red Apple
15.  Cotton Candy
16.  Green Apple
17.  Wild Blackberry
18.  Blueberry
19.  Grape
20.  Island Punch
21.  Crushed Pineapple
22.  Strawberry Cheesecake
23.  Pina Colada
24.  Strawberry Daiquiri
25.  Buttered Popcorn
26.  Berry Blue
27.  Margarita
28.  Cream Soda
29.  Peach
30.  Caramel Corn
31.  Very Cherry
32.  Cherry Cola
33.  Mango
34.  Kiwi
35.  Watermelon
36.  Toasted Marshmallow
37.  Coconut
38.  Chocolate Pudding
39.  Cantaloupe
40.  Caramel Apple
41.  Vanilla
42.  Juicy Pear
43.  Green Tea
44.  Top Banana
45.  Dark Chocolate
46.  Cafe Latte
47.  Liquorice
48.  Cappuccino
49.  Chili Mango
50.  Sizzling Cinnamon

No comments:

Post a Comment