Commit e35fa2b4 authored by suiguoxin's avatar suiguoxin
Browse files

fix params bug by adding float>int transition

parent 21725f96
...@@ -161,9 +161,10 @@ ...@@ -161,9 +161,10 @@
version "10.5.2" version "10.5.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.2.tgz#f19f05314d5421fe37e74153254201a7bf00a707" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.2.tgz#f19f05314d5421fe37e74153254201a7bf00a707"
"@types/node@^10.5.5": "@types/node@10.12.18":
version "10.5.5" version "10.12.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-10.5.5.tgz#8e84d24e896cd77b0d4f73df274027e3149ec2ba" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"
integrity sha512-fh+pAqt4xRzPfqA6eh3Z2y6fyZavRIumvjhaCL753+TVkGKGhpPeyrJG2JftD0T9q4GF00KjefsQ+PQNDdWQaQ==
"@types/range-parser@*": "@types/range-parser@*":
version "1.2.2" version "1.2.2"
...@@ -342,10 +343,6 @@ ansi-regex@^3.0.0: ...@@ -342,10 +343,6 @@ ansi-regex@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"
ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"
ansi-styles@^3.2.1: ansi-styles@^3.2.1:
version "3.2.1" version "3.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d"
...@@ -451,14 +448,6 @@ azure-storage@^2.10.2: ...@@ -451,14 +448,6 @@ azure-storage@^2.10.2:
xml2js "0.2.8" xml2js "0.2.8"
xmlbuilder "^9.0.7" xmlbuilder "^9.0.7"
babel-code-frame@^6.22.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b"
dependencies:
chalk "^1.1.3"
esutils "^2.0.2"
js-tokens "^3.0.2"
balanced-match@^1.0.0: balanced-match@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
...@@ -575,16 +564,6 @@ chai@^4.1.2: ...@@ -575,16 +564,6 @@ chai@^4.1.2:
pathval "^1.0.0" pathval "^1.0.0"
type-detect "^4.0.0" type-detect "^4.0.0"
chalk@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
dependencies:
ansi-styles "^2.2.1"
escape-string-regexp "^1.0.2"
has-ansi "^2.0.0"
strip-ansi "^3.0.0"
supports-color "^2.0.0"
chalk@^2.0.0, chalk@^2.3.0: chalk@^2.0.0, chalk@^2.3.0:
version "2.4.1" version "2.4.1"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.1.tgz#18c49ab16a037b6eb0152cc83e3471338215b66e"
...@@ -854,7 +833,7 @@ escape-html@~1.0.3: ...@@ -854,7 +833,7 @@ escape-html@~1.0.3:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988" resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: escape-string-regexp@1.0.5, escape-string-regexp@^1.0.5:
version "1.0.5" version "1.0.5"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
...@@ -1163,12 +1142,6 @@ har-validator@~5.1.0: ...@@ -1163,12 +1142,6 @@ har-validator@~5.1.0:
ajv "^5.3.0" ajv "^5.3.0"
har-schema "^2.0.0" har-schema "^2.0.0"
has-ansi@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91"
dependencies:
ansi-regex "^2.0.0"
has-flag@^3.0.0: has-flag@^3.0.0:
version "3.0.0" version "3.0.0"
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd" resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-3.0.0.tgz#b5d454dc2199ae225699f3467e5a07f3b955bafd"
...@@ -1426,21 +1399,25 @@ js-base64@^2.4.9: ...@@ -1426,21 +1399,25 @@ js-base64@^2.4.9:
version "2.5.0" version "2.5.0"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.0.tgz#42255ba183ab67ce59a0dee640afdc00ab5ae93e" resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.0.tgz#42255ba183ab67ce59a0dee640afdc00ab5ae93e"
js-tokens@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
js-tokens@^4.0.0: js-tokens@^4.0.0:
version "4.0.0" version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
js-yaml@^3.10.0, js-yaml@^3.7.0: js-yaml@^3.10.0:
version "3.12.0" version "3.12.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.12.0.tgz#eaed656ec8344f10f527c6bfa1b6e2244de167d1"
dependencies: dependencies:
argparse "^1.0.7" argparse "^1.0.7"
esprima "^4.0.0" esprima "^4.0.0"
js-yaml@^3.13.1:
version "3.13.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.13.1.tgz#aff151b30bfdfa8e49e05da22e7415e9dfa37847"
integrity sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==
dependencies:
argparse "^1.0.7"
esprima "^4.0.0"
jsbn@~0.1.0: jsbn@~0.1.0:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
...@@ -1797,12 +1774,6 @@ node-jose@^1.1.0: ...@@ -1797,12 +1774,6 @@ node-jose@^1.1.0:
node-forge "^0.7.6" node-forge "^0.7.6"
uuid "^3.3.2" uuid "^3.3.2"
node-nvidia-smi@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/node-nvidia-smi/-/node-nvidia-smi-1.0.0.tgz#6aa57574540b2bed91c9a80218516ffa686e5ac7"
dependencies:
xml2js "^0.4.17"
node-pre-gyp@^0.10.3: node-pre-gyp@^0.10.3:
version "0.10.3" version "0.10.3"
resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc" resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.10.3.tgz#3070040716afdc778747b61b6887bf78880b80fc"
...@@ -2384,7 +2355,7 @@ sax@0.5.x: ...@@ -2384,7 +2355,7 @@ sax@0.5.x:
version "0.5.8" version "0.5.8"
resolved "http://registry.npmjs.org/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1" resolved "http://registry.npmjs.org/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1"
sax@>=0.6.0, sax@^1.2.4: sax@^1.2.4:
version "1.2.4" version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"
...@@ -2619,10 +2590,6 @@ supports-color@5.4.0, supports-color@^5.3.0: ...@@ -2619,10 +2590,6 @@ supports-color@5.4.0, supports-color@^5.3.0:
dependencies: dependencies:
has-flag "^3.0.0" has-flag "^3.0.0"
supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"
supports-color@^5.4.0: supports-color@^5.4.0:
version "5.5.0" version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
...@@ -2716,32 +2683,43 @@ tslib@^1.8.0, tslib@^1.8.1: ...@@ -2716,32 +2683,43 @@ tslib@^1.8.0, tslib@^1.8.1:
version "1.9.3" version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
tslint-microsoft-contrib@^5.1.0: tslint-microsoft-contrib@^6.0.0:
version "5.1.0" version "6.2.0"
resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-5.1.0.tgz#777c32d51aba16f4565e47aac749a1631176cd9f" resolved "https://registry.yarnpkg.com/tslint-microsoft-contrib/-/tslint-microsoft-contrib-6.2.0.tgz#8aa0f40584d066d05e6a5e7988da5163b85f2ad4"
integrity sha512-6tfi/2tHqV/3CL77pULBcK+foty11Rr0idRDxKnteTaKm6gWF9qmaCNU17HVssOuwlYNyOmd9Jsmjd+1t3a3qw==
dependencies: dependencies:
tsutils "^2.12.1" tsutils "^2.27.2 <2.29.0"
tslint@^5.11.0: tslint@^5.12.0:
version "5.11.0" version "5.17.0"
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.11.0.tgz#98f30c02eae3cde7006201e4c33cb08b48581eed" resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.17.0.tgz#f9f0ce2011d8e90debaa6e9b4975f24cd16852b8"
integrity sha512-pflx87WfVoYepTet3xLfDOLDm9Jqi61UXIKePOuca0qoAZyrGWonDG9VTbji58Fy+8gciUn8Bt7y69+KEVjc/w==
dependencies: dependencies:
babel-code-frame "^6.22.0" "@babel/code-frame" "^7.0.0"
builtin-modules "^1.1.1" builtin-modules "^1.1.1"
chalk "^2.3.0" chalk "^2.3.0"
commander "^2.12.1" commander "^2.12.1"
diff "^3.2.0" diff "^3.2.0"
glob "^7.1.1" glob "^7.1.1"
js-yaml "^3.7.0" js-yaml "^3.13.1"
minimatch "^3.0.4" minimatch "^3.0.4"
mkdirp "^0.5.1"
resolve "^1.3.2" resolve "^1.3.2"
semver "^5.3.0" semver "^5.3.0"
tslib "^1.8.0" tslib "^1.8.0"
tsutils "^2.27.2" tsutils "^2.29.0"
"tsutils@^2.27.2 <2.29.0":
version "2.28.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.28.0.tgz#6bd71e160828f9d019b6f4e844742228f85169a1"
integrity sha512-bh5nAtW0tuhvOJnx1GLRn5ScraRLICGyJV5wJhtRWOLsxW70Kk5tZtpK3O/hW6LDnqKS9mlUMPZj9fEMJ0gxqA==
dependencies:
tslib "^1.8.1"
tsutils@^2.12.1, tsutils@^2.27.2: tsutils@^2.29.0:
version "2.29.0" version "2.29.0"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99" resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-2.29.0.tgz#32b488501467acbedd4b85498673a0812aca0b99"
integrity sha512-g5JVHCIJwzfISaXpXE1qvNalca5Jwob6FjI4AoPlqMusJ6ftFE7IkkFoMhVLRgK+4Kx3gkzb8UZK5t5yTTvEmA==
dependencies: dependencies:
tslib "^1.8.1" tslib "^1.8.1"
...@@ -2777,9 +2755,10 @@ typescript-string-operations@^1.3.1: ...@@ -2777,9 +2755,10 @@ typescript-string-operations@^1.3.1:
version "1.3.1" version "1.3.1"
resolved "https://registry.yarnpkg.com/typescript-string-operations/-/typescript-string-operations-1.3.1.tgz#461b886cc9ccd4dd16810b1f248b2e6f6580956b" resolved "https://registry.yarnpkg.com/typescript-string-operations/-/typescript-string-operations-1.3.1.tgz#461b886cc9ccd4dd16810b1f248b2e6f6580956b"
typescript@^3.0.1: typescript@^3.2.2:
version "3.0.1" version "3.5.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.1.tgz#43738f29585d3a87575520a4b93ab6026ef11fdb" resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.5.2.tgz#a09e1dc69bc9551cadf17dba10ee42cf55e5d56c"
integrity sha512-7KxJovlYhTX5RaRbUdkAXN1KUZ8PwWlTzQdHV6xNqvuFOs7+WBo10TQUqT19Q/Jz2hk5v9TQDIhyLhhJY4p5AA==
uglify-js@^3.1.4: uglify-js@^3.1.4:
version "3.4.9" version "3.4.9"
...@@ -2900,14 +2879,7 @@ xml2js@0.2.8: ...@@ -2900,14 +2879,7 @@ xml2js@0.2.8:
dependencies: dependencies:
sax "0.5.x" sax "0.5.x"
xml2js@^0.4.17: xmlbuilder@^9.0.7:
version "0.4.19"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7"
dependencies:
sax ">=0.6.0"
xmlbuilder "~9.0.1"
xmlbuilder@^9.0.7, xmlbuilder@~9.0.1:
version "9.0.7" version "9.0.7"
resolved "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" resolved "http://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"
......
...@@ -23,7 +23,6 @@ gp_tuner.py ...@@ -23,7 +23,6 @@ gp_tuner.py
import warnings import warnings
import logging import logging
import numpy as np
from sklearn.gaussian_process.kernels import Matern from sklearn.gaussian_process.kernels import Matern
from sklearn.gaussian_process import GaussianProcessRegressor from sklearn.gaussian_process import GaussianProcessRegressor
...@@ -42,7 +41,7 @@ class GPTuner(Tuner): ...@@ -42,7 +41,7 @@ class GPTuner(Tuner):
GPTuner GPTuner
''' '''
def __init__(self, optimize_mode="maximize", cold_start_num=3, random_state=None): def __init__(self, optimize_mode="maximize", cold_start_num=1, random_state=None):
self.optimize_mode = optimize_mode self.optimize_mode = optimize_mode
self._random_state = ensure_rng(random_state) self._random_state = ensure_rng(random_state)
...@@ -59,7 +58,7 @@ class GPTuner(Tuner): ...@@ -59,7 +58,7 @@ class GPTuner(Tuner):
self.supplement_data_num = 0 self.supplement_data_num = 0
def update_search_space(self, search_space): def update_search_space(self, search_space):
"""Update the self.x_bounds and self.x_types by the search_space.json """Update the self.bounds and self.types by the search_space.json
Parameters Parameters
---------- ----------
...@@ -70,7 +69,7 @@ class GPTuner(Tuner): ...@@ -70,7 +69,7 @@ class GPTuner(Tuner):
def generate_parameters(self, parameter_id): def generate_parameters(self, parameter_id):
"""Generate next parameter for trial """Generate next parameter for trial
If the number of trial result is lower than cold start number, If the number of trial result is lower than cold start number,
metis will first random generate some parameters. gp will first randomly generate some parameters.
Otherwise, choose the parameters by the Gussian Process Model Otherwise, choose the parameters by the Gussian Process Model
Parameters Parameters
...@@ -81,35 +80,27 @@ class GPTuner(Tuner): ...@@ -81,35 +80,27 @@ class GPTuner(Tuner):
------- -------
result : dict result : dict
""" """
"""Most promissing point to probe next"""
if len(self._space) == 0 or len(self._space._target) < self.cold_start_num: if len(self._space) == 0 or len(self._space._target) < self.cold_start_num:
return self._space.array_to_params(self._space.random_sample()) results = self._space.random_sample()
else:
# Sklearn's GP throws a large number of warnings at times, but # Sklearn's GP throws a large number of warnings at times, but
# we don't really need to see them here. # we don't really need to see them here.
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore") warnings.simplefilter("ignore")
self._gp.fit(self._space.params, self._space.target) self._gp.fit(self._space.params, self._space.target)
util = UtilityFunction(kind='ei', kappa=0, xi=0) util = UtilityFunction(kind='ei', kappa=0, xi=0)
results = acq_max(
# Finding argmax of the acquisition function. ac=util.utility,
suggestion = acq_max( gp=self._gp,
ac=util.utility, y_max=self._space.target.max(),
gp=self._gp, bounds=self._space.bounds,
y_max=self._space.target.max(), random_state=self._random_state,
bounds=self._space.bounds, space=self._space
random_state=self._random_state, )
space=self._space
) results = self._space.array_to_params(results)
logger.info("Generate paramageters(array):\n" + str(suggestion))
print("Generate paramageters(array):\n" + str(suggestion))
results = self._space.array_to_params(suggestion)
logger.info("Generate paramageters(json):\n" + str(results)) logger.info("Generate paramageters(json):\n" + str(results))
print("Generate paramageters(json):\n" + str(results))
return results return results
def receive_trial_result(self, parameter_id, parameters, value): def receive_trial_result(self, parameter_id, parameters, value):
......
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import numpy as np import numpy as np
from .util import ensure_rng from .util import ensure_rng
def _hashable(x): def _hashable(x):
""" ensure that an point is hashable by a python dict """ """ ensure that an point is hashable by a python dict """
#return tuple(map(float, x)) return tuple(map(float, x))
return x
class TargetSpace(object): class TargetSpace(object):
""" """
...@@ -99,24 +119,17 @@ class TargetSpace(object): ...@@ -99,24 +119,17 @@ class TargetSpace(object):
"Size of array ({}) is different than the ".format(len(x)) + "Size of array ({}) is different than the ".format(len(x)) +
"expected number of parameters ({}).".format(len(self.keys)) "expected number of parameters ({}).".format(len(self.keys))
) )
return dict(zip(self.keys, x))
def _as_array(self, x): # maintain int type if the choices are int
try: # TODO: better implementation
#x = np.asarray(x, dtype=float) params = {}
x = np.asarray(x) for i, _bound in enumerate(self._bounds):
except TypeError: if _bound['_type'] == "choice" and isinstance(_bound['_value'][0], int):
x = self.params_to_array(x) params.update({self.keys[i]: int(x[i])})
else:
params.update({self.keys[i]: x[i]})
x = x.ravel() return params
try:
assert x.size == self.dim
except AssertionError:
raise ValueError(
"Size of array ({}) is different than the ".format(len(x)) +
"expected number of parameters ({}).".format(len(self.keys))
)
return x
def register(self, params, target): def register(self, params, target):
""" """
...@@ -124,8 +137,7 @@ class TargetSpace(object): ...@@ -124,8 +137,7 @@ class TargetSpace(object):
Parameters Parameters
---------- ----------
x : ndarray x : dict
a single point, with len(x) == self.dim
y : float y : float
target function value target function value
...@@ -134,24 +146,9 @@ class TargetSpace(object): ...@@ -134,24 +146,9 @@ class TargetSpace(object):
------ ------
KeyError: KeyError:
if the point is not unique if the point is not unique
Notes
-----
runs in ammortized constant time
Example
-------
>>> pbounds = {'p1': (0, 1), 'p2': (1, 100)}
>>> space = TargetSpace(lambda p1, p2: p1 + p2, pbounds)
>>> len(space)
0
>>> x = np.array([0, 0])
>>> y = 1
>>> space.add_observation(x, y)
>>> len(space)
1
""" """
x = self._as_array(params)
x = self.params_to_array(params)
if x in self: if x in self:
raise KeyError('Data point {} is not unique'.format(x)) raise KeyError('Data point {} is not unique'.format(x))
...@@ -174,18 +171,18 @@ class TargetSpace(object): ...@@ -174,18 +171,18 @@ class TargetSpace(object):
------- -------
>>> target_func = lambda p1, p2: p1 + p2 >>> target_func = lambda p1, p2: p1 + p2
>>> pbounds = { "dropout_rate":{"_type":"uniform","_value":[0.5, 0.9]}, "conv_size":{"_type":"choice","_value":[2,3,5,7]}} >>> pbounds = { "dropout_rate":{"_type":"uniform","_value":[0.5, 0.9]}, "conv_size":{"_type":"choice","_value":[2,3,5,7]}}
>>> space = TargetSpace( pbounds, random_state=0) >>> space = TargetSpace(pbounds, random_state=0)
>>> space.random_points(1) >>> space.random_points()
array([[ 55.33253689, 0.54488318]]) array([[ 55.33253689, 0.54488318]])
""" """
# TODO: support randint, quniform # TODO: support randint, quniform
data = np.empty((1, self.dim)) data = np.empty((1, self.dim))
for col, _bound in enumerate(self._bounds): for col, _bound in enumerate(self._bounds):
if _bound['_type'] == 'uniform': if _bound['_type'] == 'uniform':
data.T[col] = self.random_state.uniform(_bound['_value'][0], _bound['_value'][1], size=1) data.T[col] = self.random_state.uniform(
_bound['_value'][0], _bound['_value'][1], size=1)
elif _bound['_type'] == 'choice': elif _bound['_type'] == 'choice':
data.T[col] = self.random_state.choice(_bound['_value']) data.T[col] = self.random_state.choice(_bound['_value'])
print("rand sample:", data.ravel())
return data.ravel() return data.ravel()
def max(self): def max(self):
...@@ -222,4 +219,3 @@ class TargetSpace(object): ...@@ -222,4 +219,3 @@ class TargetSpace(object):
for row, key in enumerate(self.keys): for row, key in enumerate(self.keys):
if key in new_bounds: if key in new_bounds:
self._bounds[row] = new_bounds[key] self._bounds[row] = new_bounds[key]
# Copyright (c) Microsoft Corporation
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge,
# to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and
# to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import warnings import warnings
import numpy as np import numpy as np
from scipy.stats import norm from scipy.stats import norm
...@@ -10,8 +30,8 @@ def _match_val_type(vals, bounds): ...@@ -10,8 +30,8 @@ def _match_val_type(vals, bounds):
''' '''
vals_new = [] vals_new = []
for i, _ in enumerate(bounds): for i, bound in enumerate(bounds):
_type = bounds['_type'] _type = bound['_type']
if _type == "choice": if _type == "choice":
# Find the closest integer in the array, vals_bounds # Find the closest integer in the array, vals_bounds
vals_new.append( vals_new.append(
...@@ -22,7 +42,7 @@ def _match_val_type(vals, bounds): ...@@ -22,7 +42,7 @@ def _match_val_type(vals, bounds):
return vals_new return vals_new
def acq_max(ac, gp, y_max, bounds, random_state, space, n_warmup=100000, n_iter=250): def acq_max(ac, gp, y_max, bounds, random_state, space, n_warmup=1000, n_iter=250):
""" """
A function to find the maximum of the acquisition function A function to find the maximum of the acquisition function
......
...@@ -1898,6 +1898,13 @@ copy-descriptor@^0.1.0: ...@@ -1898,6 +1898,13 @@ copy-descriptor@^0.1.0:
version "0.1.1" version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
copy-to-clipboard@^3.0.8:
version "3.2.0"
resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.2.0.tgz#d2724a3ccbfed89706fac8a894872c979ac74467"
integrity sha512-eOZERzvCmxS8HWzugj4Uxl8OJxa7T2k1Gi0X5qavwydHIfuSHq2dTD09LOg/XyGq4Zpb5IsR/2OJ5lbOegz78w==
dependencies:
toggle-selection "^1.0.6"
core-js@^1.0.0: core-js@^1.0.0:
version "1.2.7" version "1.2.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636" resolved "https://registry.yarnpkg.com/core-js/-/core-js-1.2.7.tgz#652294c14651db28fa93bd2d5ff2983a4f08c636"
...@@ -5008,6 +5015,11 @@ moment@2.x, moment@^2.22.2: ...@@ -5008,6 +5015,11 @@ moment@2.x, moment@^2.22.2:
version "2.22.2" version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66" resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"
monaco-editor@^0.15.1:
version "0.15.6"
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.15.6.tgz#d63b3b06f86f803464f003b252627c3eb4a09483"
integrity sha512-JoU9V9k6KqT9R9Tiw1RTU8ohZ+Xnf9DMg6Ktqqw5hILumwmq7xqa/KLXw513uTUsWbhtnHoSJYYR++u3pkyxJg==
move-concurrently@^1.0.1: move-concurrently@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92"
...@@ -6775,6 +6787,15 @@ react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4: ...@@ -6775,6 +6787,15 @@ react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4:
version "3.0.4" version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362"
react-monaco-editor@^0.22.0:
version "0.22.0"
resolved "https://registry.yarnpkg.com/react-monaco-editor/-/react-monaco-editor-0.22.0.tgz#2ba4c9557d2e95bb0f097a56f5e5d30598f7f2f9"
integrity sha512-SdkfmdbHNzKLd33w98Wxm1MvvGC7sKqdxb79ij6XnYV5WH2zgL5BgJ2FCo/ZDh/JZgUp1mXGt8NjTcbLJVhqVw==
dependencies:
"@types/react" "*"
monaco-editor "^0.15.1"
prop-types "^15.6.2"
react-router@3.2.1: react-router@3.2.1:
version "3.2.1" version "3.2.1"
resolved "http://registry.npmjs.org/react-router/-/react-router-3.2.1.tgz#b9a3279962bdfbe684c8bd0482b81ef288f0f244" resolved "http://registry.npmjs.org/react-router/-/react-router-3.2.1.tgz#b9a3279962bdfbe684c8bd0482b81ef288f0f244"
...@@ -7976,6 +7997,11 @@ to-regex@^3.0.1, to-regex@^3.0.2: ...@@ -7976,6 +7997,11 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2" regex-not "^1.0.2"
safe-regex "^1.1.0" safe-regex "^1.1.0"
toggle-selection@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"
integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI=
toposort@^1.0.0: toposort@^1.0.0:
version "1.0.7" version "1.0.7"
resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029" resolved "https://registry.yarnpkg.com/toposort/-/toposort-1.0.7.tgz#2e68442d9f64ec720b8cc89e6443ac6caa950029"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment