def test_read_parameters_from_command_line(self): # Legal call sys.argv = ["test.py", "--folds", "10", "--fold", "0", "--params", "-x", "3"] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0'}) sys.argv = ["test.py", "--folds", "10", "--fold", "0", "--long", "long", "long", "li", "long", "long", "long", "HEY", "--params", "-x", "3"] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0', 'long': "long long li long long long HEY"}) sys.argv = ["test.py", "--folds", "10", "--fold", "0", "--long", '"', "long", "long", "li", "long", "long", "'", "lng", "HEY", "--params", "-x", "3"] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0', 'long': "\" long long li long long \' lng HEY"}) sys.argv = ["test.py", "--folds", "10", "--fold", "0", "--long", "--params", "-x", "3"] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0', 'long': ""}) # illegal call, arguments with one minus before --params sys.argv = ["test.py", "-folds", "10", "--fold", "0", "--params", "-x", "3"] with self.assertRaises(ValueError) as cm1: benchmark_util.parse_cli() self.assertEqual(cm1.exception.message, "You either try to use arguments" " with only one leading minus or try to specify a " "hyperparameter before the --params argument. test.py" " -folds 10 --fold 0 --params -x 3") # illegal call, trying to specify an arguments after --params sys.argv = ["test.py", "--folds", "10", "--params", "-x", "'3'", "--fold", "0"] with self.assertRaises(ValueError) as cm5: benchmark_util.parse_cli() self.assertEqual(cm5.exception.message, "You are trying to specify an argument after the " "--params argument. Please change the order.") # illegal call, no - in front of parameter name sys.argv = ["test_cv.py", "--params", "x", "'5'"] with self.assertRaises(ValueError) as cm2: benchmark_util.parse_cli() self.assertEqual(cm2.exception.message, "Illegal command line string, expected a hyperpara" "meter starting with - but found x")
vals_2 = [3, 4, 2, 1, -1, 2, 2, 3, 3, 2., -1., -2., 4., -3.] f = sum([ vals_2[i] * covSEard(hyp_2, np.atleast_2d(np.array(s)), x) for i, s in enumerate(support_2) ]) f += sum([ vals_1[i] * covSEard(hyp_1, np.atleast_2d(np.array(s)), x) for i, s in enumerate(support_1) ]) return float(f) def main(params, **kwargs): print 'Params: ', params['x'], print 'kwargs: ', kwargs, y = rkhs_synth(params, **kwargs) return -y if __name__ == "__main__": starttime = time.time() args, params = benchmark_util.parse_cli() result = main(params, **args) duration = time.time() - starttime print "Result for ParamILS: %s, %f, 1, %f, %d, %s" % \ ("SAT", abs(duration), result, -1, str(__file__))
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import HPOlib.benchmarks.svm_on_grid import HPOlib.benchmarks.benchmark_util as benchmark_util __authors__ = ["Katharina Eggensperger", "Matthias Feurer"] __contact__ = "automl.org" __credits__ = ["Jasper Snoek", "Ryan P. Adams", "Hugo Larochelle"] def main(params, ret_time=False, **kwargs): print 'Params: ', params, '\n' y = HPOlib.benchmarks.svm_on_grid.save_svm_on_grid(params, ret_time=ret_time, **kwargs) print 'Result: ', y return y if __name__ == "__main__": args, cli_params = benchmark_util.parse_cli() result = main(cli_params, ret_time=False, **args) duration = main(cli_params, ret_time=True, **args) print "Result for ParamILS: %s, %f, 1, %f, %d, %s" % \ ("SAT", abs(duration), result, -1, str(__file__))
import time import re from HPOlib.benchmarks.benchmark_util import parse_cli from autosklearn.cli import base_interface if __name__ == "__main__": starttime = time.time() args, params = parse_cli() dataset = args['dataset'] mode = args['mode'] seed = args.get('seed') fold = int(args['fold']) folds = int(args['folds']) if seed is None: seed = 1 if "nested-cv" in mode: # Specifiy like this 5/5-nested-cv cv_match = re.match(r"([0-9]+)/([0-9]+)-nested-cv", mode) outer_folds = int(cv_match.group(1)) inner_folds = int(cv_match.group(2)) mode = "nested-cv" mode_args = {"inner_folds": inner_folds, "outer_folds": outer_folds} elif mode.endswith("cv"): if folds == 1: cv_match = re.match(r"([0-9]*)cv", mode)
def test_read_parameters_from_command_line(self): # Legal call sys.argv = [ "test.py", "--folds", "10", "--fold", "0", "--params", "-x", "3" ] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0'}) sys.argv = [ "test.py", "--folds", "10", "--fold", "0", "--long", "long", "long", "li", "long", "long", "long", "HEY", "--params", "-x", "3" ] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, { 'folds': '10', 'fold': '0', 'long': "long long li long long long HEY" }) sys.argv = [ "test.py", "--folds", "10", "--fold", "0", "--long", '"', "long", "long", "li", "long", "long", "'", "lng", "HEY", "--params", "-x", "3" ] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual( args, { 'folds': '10', 'fold': '0', 'long': "\" long long li long long \' lng HEY" }) sys.argv = [ "test.py", "--folds", "10", "--fold", "0", "--long", "--params", "-x", "3" ] args, params = benchmark_util.parse_cli() self.assertEqual(params, {'x': '3'}) self.assertEqual(args, {'folds': '10', 'fold': '0', 'long': ""}) # illegal call, arguments with one minus before --params sys.argv = [ "test.py", "-folds", "10", "--fold", "0", "--params", "-x", "3" ] with self.assertRaises(ValueError) as cm1: benchmark_util.parse_cli() self.assertEqual( cm1.exception.message, "You either try to use arguments" " with only one leading minus or try to specify a " "hyperparameter before the --params argument. test.py" " -folds 10 --fold 0 --params -x 3") # illegal call, trying to specify an arguments after --params sys.argv = [ "test.py", "--folds", "10", "--params", "-x", "'3'", "--fold", "0" ] with self.assertRaises(ValueError) as cm5: benchmark_util.parse_cli() self.assertEqual( cm5.exception.message, "You are trying to specify an argument after the " "--params argument. Please change the order.") # illegal call, no - in front of parameter name sys.argv = ["test_cv.py", "--params", "x", "'5'"] with self.assertRaises(ValueError) as cm2: benchmark_util.parse_cli() self.assertEqual( cm2.exception.message, "Illegal command line string, expected a hyperpara" "meter starting with - but found x")
import time import re from HPOlib.benchmarks.benchmark_util import parse_cli from autosklearn.cli import base_interface if __name__ == "__main__": starttime = time.time() args, params = parse_cli() dataset = args['dataset'] mode = args['mode'] seed = args.get('seed') fold = int(args['fold']) folds = int(args['folds']) if seed is None: seed = 1 if "nested-cv" in mode: # Specifiy like this 5/5-nested-cv cv_match = re.match(r"([0-9]+)/([0-9]+)-nested-cv", mode) outer_folds = int(cv_match.group(1)) inner_folds = int(cv_match.group(2)) mode = "nested-cv" mode_args = {"inner_folds": inner_folds, "outer_folds": outer_folds} elif mode.endswith("cv"): if folds == 1: cv_match = re.match(r"([0-9]*)cv", mode) real_folds = cv_match.group(1) real_folds = 10 if not real_folds else int(real_folds)