-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
972 additions
and
1,762 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ __pycache__ | |
build/ | ||
dist/ | ||
*.egg-info | ||
.hypothesis | ||
|
||
nbs/data/* | ||
nbs/*.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.0.0" | ||
__version__ = "1.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from category import Category | ||
import numpy as np | ||
|
||
def cache(f): | ||
data = dict() | ||
def wrapper(name, parent_map): | ||
if name in data: | ||
return data[name] | ||
rt = f(name, parent_map) | ||
data[name]=rt | ||
return rt | ||
return wrapper | ||
|
||
@cache | ||
def find_ancestor_map(name, parent_map): | ||
if name not in parent_map: | ||
return [] | ||
else: | ||
return [name,]+find_ancestor_map(parent_map[name], parent_map) | ||
|
||
def tree_hot(cate, name, ancestor_map): | ||
target = np.zeros(len(cate), dtype=int) | ||
target[cate.c2i[ancestor_map[name]]]=1 | ||
return target | ||
|
||
def get_depth_map(cate, ancestor_map): | ||
cate.depth_map = dict( | ||
(k, len(v)) for k,v in ancestor_map.items()) | ||
return cate.depth_map | ||
|
||
def get_depth_map_array(cate, ancestor_map): | ||
cate.depth_map_array = np.vectorize(cate.get_depth_map(ancestor_map).get)(cate.i2c) | ||
return cate.depth_map_array | ||
|
||
Category.tree_hot = tree_hot | ||
Category.get_depth_map = get_depth_map | ||
Category.get_depth_map_array = get_depth_map_array |
Oops, something went wrong.