Skip to content

Commit

Permalink
Fix arguments handling in Python
Browse files Browse the repository at this point in the history
  • Loading branch information
mwydmuch committed Sep 7, 2020
1 parent 5a8c20b commit 32c57c4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/napkinxc/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def download_file(url, dest_path, overwrite=False, unzip=False, delete_zip=False

if not path.exists(dest_path) or overwrite:
if verbose:
print('Downloading {} into {}... '.format(url, dest_path))
print('Downloading {} into {} ... '.format(url, dest_path))

session = requests.Session()
response = session.get(GoogleDriveDownloader.DOWNLOAD_URL, params={'id': file_id}, stream=True)
Expand All @@ -250,7 +250,7 @@ def download_file(url, dest_path, overwrite=False, unzip=False, delete_zip=False
if unzip:
try:
if verbose:
print('Unzipping...')
print('Unzipping ...')

with zipfile.ZipFile(dest_path, 'r') as z:
z.extractall(destination_directory)
Expand Down
10 changes: 5 additions & 5 deletions python/napkinxc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Model():
def __init__(self, **params):
self._model = CPPModel() # In the feature more CPP classes may be available
self._params = {}
self.set_params(**self._params)
self.set_params(**params)

def fit(self, X, Y):
"""
Expand Down Expand Up @@ -175,7 +175,7 @@ def __init__(self,
output,

# Tree params
tree_type='k-means',
tree_type='hierarchicalKmeans',
arity=2,
max_leaves=100,
kmeans_eps=0.0001,
Expand Down Expand Up @@ -208,7 +208,7 @@ def __init__(self,
Initialize Probabilistic Labels Trees
:param output: directory where the model will be stored
:type output: str
:param tree_type: tree type to construct {'hierachicalKmeans', 'balancedRandom', 'completeKaryRandom', 'huffman'}, defaults to 'hierachicalKmeans'
:param tree_type: tree type to construct {'hierarchicalKmeans', 'balancedRandom', 'completeKaryRandom', 'huffman'}, defaults to 'hierarchicalKmeans'
:type tree_type: str
:param arity: arity of tree nodes, k for k-means clustering used in hierarchical k-means tree building procedure, defaults to 2
:type arity: int
Expand Down Expand Up @@ -266,7 +266,7 @@ def __init__(self,
output,

# Tree params
tree_type='k-means',
tree_type='hierarchicalKmeans',
arity=2,
max_leaves=100,
kmeans_eps=0.0001,
Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(self,
Initialize Hierarchical Softmax
:param output: directory where the model will be stored
:type output: str
:param tree_type: tree type to construct {'hierachicalKmeans', 'balancedRandom', 'completeKaryRandom', 'huffman'}, defaults to 'hierachicalKmeans'
:param tree_type: tree type to construct {'hierarchicalKmeans', 'balancedRandom', 'completeKaryRandom', 'huffman'}, defaults to 'hierarchicalKmeans'
:type tree_type: str
:param arity: arity of tree nodes, k for k-means clustering used in hierarchical k-means tree building procedure, defaults to 2
:type arity: int
Expand Down
4 changes: 4 additions & 0 deletions src/args.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ Args::Args() {

// Parse args
void Args::parseArgs(const std::vector<std::string>& args) {
LOG(CERR_DEBUG) << "Parsing args...\n";

for (int ai = 0; ai < args.size(); ai += 2) {
LOG(CERR_DEBUG) << " " << args[ai] << " " << args[ai + 1] << "\n";

if (args[ai][0] != '-')
throw std::invalid_argument("Provided argument without a dash: " + args[ai]);

Expand Down
1 change: 1 addition & 0 deletions src/ensemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,5 @@ template <typename T> void Ensemble<T>::printInfo() {}

template <typename T> void Ensemble<T>::predictWithThresholds(std::vector<Prediction>& prediction, Feature* features, Args& args){
LOG(CERR) << " Threshold prediction is not available for ensemble";
// TODO
}
5 changes: 4 additions & 1 deletion src/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
enum LogLevel {
NONE,
COUT,
CERR
CERR,
CERR_DEBUG,
};

// Log config
Expand Down Expand Up @@ -60,6 +61,7 @@ class LOG {
case NONE: break;
case COUT: std::cout << msg; opened = true; break;
case CERR: std::cerr << msg; opened = true; break;
case CERR_DEBUG: std::cerr << msg; opened = true; break;
}
}
return *this;
Expand All @@ -80,6 +82,7 @@ class LOG {
case NONE: break;
case COUT: label = "COUT"; break;
case CERR: label = "CERR"; break;
case CERR_DEBUG: label = "DEBUG"; break;
}
return label;
}
Expand Down
2 changes: 1 addition & 1 deletion src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
std::shared_ptr<Model> Model::factory(Args& args) {
std::shared_ptr<Model> model = nullptr;

if (args.ensemble > 0) {
if (args.ensemble > 1) {
switch (args.modelType) {
case hsm: model = std::static_pointer_cast<Model>(std::make_shared<Ensemble<HSM>>()); break;
case plt: model = std::static_pointer_cast<Model>(std::make_shared<Ensemble<BatchPLT>>()); break;
Expand Down

0 comments on commit 32c57c4

Please sign in to comment.