diff --git a/README.md b/README.md index 2d7ab0f0..5db8fe52 100644 --- a/README.md +++ b/README.md @@ -143,13 +143,13 @@ adjacency matrix by running the NEMtropy build graph function. from NEMtropy.network_functions import build_graph_from_edgelist edgelist_ens = np.loadtxt("sample/0.txt") - ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens, - is_directed = False, - is_sparse = False, - is_weighted = False) + ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens, + is_directed = False, + is_sparse = False, + is_weighted = False) ``` -These collection of random adjacency matrices can be used as a null model: +These collections of random adjacency matrices can be used as a null model: it is enough to compute the expected value of the selected network feature on the ensemble of matrices and to compare it with its original value. @@ -162,7 +162,7 @@ You can find complete documentation about NEMtropy library in [docs](https://nem Development ----------- Please work on a feature branch and create a pull request to the development -branch. If necessary to merge manually do so without fast forward: +branch. If necessary to merge manually do so without fast-forward: ``` $ git merge --no-ff myfeature @@ -179,7 +179,7 @@ To build a development environment run: Testing ------- If you want to test the package integrity, you can run the following -bash command from the tests directory: +bash command from the tests' directory: ``` $ bash run_all.sh diff --git a/examples/Directed Graphs.ipynb b/examples/Directed Graphs.ipynb index 621f5862..f00c91c0 100644 --- a/examples/Directed Graphs.ipynb +++ b/examples/Directed Graphs.ipynb @@ -2,7 +2,7 @@ "cells": [ { "source": [ - "The aim of the notebook is to help you to take confidence with the directed graph class of NEMtropy. We will guide you through the functionality of the module and they can be use to reconstruct a network given partial information or to generate a null model given a certain network.\n", + "The aim of the notebook is to help you to take confidence with the directed graph class of NEMtropy. We will guide you through the functionality of the module, how they can be use to reconstruct a network given partial information or to generate a null model given a certain network.\n", "For more detail about the theory behind this, we suggest you to read ....." ], "cell_type": "markdown", @@ -18,7 +18,7 @@ "import networkx as nx\n", "from NEMtropy import DirectedGraph\n", "from NEMtropy import matrix_generator as mg\n", - "from NEMtropy.network_functions import build_graph_from_edgelist\n" + "from NEMtropy.network_functions import build_adjacency_from_edgelist\n" ] }, { @@ -59,7 +59,7 @@ }, { "source": [ - "DirectedGraph instance can be initialised using adjacency matrix, edgelist or degree and strength sequences. As an example we initialise a graph instance using the adjacency matrix." + "DirectedGraph instance can be initialised using adjacency matrix, edgelist or degree and strength sequences. As an example, we initialise a graph instance using the adjacency matrix." ], "cell_type": "markdown", "metadata": {} @@ -75,7 +75,7 @@ }, { "source": [ - "When you use an initiliasition instance that is not the adjacency matrix you must specify what you are passing to DirectedGraph. As an exaple we can use the edgelist." + "When the initiliasition instance is not an adjacency matrix, you must specify what you are passing to DirectedGraph: for exaple we can use an edgelist." ], "cell_type": "markdown", "metadata": {} @@ -173,10 +173,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# and build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = True,\n", - " is_sparse = False,\n", - " is_weighted = False)" + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = True,\n", + " is_sparse = False,\n", + " is_weighted = False)" ] }, { @@ -188,7 +188,7 @@ }, { "source": [ - "Suppose now that you have only partial information about yournetwork: only the degree sequence is disclosed. Following the same procedure described above, we can generate generate a network satisfying (on average) the observed degree sequence." + "Suppose now that you have only partial information about yournetwork: only the degree sequence is disclosed. Following the same procedure described above, we can generate a network satisfying (on average) the observed degree sequence." ], "cell_type": "markdown", "metadata": {} @@ -216,10 +216,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = True,\n", - " is_sparse = False,\n", - " is_weighted = False)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = True,\n", + " is_sparse = False,\n", + " is_weighted = False)\n", "\n", "# or generate a networkx graph from it\n", "G = nx.DiGraph()\n", @@ -297,18 +297,18 @@ { "output_type": "error", "ename": "TypingError", - "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001b[1m\u001b[1m\u001b[1mNo implementation of function Function() found for signature:\n \n >>> len(none)\n \nThere are 16 candidate implementations:\n\u001b[1m - Of which 16 did not match due to:\n Overload of function 'len': File: : Line N/A.\n With argument(s): '(none)':\u001b[0m\n\u001b[1m No match.\u001b[0m\n\u001b[0m\n\u001b[0m\u001b[1mDuring: resolving callee type: Function()\u001b[0m\n\u001b[0m\u001b[1mDuring: typing of call at /Users/emiliano/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/models_functions.py (4100)\n\u001b[0m\n\u001b[1m\nFile \"../src/NEMtropy/models_functions.py\", line 4100:\u001b[0m\n\u001b[1mdef loglikelihood_prime_crema_directed(beta, args):\n \n\n\u001b[1m aux_n = len(s_out)\n\u001b[0m \u001b[1m^\u001b[0m\u001b[0m\n", + "evalue": "Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1m\u001B[1mNo implementation of function Function() found for signature:\n \n >>> len(none)\n \nThere are 16 candidate implementations:\n\u001B[1m - Of which 16 did not match due to:\n Overload of function 'len': File: : Line N/A.\n With argument(s): '(none)':\u001B[0m\n\u001B[1m No match.\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: resolving callee type: Function()\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of call at /Users/emiliano/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/models_functions.py (4100)\n\u001B[0m\n\u001B[1m\nFile \"../src/NEMtropy/models_functions.py\", line 4100:\u001B[0m\n\u001B[1mdef loglikelihood_prime_crema_directed(beta, args):\n \n\n\u001B[1m aux_n = len(s_out)\n\u001B[0m \u001B[1m^\u001B[0m\u001B[0m\n", "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mTypingError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0minitial_guess\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"random\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0madjacency\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"dcm_exp\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m method_adjacency=\"newton\")\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;31m# The optimisation problem is divided in two steps: firstly the binary model is solved and its solution are one\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001b[0m in \u001b[0;36msolve_tool\u001b[0;34m(self, model, method, initial_guess, adjacency, method_adjacency, initial_guess_adjacency, max_steps, full_return, verbose, linsearch, tol, eps)\u001b[0m\n\u001b[1;32m 2469\u001b[0m \u001b[0mlinsearch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlinsearch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2470\u001b[0m \u001b[0mtol\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtol\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2471\u001b[0;31m \u001b[0meps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0meps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2472\u001b[0m )\n\u001b[1;32m 2473\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_solution_error\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001b[0m in \u001b[0;36m_solve_problem_crema_directed\u001b[0;34m(self, initial_guess, model, adjacency, method, method_adjacency, initial_guess_adjacency, max_steps, tol, eps, full_return, verbose, linsearch, regularise, regularise_eps)\u001b[0m\n\u001b[1;32m 2360\u001b[0m \u001b[0mregularise_eps\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mregularise_eps\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2361\u001b[0m \u001b[0mlinsearch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlinsearch\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2362\u001b[0;31m \u001b[0mfull_return\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfull_return\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2363\u001b[0m )\n\u001b[1;32m 2364\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/solver_functions.py\u001b[0m in \u001b[0;36msolver\u001b[0;34m(x0, fun, step_fun, linsearch_fun, hessian_regulariser, fun_jac, tol, eps, max_steps, method, verbose, regularise, regularise_eps, full_return, linsearch)\u001b[0m\n\u001b[1;32m 146\u001b[0m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mx0\u001b[0m \u001b[0;31m# initial point\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 148\u001b[0;31m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 149\u001b[0m \u001b[0mnorm\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnorm\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mf\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 150\u001b[0m \u001b[0mdiff\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001b[0m in \u001b[0;36m\u001b[0;34m(x)\u001b[0m\n\u001b[1;32m 2027\u001b[0m \"crema-newton\": lambda x: -mof.loglikelihood_prime_crema_directed(\n\u001b[1;32m 2028\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2029\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2030\u001b[0m ),\n\u001b[1;32m 2031\u001b[0m \"crema-quasinewton\": lambda x: -mof.loglikelihood_prime_crema_directed(\n", - "\u001b[0;32m/usr/local/lib/python3.7/site-packages/numba/core/dispatcher.py\u001b[0m in \u001b[0;36m_compile_for_args\u001b[0;34m(self, *args, **kws)\u001b[0m\n\u001b[1;32m 412\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpatch_message\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 414\u001b[0;31m \u001b[0merror_rewrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'typing'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 415\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mUnsupportedError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 416\u001b[0m \u001b[0;31m# Something unsupported is present in the user code, add help info\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;32m/usr/local/lib/python3.7/site-packages/numba/core/dispatcher.py\u001b[0m in \u001b[0;36merror_rewrite\u001b[0;34m(e, issue_type)\u001b[0m\n\u001b[1;32m 355\u001b[0m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 356\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 357\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 358\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 359\u001b[0m \u001b[0margtypes\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypingError\u001b[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001b[1m\u001b[1m\u001b[1mNo implementation of function Function() found for signature:\n \n >>> len(none)\n \nThere are 16 candidate implementations:\n\u001b[1m - Of which 16 did not match due to:\n Overload of function 'len': File: : Line N/A.\n With argument(s): '(none)':\u001b[0m\n\u001b[1m No match.\u001b[0m\n\u001b[0m\n\u001b[0m\u001b[1mDuring: resolving callee type: Function()\u001b[0m\n\u001b[0m\u001b[1mDuring: typing of call at /Users/emiliano/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/models_functions.py (4100)\n\u001b[0m\n\u001b[1m\nFile \"../src/NEMtropy/models_functions.py\", line 4100:\u001b[0m\n\u001b[1mdef loglikelihood_prime_crema_directed(beta, args):\n \n\n\u001b[1m aux_n = len(s_out)\n\u001b[0m \u001b[1m^\u001b[0m\u001b[0m\n" + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mTypingError\u001B[0m Traceback (most recent call last)", + "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 4\u001B[0m \u001B[0minitial_guess\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m\"random\"\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 5\u001B[0m \u001B[0madjacency\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0;34m\"dcm_exp\"\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 6\u001B[0;31m method_adjacency=\"newton\")\n\u001B[0m\u001B[1;32m 7\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 8\u001B[0m \u001B[0;31m# The optimisation problem is divided in two steps: firstly the binary model is solved and its solution are one\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001B[0m in \u001B[0;36msolve_tool\u001B[0;34m(self, model, method, initial_guess, adjacency, method_adjacency, initial_guess_adjacency, max_steps, full_return, verbose, linsearch, tol, eps)\u001B[0m\n\u001B[1;32m 2469\u001B[0m \u001B[0mlinsearch\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mlinsearch\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 2470\u001B[0m \u001B[0mtol\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mtol\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m-> 2471\u001B[0;31m \u001B[0meps\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0meps\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 2472\u001B[0m )\n\u001B[1;32m 2473\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0m_solution_error\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001B[0m in \u001B[0;36m_solve_problem_crema_directed\u001B[0;34m(self, initial_guess, model, adjacency, method, method_adjacency, initial_guess_adjacency, max_steps, tol, eps, full_return, verbose, linsearch, regularise, regularise_eps)\u001B[0m\n\u001B[1;32m 2360\u001B[0m \u001B[0mregularise_eps\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mregularise_eps\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 2361\u001B[0m \u001B[0mlinsearch\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mlinsearch\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m-> 2362\u001B[0;31m \u001B[0mfull_return\u001B[0m\u001B[0;34m=\u001B[0m\u001B[0mfull_return\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 2363\u001B[0m )\n\u001B[1;32m 2364\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/solver_functions.py\u001B[0m in \u001B[0;36msolver\u001B[0;34m(x0, fun, step_fun, linsearch_fun, hessian_regulariser, fun_jac, tol, eps, max_steps, method, verbose, regularise, regularise_eps, full_return, linsearch)\u001B[0m\n\u001B[1;32m 146\u001B[0m \u001B[0mx\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mx0\u001B[0m \u001B[0;31m# initial point\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 147\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 148\u001B[0;31m \u001B[0mf\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mfun\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mx\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 149\u001B[0m \u001B[0mnorm\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mnp\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mlinalg\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mnorm\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mf\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 150\u001B[0m \u001B[0mdiff\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;36m1\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/graph_classes.py\u001B[0m in \u001B[0;36m\u001B[0;34m(x)\u001B[0m\n\u001B[1;32m 2027\u001B[0m \"crema-newton\": lambda x: -mof.loglikelihood_prime_crema_directed(\n\u001B[1;32m 2028\u001B[0m \u001B[0mx\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m-> 2029\u001B[0;31m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0margs\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 2030\u001B[0m ),\n\u001B[1;32m 2031\u001B[0m \"crema-quasinewton\": lambda x: -mof.loglikelihood_prime_crema_directed(\n", + "\u001B[0;32m/usr/local/lib/python3.7/site-packages/numba/core/dispatcher.py\u001B[0m in \u001B[0;36m_compile_for_args\u001B[0;34m(self, *args, **kws)\u001B[0m\n\u001B[1;32m 412\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mpatch_message\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mmsg\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 413\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 414\u001B[0;31m \u001B[0merror_rewrite\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0me\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m'typing'\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 415\u001B[0m \u001B[0;32mexcept\u001B[0m \u001B[0merrors\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mUnsupportedError\u001B[0m \u001B[0;32mas\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 416\u001B[0m \u001B[0;31m# Something unsupported is present in the user code, add help info\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m/usr/local/lib/python3.7/site-packages/numba/core/dispatcher.py\u001B[0m in \u001B[0;36merror_rewrite\u001B[0;34m(e, issue_type)\u001B[0m\n\u001B[1;32m 355\u001B[0m \u001B[0;32mraise\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 356\u001B[0m \u001B[0;32melse\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 357\u001B[0;31m \u001B[0;32mraise\u001B[0m \u001B[0me\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mwith_traceback\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;32mNone\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 358\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 359\u001B[0m \u001B[0margtypes\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;31mTypingError\u001B[0m: Failed in nopython mode pipeline (step: nopython frontend)\n\u001B[1m\u001B[1m\u001B[1mNo implementation of function Function() found for signature:\n \n >>> len(none)\n \nThere are 16 candidate implementations:\n\u001B[1m - Of which 16 did not match due to:\n Overload of function 'len': File: : Line N/A.\n With argument(s): '(none)':\u001B[0m\n\u001B[1m No match.\u001B[0m\n\u001B[0m\n\u001B[0m\u001B[1mDuring: resolving callee type: Function()\u001B[0m\n\u001B[0m\u001B[1mDuring: typing of call at /Users/emiliano/Documents/PhD/Directed_Class_Master/classes/src/NEMtropy/models_functions.py (4100)\n\u001B[0m\n\u001B[1m\nFile \"../src/NEMtropy/models_functions.py\", line 4100:\u001B[0m\n\u001B[1mdef loglikelihood_prime_crema_directed(beta, args):\n \n\n\u001B[1m aux_n = len(s_out)\n\u001B[0m \u001B[1m^\u001B[0m\u001B[0m\n" ] } ], @@ -356,10 +356,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# and build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = True,\n", - " is_sparse = False,\n", - " is_weighted = True)" + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = True,\n", + " is_sparse = False,\n", + " is_weighted = True)" ] }, { @@ -372,10 +372,10 @@ { "source": [ "Suppose you have only partial information about the network, for example:\n", - " - The binary structure is well-known and you want to assign weights to network edges;\n", - " - Only marginals information are available: degree and strength sequences.\n", + " - The binary structure is well-known, and you want to assign weights to network edges;\n", + " - Only marginal information are available: degree and strength sequences.\n", "\n", - "You can use NEMtropy methods to reconstruct a network configuration that is consistent with the available informations." + "You can use NEMtropy methods to reconstruct a network configuration that is consistent with the available information." ], "cell_type": "markdown", "metadata": {} @@ -457,10 +457,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = True,\n", - " is_sparse = False,\n", - " is_weighted = True)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = True,\n", + " is_sparse = False,\n", + " is_weighted = True)\n", "\n", "# and generate a networkx graph from it\n", "G = nx.from_numpy_array(ens_adj)" @@ -567,10 +567,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = True,\n", - " is_sparse = False,\n", - " is_weighted = True)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = True,\n", + " is_sparse = False,\n", + " is_weighted = True)\n", "\n", "# and generate a networkx graph from it\n", "G = nx.from_numpy_array(ens_adj)" diff --git a/examples/Undirected Graphs.ipynb b/examples/Undirected Graphs.ipynb index c1e6250f..22c6c722 100644 --- a/examples/Undirected Graphs.ipynb +++ b/examples/Undirected Graphs.ipynb @@ -2,7 +2,7 @@ "cells": [ { "source": [ - "The aim of the notebook is to help you to take confidence with the undirected graph class of NEMtropy. We will guide you through the functionality of the module and they can be use to reconstruct a network given partial information or to generate a null model given a certain network.\n", + "The aim of the notebook is to help you to take confidence with the undirected graph class of NEMtropy. We will guide you through the functionality of the module, and how they can be use to reconstruct a network given partial information or to generate a null model given a certain network.\n", "For more detail about the theory behind this, we suggest you to read ....." ], "cell_type": "markdown", @@ -17,34 +17,13 @@ "import numpy as np\n", "import networkx as nx\n", "from NEMtropy import UndirectedGraph, matrix_generator\n", - "from NEMtropy.network_functions import build_graph_from_edgelist" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "output_type": "error", - "ename": "ModuleNotFoundError", - "evalue": "No module named 'nemtropy'", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mnemtropy\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'nemtropy'" - ] - } - ], - "source": [ - "import nemtropy" + "from NEMtropy.network_functions import build_adjacency_from_edgelist" ] }, { "source": [ "According to the type of undirected graph, the available models can be divided in:\n", - " - models for binary network: \"cm\" and \"cm_exp\"\n", + " - models for binary networks: \"cm\" and \"cm_exp\"\n", " - models for weighted networks: \"crema\", \"ecm\" and \"ecm_exp\"\n", "\n", "We will make some examples about both classes of models, lets start from binary models." @@ -76,7 +55,7 @@ }, { "source": [ - "UndirectedGraph instance can be initialised using adjacency matrix, edgelist or degree and strength sequences. As an example we initialise a graph instance using the adjacency matrix." + "UndirectedGraph instance can be initialised using adjacency matrix, edgelist or degree and strength sequences. As an example, we initialise a graph instance using the adjacency matrix." ], "cell_type": "markdown", "metadata": {} @@ -92,7 +71,7 @@ }, { "source": [ - "When you use an initiliasition instance that isn't the adjacency matrix you must specify what you are passing to UndirectedGraph. As an exaple we can use the edgelist." + "When you use an initiliasition instance that isn't the adjacency matrix, you must specify what you are passing to UndirectedGraph: for exaple an edgelist." ], "cell_type": "markdown", "metadata": {} @@ -198,10 +177,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# and build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = False,\n", - " is_sparse = False,\n", - " is_weighted = False)" + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = False,\n", + " is_sparse = False,\n", + " is_weighted = False)" ] }, { @@ -220,7 +199,7 @@ }, { "source": [ - "Suppose now that you have only partial information about the zachary karate club network: only the degree sequence is disclosed. Following the same procedure described above, we can generate generate a network having (on average) the same observed degree sequence." + "Suppose now that you have only partial information about the zachary karate club network: only the degree sequence is disclosed. Following the same procedure described above, we can generate a network having (on average) the same observed degree sequence." ], "cell_type": "markdown", "metadata": {} @@ -250,10 +229,10 @@ "G.add_edges_from(edgelist_ens)\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = False,\n", - " is_sparse = False,\n", - " is_weighted = False)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = False,\n", + " is_sparse = False,\n", + " is_weighted = False)\n", "\n", "# or generate a networkx graph from it\n", "G = nx.DiGraph()\n", @@ -373,10 +352,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# and build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = False,\n", - " is_sparse = False,\n", - " is_weighted = True)" + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = False,\n", + " is_sparse = False,\n", + " is_weighted = True)" ] }, { @@ -389,10 +368,10 @@ { "source": [ "Suppose you have only partial information about the network, for example:\n", - " - The binary structure is well-known and you want to assign weights to network edges;\n", - " - Only marginals information are available: degree and strength sequences.\n", + " - The binary structure is well-known, and you want to assign weights to network edges;\n", + " - Only marginal information are available: degree and strength sequences.\n", "\n", - "You can use NEMtropy methods to reconstruct a network configuration that is consistent with the available informations." + "You can use NEMtropy methods to reconstruct a network configuration that is consistent with the available information." ], "cell_type": "markdown", "metadata": {} @@ -473,10 +452,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = False,\n", - " is_sparse = False,\n", - " is_weighted = True)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = False,\n", + " is_sparse = False,\n", + " is_weighted = True)\n", "\n", "# and generate a networkx graph from it\n", "G = nx.from_numpy_array(ens_adj)" @@ -580,10 +559,10 @@ "edgelist_ens = np.loadtxt(\"sample/0.txt\")\n", "\n", "# then we can build the adjacency matrix\n", - "ens_adj = build_graph_from_edgelist(edgelist = edgelist_ens,\n", - " is_directed = False,\n", - " is_sparse = False,\n", - " is_weighted = True)\n", + "ens_adj = build_adjacency_from_edgelist(edgelist = edgelist_ens,\n", + " is_directed = False,\n", + " is_sparse = False,\n", + " is_weighted = True)\n", "\n", "# and generate a networkx graph from it\n", "G = nx.from_numpy_array(ens_adj)" diff --git a/requirements.txt b/requirements.txt index e69de29b..4e49e6a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1,19 @@ +numpy~=1.20.1 +scipy~=1.6.0 +networkx~=2.5 +powerlaw~=1.4.6 +numba~=0.52.0 +NEMtropy~=1.0.5 +setuptools~=51.1.2 +Pillow~=8.1.0 +pip~=20.3.3 +wheel~=0.36.2 +six~=1.15.0 +llvmlite~=0.35.0 +matplotlib~=3.3.4 +mpmath~=1.2.1 +python-dateutil~=2.8.1 +decorator~=4.4.2 +pyparsing~=2.4.7 +cycler~=0.10.0 +kiwisolver~=1.3.1 \ No newline at end of file