Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace graph helpers with np/builtins #38

Merged
merged 7 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graph/my_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import warnings
import json
import my_graph_helpers as mgh
from lazy_property import lazy_property
from utils.lazy_property import lazy_property
from matplotlib import pyplot as plt


Expand Down
31 changes: 3 additions & 28 deletions graph/my_graph_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,8 @@ def WeightedPick(d):
"""picks an item out of the dictionary d, with probability proportional to
the value of that item. e.g. in {a:1, b:0.6, c:0.4} selects and returns
"a" 5/10 times, "b" 3/10 times and "c" 2/10 times. """

r = random.uniform(0, sum(d.values()))
s = 0.0
for k, w in d.items():
s += w
if r < s:
return k
return k


def mat_reorder(matrix, order):
"""sorts a square matrix so both rows and columns are
ordered by order. """

Drow = [matrix[i] for i in order]
Dcol = [[r[i] for i in order] for r in Drow]

return Dcol


def myRoll(mylist):
"""rolls a list, putting the last element into the first slot. """

mylist.insert(0, mylist[-1])
del mylist[-1]
return(mylist)
sum_p = sum(d.values())
return np.random.choice(d.keys(), p=[p/sum_p for p in d.values()])

######################
# DUALS HElPER
Expand Down Expand Up @@ -467,8 +443,7 @@ def choose_path(myG, paths, alpha, strict_greedy=False):
length more frequently """

if strict_greedy is False:
inv_weight = dict((k, 1.0/(paths[k]**alpha)) for k in paths)
target_path = WeightedPick(inv_weight)
target_path = WeightedPick({path: length**-alpha for (path, length) in paths.items()})
if strict_greedy is True:
target_path = min(paths, key=paths.get)

Expand Down
14 changes: 14 additions & 0 deletions tests/perf_test_data
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@
1d11d71 NYC 1 0.142737150192 7.00588458333
1d11d71 Prague 2 0.0788838863373 25.353720422
1d11d71 CapeTown 3 63.7222030163 0.0470793515917
e12af17 Phule_Nagar_v6 199 3.72162985802 53.4711961135
e12af17 Epworth_Before 350 84.1490020752 4.15928877787
e12af17 Epworth_demo 1 0.195746898651 5.10863777097
e12af17 Las_Vegas 1 52.0890500546 0.0191978928192
e12af17 NYC 1 0.135759830475 7.36594909188
e12af17 Prague 2 0.0757038593292 26.4187323833
e12af17 CapeTown 3 63.6627459526 0.0471233207916
4a121ea Phule_Nagar_v6 199 3.75716304779 52.9654948345
4a121ea Epworth_Before 350 85.5207681656 4.09257315512
4a121ea Epworth_demo 1 0.192051172256 5.20694556691
4a121ea Las_Vegas 1 51.1493070126 0.0195506070054
4a121ea NYC 1 0.129373073578 7.72958369423
4a121ea Prague 2 0.0711929798126 28.0926575242
4a121ea CapeTown 3 56.6484811306 0.052958171872
Empty file added utils/__init__.py
Empty file.
File renamed without changes.