diff --git a/VERSION b/VERSION index ad13d9996b3600276db36d6fa9e8a81909d28b95..e19bf06615016b7d1b6b87c8c27ae4becf797977 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -splearn:1.0.1 \ No newline at end of file +splearn:1.1.0 \ No newline at end of file diff --git a/examples/3.pautomac_light.train.dot.gv b/examples/3.pautomac_light.train.dot.gv new file mode 100644 index 0000000000000000000000000000000000000000..c3ac1dc8017bc9d5ff6f406afafac9c1ef275d9c --- /dev/null +++ b/examples/3.pautomac_light.train.dot.gv @@ -0,0 +1,48 @@ +//3.pautomac_light.train.dot +digraph { + 0 [label="0 +______ +> -0.00 +0.08 >"] + 1 [label="1 +______ +> 0.00 +-0.02 >"] + 2 [label="2 +______ +> -0.04 +-0.45 >"] + 3 [label="3 +______ +> -0.11 +0.63 >"] + 4 [label="4 +______ +> -0.09 +-0.55 >"] + 0 -> 1 [label="0:-0.24"] + 0 -> 2 [label="0:0.35"] + 0 -> 3 [label="0:-0.28"] + 0 -> 4 [label="0:-0.21"] + 1 -> 1 [label="0:-0.30"] + 1 -> 2 [label="0:0.21"] + 1 -> 4 [label="0:-0.56"] + 2 -> 3 [label="0:-0.21"] + 4 -> 4 [label="0:0.24"] + 0 -> 2 [label="1:-0.30"] + 0 -> 3 [label="1:0.28"] + 0 -> 4 [label="1:0.20"] + 1 -> 2 [label="1:0.26"] + 0 -> 2 [label="2:0.38"] + 0 -> 3 [label="2:-0.22"] + 0 -> 4 [label="2:-0.23"] + 1 -> 4 [label="2:0.35"] + 1 -> 2 [label="3:0.28"] + 1 -> 3 [label="3:-0.24"] + 2 -> 2 [label="3:-0.63"] + 2 -> 3 [label="3:0.47"] + 3 -> 2 [label="3:-0.37"] + 3 -> 4 [label="3:0.65"] + 4 -> 3 [label="3:-0.38"] + 4 -> 4 [label="3:0.66"] +} diff --git a/examples/3.pautomac_light.train.dot.gv.pdf b/examples/3.pautomac_light.train.dot.gv.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ec0f99e07bfcdac4b0e0c21fe5c94795515f90c1 Binary files /dev/null and b/examples/3.pautomac_light.train.dot.gv.pdf differ diff --git a/examples/GraphvizTests.ipynb b/examples/GraphvizTests.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..e5b19df6b49006144f5fc69fb0bd0ec02221226a --- /dev/null +++ b/examples/GraphvizTests.ipynb @@ -0,0 +1,776 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from graphviz import Digraph\n", + "from graphviz import Source\n", + "from splearn.datasets.base import load_data_sample\n", + "from splearn.tests.datasets.get_dataset_path import get_dataset_path" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "train_file = '3.pautomac_light.train'\n", + "data = load_data_sample(adr=get_dataset_path(train_file))" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.nbL" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5000" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.nbEx" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Splearn_array([[ 3., 0., 3., ..., -1., -1., -1.],\n", + " [ 3., 3., -1., ..., -1., -1., -1.],\n", + " [ 3., 2., 0., ..., -1., -1., -1.],\n", + " ...,\n", + " [ 3., 1., 3., ..., -1., -1., -1.],\n", + " [ 3., 0., 3., ..., -1., -1., -1.],\n", + " [ 3., 3., 1., ..., -1., -1., -1.]])" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data.data" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "from splearn import Learning, Hankel , Spectral" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Start Hankel matrix computation\n", + "End of Hankel matrix computation\n", + "Start Building Automaton from Hankel matrix\n", + "End of Automaton computation\n" + ] + }, + { + "data": { + "text/plain": [ + "Spectral(lcolumns=7, lrows=7, mode_quiet=False, partial=True, rank=5,\n", + " smooth_method='none', sparse=True, version='classic')" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sp = Spectral()\n", + "sp.fit(X=data.data)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "A = sp.Automaton" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([-0.00049344, 0.00306347, -0.04407393, -0.10777703, -0.08663914])" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.initial" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0.07757137, -0.02422029, -0.44681254, 0.62773208, -0.55467443])" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.final" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[array([[ 0.04512121, -0.2403897 , 0.34945 , -0.28116807, -0.21402523],\n", + " [ 0.06925801, -0.30062293, 0.20641375, -0.14960814, -0.55805732],\n", + " [ 0.02980115, -0.13866481, 0.18362213, -0.20969545, -0.14481622],\n", + " [ 0.00569934, -0.02338583, -0.06600665, 0.10749935, -0.15103655],\n", + " [-0.02008655, 0.09026348, -0.00552559, -0.03135532, 0.24329022]]),\n", + " array([[ 0.07744772, 0.09007074, -0.30472201, 0.27676245, 0.20289396],\n", + " [-0.0990298 , -0.08061847, 0.25853171, -0.1208633 , -0.11085208],\n", + " [-0.06171079, -0.06244152, 0.12007655, 0.00250637, -0.15679675],\n", + " [-0.00273697, -0.00900572, -0.00046003, -0.00855043, -0.05375465],\n", + " [ 0.03098733, 0.0397268 , -0.04997113, 0.00357694, 0.14182576]]),\n", + " array([[-0.06791915, -0.11357938, 0.37955393, -0.2178498 , -0.22977695],\n", + " [ 0.11596642, 0.14914957, -0.13357508, -0.00891606, 0.34841537],\n", + " [ 0.01173082, 0.0192738 , 0.04142658, -0.03534659, 0.02316491],\n", + " [ 0.00732891, 0.00553651, -0.02245608, 0.03611543, -0.03851434],\n", + " [-0.01058989, -0.01062662, -0.00054311, -0.02556748, 0.04984889]]),\n", + " array([[ 0.07276211, -0.01571956, 0.07428593, -0.10369862, 0.02475347],\n", + " [-0.05607105, -0.08896207, 0.27638225, -0.23711256, 0.07372294],\n", + " [-0.00739129, -0.0487418 , -0.62912397, 0.46816277, 0.09251699],\n", + " [-0.00711022, -0.05623318, -0.36606659, -0.0132978 , 0.64910332],\n", + " [ 0.00233552, -0.02156115, 0.09096243, -0.38438823, 0.66164772]])]" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.transitions" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'classic'" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.type" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.nbL" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A.nbS" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "th = 0.2\n", + "wa = Digraph(comment='3.pautomac_light.train')\n", + "for i in range(A.nbS):\n", + " label = \"{0:d}\\n______\\n> {1:.2f}\\n{2:.2f} >\".format(i, A.initial[i], A.final[i])\n", + " wa.node(str(i),label)\n", + "for l in range(A.nbL):\n", + " for i in range(A.nbS):\n", + " for j in range(A.nbS):\n", + " weight = A.transitions[l][i,j]\n", + " if (np.abs(weight) > th):\n", + " label = \"{0:d}:{1:.2f}\".format(l,weight)\n", + " wa.edge(str(i), str(j), label)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "// 3.pautomac_light.train\n", + "digraph {\n", + "\t0 [label=\"0\n", + "______\n", + "> -0.00\n", + "0.08 >\"]\n", + "\t1 [label=\"1\n", + "______\n", + "> 0.00\n", + "-0.02 >\"]\n", + "\t2 [label=\"2\n", + "______\n", + "> -0.04\n", + "-0.45 >\"]\n", + "\t3 [label=\"3\n", + "______\n", + "> -0.11\n", + "0.63 >\"]\n", + "\t4 [label=\"4\n", + "______\n", + "> -0.09\n", + "-0.55 >\"]\n", + "\t0 -> 1 [label=\"0:-0.24\"]\n", + "\t0 -> 2 [label=\"0:0.35\"]\n", + "\t0 -> 3 [label=\"0:-0.28\"]\n", + "\t0 -> 4 [label=\"0:-0.21\"]\n", + "\t1 -> 1 [label=\"0:-0.30\"]\n", + "\t1 -> 2 [label=\"0:0.21\"]\n", + "\t1 -> 4 [label=\"0:-0.56\"]\n", + "\t2 -> 3 [label=\"0:-0.21\"]\n", + "\t4 -> 4 [label=\"0:0.24\"]\n", + "\t0 -> 2 [label=\"1:-0.30\"]\n", + "\t0 -> 3 [label=\"1:0.28\"]\n", + "\t0 -> 4 [label=\"1:0.20\"]\n", + "\t1 -> 2 [label=\"1:0.26\"]\n", + "\t0 -> 2 [label=\"2:0.38\"]\n", + "\t0 -> 3 [label=\"2:-0.22\"]\n", + "\t0 -> 4 [label=\"2:-0.23\"]\n", + "\t1 -> 4 [label=\"2:0.35\"]\n", + "\t1 -> 2 [label=\"3:0.28\"]\n", + "\t1 -> 3 [label=\"3:-0.24\"]\n", + "\t2 -> 2 [label=\"3:-0.63\"]\n", + "\t2 -> 3 [label=\"3:0.47\"]\n", + "\t3 -> 2 [label=\"3:-0.37\"]\n", + "\t3 -> 4 [label=\"3:0.65\"]\n", + "\t4 -> 3 [label=\"3:-0.38\"]\n", + "\t4 -> 4 [label=\"3:0.66\"]\n", + "}\n" + ] + } + ], + "source": [ + "print(wa.source)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "//automata.dot\n", + "digraph {\n", + "\t0 [label=\"0\n", + "______\n", + "> -0.00\n", + "0.08 >\"]\n", + "\t1 [label=\"1\n", + "______\n", + "> 0.00\n", + "-0.02 >\"]\n", + "\t2 [label=\"2\n", + "______\n", + "> -0.04\n", + "-0.45 >\"]\n", + "\t3 [label=\"3\n", + "______\n", + "> -0.11\n", + "0.63 >\"]\n", + "\t4 [label=\"4\n", + "______\n", + "> -0.09\n", + "-0.55 >\"]\n", + "\t0 -> 1 [label=\"0:-0.24\"]\n", + "\t0 -> 2 [label=\"0:0.35\"]\n", + "\t0 -> 3 [label=\"0:-0.28\"]\n", + "\t0 -> 4 [label=\"0:-0.21\"]\n", + "\t1 -> 1 [label=\"0:-0.30\"]\n", + "\t1 -> 2 [label=\"0:0.21\"]\n", + "\t1 -> 4 [label=\"0:-0.56\"]\n", + "\t2 -> 3 [label=\"0:-0.21\"]\n", + "\t4 -> 4 [label=\"0:0.24\"]\n", + "\t0 -> 2 [label=\"1:-0.30\"]\n", + "\t0 -> 3 [label=\"1:0.28\"]\n", + "\t0 -> 4 [label=\"1:0.20\"]\n", + "\t1 -> 2 [label=\"1:0.26\"]\n", + "\t0 -> 2 [label=\"2:0.38\"]\n", + "\t0 -> 3 [label=\"2:-0.22\"]\n", + "\t0 -> 4 [label=\"2:-0.23\"]\n", + "\t1 -> 4 [label=\"2:0.35\"]\n", + "\t1 -> 2 [label=\"3:0.28\"]\n", + "\t1 -> 3 [label=\"3:-0.24\"]\n", + "\t2 -> 2 [label=\"3:-0.63\"]\n", + "\t2 -> 3 [label=\"3:0.47\"]\n", + "\t3 -> 2 [label=\"3:-0.37\"]\n", + "\t3 -> 4 [label=\"3:0.65\"]\n", + "\t4 -> 3 [label=\"3:-0.38\"]\n", + "\t4 -> 4 [label=\"3:0.66\"]\n", + "}\n", + "\n" + ] + } + ], + "source": [ + "nb_dec = 2\n", + "threshold = th\n", + "filename = \"automata.dot\"\n", + "prec = \".{:d}f\".format(nb_dec)\n", + "out = \"//{:s}\\ndigraph {{\\n\".format(filename)\n", + "for i in range(A.nbS):\n", + " label = \"{0:d}\\n______\\n> {1:\" + prec + \"}\\n{2:\" + prec + \"} >\"\n", + " label = label.format(i, A.initial[i], A.final[i])\n", + " out += \"\\t{0:d} [label=\\\"\".format(i)\n", + " out += label + \"\\\"]\\n\"\n", + "for l in range(A.nbL):\n", + " for i in range(A.nbS):\n", + " for j in range(A.nbS):\n", + " weight = A.transitions[l][i,j]\n", + " if (np.abs(weight) > threshold):\n", + " label = \"{0:d}:{1:\" + prec + \"}\"\n", + " label = label.format(l,weight)\n", + " out += \"\\t{0:d} -> {1:d} [label=\\\"\".format(i,j)\n", + " out += label + \"\\\"]\\n\"\n", + "out += \"}\\n\"\n", + "print(out)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", + "<!-- Generated by graphviz version 2.38.0 (20140413.2041)\n", + " -->\n", + "<!-- Title: %3 Pages: 1 -->\n", + "<svg width=\"769pt\" height=\"693pt\"\n", + " viewBox=\"0.00 0.00 769.23 692.83\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", + "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 688.833)\">\n", + "<title>%3</title>\n", + "<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-688.833 765.226,-688.833 765.226,4 -4,4\"/>\n", + "<!-- 0 -->\n", + "<g id=\"node1\" class=\"node\"><title>0</title>\n", + "<ellipse fill=\"none\" stroke=\"black\" cx=\"454.226\" cy=\"-636.749\" rx=\"40.1111\" ry=\"48.1667\"/>\n", + "<text text-anchor=\"middle\" x=\"454.226\" y=\"-655.549\" font-family=\"Times,serif\" font-size=\"14.00\">0</text>\n", + "<text text-anchor=\"middle\" x=\"454.226\" y=\"-640.549\" font-family=\"Times,serif\" font-size=\"14.00\">______</text>\n", + "<text text-anchor=\"middle\" x=\"454.226\" y=\"-625.549\" font-family=\"Times,serif\" font-size=\"14.00\">> -0.00</text>\n", + "<text text-anchor=\"middle\" x=\"454.226\" y=\"-610.549\" font-family=\"Times,serif\" font-size=\"14.00\">0.08 ></text>\n", + "</g>\n", + "<!-- 1 -->\n", + "<g id=\"node2\" class=\"node\"><title>1</title>\n", + "<ellipse fill=\"none\" stroke=\"black\" cx=\"91.2259\" cy=\"-489.583\" rx=\"40.1111\" ry=\"48.1667\"/>\n", + "<text text-anchor=\"middle\" x=\"91.2259\" y=\"-508.383\" font-family=\"Times,serif\" font-size=\"14.00\">1</text>\n", + "<text text-anchor=\"middle\" x=\"91.2259\" y=\"-493.383\" font-family=\"Times,serif\" font-size=\"14.00\">______</text>\n", + "<text text-anchor=\"middle\" x=\"91.2259\" y=\"-478.383\" font-family=\"Times,serif\" font-size=\"14.00\">> 0.00</text>\n", + "<text text-anchor=\"middle\" x=\"91.2259\" y=\"-463.383\" font-family=\"Times,serif\" font-size=\"14.00\">-0.02 ></text>\n", + "</g>\n", + "<!-- 0->1 -->\n", + "<g id=\"edge1\" class=\"edge\"><title>0->1</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M413.762,-633.458C356.474,-628.716 249.94,-614.281 171.226,-570.666 154.111,-561.183 138.209,-546.963 125.164,-533.125\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"127.545,-530.542 118.221,-525.509 122.371,-535.257 127.545,-530.542\"/>\n", + "<text text-anchor=\"middle\" x=\"191.226\" y=\"-559.466\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.24</text>\n", + "</g>\n", + "<!-- 2 -->\n", + "<g id=\"node3\" class=\"node\"><title>2</title>\n", + "<ellipse fill=\"none\" stroke=\"black\" cx=\"271.226\" cy=\"-342.416\" rx=\"40.1111\" ry=\"48.1667\"/>\n", + "<text text-anchor=\"middle\" x=\"271.226\" y=\"-361.216\" font-family=\"Times,serif\" font-size=\"14.00\">2</text>\n", + "<text text-anchor=\"middle\" x=\"271.226\" y=\"-346.216\" font-family=\"Times,serif\" font-size=\"14.00\">______</text>\n", + "<text text-anchor=\"middle\" x=\"271.226\" y=\"-331.216\" font-family=\"Times,serif\" font-size=\"14.00\">> -0.04</text>\n", + "<text text-anchor=\"middle\" x=\"271.226\" y=\"-316.216\" font-family=\"Times,serif\" font-size=\"14.00\">-0.45 ></text>\n", + "</g>\n", + "<!-- 0->2 -->\n", + "<g id=\"edge2\" class=\"edge\"><title>0->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M413.716,-631.974C360.806,-624.502 271.16,-602.428 239.226,-537.666 220.324,-499.332 225.355,-481.927 239.226,-441.5 242.515,-431.913 248.899,-432.665 253.226,-423.5 256.729,-416.079 259.567,-407.944 261.862,-399.793\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"265.308,-400.444 264.4,-389.888 258.527,-398.706 265.308,-400.444\"/>\n", + "<text text-anchor=\"middle\" x=\"256.726\" y=\"-485.883\" font-family=\"Times,serif\" font-size=\"14.00\">0:0.35</text>\n", + "</g>\n", + "<!-- 0->2 -->\n", + "<g id=\"edge10\" class=\"edge\"><title>0->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M416.405,-620.115C383.087,-604.321 335.967,-576.672 310.226,-537.666 283.416,-497.041 274.329,-441.975 271.563,-400.846\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"275.049,-400.494 270.989,-390.707 268.06,-400.889 275.049,-400.494\"/>\n", + "<text text-anchor=\"middle\" x=\"330.226\" y=\"-485.883\" font-family=\"Times,serif\" font-size=\"14.00\">1:-0.30</text>\n", + "</g>\n", + "<!-- 0->2 -->\n", + "<g id=\"edge14\" class=\"edge\"><title>0->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M426.805,-600.768C413.418,-582.624 397.756,-559.695 386.226,-537.666 365.062,-497.233 372.828,-481.147 350.226,-441.5 338.394,-420.744 322.27,-399.838 307.674,-382.691\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"310.287,-380.362 301.096,-375.092 304.994,-384.943 310.287,-380.362\"/>\n", + "<text text-anchor=\"middle\" x=\"403.726\" y=\"-485.883\" font-family=\"Times,serif\" font-size=\"14.00\">2:0.38</text>\n", + "</g>\n", + "<!-- 3 -->\n", + "<g id=\"node4\" class=\"node\"><title>3</title>\n", + "<ellipse fill=\"none\" stroke=\"black\" cx=\"379.226\" cy=\"-195.25\" rx=\"40.1111\" ry=\"48.1667\"/>\n", + "<text text-anchor=\"middle\" x=\"379.226\" y=\"-214.05\" font-family=\"Times,serif\" font-size=\"14.00\">3</text>\n", + "<text text-anchor=\"middle\" x=\"379.226\" y=\"-199.05\" font-family=\"Times,serif\" font-size=\"14.00\">______</text>\n", + "<text text-anchor=\"middle\" x=\"379.226\" y=\"-184.05\" font-family=\"Times,serif\" font-size=\"14.00\">> -0.11</text>\n", + "<text text-anchor=\"middle\" x=\"379.226\" y=\"-169.05\" font-family=\"Times,serif\" font-size=\"14.00\">0.63 ></text>\n", + "</g>\n", + "<!-- 0->3 -->\n", + "<g id=\"edge3\" class=\"edge\"><title>0->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M452.202,-588.563C449.086,-548.16 441.192,-489.137 421.226,-441.5 417.411,-432.398 411.851,-432.678 408.226,-423.5 402.101,-407.994 391.559,-315.319 385.014,-253.21\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"388.482,-252.721 383.959,-243.14 381.52,-253.45 388.482,-252.721\"/>\n", + "<text text-anchor=\"middle\" x=\"428.226\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.28</text>\n", + "</g>\n", + "<!-- 0->3 -->\n", + "<g id=\"edge11\" class=\"edge\"><title>0->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M458.728,-588.765C459.333,-577.901 459.626,-566.385 459.226,-555.666 456.78,-490.122 460.9,-472.853 448.226,-408.5 437.216,-352.597 416.089,-290.887 400.1,-248.485\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"403.294,-247.039 396.464,-238.94 396.753,-249.531 403.294,-247.039\"/>\n", + "<text text-anchor=\"middle\" x=\"467.726\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">1:0.28</text>\n", + "</g>\n", + "<!-- 0->3 -->\n", + "<g id=\"edge15\" class=\"edge\"><title>0->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M469.799,-592.029C484.073,-546.158 501.295,-472.031 489.226,-408.5 477.258,-345.499 439.666,-281.229 411.741,-240.172\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"414.503,-238.013 405.941,-231.772 408.743,-241.99 414.503,-238.013\"/>\n", + "<text text-anchor=\"middle\" x=\"511.226\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">2:-0.22</text>\n", + "</g>\n", + "<!-- 4 -->\n", + "<g id=\"node5\" class=\"node\"><title>4</title>\n", + "<ellipse fill=\"none\" stroke=\"black\" cx=\"442.226\" cy=\"-48.0833\" rx=\"40.1111\" ry=\"48.1667\"/>\n", + "<text text-anchor=\"middle\" x=\"442.226\" y=\"-66.8833\" font-family=\"Times,serif\" font-size=\"14.00\">4</text>\n", + "<text text-anchor=\"middle\" x=\"442.226\" y=\"-51.8833\" font-family=\"Times,serif\" font-size=\"14.00\">______</text>\n", + "<text text-anchor=\"middle\" x=\"442.226\" y=\"-36.8833\" font-family=\"Times,serif\" font-size=\"14.00\">> -0.09</text>\n", + "<text text-anchor=\"middle\" x=\"442.226\" y=\"-21.8833\" font-family=\"Times,serif\" font-size=\"14.00\">-0.55 ></text>\n", + "</g>\n", + "<!-- 0->4 -->\n", + "<g id=\"edge4\" class=\"edge\"><title>0->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M477.607,-597.504C482.438,-588.842 487.257,-579.57 491.226,-570.666 507.101,-535.055 530.584,-456.273 535.226,-423.5 551.99,-305.134 500.17,-169.815 467.252,-98.7205\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"470.36,-97.1038 462.941,-89.5402 464.024,-100.08 470.36,-97.1038\"/>\n", + "<text text-anchor=\"middle\" x=\"558.226\" y=\"-338.716\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.21</text>\n", + "</g>\n", + "<!-- 0->4 -->\n", + "<g id=\"edge12\" class=\"edge\"><title>0->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M493.889,-625.691C551.161,-608.509 650.226,-567.65 650.226,-490.583 650.226,-490.583 650.226,-490.583 650.226,-194.25 650.226,-117.288 553.282,-77.7506 491.761,-60.4088\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"492.406,-56.9574 481.839,-57.7163 490.573,-63.7131 492.406,-56.9574\"/>\n", + "<text text-anchor=\"middle\" x=\"667.726\" y=\"-338.716\" font-family=\"Times,serif\" font-size=\"14.00\">1:0.20</text>\n", + "</g>\n", + "<!-- 0->4 -->\n", + "<g id=\"edge16\" class=\"edge\"><title>0->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M494.488,-632.238C569.076,-623.292 721.226,-592.546 721.226,-490.583 721.226,-490.583 721.226,-490.583 721.226,-194.25 721.226,-92.4819 573.338,-61.9517 492.904,-52.8728\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"492.809,-49.3435 482.497,-51.7751 492.075,-56.3048 492.809,-49.3435\"/>\n", + "<text text-anchor=\"middle\" x=\"741.226\" y=\"-338.716\" font-family=\"Times,serif\" font-size=\"14.00\">2:-0.23</text>\n", + "</g>\n", + "<!-- 1->1 -->\n", + "<g id=\"edge5\" class=\"edge\"><title>1->1</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M130.19,-503.016C141.132,-502.428 149.531,-497.95 149.531,-489.583 149.531,-484.092 145.914,-480.276 140.335,-478.135\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"140.676,-474.636 130.19,-476.15 139.332,-481.505 140.676,-474.636\"/>\n", + "<text text-anchor=\"middle\" x=\"169.531\" y=\"-485.883\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.30</text>\n", + "</g>\n", + "<!-- 1->2 -->\n", + "<g id=\"edge6\" class=\"edge\"><title>1->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M92.1967,-441.117C94.4462,-429.435 98.6615,-417.663 106.226,-408.5 134.628,-374.095 183.729,-357.787 221.004,-350.112\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"222.011,-353.483 231.177,-348.168 220.698,-346.607 222.011,-353.483\"/>\n", + "<text text-anchor=\"middle\" x=\"123.726\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">0:0.21</text>\n", + "</g>\n", + "<!-- 1->2 -->\n", + "<g id=\"edge13\" class=\"edge\"><title>1->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M118.753,-454.187C131.671,-439.203 147.818,-422.016 164.226,-408.5 183,-393.035 205.798,-378.658 225.518,-367.371\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"227.338,-370.363 234.337,-362.41 223.905,-364.263 227.338,-370.363\"/>\n", + "<text text-anchor=\"middle\" x=\"181.726\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">1:0.26</text>\n", + "</g>\n", + "<!-- 1->2 -->\n", + "<g id=\"edge18\" class=\"edge\"><title>1->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M128.266,-469.839C149.989,-457.997 177.369,-441.554 199.226,-423.5 212.595,-412.456 225.728,-398.902 237.041,-386.107\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"239.931,-388.117 243.835,-378.268 234.641,-383.532 239.931,-388.117\"/>\n", + "<text text-anchor=\"middle\" x=\"231.726\" y=\"-412.3\" font-family=\"Times,serif\" font-size=\"14.00\">3:0.28</text>\n", + "</g>\n", + "<!-- 1->3 -->\n", + "<g id=\"edge19\" class=\"edge\"><title>1->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M58.6787,-460.48C48.705,-449.963 38.8801,-437.212 33.2259,-423.5 5.7168,-356.787 -20.957,-316.781 25.2259,-261.333 63.262,-215.666 240.22,-201.931 328.651,-197.887\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"328.885,-201.381 338.724,-197.451 328.582,-194.387 328.885,-201.381\"/>\n", + "<text text-anchor=\"middle\" x=\"39.2259\" y=\"-338.716\" font-family=\"Times,serif\" font-size=\"14.00\">3:-0.24</text>\n", + "</g>\n", + "<!-- 1->4 -->\n", + "<g id=\"edge7\" class=\"edge\"><title>1->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M70.1223,-448.415C66.6297,-440.348 63.433,-431.796 61.2259,-423.5 42.6367,-353.625 36.8748,-332.742 48.2259,-261.333 59.0265,-193.388 44.5356,-159.569 96.2259,-114.167 139.484,-76.1709 306.454,-58.8513 391.628,-52.3534\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"392.13,-55.8259 401.844,-51.5961 391.612,-48.845 392.13,-55.8259\"/>\n", + "<text text-anchor=\"middle\" x=\"68.2259\" y=\"-265.133\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.56</text>\n", + "</g>\n", + "<!-- 1->4 -->\n", + "<g id=\"edge17\" class=\"edge\"><title>1->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M88.146,-441.308C88.5952,-430.35 90.0294,-418.866 93.2259,-408.5 116.165,-334.105 136.66,-319.658 188.226,-261.333 253.622,-187.364 345.645,-117.08 399.099,-78.852\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"401.214,-81.6427 407.337,-72.9962 397.158,-75.9373 401.214,-81.6427\"/>\n", + "<text text-anchor=\"middle\" x=\"205.726\" y=\"-265.133\" font-family=\"Times,serif\" font-size=\"14.00\">2:0.35</text>\n", + "</g>\n", + "<!-- 2->2 -->\n", + "<g id=\"edge20\" class=\"edge\"><title>2->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M310.19,-355.85C321.132,-355.261 329.531,-350.783 329.531,-342.416 329.531,-336.925 325.914,-333.109 320.335,-330.969\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"320.676,-327.469 310.19,-328.983 319.332,-334.339 320.676,-327.469\"/>\n", + "<text text-anchor=\"middle\" x=\"349.531\" y=\"-338.716\" font-family=\"Times,serif\" font-size=\"14.00\">3:-0.63</text>\n", + "</g>\n", + "<!-- 2->3 -->\n", + "<g id=\"edge8\" class=\"edge\"><title>2->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M241.048,-310.41C229.908,-295.145 222.187,-276.756 232.226,-261.333 253.475,-228.687 295.245,-212.293 328.845,-204.133\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"329.99,-207.463 338.979,-201.856 328.455,-200.634 329.99,-207.463\"/>\n", + "<text text-anchor=\"middle\" x=\"252.226\" y=\"-265.133\" font-family=\"Times,serif\" font-size=\"14.00\">0:-0.21</text>\n", + "</g>\n", + "<!-- 2->3 -->\n", + "<g id=\"edge21\" class=\"edge\"><title>2->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M279.828,-295.156C283.373,-283.464 288.328,-271.386 295.226,-261.333 305.522,-246.328 320.355,-233.224 334.7,-222.783\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"336.858,-225.545 343.051,-216.949 332.849,-219.806 336.858,-225.545\"/>\n", + "<text text-anchor=\"middle\" x=\"312.726\" y=\"-265.133\" font-family=\"Times,serif\" font-size=\"14.00\">3:0.47</text>\n", + "</g>\n", + "<!-- 3->2 -->\n", + "<g id=\"edge22\" class=\"edge\"><title>3->2</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M356.967,-235.908C349.033,-249.115 339.703,-263.678 330.226,-276.333 323.577,-285.212 315.943,-294.3 308.422,-302.76\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"305.688,-300.565 301.577,-310.33 310.88,-305.26 305.688,-300.565\"/>\n", + "<text text-anchor=\"middle\" x=\"360.226\" y=\"-265.133\" font-family=\"Times,serif\" font-size=\"14.00\">3:-0.37</text>\n", + "</g>\n", + "<!-- 3->4 -->\n", + "<g id=\"edge23\" class=\"edge\"><title>3->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M404.82,-157.78C410.438,-148.714 415.971,-138.82 420.226,-129.167 423.653,-121.39 426.668,-112.95 429.28,-104.564\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"432.691,-105.368 432.16,-94.7864 425.977,-103.39 432.691,-105.368\"/>\n", + "<text text-anchor=\"middle\" x=\"442.726\" y=\"-117.967\" font-family=\"Times,serif\" font-size=\"14.00\">3:0.65</text>\n", + "</g>\n", + "<!-- 4->3 -->\n", + "<g id=\"edge24\" class=\"edge\"><title>4->3</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M407.931,-73.4177C395.491,-84.3055 382.871,-98.2815 376.226,-114.167 373.096,-121.649 371.547,-129.877 371.021,-138.122\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"367.522,-138.081 370.85,-148.139 374.521,-138.201 367.522,-138.081\"/>\n", + "<text text-anchor=\"middle\" x=\"396.226\" y=\"-117.967\" font-family=\"Times,serif\" font-size=\"14.00\">3:-0.38</text>\n", + "</g>\n", + "<!-- 4->4 -->\n", + "<g id=\"edge9\" class=\"edge\"><title>4->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M482.285,-54.7636C492.687,-54.353 500.531,-52.1262 500.531,-48.0833 500.531,-45.4932 497.312,-43.6486 492.263,-42.5493\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"492.619,-39.0672 482.285,-41.4029 491.82,-46.0214 492.619,-39.0672\"/>\n", + "<text text-anchor=\"middle\" x=\"518.031\" y=\"-44.3833\" font-family=\"Times,serif\" font-size=\"14.00\">0:0.24</text>\n", + "</g>\n", + "<!-- 4->4 -->\n", + "<g id=\"edge25\" class=\"edge\"><title>4->4</title>\n", + "<path fill=\"none\" stroke=\"black\" d=\"M481.459,-60.5739C508.016,-63.7077 535.531,-59.5442 535.531,-48.0833 535.531,-38.0997 514.652,-33.6535 491.715,-34.7445\"/>\n", + "<polygon fill=\"black\" stroke=\"black\" points=\"491.136,-31.2804 481.459,-35.5926 491.713,-38.2566 491.136,-31.2804\"/>\n", + "<text text-anchor=\"middle\" x=\"553.031\" y=\"-44.3833\" font-family=\"Times,serif\" font-size=\"14.00\">3:0.66</text>\n", + "</g>\n", + "</g>\n", + "</svg>\n" + ], + "text/plain": [ + "<graphviz.files.Source at 0x7f25558204a8>" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "wa.render('graphivz-output/3.pautomac_light.train.gv', view=False)\n", + "Source.from_file(\"graphivz-output/3.pautomac_light.train.gv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "src = Source(out)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'graphivz-output/3.pautomac_light_man.train.gv.pdf'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "src.render('graphivz-output/3.pautomac_light_man.train.gv', view=True) " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Start Hankel matrix computation\n", + "End of Hankel matrix computation\n", + "Start Building Automaton from Hankel matrix\n", + "End of Automaton computation\n" + ] + }, + { + "data": { + "text/plain": [ + "'3.pautomac_light.train.dot.gv.pdf'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from splearn.datasets.base import load_data_sample\n", + "from splearn.tests.datasets.get_dataset_path import get_dataset_path\n", + "from splearn import Spectral\n", + "train_file = '3.pautomac_light.train'\n", + "data = load_data_sample(adr=get_dataset_path(train_file))\n", + "sp = Spectral()\n", + "sp.fit(X=data.data)\n", + "dotfile = \"3.pautomac_light.train.dot\"\n", + "dot = sp.Automaton.get_dot(threshold = 0.2, title = dotfile)\n", + "# To display the dot string one can use graphviz:\n", + "from graphviz import Source\n", + "src = Source(dot)\n", + "src.render(dotfile + '.gv', view=True) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/graphivz-output/3.pautomac_light.train.gv b/examples/graphivz-output/3.pautomac_light.train.gv new file mode 100644 index 0000000000000000000000000000000000000000..4e539a24850c3d44cae8a1e118f6eb50ec05dab9 --- /dev/null +++ b/examples/graphivz-output/3.pautomac_light.train.gv @@ -0,0 +1,48 @@ +// 3.pautomac_light.train +digraph { + 0 [label="0 +______ +> -0.00 +0.08 >"] + 1 [label="1 +______ +> 0.00 +-0.02 >"] + 2 [label="2 +______ +> -0.04 +-0.45 >"] + 3 [label="3 +______ +> -0.11 +0.63 >"] + 4 [label="4 +______ +> -0.09 +-0.55 >"] + 0 -> 1 [label="0:-0.24"] + 0 -> 2 [label="0:0.35"] + 0 -> 3 [label="0:-0.28"] + 0 -> 4 [label="0:-0.21"] + 1 -> 1 [label="0:-0.30"] + 1 -> 2 [label="0:0.21"] + 1 -> 4 [label="0:-0.56"] + 2 -> 3 [label="0:-0.21"] + 4 -> 4 [label="0:0.24"] + 0 -> 2 [label="1:-0.30"] + 0 -> 3 [label="1:0.28"] + 0 -> 4 [label="1:0.20"] + 1 -> 2 [label="1:0.26"] + 0 -> 2 [label="2:0.38"] + 0 -> 3 [label="2:-0.22"] + 0 -> 4 [label="2:-0.23"] + 1 -> 4 [label="2:0.35"] + 1 -> 2 [label="3:0.28"] + 1 -> 3 [label="3:-0.24"] + 2 -> 2 [label="3:-0.63"] + 2 -> 3 [label="3:0.47"] + 3 -> 2 [label="3:-0.37"] + 3 -> 4 [label="3:0.65"] + 4 -> 3 [label="3:-0.38"] + 4 -> 4 [label="3:0.66"] +} diff --git a/examples/graphivz-output/3.pautomac_light.train.gv.pdf b/examples/graphivz-output/3.pautomac_light.train.gv.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ec0f99e07bfcdac4b0e0c21fe5c94795515f90c1 Binary files /dev/null and b/examples/graphivz-output/3.pautomac_light.train.gv.pdf differ diff --git a/examples/graphivz-output/3.pautomac_light_man.train.gv b/examples/graphivz-output/3.pautomac_light_man.train.gv new file mode 100644 index 0000000000000000000000000000000000000000..d0bd11b3045b9f722f9097bc03efa9c2b894cf26 --- /dev/null +++ b/examples/graphivz-output/3.pautomac_light_man.train.gv @@ -0,0 +1,48 @@ +//automata.dot +digraph { + 0 [label="0 +______ +> -0.00 +0.08 >"] + 1 [label="1 +______ +> 0.00 +-0.02 >"] + 2 [label="2 +______ +> -0.04 +-0.45 >"] + 3 [label="3 +______ +> -0.11 +0.63 >"] + 4 [label="4 +______ +> -0.09 +-0.55 >"] + 0 -> 1 [label="0:-0.24"] + 0 -> 2 [label="0:0.35"] + 0 -> 3 [label="0:-0.28"] + 0 -> 4 [label="0:-0.21"] + 1 -> 1 [label="0:-0.30"] + 1 -> 2 [label="0:0.21"] + 1 -> 4 [label="0:-0.56"] + 2 -> 3 [label="0:-0.21"] + 4 -> 4 [label="0:0.24"] + 0 -> 2 [label="1:-0.30"] + 0 -> 3 [label="1:0.28"] + 0 -> 4 [label="1:0.20"] + 1 -> 2 [label="1:0.26"] + 0 -> 2 [label="2:0.38"] + 0 -> 3 [label="2:-0.22"] + 0 -> 4 [label="2:-0.23"] + 1 -> 4 [label="2:0.35"] + 1 -> 2 [label="3:0.28"] + 1 -> 3 [label="3:-0.24"] + 2 -> 2 [label="3:-0.63"] + 2 -> 3 [label="3:0.47"] + 3 -> 2 [label="3:-0.37"] + 3 -> 4 [label="3:0.65"] + 4 -> 3 [label="3:-0.38"] + 4 -> 4 [label="3:0.66"] +} diff --git a/examples/graphivz-output/3.pautomac_light_man.train.gv.pdf b/examples/graphivz-output/3.pautomac_light_man.train.gv.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ec0f99e07bfcdac4b0e0c21fe5c94795515f90c1 Binary files /dev/null and b/examples/graphivz-output/3.pautomac_light_man.train.gv.pdf differ diff --git a/examples/graphivz-output/round-table.gv b/examples/graphivz-output/round-table.gv new file mode 100644 index 0000000000000000000000000000000000000000..48aa015997756e0312cae651ceffdc8082ced691 --- /dev/null +++ b/examples/graphivz-output/round-table.gv @@ -0,0 +1,9 @@ +// The Round Table +digraph { + A [label="King Arthur"] + B [label="Sir Bedevere the Wise"] + L [label="Sir Lancelot the Brave"] + A -> B + A -> L + B -> L [constraint=false] +} diff --git a/examples/graphivz-output/round-table.gv.pdf b/examples/graphivz-output/round-table.gv.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ed7810cf4f968b2f4ccd117b59a3e01137c243bd Binary files /dev/null and b/examples/graphivz-output/round-table.gv.pdf differ diff --git a/setup.py b/setup.py index 66e014ebc5c1768c2ec0f6bed96a981c1d8b11b6..cbb1d501ea1f1c16a62f537e621ffe376d0a187f 100755 --- a/setup.py +++ b/setup.py @@ -1,39 +1,5 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import print_function import os diff --git a/splearn/__init__.py b/splearn/__init__.py index 056f036c4eb11d0db67694b32c00437b5932620c..384681e1332f8beeacb454fcc22ae815bc98850c 100644 --- a/splearn/__init__.py +++ b/splearn/__init__.py @@ -2,4 +2,4 @@ from splearn.automaton import Automaton from splearn.spectral import Learning from splearn.spectral import Spectral from splearn.hankel import Hankel -__version__ = "1.0.1" +__version__ = "1.1.0" diff --git a/splearn/automaton.py b/splearn/automaton.py index 98375c8c2bbea956e96c00adef2830b81af34d80..44338b9e36d867799c36f21f2bccf29189135e7e 100644 --- a/splearn/automaton.py +++ b/splearn/automaton.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### """This module contains the Automaton class """ @@ -639,3 +605,50 @@ class Automaton(object): toReturn.update({i: max(w, 0)}) toReturn.update({-1: max(p_w, 0)}) return toReturn + + def get_dot(self, threshold = 0., nb_dec = 2, title = "Weighted Automata"): + """ Return a string that contains the Automata into dot (graphviz) format + :Example: + + >>> from splearn.datasets.base import load_data_sample + >>> from splearn.tests.datasets.get_dataset_path import get_dataset_path + >>> from splearn import Spectral + >>> train_file = '3.pautomac_light.train' + >>> data = load_data_sample(adr=get_dataset_path(train_file)) + >>> sp = Spectral() + >>> sp.fit(X=data.data) + >>> dotfile = "3.pautomac_light.train.dot" + >>> dot = sp.Automaton.get_dot(threshold = 0.2, title = dotfile) + >>> # To display the dot string one can use graphviz: + >>> from graphviz import Source + >>> src = Source(dot) + >>> src.render(dotfile + '.gv', view=True) + + - Input: + + :param Automaton self + :param float threshold for the value to keep. If |weight| < threshold, the + corresponding transition is not kept as an edge in the final dot string. + :param int nb_dec is the number of decimals to keep for the weights. + :param string title corresponds to the top comment of the string + + :returns: a string with the current Automata in dot format + """ + prec = ".{:d}f".format(nb_dec) + out = "//{:s}\ndigraph {{\n".format(title) + for i in range(self.nbS): + label = "{0:d}\n______\n> {1:" + prec + "}\n{2:" + prec + "} >" + label = label.format(i, self.initial[i], self.final[i]) + out += "\t{0:d} [label=\"".format(i) + out += label + "\"]\n" + for l in range(self.nbL): + for i in range(self.nbS): + for j in range(self.nbS): + weight = self.transitions[l][i,j] + if (np.abs(weight) > threshold): + label = "{0:d}:{1:" + prec + "}" + label = label.format(l,weight) + out += "\t{0:d} -> {1:d} [label=\"".format(i,j) + out += label + "\"]\n" + out += "}\n" + return out diff --git a/splearn/datasets/data_sample.py b/splearn/datasets/data_sample.py index 1305b04ab276db9c6cfd7e404ec10f0043227864..26746e337a053640020e05bdc2498aa655829911 100644 --- a/splearn/datasets/data_sample.py +++ b/splearn/datasets/data_sample.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### """This module contains the DataSample class and Splearn_array class The DataSample class encapsulates a sample 's components nbL and nbEx numbers, diff --git a/splearn/hankel.py b/splearn/hankel.py index 446d4a52cafc4354e64af339be7934f79d836428..b20f7bd0929a2e8f24709df6d4cc7f29b14a2722 100644 --- a/splearn/hankel.py +++ b/splearn/hankel.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### """This module contains the Hankel class """ diff --git a/splearn/spectral.py b/splearn/spectral.py index 64e4a026268e73babfc52b1abc78843ec6ceb121..ce8e027aa4ecaaaa230cccec7cb109bea7912b7b 100644 --- a/splearn/spectral.py +++ b/splearn/spectral.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### """This module contains the Spectral and Learning class .. module author:: François Denis diff --git a/splearn/tests/datasets/get_dataset_path.py b/splearn/tests/datasets/get_dataset_path.py index 1a37ebb92fd2c979f35a1feda8724c58d68559a6..f497951469e8d0e1f0d284443f6a70bd8bfcd19a 100644 --- a/splearn/tests/datasets/get_dataset_path.py +++ b/splearn/tests/datasets/get_dataset_path.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### """Module to get the absolute path of a reference dataset for tests .. moduleauthor:: Denis Arrivault diff --git a/splearn/tests/test_automaton.py b/splearn/tests/test_automaton.py index c9df0f8897d3dc7d6c84967676abf9056558f9ac..69dd1e84ef323b7219b5220f40709bbabbc92619 100644 --- a/splearn/tests/test_automaton.py +++ b/splearn/tests/test_automaton.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import division, print_function import unittest import numpy as np diff --git a/splearn/tests/test_base.py b/splearn/tests/test_base.py index e7684c0d959f9b0080c5811a97ff2df78093a34a..1fbe062c0b71312378cb06caa4a4f38e541c0cab 100644 --- a/splearn/tests/test_base.py +++ b/splearn/tests/test_base.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import division, print_function import numpy as np diff --git a/splearn/tests/test_data_sample.py b/splearn/tests/test_data_sample.py index f7cf18f5bf1b9c4651d4f5e4e52e8996bbc8ca3e..326ca5fa4bffed389fa5dcb22d9deb5286e54a74 100644 --- a/splearn/tests/test_data_sample.py +++ b/splearn/tests/test_data_sample.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import division, print_function import numpy as np diff --git a/splearn/tests/test_hankel.py b/splearn/tests/test_hankel.py index 86d48656335f50df7540009ef5746e73f3ecb69f..8e6e34eb0fe46eb30ae56dbd9cd3d0d0ed287b30 100644 --- a/splearn/tests/test_hankel.py +++ b/splearn/tests/test_hankel.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import division, print_function import unittest diff --git a/splearn/tests/test_spectral.py b/splearn/tests/test_spectral.py index b0c9beee47278b4d7045cf6d0ba06e7e7ec9b705..ce71a715785c9a240107f8d89f860ae288e1ecc0 100644 --- a/splearn/tests/test_spectral.py +++ b/splearn/tests/test_spectral.py @@ -1,38 +1,4 @@ # -*- coding: utf-8 -*- -# ######### COPYRIGHT ######### -# -# Copyright(c) 2016 -# ----------------- -# -# * LabEx Archimède: http://labex-archimede.univ-amu.fr/ -# * Laboratoire d'Informatique Fondamentale : http://www.lif.univ-mrs.fr/ -# -# Contributors: -# ------------ -# -# * François Denis <francois.denis_AT_lif.univ-mrs.fr> -# * Rémy Eyraud <remy.eyraud_AT_lif.univ-mrs.fr> -# * Denis Arrivault <contact.dev_AT_lif.univ-mrs.fr> -# * Dominique Benielli <dominique.benielli_AT_univ-amu.fr> -# -# Description: -# ----------- -# -# scitkit-splearn is a toolbox in -# python for spectral learning algorithms. -# -# Version: -# ------- -# -# * splearn version = 1.0.1 -# -# Licence: -# ------- -# -# License: 3-clause BSD -# -# -# ######### COPYRIGHT ######### from __future__ import division, print_function import numpy as np