diff --git a/guix.scm b/guix.scm index cbacef15272ce38b306497c32ae3254a1d829922..ae0c88c27bb553b3ffe9bee6f97fb060060c91de 100644 --- a/guix.scm +++ b/guix.scm @@ -2,6 +2,7 @@ ((gnu packages python-xyz) #:select (python-matplotlib python-nltk python-seaborn)) + ((gnu packages graphviz) #:select (graphviz python-graphviz)) (guix gexp) (guix git-download) ((guix licenses) #:select (lgpl3+)) @@ -19,14 +20,17 @@ #:select? (git-predicate %source-dir))) (build-system python-build-system) (propagated-inputs - (list python-matplotlib + (list graphviz + python-graphviz + python-matplotlib python-nltk python-pandas - python-seaborn)) + python-seaborn + )) (home-page "https://gitlab.liris.cnrs.fr/geode/pyedda") (synopsis "A set of tools to explore the EDdA") (description - "PyEDdA provides a python library to expose the data from the Encyclopédie - by Diderot & d'Alembert, as well as several subpackages for the various - approach tested in the course of project GÉODE.") + "PyEDdA provides a python library to expose the data from the Encyclopédie + by Diderot & d'Alembert, as well as several subpackages for the various + approach tested in the course of project GÉODE.") (license lgpl3+))) diff --git a/notebooks/Domains Graphs.ipynb b/notebooks/Domains Graphs.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..01bc7d85e5ab91c095f0f2927c94d3a80f73ae47 --- /dev/null +++ b/notebooks/Domains Graphs.ipynb @@ -0,0 +1,122 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "fc7a6e69", + "metadata": {}, + "outputs": [], + "source": [ + "from EDdA import data\n", + "from EDdA.store import preparePath\n", + "from EDdA.classification import confusionMatrix, metrics, toPNG, topNGrams\n", + "from IPython.display import Image\n", + "import graphviz\n", + "import os" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "f49c39b5", + "metadata": {}, + "outputs": [], + "source": [ + "source = data.load('training_set')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3a37bfa1", + "metadata": {}, + "outputs": [], + "source": [ + "def nearestAdjacency(matrix):\n", + " m = []\n", + " dimension = len(matrix)\n", + " for i in range(0, dimension):\n", + " link = max([matrix[i][j] for j in range(0, dimension) if j != i])\n", + " if link == 0:\n", + " m.append([])\n", + " else:\n", + " m.append([j for j in range(0, dimension) if j != i and matrix[i][j] == link])\n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "b9c92861", + "metadata": {}, + "outputs": [], + "source": [ + "def listToMatrix(adjacencyList):\n", + " m = []\n", + " dimension = len(adjacencyList)\n", + " for i in range(0, dimension):\n", + " m.append(dimension * [0])\n", + " for j in adjacencyList[i]:\n", + " m[i][j] = 1\n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "69d494ab", + "metadata": {}, + "outputs": [], + "source": [ + "def showGraph(n, ranks, metricsName):\n", + " adjacencyList = nearestAdjacency(confusionMatrix(topNGrams(source, n, ranks), metrics[metricsName]))\n", + " g = graphviz.Digraph()\n", + " g.graph_attr['rankdir'] = 'LR'\n", + " dimension = len(adjacencyList)\n", + " for i in range(0, dimension):\n", + " g.node(data.domains[i])\n", + " for i in range(0, dimension):\n", + " for j in adjacencyList[i]:\n", + " g.edge(data.domains[i], data.domains[j])\n", + " return Image(filename=g.render(\n", + " preparePath(f'../graph/{source.hash}/{n}grams_top{ranks}_{metricsName}.gv'),\n", + " format='png')\n", + " )" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "3d0f3709", + "metadata": {}, + "outputs": [], + "source": [ + "for n in range(1, 4):\n", + " for ranks in [10, 50, 100]:\n", + " for name in metrics:\n", + " showGraph(n, ranks, name)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "/gnu/store/2rpsj69fzmcnafz4rml0blrynfayxqzr-python-wrapper-3.9.9/bin/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.9.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}