Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Saturday, January 08, 2005

Fitaly vs. Atomik - Comparison of Distances for Two Popular Texts

I have written a simple computer script to compare distances for Fitaly and Atomik, two keyboard layouts optimized for stylus input (e.g. for PDAs). To keep things simple, the script ignores punctuation, capitalization, and spaces. So, for example, "Hello, world!" becomes "helloworld".

(For a visual comparison of Fitaly and Atomik, click here)

Here are the results for two famous texts:


C:\>cat BookOfMatthew.txt | groovy fitaly.groovy
Fitaly distance: 192163.3 units
Atomik distance: 198783.9 units
Fitaly is better by 3.4%

C:\>cat GrimmsFairyTales.txt | groovy fitaly.groovy
Fitaly distance: 814045.4 units
Atomik distance: 834466.2 units
Fitaly is better by 2.5%




Below is the script, written in Groovy. It can easily be extended to test layouts other than Fitaly and Atomik.


fitalyLayout = [
"z":[1,5], "v":[2,5], "c":[3,5], "h":[4,5], "w":[5,5], "k":[6,5],
"f":[1,4], "i":[2,4], "t":[3,4], "a":[4,4], "l":[5,4], "y":[6,4],
"n":[3,3], "e":[4,3],
"g":[1,2], "d":[2,2], "o":[3,2], "r":[4,2], "s":[5,2], "b":[6,2],
"q":[1,1], "j":[2,1], "u":[3,1], "m":[4,1], "p":[5,1], "x":[6,1] ]

atomikLayout = [
"b":[1,5], "k":[2,5], "d":[3,5], "g":[4,5],
"c":[1.5,4], "a":[2.5,4], "n":[3.5,4], "i":[4.5,4], "m":[5.5,4], "q":[6.5,4],
"f":[1,3], "l":[2,3], "e":[3,3], "s":[5,3], "y":[6,3], "x":[7,3],
"j":[1.5,2], "h":[2.5,2], "t":[3.5,2], "o":[4.5,2], "p":[5.5,2], "v":[6.5,2],
"r":[4,1], "u":[5,1], "w":[6,1], "z":[7,1] ]

def clean(text) {
text.toLowerCase().replaceAll("[^a-z]", "")
}

text = clean(System.in.getText())

def distance2(a, b, layout) {
Math.pow(Math.pow(layout[a][0]-layout[b][0], 2)+Math.pow(layout[a][1]-layout[b][1], 2), 0.5)
}

def distance(layout) {
distance = 0
1.upto(text.length()-1) { i |
distance += distance2(text[i], text[i-1], layout)
if (i % 1000 == 0) { println(i + "/" + text.length() + " (" + (i/text.length()) + ")") }
}
distance
}

formatter = new java.text.DecimalFormat("0.0")

fitalyDistance = distance(fitalyLayout)
atomikDistance = distance(atomikLayout)

println "Fitaly distance: " + formatter.format(fitalyDistance) + " units"
println "Atomik distance: " + formatter.format(atomikDistance) + " units"
print fitalyDistance < atomikDistance ? "Fitaly" : "Atomik"
println " is better by " + formatter.format(Math.abs(fitalyDistance - atomikDistance)/((fitalyDistance + atomikDistance)/2)*100) + "%"

2 Comments:

  • Jon, I'm wondering if you would consider running this same analysis on a Qwerty keyboard, just for the sake of reference? I'm curious to see the results. Thanks!

    By Blogger Tory, at 2/12/2006 2:05 AM  

  • Hi Tory - hm - a bit of work to set up the code - let me know if you want it badly!

    By Blogger Jonathan, at 2/18/2006 12:50 AM  

Post a Comment

<< Home