Skip to content
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.

Commit

Permalink
Hacky reorg for scattered code (#31)
Browse files Browse the repository at this point in the history
Reorg, refactor and rerun notebooks; updated PR description with links and next steps. Due to the reorg, many of these experiments file references were broken, i fixed the references and reran all of the experiments.

I believe one can still read those notes after I merge: #31 (comment)
  • Loading branch information
mzargham authored Jul 4, 2019
1 parent a07cef6 commit 93105d9
Show file tree
Hide file tree
Showing 42 changed files with 9,105 additions and 5,079 deletions.
944 changes: 944 additions & 0 deletions analysis/Contextualizing Cred.md

Large diffs are not rendered by default.

313 changes: 313 additions & 0 deletions experiments/.ipynb_checkpoints/biline-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'page_ranker'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-99a27dde11b2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m#import json\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[0;31m#import os\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 \u001b[0;32mimport\u001b[0m \u001b[0mpage_ranker\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpr\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;31m#import import_graph as ig\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0minspect_subgraph\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0misg\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'page_ranker'"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import networkx as nx\n",
"#import json\n",
"#import os\n",
"import page_ranker as pr\n",
"#import import_graph as ig\n",
"import inspect_subgraph as isg\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"cwd = os.getcwd()\n",
"\n",
"dir_as_list = cwd.split('/')\n",
"base_path=''\n",
"go = True\n",
"i=0\n",
"while go:\n",
" base_path= base_path+dir_as_list[i]+'/'\n",
" if dir_as_list[i]=='research':\n",
" go = False\n",
" i=i+1\n",
" \n",
"rel_path = \"sample-graphs/sourcecred_sourcecred.json\"\n",
"\n",
"abs_file_path = os.path.abspath(os.path.join(base_path, rel_path))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"N =10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"line = nx.path_graph(N, create_using=nx.MultiDiGraph)\n",
"edges = line.edges\n",
"\n",
"G = nx.MultiDiGraph()\n",
"for e in edges:\n",
" G.add_edge(e[0],e[1])\n",
" G.add_edge(e[1],e[0])\n",
" \n",
"nx.set_node_attributes(G,'vanilla', 'type')\n",
"nx.set_edge_attributes(G,'vanilla', 'type')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"G.nodes[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"G.edges[(0,1,0)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"isg.inspectSubGraph(G, G.nodes, expand=False, verbose=False, label=True,pos = \"kk\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"G.edges[(0,1,0)]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"alpha = .1\n",
"iterations = 25\n",
"\n",
"seed = {n:1/len(G.nodes) for n in G.nodes}\n",
"#seed = {n:0 for n in G.nodes}\n",
"#seed[0] =1\n",
"\n",
"node_wt_by_type = {'vanilla': 1}\n",
"edge_wt_by_type = {'vanilla': (1,1/2)}\n",
"\n",
"self_loop_wt= .1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r, df, g = pr.pageRanker(G,\n",
" alpha,\n",
" iterations,\n",
" seed=seed,\n",
" initial_value = seed,\n",
" lazy=True,\n",
" lazy_decay=True,\n",
" self_loop_wt=self_loop_wt, \n",
" node_wt_by_type =node_wt_by_type,\n",
" edge_wt_by_type=edge_wt_by_type)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.tail(1).T.plot(kind='bar',legend=False, title='PageRank Distribution')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.plot(figsize=(20,10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"df.sum(axis=1).plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ns = [10000*G.nodes[n]['score'] for n in G.nodes]\n",
"nl = {n:n for n in G.nodes}\n",
"\n",
"nx.draw_circular(G, node_size=ns, labels=nl, font_size=8, alpha=.5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nx.get_node_attributes(G,'self_wt')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nx.get_edge_attributes(G,'out_weight')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nx.get_edge_attributes(G,'in_weight')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nx.get_node_attributes(G,'total_wt')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"all_nbr = {n:list(nx.all_neighbors(G,n)) for n in G.nodes}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"all_nbr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nbr = {n:list(G.neighbors(n)) for n in G.nodes}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nbr"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"G.edges"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 93105d9

Please sign in to comment.