Procházet zdrojové kódy

Added example notebook for NextConvGeN.

Kristian Schultz před 3 roky
rodič
revize
2cc0111be1
1 změnil soubory, kde provedl 339 přidání a 0 odebrání
  1. 339 0
      NextConvGeN-Example.ipynb

+ 339 - 0
NextConvGeN-Example.ipynb

@@ -0,0 +1,339 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "id": "b9b5254c",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2022-10-24 13:21:55.361983: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory\n",
+      "2022-10-24 13:21:55.362017: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.\n"
+     ]
+    }
+   ],
+   "source": [
+    "from library.analysis import loadDataset, testSets\n",
+    "from library.generators.NextConvGeN import NextConvGeN\n",
+    "from fdc.fdc import FDC"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "id": "6bfec0a2",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Load 'folding_flare-F'\n",
+      "from pickle file\n",
+      "non empty cut in folding_flare-F! (70 points)\n",
+      "Data loaded.\n"
+     ]
+    }
+   ],
+   "source": [
+    "data = loadDataset(testSets[4])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 3,
+   "id": "6d686da5",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "(1066, 1023, 43)\n"
+     ]
+    }
+   ],
+   "source": [
+    "print((len(data.data), len(data.data0), len(data.data1)))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 4,
+   "id": "9e3e3806",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "fdc = FDC()\n",
+    "fdc.nom_list = list(range(data.data0.shape[1]))"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "id": "01d71d6a",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "gen = NextConvGeN(data.data0.shape[1], neb=5, fdc=fdc)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 6,
+   "id": "ad01be2b",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2022-10-24 13:22:01.772778: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory\n",
+      "2022-10-24 13:22:01.772808: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)\n",
+      "2022-10-24 13:22:01.772828: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (efdcb09fb24e): /proc/driver/nvidia/version does not exist\n",
+      "2022-10-24 13:22:01.773733: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA\n",
+      "To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n"
+     ]
+    }
+   ],
+   "source": [
+    "gen.reset(data.data1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 7,
+   "id": "4698522c",
+   "metadata": {
+    "scrolled": false
+   },
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "FDC.normalize (init): 0.00003 / 0.000s\n",
+      "|data| = (43, 11)\n",
+      "FDC.normalize (clustering CONT): 0.00005 / 0.000s\n",
+      "FDC.normalize (clustering ORD): 0.00001 / 0.000s\n",
+      "umap with metric 'hamming'\n",
+      "|part| = (43, 11)\n",
+      "|emb_A| = (43, 1)\n",
+      "|emb_A| = (43, 1)\n",
+      "FDC.normalize (clustering NOM): 5.66512 / 5.665s\n",
+      "FDC.normalize (concat): 0.00007 / 5.665s\n",
+      "|fdc| = (43, 1)\n",
+      "FDC.normalize (total): 0.00002 / 5.665s\n",
+      "|N| = (43, 1)\n",
+      "|D| = (43, 11)\n",
+      "[==========] [==========] [==========]\r"
+     ]
+    }
+   ],
+   "source": [
+    "gen.train(data.data1)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 8,
+   "id": "fe3027a2",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Train: #1 213.6447s\n",
+      "BMB: #2580 0.8377s\n",
+      "NbhSearch: #1 0.0139s\n",
+      "NBH: #2150 1.4677s\n",
+      "GenSamples: #2150 68.9012s\n",
+      "Fit: #2150 89.1429s\n"
+     ]
+    }
+   ],
+   "source": [
+    "for x in gen.timing:\n",
+    "    print(gen.timing[x])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 9,
+   "id": "919390c3",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "<fdc.fdc.FDC at 0x7ff70b133910>"
+      ]
+     },
+     "execution_count": 9,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "gen.fdc"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "cda17654",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "syntheticPoints = gen.generateData(10)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "id": "41853bd3",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "array([[2., 0., 0., 1., 0., 1., 1., 1., 0., 1., 1.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 1., 2., 0., 0.],\n",
+       "       [4., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [2., 1., 1., 2., 0., 1., 1., 1., 3., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 2., 0., 0., 1., 0., 1., 0., 0.],\n",
+       "       [2., 1., 1., 2., 0., 1., 1., 1., 3., 0., 0.],\n",
+       "       [4., 2., 0., 0., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 0., 0., 0., 1., 0., 0., 0., 0.]], dtype=float32)"
+      ]
+     },
+     "execution_count": 11,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "syntheticPoints"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "id": "da5ebdb9",
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "array([[2., 0., 1., 2., 0., 1., 1., 1., 0., 0., 0.],\n",
+       "       [2., 0., 1., 1., 0., 1., 1., 0., 4., 0., 0.],\n",
+       "       [0., 0., 1., 1., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [2., 0., 1., 2., 2., 1., 1., 1., 1., 0., 0.],\n",
+       "       [2., 1., 1., 1., 0., 1., 1., 1., 1., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 2., 0., 0.],\n",
+       "       [2., 1., 1., 2., 0., 1., 1., 1., 3., 0., 0.],\n",
+       "       [4., 2., 0., 0., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 0., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [4., 1., 0., 2., 0., 1., 1., 0., 2., 0., 0.],\n",
+       "       [4., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [3., 1., 0., 1., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [1., 2., 0., 2., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [2., 1., 0., 1., 0., 1., 1., 0., 4., 0., 0.],\n",
+       "       [0., 1., 1., 2., 0., 1., 1., 1., 1., 1., 0.],\n",
+       "       [0., 1., 1., 2., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [0., 1., 0., 2., 0., 0., 1., 0., 0., 0., 0.],\n",
+       "       [2., 0., 0., 1., 0., 1., 1., 1., 0., 1., 1.],\n",
+       "       [2., 0., 0., 2., 0., 1., 1., 1., 0., 0., 0.],\n",
+       "       [2., 1., 0., 1., 0., 1., 1., 1., 0., 0., 0.],\n",
+       "       [4., 1., 1., 1., 0., 1., 1., 0., 2., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 1., 1., 0., 0.],\n",
+       "       [2., 0., 1., 2., 0., 1., 1., 1., 0., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 1., 0., 1.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 3., 0., 0.],\n",
+       "       [4., 2., 1., 1., 0., 0., 1., 0., 0., 0., 0.],\n",
+       "       [2., 1., 0., 1., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [0., 1., 1., 1., 2., 1., 1., 0., 0., 0., 0.],\n",
+       "       [4., 1., 0., 2., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 0., 1., 2., 0., 1., 1., 1., 2., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 2., 0., 0.],\n",
+       "       [2., 1., 1., 1., 2., 1., 1., 0., 0., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 4., 0., 0.],\n",
+       "       [0., 1., 1., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [1., 2., 0., 1., 0., 0., 1., 0., 0., 0., 0.],\n",
+       "       [4., 1., 0., 2., 0., 1., 1., 0., 1., 0., 0.],\n",
+       "       [0., 1., 0., 1., 0., 1., 1., 0., 0., 0., 0.],\n",
+       "       [1., 2., 0., 1., 0., 1., 1., 0., 1., 0., 0.]])"
+      ]
+     },
+     "execution_count": 12,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "data.data1"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "id": "4043256c",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "0.0\n",
+      "1.0\n",
+      "0.0\n",
+      "0.0\n",
+      "0.0\n",
+      "0.0\n",
+      "1.0\n",
+      "0.0\n",
+      "0.0\n",
+      "1.0\n"
+     ]
+    }
+   ],
+   "source": [
+    "import math\n",
+    "for p in syntheticPoints:\n",
+    "    print(min([math.sqrt(sum(y*y)) for y in (data.data1 - p) ]))"
+   ]
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.8.15"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}