change partial shuffle to split shuffle
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"from src.benchmark import partial_shuffle_benchmark, full_shuffle_benchmark\n",
|
||||
"from src.benchmark import split_shuffle_benchmark, full_shuffle_benchmark\n",
|
||||
"import matplotlib.pyplot as plt"
|
||||
],
|
||||
"outputs": [],
|
||||
@@ -32,7 +32,7 @@
|
||||
"max_tries_before_lockout=5\n",
|
||||
"run_count=1000\n",
|
||||
"\n",
|
||||
"bench_partial = partial_shuffle_benchmark(\n",
|
||||
"bench_split = split_shuffle_benchmark(\n",
|
||||
" number_of_keys=number_of_keys,\n",
|
||||
" properties_per_key=properties_per_key,\n",
|
||||
" passcode_len=passcode_len,\n",
|
||||
@@ -60,8 +60,8 @@
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"print(f\"Bench Partial Mean {bench_partial.mean}\\n\"\n",
|
||||
" f\"Bench Partial Var: {bench_partial.variance}\\n\"\n",
|
||||
"print(f\"Bench Split Mean {bench_split.mean}\\n\"\n",
|
||||
" f\"Bench Split Var: {bench_split.variance}\\n\"\n",
|
||||
" f\"Bench Full Mean {bench_full.mean}\\n\"\n",
|
||||
" f\"Bench Full Var: {bench_full.variance}\")"
|
||||
],
|
||||
@@ -122,7 +122,7 @@
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"bench_histogram(bench_full.runs, \"bench full\")\n",
|
||||
"bench_histogram(bench_partial.runs, \"bench partial\")"
|
||||
"bench_histogram(bench_split.runs, \"bench split\")"
|
||||
],
|
||||
"id": "9cbf9282eba285e6",
|
||||
"outputs": [
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"id": "initial_id",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"ExecuteTime": {
|
||||
"end_time": "2024-12-10T14:54:42.059468Z",
|
||||
"start_time": "2024-12-10T14:54:42.057421Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"from src.keypad import Keypad\n",
|
||||
"from src.utils import total_shuffle_states, total_valid_nkode_states"
|
||||
],
|
||||
"outputs": [],
|
||||
"execution_count": 3
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2024-12-10T14:54:43.388607Z",
|
||||
"start_time": "2024-12-10T14:54:43.373898Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"p = 4 # properties_per_key\n",
|
||||
"k = 3 # number_of_keys\n",
|
||||
"keypad = Keypad.new_keypad(k, p)\n",
|
||||
"print(keypad.keypad)\n",
|
||||
"keypad.partial_shuffle()\n",
|
||||
"print(keypad.keypad)\n",
|
||||
"keypad.partial_shuffle()\n",
|
||||
"print(keypad.keypad)\n"
|
||||
],
|
||||
"id": "dd4b3cb6405a56e0",
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[[ 8 1 2 3]\n",
|
||||
" [ 4 5 6 11]\n",
|
||||
" [ 0 9 10 7]]\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "UnboundLocalError",
|
||||
"evalue": "cannot access local variable 'shuffled_keypad' where it is not associated with a value",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
||||
"\u001B[0;31mUnboundLocalError\u001B[0m Traceback (most recent call last)",
|
||||
"Cell \u001B[0;32mIn[4], line 5\u001B[0m\n\u001B[1;32m 3\u001B[0m keypad \u001B[38;5;241m=\u001B[39m Keypad\u001B[38;5;241m.\u001B[39mnew_keypad(k, p)\n\u001B[1;32m 4\u001B[0m \u001B[38;5;28mprint\u001B[39m(keypad\u001B[38;5;241m.\u001B[39mkeypad)\n\u001B[0;32m----> 5\u001B[0m keypad\u001B[38;5;241m.\u001B[39mpartial_shuffle()\n\u001B[1;32m 6\u001B[0m \u001B[38;5;28mprint\u001B[39m(keypad\u001B[38;5;241m.\u001B[39mkeypad)\n\u001B[1;32m 7\u001B[0m keypad\u001B[38;5;241m.\u001B[39mpartial_shuffle()\n",
|
||||
"File \u001B[0;32m~/repos/nkode-analysis/src/keypad.py:32\u001B[0m, in \u001B[0;36mKeypad.partial_shuffle\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 28\u001B[0m perm_indices \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mrandom\u001B[38;5;241m.\u001B[39mpermutation(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mk)\n\u001B[1;32m 30\u001B[0m shuffled_sets \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkeypad[perm_indices, :][:, column_subset]\n\u001B[0;32m---> 32\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m shuffled_keypad \u001B[38;5;129;01min\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkeypad_cache:\n\u001B[1;32m 33\u001B[0m shuffled_keypad \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkeypad[perm_indices, :][:, column_subset]\n\u001B[1;32m 35\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mkeypad_cache\u001B[38;5;241m.\u001B[39mappend(shuffled_keypad)\n",
|
||||
"\u001B[0;31mUnboundLocalError\u001B[0m: cannot access local variable 'shuffled_keypad' where it is not associated with a value"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 4
|
||||
},
|
||||
{
|
||||
"metadata": {
|
||||
"ExecuteTime": {
|
||||
"end_time": "2024-12-10T14:52:52.461529Z",
|
||||
"start_time": "2024-12-09T21:51:54.241796Z"
|
||||
}
|
||||
},
|
||||
"cell_type": "code",
|
||||
"source": [
|
||||
"print(total_shuffle_states(k,p))\n",
|
||||
"print(total_valid_nkode_states(k,p))"
|
||||
],
|
||||
"id": "6e031aca38204895",
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "NameError",
|
||||
"evalue": "name 'k' is not defined",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
||||
"\u001B[0;31mNameError\u001B[0m Traceback (most recent call last)",
|
||||
"Cell \u001B[0;32mIn[2], line 1\u001B[0m\n\u001B[0;32m----> 1\u001B[0m \u001B[38;5;28mprint\u001B[39m(total_shuffle_states(k,p))\n\u001B[1;32m 2\u001B[0m \u001B[38;5;28mprint\u001B[39m(total_valid_nkode_states(k,p))\n",
|
||||
"\u001B[0;31mNameError\u001B[0m: name 'k' is not defined"
|
||||
]
|
||||
}
|
||||
],
|
||||
"execution_count": 2
|
||||
},
|
||||
{
|
||||
"metadata": {},
|
||||
"cell_type": "code",
|
||||
"outputs": [],
|
||||
"execution_count": null,
|
||||
"source": "",
|
||||
"id": "df3525c6e2bdaa8d"
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 2
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython2",
|
||||
"version": "2.7.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -13,9 +13,9 @@ class Benchmark:
|
||||
|
||||
class ShuffleTypes(Enum):
|
||||
FULL_SHUFFLE = "FULL_SHUFFLE"
|
||||
PARTIAL_SHUFFLE = "PARTIAL_SHUFFLE"
|
||||
SPLIT_SHUFFLE = "SPLIT_SHUFFLE"
|
||||
|
||||
def observations(number_of_keys, properties_per_key, passcode_len, shuffle_type: ShuffleTypes = ShuffleTypes.PARTIAL_SHUFFLE ):
|
||||
def observations(number_of_keys, properties_per_key, passcode_len, shuffle_type: ShuffleTypes = ShuffleTypes.SPLIT_SHUFFLE):
|
||||
k = number_of_keys
|
||||
p = properties_per_key
|
||||
n = passcode_len
|
||||
@@ -31,14 +31,14 @@ def observations(number_of_keys, properties_per_key, passcode_len, shuffle_type:
|
||||
match shuffle_type:
|
||||
case ShuffleTypes.FULL_SHUFFLE:
|
||||
keypad.full_shuffle()
|
||||
case ShuffleTypes.PARTIAL_SHUFFLE:
|
||||
keypad.partial_shuffle()
|
||||
case ShuffleTypes.SPLIT_SHUFFLE:
|
||||
keypad.split_shuffle()
|
||||
case _:
|
||||
raise Exception(f"no shuffle type {shuffle_type}")
|
||||
|
||||
return obs_gen()
|
||||
|
||||
def partial_shuffle_benchmark(
|
||||
def split_shuffle_benchmark(
|
||||
number_of_keys: int,
|
||||
properties_per_key: int,
|
||||
passcode_len: int,
|
||||
|
||||
@@ -23,7 +23,7 @@ class Keypad:
|
||||
|
||||
return Keypad(keypad=set_view.T, k=k, p=p, keypad_cache=[])
|
||||
|
||||
def partial_shuffle(self):
|
||||
def split_shuffle(self):
|
||||
shuffled_sets = self._shuffle()
|
||||
sorted_set = shuffled_sets[np.argsort(shuffled_sets[:, 0])]
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ def observations(number_of_keys, properties_per_key, passcode_len):
|
||||
keypad=keypad.keypad.copy(),
|
||||
key_selection=keypad.key_entry(target_passcode=nkode)
|
||||
)
|
||||
keypad.partial_shuffle()
|
||||
keypad.split_shuffle()
|
||||
|
||||
return obs_gen()
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ def test_keypad():
|
||||
|
||||
assert keypad.key_entry([8, 5, 6, 11]) == [0,1,2,0]
|
||||
|
||||
def test_partial_shuffle():
|
||||
def test_split_shuffle():
|
||||
p = 4 # properties_per_key
|
||||
k = 3 # number_of_keys
|
||||
keypad = Keypad.new_keypad(k, p)
|
||||
print(keypad.keypad)
|
||||
keypad.partial_shuffle()
|
||||
keypad.split_shuffle()
|
||||
print(keypad.keypad)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user