Skip to content

Commit

Permalink
Give an errror for ds.get() rather than Dataset.get(); don't compute …
Browse files Browse the repository at this point in the history
…perms, just count them; fixed bug in first layer; don't expand all 70000 permutations at once, ever
  • Loading branch information
dsblank committed Sep 10, 2018
1 parent 01c4282 commit f64014b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 4 additions & 8 deletions conx/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,7 @@ def datasets(self=None):
self = Dataset()
return sorted(self.DATASETS.keys())

@classmethod
def get(cls, dataset_name, *args, **kwargs):
def get(dataset_name=None, *args, **kwargs):
"""
Get a known dataset by name.
Expand All @@ -1108,14 +1107,11 @@ def get(cls, dataset_name, *args, **kwargs):
>>> ds.clear()
"""
if not isinstance(dataset_name, str):
raise Exception("Please use network.get_dataset() or Dataset.get()")
self = Dataset() ## a dummy to load the datasets
if dataset_name.lower() in self.DATASETS:
if isinstance(dataset_name, str):
return self.DATASETS[dataset_name.lower()](*args, **kwargs)
else:
raise Exception(
("dataset_name should be one of %s" %
(list(self.DATASETS.keys(),))))
return self.DATASETS[dataset_name.lower()](*args, **kwargs)
else:
raise Exception(
("unknown dataset name '%s': should be one of %s" %
Expand Down
10 changes: 6 additions & 4 deletions conx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3667,12 +3667,14 @@ def find_start(cend, canchor, name, plevel):
raise Exception("connecting layer not found!")

## First level needs to be in bank_order, and cannot permutate:
ordering[0] = [(bank_name, False, []) for bank_name in self.input_bank_order]
permutations = [ordering[0]] + list(itertools.product(*[perms(x) for x in ordering[1:]]))
if len(permutations) < 70000: ## globally minimize
first_level = [(bank_name, False, []) for bank_name in self.input_bank_order]
perm_count = reduce(operator.mul, [math.factorial(len(level)) for level in ordering[1:]])
if perm_count < 70000: ## globally minimize
permutations = itertools.product(*[perms(x) for x in ordering[1:]])
## measure arrow distances for them all and find the shortest:
best = (10000000, None, None)
for ordering in permutations:
ordering = (first_level,) + ordering
sum = 0.0
for level_num in range(1, len(ordering)):
level = ordering[level_num]
Expand All @@ -3692,7 +3694,7 @@ def find_start(cend, canchor, name, plevel):
best = (sum, ordering)
return best[1]
else: # locally minimize, between layers:
del permutations
ordering[0] = first_level ## replace first level with sorted
for level_num in range(1, len(ordering)):
best = (10000000, None, None)
plevel = ordering[level_num - 1]
Expand Down

0 comments on commit f64014b

Please sign in to comment.