Skip to content

Commit 59b63a9

Browse files
committed
Clear out unnecessary functions from the layout comparison notebook
1 parent cca6b7f commit 59b63a9

1 file changed

Lines changed: 48 additions & 94 deletions

File tree

compare_layouts.ipynb

Lines changed: 48 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,54 @@
118118
"id": "2eTQ4jxPa8Pv"
119119
},
120120
"source": [
121-
"### Import dependencies and functions <a name=\"import\">"
121+
"### Layouts\n",
122+
"\n",
123+
"Each layout is represented by a list of 32 characters in the following order:\n",
124+
"\n",
125+
" 1 2 3 4 25 28 13 14 15 16 31\n",
126+
" 5 6 7 8 26 29 17 18 19 20 32\n",
127+
" 9 10 11 12 27 30 21 22 23 24 "
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": 108,
133+
"metadata": {},
134+
"outputs": [],
135+
"source": [
136+
"# Layouts\n",
137+
"engram_letters = ['Y','P','O','X', 'H','I','E','A', 'G','K','J','U', 'F','C','M','W', 'T','S','N','R', 'D','V','B','L', \"'\",',','-', '\"','.','?', 'Q','Z']\n",
138+
"hieamtsrn_letters = ['B','Y','O','U', 'H','I','E','A', 'X','-','\"','.', 'D','C','L','P', 'T','S','R','N', 'G','F','J','Z', \"'\",',','?', 'K','M','W', 'Q','V']\n",
139+
"#balance12_letters = ['P','L','C','D', 'N','R','S','T', 'Z','J','F','G', 'U','O','Y','K', 'A','E','I','H', '.','\"','-','X', 'W','M','B', \"'\",',','?', 'Q','V'] # Sasha Viminitz (2014): https://www.keyboard-design.com/letterlayout.html?layout=balance-twelve.en.ansi\n",
140+
"halmak_letters = ['W','L','R','B', 'S','H','N','T', 'F','M','V','C', 'Q','U','D','J', 'A','E','O','I', 'P','X','K','Y', 'Z',',','/', ';','.','G', '[',\"'\"]\n",
141+
"#vukeys_letters = ['Q','C','D','M', 'N','S','T','R', 'Z','F','G','L', 'W','U','K',\"'\", 'I','E','O','A', 'P',',','.','/', 'V','H','X', 'J','Y','B', '[',\";\"] # ?\n",
142+
"workman_letters = ['Q','D','R','W', 'A','S','H','T', 'Z','X','M','C', 'F','U','P',';', 'N','E','O','I', 'L',',','.','/', 'B','G','V', 'J','Y','K', '[',\"'\"]\n",
143+
"mtgap2_letters = [',','F','H','D', 'O','A','N','T', 'Q','X','B','P', 'C','U','L','.', 'S','E','R','I', 'W',\"'\",'V',';', \"K\",'G','Z', 'J','M','Y', '[','/'] # Michael Dickens 2010: https://mathematicalmulticore.wordpress.com/2010/06/21/mtgaps-keyboard-layout-2-0/ https://www.keyboard-design.com/letterlayout.html?layout=mtgap-2-0.en.ansi\n",
144+
"colemak_letters = ['Q','W','F','P', 'A','R','S','T', 'Z','X','C','V', 'L','U','Y',';', 'N','E','I','O', 'M',',','.','/', 'G','D','B', 'J','H','K', '[',\"'\"]\n",
145+
"colemakModDH_letters = ['Q','W','F','P', 'A','R','S','T', 'Z','X','C','D', 'L','U','Y',';', 'N','E','I','O', 'H',',','.','/', 'B','J','G', 'K','V','M', '[',\"'\"]\n",
146+
"norman_letters = ['Q','W','D','F', 'A','S','E','T', 'Z','X','C','V', 'U','R','L',';', 'N','I','O','H', 'M',',','.','/', 'K','G','B', 'J','Y','P', '[',\"'\"]\n",
147+
"klausler_letters = ['K',',','U','Y', 'O','A','E','I', 'Q','.',\"'\",';', 'L','M','F','C', 'N','T','H','S', 'V','G','B','J', 'P','D','Z', 'W','R','X', '/',\"-\"]\n",
148+
"qgmlwb_letters = ['Q','G','M','L', 'D','S','T','N', 'Z','X','C','F', 'Y','U','V',';', 'A','E','O','H', 'P',',','.','/', 'W','R','J', 'B','I','K', '[',\"'\"]\n",
149+
"beakl_letters = ['Q','H','O','U', 'Y','I','E','A', 'J','/',',','K', 'C','R','F','Z', 'S','T','N','B', 'M','L','P','V', 'X','.',\"'\", 'G','D','W', '',';']\n",
150+
"capewell_letters = [\"'\",',','.','P', 'O','A','E','I', 'Z','X','C','V', 'F','G','R','K', 'H','T','N','S', 'M','W','B',';', 'Y','Q','U', 'D','J','L', '/','-']\n",
151+
"asset_letters = ['Q','W','J','F', 'A','S','E','T', 'Z','X','C','V', 'P','U','L',';', 'N','I','O','R', 'M',',','.','/', 'G','Y','D', 'H','B','K', '[',\"'\"] \n",
152+
"dvorak_letters = [\"'\",',','.','P', 'A','O','E','U', ';','Q','J','K', 'G','C','R','L', 'H','T','N','S', 'M','W','V','Z', 'Y','F','I', 'D','X','B', '/','-']\n",
153+
"qwerty_letters = ['Q','W','E','R', 'A','S','D','F', 'Z','X','C','V', 'U','I','O','P', 'J','K','L',';', 'M',',','.','/', 'T','G','B', 'Y','H','N', '[',\"'\"]\n",
154+
"\n",
155+
"layout_names = ['Engram','Hieamtsrn','Halmak','Workman','MTGap 2.0','Colemak','Colemak Mod-DH',\n",
156+
" 'Norman','Klausler','QGMLWB','BEAKL 15','Capewell-Dvorak','Asset','Dvorak','QWERTY']\n",
157+
"layout_letters = [engram_letters, hieamtsrn_letters, halmak_letters, workman_letters, mtgap2_letters, colemak_letters, colemakModDH_letters, \n",
158+
" norman_letters, klausler_letters, qgmlwb_letters, beakl_letters, capewell_letters, asset_letters, dvorak_letters, qwerty_letters]"
159+
]
160+
},
161+
{
162+
"cell_type": "markdown",
163+
"metadata": {
164+
"colab_type": "text",
165+
"id": "2eTQ4jxPa8Pv"
166+
},
167+
"source": [
168+
"### Import dependencies and functions"
122169
]
123170
},
124171
{
@@ -151,34 +198,6 @@
151198
"apply_speed = False\n",
152199
"speed_factor = 0.9 # Published inter-key speed data.\n",
153200
"\n",
154-
"# Select keys to quantify pairwise relationships:\n",
155-
"def select_keys(data_matrix, keys, verbose=False):\n",
156-
"\n",
157-
" # Extract pairwise entries for the keys:\n",
158-
" nkeys = len(keys)\n",
159-
" Select = np.zeros((nkeys, nkeys))\n",
160-
" u = 0\n",
161-
" for i in keys:\n",
162-
" u += 1\n",
163-
" v = 0\n",
164-
" for j in keys:\n",
165-
" v += 1\n",
166-
" Select[u-1,v-1] = data_matrix[i-1,j-1]\n",
167-
"\n",
168-
" # Normalize matrix with min-max scaling to a range with max 1:\n",
169-
" newMin = np.min(Select) / np.max(Select)\n",
170-
" newMax = 1.0\n",
171-
" Select = newMin + (Select - np.min(Select)) * (newMax - newMin) / (np.max(Select) - np.min(Select))\n",
172-
" \n",
173-
" if verbose:\n",
174-
" #print(\"Matrix:\")\n",
175-
" #np.set_printoptions(precision=2); print(Select)\n",
176-
"\n",
177-
" # Heatmap of array\n",
178-
" heatmap(data=Select, title=\"Matrix heatmap\", xlabel=\"Key 1\", ylabel=\"Key 2\"); plt.show()\n",
179-
" \n",
180-
" return Select\n",
181-
"\n",
182201
"\n",
183202
"# Compute the score for a given letter-key layout (NOTE normalization step):\n",
184203
"def score_layout(data_matrix, letters, bigrams, bigram_frequencies, verbose=False):\n",
@@ -209,40 +228,6 @@
209228
" return score\n",
210229
"\n",
211230
"\n",
212-
"# Compute the Workman score for a given letter-key layout:\n",
213-
"# https://workmanlayout.org/\n",
214-
"def workman_score_layout(layout_name, layout_letters, input_text, penalties, verbose=False):\n",
215-
"\n",
216-
" $points_array = get_points($layout);\n",
217-
" $score = 0;\n",
218-
" foreach ($count as $i => $val) {\n",
219-
" $char = chr($i);\n",
220-
" foreach ($points_array as $points => $cap) {\n",
221-
" if (in_array(chr($i), $cap)) {\n",
222-
" $score = $score + ($points * $val);\n",
223-
" break;\n",
224-
"\n",
225-
" # Create a matrix of bigram frequencies:\n",
226-
" nletters = len(letters)\n",
227-
" F = np.zeros((nletters, nletters))\n",
228-
"\n",
229-
" # Find the bigram frequency for each ordered pair of letters in the permutation:\n",
230-
" for i1 in range(nletters):\n",
231-
" for i2 in range(nletters):\n",
232-
" bigram = letters[i1] + letters[i2]\n",
233-
" i2gram = np.where(bigrams == bigram)\n",
234-
" if np.size(i2gram) > 0:\n",
235-
" F[i1, i2] = bigram_frequencies[i2gram][0]\n",
236-
"\n",
237-
" # Compute the score for this permutation:\n",
238-
" score = np.average(data_matrix * F) \n",
239-
"\n",
240-
" if verbose:\n",
241-
" print(\"Workman score for letter permutation {0}: {1}\".format(letters, score))\n",
242-
"\n",
243-
" return score\n",
244-
"\n",
245-
"\n",
246231
"# Compute the score for a given letter-key layout (NOTE normalization step):\n",
247232
"def tally_bigrams(input_text, bigrams, normalize=True, verbose=False):\n",
248233
" \n",
@@ -2333,37 +2318,6 @@
23332318
"## Score layouts using Engram's scoring model <a name=\"Engram\">\n"
23342319
]
23352320
},
2336-
{
2337-
"cell_type": "code",
2338-
"execution_count": 108,
2339-
"metadata": {},
2340-
"outputs": [],
2341-
"source": [
2342-
"# Layouts\n",
2343-
"engram_letters = ['Y','P','O','X', 'H','I','E','A', 'G','K','J','U', 'F','C','M','W', 'T','S','N','R', 'D','V','B','L', \"'\",',','-', '\"','.','?', 'Q','Z']\n",
2344-
"hieamtsrn_letters = ['B','Y','O','U', 'H','I','E','A', 'X','-','\"','.', 'D','C','L','P', 'T','S','R','N', 'G','F','J','Z', \"'\",',','?', 'K','M','W', 'Q','V']\n",
2345-
"#balance12_letters = ['P','L','C','D', 'N','R','S','T', 'Z','J','F','G', 'U','O','Y','K', 'A','E','I','H', '.','\"','-','X', 'W','M','B', \"'\",',','?', 'Q','V'] # Sasha Viminitz (2014): https://www.keyboard-design.com/letterlayout.html?layout=balance-twelve.en.ansi\n",
2346-
"halmak_letters = ['W','L','R','B', 'S','H','N','T', 'F','M','V','C', 'Q','U','D','J', 'A','E','O','I', 'P','X','K','Y', 'Z',',','/', ';','.','G', '[',\"'\"]\n",
2347-
"#vukeys_letters = ['Q','C','D','M', 'N','S','T','R', 'Z','F','G','L', 'W','U','K',\"'\", 'I','E','O','A', 'P',',','.','/', 'V','H','X', 'J','Y','B', '[',\";\"] # ?\n",
2348-
"workman_letters = ['Q','D','R','W', 'A','S','H','T', 'Z','X','M','C', 'F','U','P',';', 'N','E','O','I', 'L',',','.','/', 'B','G','V', 'J','Y','K', '[',\"'\"]\n",
2349-
"mtgap2_letters = [',','F','H','D', 'O','A','N','T', 'Q','X','B','P', 'C','U','L','.', 'S','E','R','I', 'W',\"'\",'V',';', \"K\",'G','Z', 'J','M','Y', '[','/'] # Michael Dickens 2010: https://mathematicalmulticore.wordpress.com/2010/06/21/mtgaps-keyboard-layout-2-0/ https://www.keyboard-design.com/letterlayout.html?layout=mtgap-2-0.en.ansi\n",
2350-
"colemak_letters = ['Q','W','F','P', 'A','R','S','T', 'Z','X','C','V', 'L','U','Y',';', 'N','E','I','O', 'M',',','.','/', 'G','D','B', 'J','H','K', '[',\"'\"]\n",
2351-
"colemakModDH_letters = ['Q','W','F','P', 'A','R','S','T', 'Z','X','C','D', 'L','U','Y',';', 'N','E','I','O', 'H',',','.','/', 'B','J','G', 'K','V','M', '[',\"'\"]\n",
2352-
"norman_letters = ['Q','W','D','F', 'A','S','E','T', 'Z','X','C','V', 'U','R','L',';', 'N','I','O','H', 'M',',','.','/', 'K','G','B', 'J','Y','P', '[',\"'\"]\n",
2353-
"klausler_letters = ['K',',','U','Y', 'O','A','E','I', 'Q','.',\"'\",';', 'L','M','F','C', 'N','T','H','S', 'V','G','B','J', 'P','D','Z', 'W','R','X', '/',\"-\"]\n",
2354-
"qgmlwb_letters = ['Q','G','M','L', 'D','S','T','N', 'Z','X','C','F', 'Y','U','V',';', 'A','E','O','H', 'P',',','.','/', 'W','R','J', 'B','I','K', '[',\"'\"]\n",
2355-
"beakl_letters = ['Q','H','O','U', 'Y','I','E','A', 'J','/',',','K', 'C','R','F','Z', 'S','T','N','B', 'M','L','P','V', 'X','.',\"'\", 'G','D','W', '',';']\n",
2356-
"capewell_letters = [\"'\",',','.','P', 'O','A','E','I', 'Z','X','C','V', 'F','G','R','K', 'H','T','N','S', 'M','W','B',';', 'Y','Q','U', 'D','J','L', '/','-']\n",
2357-
"asset_letters = ['Q','W','J','F', 'A','S','E','T', 'Z','X','C','V', 'P','U','L',';', 'N','I','O','R', 'M',',','.','/', 'G','Y','D', 'H','B','K', '[',\"'\"] \n",
2358-
"dvorak_letters = [\"'\",',','.','P', 'A','O','E','U', ';','Q','J','K', 'G','C','R','L', 'H','T','N','S', 'M','W','V','Z', 'Y','F','I', 'D','X','B', '/','-']\n",
2359-
"qwerty_letters = ['Q','W','E','R', 'A','S','D','F', 'Z','X','C','V', 'U','I','O','P', 'J','K','L',';', 'M',',','.','/', 'T','G','B', 'Y','H','N', '[',\"'\"]\n",
2360-
"\n",
2361-
"layout_names = ['Engram','Hieamtsrn','Halmak','Workman','MTGap 2.0','Colemak','Colemak Mod-DH',\n",
2362-
" 'Norman','Klausler','QGMLWB','BEAKL 15','Capewell-Dvorak','Asset','Dvorak','QWERTY']\n",
2363-
"layout_letters = [engram_letters, hieamtsrn_letters, halmak_letters, workman_letters, mtgap2_letters, colemak_letters, colemakModDH_letters, \n",
2364-
" norman_letters, klausler_letters, qgmlwb_letters, beakl_letters, capewell_letters, asset_letters, dvorak_letters, qwerty_letters]"
2365-
]
2366-
},
23672321
{
23682322
"cell_type": "code",
23692323
"execution_count": 109,

0 commit comments

Comments
 (0)