From 1326549b68f27801b79984ca227f4183d984107d Mon Sep 17 00:00:00 2001 From: Ruben Martinez-Cantin Date: Tue, 28 Aug 2018 12:11:33 +0200 Subject: [PATCH] Fixing issues #16 and #19 on github --- python/demo_quad.py | 20 ++++++++++---------- utils/fileparser.cpp | 4 +--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/python/demo_quad.py b/python/demo_quad.py index 54e3354..ee46265 100644 --- a/python/demo_quad.py +++ b/python/demo_quad.py @@ -1,16 +1,16 @@ #!/usr/bin/env python # ------------------------------------------------------------------------- -# This file is part of BayesOpt, an efficient C++ library for +# This file is part of BayesOpt, an efficient C++ library for # Bayesian optimization. # # Copyright (C) 2011-2015 Ruben Martinez-Cantin -# -# BayesOpt is free software: you can redistribute it and/or modify it +# +# BayesOpt is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # -# BayesOpt is distributed in the hope that it will be useful, but +# BayesOpt is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. @@ -27,14 +27,14 @@ from time import clock # Python3 compat -if sys.version_info[0] == 3: - raw_input = input +if hasattr(__builtins__, 'raw_input'): + input = raw_input # Function for testing. def testfunc(Xin): total = 5.0 for value in Xin: - total = total + (value -0.33)*(value-0.33) + total = total + (value - 0.33) * (value - 0.33) return total @@ -64,7 +64,7 @@ def evaluateSample(self,Xin): print("Result", mvalue, "at", x_out) print("Running time:", clock() - start, "seconds") -raw_input('Press INTRO to continue') +input('Press INTRO to continue') print("OO implementation") bo_test = BayesOptTest(n) @@ -77,10 +77,10 @@ def evaluateSample(self,Xin): print("Result", mvalue, "at", x_out) print("Running time:", clock() - start, "seconds") -raw_input('Press INTRO to continue') +input('Press INTRO to continue') print("Callback discrete implementation") -x_set = np.random.rand(100,n) +x_set = np.random.rand(100, n) start = clock() mvalue, x_out, error = bayesopt.optimize_discrete(testfunc, x_set, params) diff --git a/utils/fileparser.cpp b/utils/fileparser.cpp index 405e1e8..4865dde 100644 --- a/utils/fileparser.cpp +++ b/utils/fileparser.cpp @@ -85,9 +85,7 @@ namespace bayesopt /* Checks if a file exists */ bool FileParser::fileExists(){ std::ifstream ifile(filename.c_str()); - bool result = ifile; - ifile.close(); - return result; + return ifile.good(); } /* Data write/read function */