forked from apache/mxnet
-
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.
benchmark dot code refactor (apache#87)
* q^x6x add some code in benchmark * refactor * minor fixes * fix * lint fix
- Loading branch information
1 parent
85d59ce
commit f773706
Showing
2 changed files
with
142 additions
and
72 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
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,33 @@ | ||
import os | ||
import random | ||
|
||
|
||
def get_data(data_dir, data_name, url, data_origin_name): | ||
if not os.path.isdir(data_dir): | ||
os.system("mkdir " + data_dir) | ||
os.chdir(data_dir) | ||
if (not os.path.exists(data_name)): | ||
import urllib | ||
zippath = os.path.join(data_dir, data_origin_name) | ||
urllib.urlretrieve(url, zippath) | ||
os.system("bzip2 -d %r" % data_origin_name) | ||
os.chdir("..") | ||
|
||
|
||
def estimate_density(DATA_PATH, feature_size): | ||
"""sample 10 times of a size of 1000 for estimating the density of the sparse dataset""" | ||
if not os.path.exists(DATA_PATH): | ||
raise Exception("Data is not there!") | ||
density = [] | ||
P = 0.01 | ||
for _ in xrange(10): | ||
num_non_zero = 0 | ||
num_sample = 0 | ||
with open(DATA_PATH) as f: | ||
for line in f: | ||
if (random.random() < P): | ||
num_non_zero += len(line.split(" ")) - 1 | ||
num_sample += 1 | ||
density.append(num_non_zero * 1.0 / (feature_size * num_sample)) | ||
return sum(density) / len(density) | ||
|