File size: 25,552 Bytes
68ef771 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyOqoPlJxEzXB/rGffrk47H3",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/jcandane/gym_rings/blob/main/ring_dataset.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Ring Dataset for Calibration of Classification & Manifold Models"
],
"metadata": {
"id": "H-BUP1FKiX4R"
}
},
{
"cell_type": "markdown",
"source": [
"## defs"
],
"metadata": {
"id": "PBkKn7m0ydvB"
}
},
{
"cell_type": "markdown",
"source": [
"### optional download from github repo"
],
"metadata": {
"id": "t2ypmzGg6PaJ"
}
},
{
"cell_type": "code",
"source": [
"try:\n",
" from gym_rings import get_rings\n",
"except:\n",
" !wget https://raw.githubusercontent.com/jcandane/gym_rings/main/gym_rings.py\n",
" from gym_rings import get_rings"
],
"metadata": {
"id": "0MWhz-V36ZjT"
},
"execution_count": 1,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"### raw code"
],
"metadata": {
"id": "JiZ9NcKW6Xpi"
}
},
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"\n",
"def define_ring(A, radii):\n",
" \"\"\"\n",
" define a Boolean ring, such that the image is made from \"True\" or \"1\".\n",
" A:np.ndarray (initial array)\n",
" radius_range:tuple defined by (minimum radius, maximum radius)\n",
" GET>\n",
" A:np.ndarray (initial array with an additional ring with radius_range)\n",
" \"\"\"\n",
" height, width = A.shape\n",
" radii = radii.reshape(-1,2).T\n",
"\n",
" center = np.array([width / 2, height / 2])\n",
" I_xi = np.indices((height, width)).reshape(2, -1) ## meshgrid -> flatten image\n",
" I_xi = np.vstack((I_xi[1], I_xi[0]))\n",
"\n",
" ### RINGS\n",
" mask_i = (np.linalg.norm(I_xi-center[:,None], axis=0)[:,None] >= radii[0][None,:]) ##&\n",
" mask_i &= (np.linalg.norm(I_xi-center[:,None], axis=0)[:,None] < radii[1][None,:])\n",
" mask_i = np.any(mask_i, axis=-1)\n",
"\n",
" A = A.reshape(-1)\n",
" A[mask_i] = 1\n",
" return A.reshape(height, width)\n",
"\n",
"def ring_notch(image_shape, θ:np.ndarray, radius_range, notch_width=5.):\n",
" \"\"\"\n",
" GIVEN>\n",
" image_shape:tuple (The shape of the image (height, width))\n",
" θ:np.ndarray[1d] (list of angles, θ.shape=(samples,))\n",
" radius_range:np.ndarray (for a given ring, [R_min,R_max])\n",
" notch_width:float (in degrees)\n",
" GET>\n",
" np.ndarray (A boolean mask for the notches)\n",
" \"\"\"\n",
" height, width = image_shape\n",
"\n",
" θ = (θ).astype(float)\n",
" θ *= -1.\n",
" #θ -= 1.*notch_width\n",
" θ_min = np.deg2rad(θ - notch_width)\n",
" θ_max = np.deg2rad(θ + notch_width)\n",
"\n",
" # Create a grid of x and y coordinates\n",
" y, x = np.ogrid[:height, :width]\n",
"\n",
" # Calculate the distances and angles\n",
" y = y - width / 2\n",
" x = x - height / 2\n",
" distance = np.sqrt(x**2 + y**2)\n",
" angle = np.arctan2(y, x) ## every pixel associated an angle\n",
"\n",
" # Normalize angles to [0, 2*pi)\n",
" angle = np.mod(angle, 2 * np.pi)\n",
" θ_min = np.mod(θ_min, 2 * np.pi)\n",
" θ_max = np.mod(θ_max, 2 * np.pi)\n",
"\n",
" # Create the mask for the angle range\n",
" R_min, R_max = radius_range\n",
" R_min = float(R_min)-0.01\n",
" R_max = float(R_max)+0.01\n",
"\n",
" shifted_angle = (angle[:,:,None] - θ_min[None,None,:]) % 360 ### why not % 2*np.pi ???\n",
" shifted_end_angle = (θ_max - θ_min) % 360\n",
" angle_mask = (shifted_angle <= shifted_end_angle[None,None,:])\n",
"\n",
" radius_mask = (distance <= R_max) & (distance > R_min)\n",
" mask = angle_mask & radius_mask[:,:,None]\n",
" return mask.swapaxes(0,2).swapaxes(1,2) ### s.t. snapshots, pixels\n",
"\n",
"def get_rings(N:int, θs:np.ndarray, radii, notch_width=5.): ##\n",
" \"\"\"\n",
" GIVEN>\n",
" N:int (image side size, such that image.shape=(N,N))\n",
" θs:np.ndarray[2d] (list of angles for each ring, with θs.shape=(ring count, samples) )\n",
" radii:np.ndarray[2] (with shape=(ring count, 2), i.e. axis=1 is the R_min, R_max for each ring)\n",
" notch_width:float (notch angle, default=5 degrees, this can be generalized)\n",
" GET>\n",
" np.ndarray (dataset of shape=(θs.shape[1], N, N))\n",
" \"\"\"\n",
" img_shape = (N,N)\n",
"\n",
" R = define_ring(np.zeros(img_shape, dtype=bool), radii)\n",
" mask = np.asarray([ ring_notch(img_shape, θs[r], radii[r], notch_width=notch_width) for r in range(len(radii))])\n",
" mask = np.sum(mask, axis=0)\n",
"\n",
" return R[None,:,:]*np.logical_not( mask )"
],
"metadata": {
"id": "53embXj5iqV6"
},
"execution_count": 2,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Rings test"
],
"metadata": {
"id": "Jm3p1JlLqxO5"
}
},
{
"cell_type": "code",
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"### input\n",
"N = 256\n",
"angles = np.array([[90,270,180.,0,360,65,182, 234], [45,86,243,360,97,12, 311, 34], [90,270,90,5,156,65,182, 211]])\n",
"radii = np.array([[30,50],[70,90],[110,130]])\n",
"\n",
"### ouput\n",
"A = get_rings(N, angles, radii)\n",
"\n",
"plt.imshow(A[-8], interpolation='none', cmap='Greys')\n",
"plt.axis(\"off\")\n",
"plt.show()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 406
},
"id": "2by18XdLq1bh",
"outputId": "e71e882d-e45e-479b-fb72-bb49f74efe99"
},
"execution_count": 3,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAATzElEQVR4nO3d0ZbqOA4FUDOr//+XmYdufLlVFEUgiY/svd9mreluIsmRraTgcr1erw0AWmv/G/0BAMihKQDQaQoAdJoCAJ2mAECnKQDQaQoAdJoCAN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JcGsAbPFADonBQWY7TEFk4H69EUFma0xFeaAMZHAHROCnRGS2tyOuCepsBDj24UGsUcNAGeMT4CoHNS4GVOD7U4EfAOTYGP/HTj0SzO4+bPnoyPAOicFDiEE8T+nAg4g6bAqdzYIJvxEQCdpgBApykA0GkKAHSaAgCdpgBApykA0GkKAHSaAgDd/wHCLXipRXdU0gAAAABJRU5ErkJggg==\n"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [
"import matplotlib.pyplot as plt\n",
"\n",
"### input\n",
"N = 64\n",
"angles = 360*np.random.rand(3,100000)\n",
"radii = np.array([[1,10],[15,30]]) #np.array([[30,50],[70,90],[110,130]])\n",
"\n",
"### ouput\n",
"A = get_rings(N, angles, radii)\n",
"\n",
"\n",
"print(A.size/1024/1024, A.dtype)\n",
"plt.imshow(A[-8], interpolation='none', cmap='Greys')\n",
"plt.axis(\"off\")\n",
"plt.show()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 424
},
"id": "9KT-Nq39oJw_",
"outputId": "27070a9b-8f0a-425b-c843-c28883e82282"
},
"execution_count": 4,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"390.625 bool\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAHf0lEQVR4nO3dwW7bRhRAUarI//8yuyhwExRiFDm0ODM8Zxl0QVuULx7mlXzs+75vALBt2z9XXwAA4xAFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCAPlx9QVwH4/H4+pLWNK+71dfAgsxK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4iXztpKscX0PWwNcSaTAgARBQAiCgBEFACIg2Y+xoEojM+kAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAORfYbo0OJmrIksAAAAASUVORK5CYII=\n"
},
"metadata": {}
}
]
},
{
"cell_type": "markdown",
"source": [
"## Pendulum Data Set"
],
"metadata": {
"id": "xIZtaQQp710J"
}
},
{
"cell_type": "code",
"source": [
"### download numpy zip file for pendulum trajectory\n",
"try:\n",
" angles = np.load(\"pendulum_L100m_1000s_90deg_a0_0014mss.npy\")[1]\n",
"except:\n",
" !wget https://raw.githubusercontent.com/jcandane/gym_rings/main/pendulum_L100m_1000s_90deg_a0_0014mss.npy\n",
" angles = np.load(\"pendulum_L100m_1000s_90deg_a0_0014mss.npy\")[1] ## for angles, [0] are real time-stamps\n",
"\n",
"angles=np.array([angles])-90\n",
"N = 32\n",
"radii = np.array([[5,15]])\n",
"\n",
"### ouput data_set\n",
"A = get_rings(N, angles, radii)"
],
"metadata": {
"id": "ppzst4Fjpje4"
},
"execution_count": 5,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(A.size/1024/1024, A.dtype)\n",
"plt.imshow(A[0], interpolation='none', cmap='Greys')\n",
"plt.axis(\"off\")\n",
"plt.show()\n",
"\n",
"plt.imshow(A[-1], interpolation='none', cmap='Greys')\n",
"plt.axis(\"off\")\n",
"plt.show()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 813
},
"id": "AzxYEkL5AEGy",
"outputId": "26a585a7-41d6-47c3-b726-7ec69366cfa2"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"97.65625 bool\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bG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CC\n"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAGFCAYAAAASI+9IAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/bCgiHAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAGJ0lEQVR4nO3cwW5TMRRF0Rjl/3/ZzDaCAdQ0L3aStcaRsKo2W3fAGXPOeQOA2+32Y/cDADiHKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAct/9AM43xtj9BDaZc+5+Ak/mUgAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgNg+ehP2ibjClb9XdpXO5FIAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEDMXBzKbAXvbvV33CzGc7gUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgto++wT4RPM+Vf292lX5xKQAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIGYu/mC6Aj7P6t/9O89iuBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAue9+wNXGGLufALyZle+VOeeFL3k8lwIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAOQlt4/sGQGvYvX7avdWkksBgIgCABEFACIKAEQUAIgoABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAkPvuB9xut9sYY/cTAI6w8n0453z4v+9SACCiAEBEAYCIAgARBQAiCgBEFACIKAAQUQAgogBARAGAHLF9BF91xdbLieyBsYtLAYCIAgARBQAi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oABBRACCiAEBEAYCIAgARBQAiCgBEFACIKAAQMxf8k6kD+BwuBQAiCgBEFACIKAAQUQAgogBARAGAiAIAEQUAIgoARBQAiCgAEFEAIKIAQEQBgIgCABEFACIKAEQUAIgoABBRACA/Aeq5ajq2wg9GAAAAAElFTkSuQmCC\n"
},
"metadata": {}
}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "W--VG00o83zE"
},
"execution_count": 6,
"outputs": []
}
]
} |