Skip to content

Commit c11f08d

Browse files
authored
Merge pull request #140 from zoq/TestFix
Import fix + better Exception handling.
2 parents 184a36d + 8e9223b commit c11f08d

File tree

13 files changed

+32
-137
lines changed

13 files changed

+32
-137
lines changed

Makefile

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ endif
4040
CONFIG := test.yaml
4141
BENCHMARKDDIR := benchmark
4242
LOG := False
43-
LIB := "shogun"
4443
SAVE := ""
4544
LOGLEVEL := "INFO"
4645
BLOCK := ""
47-
METHODBLOCK := ""
4846
UPDATE := False
4947
BUILD_CORES := 1
5048

@@ -79,19 +77,12 @@ export PYTHONPATH=$(shell printenv PYTHONPATH):$(shell echo $(ROOTPATH))/librari
7977
# Set MATLABPATH correctly.
8078
export MATLABPATH=$(shell printenv MATLABPATH):$(shell pwd)/methods/matlab
8179

82-
# Color settings.
83-
NO_COLOR=\033[0m
84-
ERROR_COLOR=\033[0;31m
85-
WARN_COLOR=\033[0;33m
86-
8780
.PHONY: help test run memory scripts
8881

8982
help: .check .help
90-
test: .check .test
9183
run: .check .run
92-
memory: .check .check_memory .memory
9384
scripts: .scripts
94-
setup: .check .setup
85+
setup: .check .setup .scripts
9586
datasets: .check .datasets
9687
checks: .check .checks
9788

@@ -103,21 +94,17 @@ checks: .check .checks
10394
@echo " For example, the following will run all scripts and methods defined"
10495
@echo " in the config.yaml file and the results are shown on the console:"
10596
@echo ""
106-
@echo " $$ make run CONFIG=config LOG=False"
97+
@echo " $$ make run CONFIG=config"
10798
@echo ""
10899
@echo " Usage: make [option] [parameters]"
109100
@echo ""
110101
@echo "Parameters:"
111102
@echo " CONFIG [string] The path to the configuration file to perform the benchmark on."
112103
@echo " Default '$(CONFIG)'."
113-
@echo " BLOCK [string] Run only the specified blocks defined in the configuration file."
114-
@echo " Default run all blocks."
115-
@echo " LOG [boolean] If set, the reports will be saved in the database."
116-
@echo " Default '$(LOG)'."
117-
@echo " UPDATE [boolean] If set, the latest reports in the database are updated."
118-
@echo " Default '$(UPDATE)'."
119-
@echo " METHODBLOCK [string] Run only the specified methods defined in the configuration file."
104+
@echo " METHODS [string] Run only the specified methods defined in the configuration file."
120105
@echo " Default run all methods."
106+
@echo " LIB [string] Run only the benchmarks for the specified library defined in the configuration file."
107+
@echo " Default run all libraries."
121108
@echo ""
122109
@echo "Options:"
123110
@echo " test [parameters] Test the configuration file. Check for correct"
@@ -129,7 +116,6 @@ checks: .check .checks
129116
@echo " setup Download packages and install into libraries/."
130117
@echo " datasets Download datasets into datasets/."
131118
@echo " help Show this info."
132-
@echo " checks Run unit tests for benchmarking scripts."
133119
@echo ""
134120
@echo "For further information consult the documentation found at \
135121
http://www.mlpack.org"
@@ -159,31 +145,26 @@ ifndef NUMPY_INSTALLED
159145
@exit 1
160146
endif
161147

162-
.check_memory:
163-
ifndef VALGRIND_BIN
164-
@echo "$(ERROR_COLOR)[ERROR]$(NO_COLOR) The valgrind executable \
165-
was not found; please install valgrind to run the memory benchmark."
166-
@exit 1
167-
endif
168-
169148
ifndef MS_PRINT_BIN
170149
@echo "$(ERROR_COLOR)[ERROR]$(NO_COLOR) The Massif 'ms_print' command was \
171150
not found; please install the massif 'ms_print' command to run the memory benchmark."
172151
@exit 1
173152
endif
174153

175-
.test:
176-
$(PYTHON_BIN) $(BENCHMARKDDIR)/test_config.py -c $(CONFIG)
177-
178154
.run:
179155
ifndef METHODS
156+
ifndef LIB
157+
$(PYTHON_BIN) run.py -c $(CONFIG) -s $(SAVE) -o $(LOGLEVEL)
158+
else
180159
$(PYTHON_BIN) run.py -c $(CONFIG) -l $(LIB) -s $(SAVE) -o $(LOGLEVEL)
160+
endif
161+
else
162+
ifndef LIB
163+
$(PYTHON_BIN) run.py -c $(CONFIG) -m $(METHODS) -s $(SAVE) -o $(LOGLEVEL)
181164
else
182165
$(PYTHON_BIN) run.py -c $(CONFIG) -l $(LIB) -m $(METHODS) -s $(SAVE) -o $(LOGLEVEL)
183166
endif
184-
185-
.memory:
186-
$(PYTHON_BIN) $(BENCHMARKDDIR)/memory_benchmark.py -c $(CONFIG) -b $(BLOCK) -l $(LOG) -u $(UPDATE) -m $(METHODBLOCK)
167+
endif
187168

188169
.scripts:
189170
# Compile the java files for the weka methods.
@@ -201,12 +182,8 @@ endif
201182
g++ -O2 -std=c++11 methods/dlibml/src/ALLKNN.cpp -o methods/dlibml/dlibml_allknn -I"$(INCLUDEPATH)" -L"$(LIBPATH)" -ldlib -lmlpack -lboost_program_options -lblas -llapack
202183
g++ -O2 -std=c++11 methods/dlibml/src/KMEANS.cpp -o methods/dlibml/dlibml_kmeans -I"$(INCLUDEPATH)" -L"$(LIBPATH)" -ldlib -lmlpack -lboost_program_options -lblas -llapack
203184

204-
205185
.setup:
206186
cd libraries/ && ./download_packages.sh && ./install_all.sh $(BUILD_CORES)
207187

208188
.datasets:
209189
cd datasets/ && ./download_datasets.sh
210-
211-
.checks:
212-
$(PYTHON_BIN) tests/tests.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

methods/mlpack/allkfn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Class to benchmark the mlpack All K-Furthest-Neighbors method.
66
'''
77

8-
import os, sys, inspect
8+
import os, sys, inspect, re
99

1010
# Import the util path, this method even works if the path contains symlinks to
1111
# modules.

methods/mlpack/allknn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Class to benchmark the mlpack All K-Nearest-Neighbors method.
66
'''
77

8-
import os, sys, inspect
8+
import os, sys, inspect, re
99

1010
# Import the util path, this method even works if the path contains symlinks to
1111
# modules.

methods/mlpack/allkrann.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Class to benchmark the mlpack All K-Rank-Approximate-Nearest-Neighbors method.
66
'''
77

8-
import os, sys, inspect
8+
import os, sys, inspect, re
99

1010
# Import the util path, this method even works if the path contains symlinks to
1111
# modules.

methods/scikit/kernel_pca.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, method_param, run_param):
3232
self.d = int(method_param["new_dimensionality"])
3333

3434
self.kernel = method_param["kernel"]
35+
self.degree = 3
3536
if self.kernel == "polynomial" and "degree" in method_param:
3637
self.degree = int(method_param["degree"])
3738

@@ -49,11 +50,9 @@ def metric(self):
4950
model = KernelPCA(n_components=self.d, kernel="poly",
5051
degree=self.degree)
5152
elif self.kernel == "cosine":
52-
model = KernelPCA(n_components=self.d, kernel="cosine",
53-
degree=self.degree)
53+
model = KernelPCA(n_components=self.d, kernel="cosine")
5454
elif self.kernel == "gaussian":
55-
model = KernelPCA(n_components=self.d, kernel="rbf",
56-
degree=self.degree)
55+
model = KernelPCA(n_components=self.d, kernel="rbf")
5756

5857
out = model.fit_transform(self.data[0])
5958

methods/scikit/allknn.py renamed to methods/scikit/knn.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'''
2-
@file allknn.py
2+
@file knn.py
33
@author Marcus Edel
44
5-
All K-Nearest-Neighbors with scikit.
5+
K-Nearest-Neighbors with scikit.
66
'''
77

88
import os, sys, inspect
@@ -18,11 +18,11 @@
1818
from sklearn.neighbors import NearestNeighbors
1919

2020
'''
21-
This class implements the All K-Nearest-Neighbors benchmark.
21+
This class implements the K-Nearest-Neighbors benchmark.
2222
'''
23-
class SCIKIT_ALLKNN(object):
23+
class SCIKIT_KNN(object):
2424
def __init__(self, method_param, run_param):
25-
self.info = "SCIKIT_ALLKNN (" + str(method_param) + ")"
25+
self.info = "SCIKIT_KNN (" + str(method_param) + ")"
2626

2727
# Assemble run model parameter.
2828
self.data = load_dataset(method_param["datasets"], ["csv"])
@@ -58,13 +58,13 @@ def metric(self):
5858
model.fit(self.data[0])
5959

6060
if len(self.data) == 2:
61-
out = model.kneighbors(self.data[1], build_opts["n_neighbors"],
61+
out = model.kneighbors(self.data[1], self.build_opts["n_neighbors"],
6262
return_distance=True)
6363
else:
6464
# We have to increment k by one because mlpack ignores the
6565
# self-neighbor, whereas scikit-learn will happily return the
6666
# nearest neighbor of point 0 as point 0.
67-
out = model.kneighbors(self.data[0], build_opts["n_neighbors"] + 1,
67+
out = model.kneighbors(self.data[0], self.build_opts["n_neighbors"] + 1,
6868
return_distance=True)
6969

7070
metric = {}

0 commit comments

Comments
 (0)