{"action":"created","issue":{"url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/58","repository_url":"https://api.github.com/repos/SheffieldML/GPyOpt","labels_url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/58/comments","events_url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/58/events","html_url":"https://github.com/SheffieldML/GPyOpt/issues/58","id":190216229,"number":58,"title":"how to parallelize nontrivial functions?","user":{"login":"ab07","id":16650295,"avatar_url":"https://avatars.githubusercontent.com/u/16650295?v=3","gravatar_id":"","url":"https://api.github.com/users/ab07","html_url":"https://github.com/ab07","followers_url":"https://api.github.com/users/ab07/followers","following_url":"https://api.github.com/users/ab07/following{/other_user}","gists_url":"https://api.github.com/users/ab07/gists{/gist_id}","starred_url":"https://api.github.com/users/ab07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ab07/subscriptions","organizations_url":"https://api.github.com/users/ab07/orgs","repos_url":"https://api.github.com/users/ab07/repos","events_url":"https://api.github.com/users/ab07/events{/privacy}","received_events_url":"https://api.github.com/users/ab07/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-18T01:53:32Z","updated_at":"2016-11-18T14:23:28Z","closed_at":null,"body":"GPyOpt BayesianOptimization doesn't seem to work with complex objective functions that don't automatically output arrays. Does the wrapper not support delayed evaluation?  For instance\r\n\r\n```\r\nimport xgboost as xgb\r\n\r\ndef train(args):\r\n   args = np.atleast_2d(args)\r\n   n = args.shape[0]\r\n   parameters = [{'gamma': args[i,0], 'lambda': args[i,1], \r\n    'max_depth': args[i,2].astype(int)} for i in range(n)]\r\n   def xgbtrain(dtrain, dtest, arg):\r\n        evals_result = {}\r\n        watchlist = [(dtest, 'eval'), (dtrain, 'train')]\r\n        model  = xgb.train(arg, dtrain, evals = watchlist)\r\n        return evals_result['eval']['rmse'][-1]\r\n   loss = map(lambda arg: xgbtrain(train, dtest, arg), args)\r\n   return np.array(loss).reshape(n,1)\r\n```\r\nwhen I run this with\r\n\r\n```\r\nbounds = [{'name': 'gamma', 'type': 'continuous', 'domain': (0, 10)},\r\n              {'name': 'lambda', 'type': 'continuous', 'domain': (1,25)},\r\n              {'name': 'max_depth', 'type': 'continuous', 'domain': (3, 5)}]\r\n\r\nbopt = GPyOpt.methods.BayesianOptimization(f=train,\r\n                               domain = bounds,\r\n                                batch_size = 3,\r\n                                num_cores = 3,\r\n                               evaluator_type='local_penalization')\r\n\r\nbopt.run_optimization(max_iter = 10)\r\n\r\n```\r\n\r\nIt returns the error `\"error in parallel computation: fall back to single process\"`. Is there a heuristic way to write training evaluation wrapper objectives that the module can handle?\r\n"},"comment":{"url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/comments/261543078","html_url":"https://github.com/SheffieldML/GPyOpt/issues/58#issuecomment-261543078","issue_url":"https://api.github.com/repos/SheffieldML/GPyOpt/issues/58","id":261543078,"user":{"login":"ab07","id":16650295,"avatar_url":"https://avatars.githubusercontent.com/u/16650295?v=3","gravatar_id":"","url":"https://api.github.com/users/ab07","html_url":"https://github.com/ab07","followers_url":"https://api.github.com/users/ab07/followers","following_url":"https://api.github.com/users/ab07/following{/other_user}","gists_url":"https://api.github.com/users/ab07/gists{/gist_id}","starred_url":"https://api.github.com/users/ab07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ab07/subscriptions","organizations_url":"https://api.github.com/users/ab07/orgs","repos_url":"https://api.github.com/users/ab07/repos","events_url":"https://api.github.com/users/ab07/events{/privacy}","received_events_url":"https://api.github.com/users/ab07/received_events","type":"User","site_admin":false},"created_at":"2016-11-18T14:23:28Z","updated_at":"2016-11-18T14:23:28Z","body":"Like for instance this example:\r\n\r\nhttps://github.com/SheffieldML/GPyOpt/blob/540fda8344a936ed315b9a929afddacbc8adf6f9/manual/tutorial/CourseBO_Lab3.ipynb\r\n\r\nThis function\r\n```\r\ndef fit_svr_val(x):\r\n    x = np.atleast_2d(np.exp(x))\r\n    fs = np.zeros((x.shape[0],1))\r\n    for i in range(x.shape[0]):\r\n        fs[i] = 0\r\n        for n in range(nfold):\r\n            idx = np.array(range(X_train.shape[0]))\r\n            idx_valid = np.logical_and(idx>=X_train.shape[0]/nfold*n, idx<X_train.shape[0]/nfold*(n+1))\r\n            idx_train = np.logical_not(idx_valid)\r\n            svr = svm.SVR(C=x[i,0], epsilon=x[i,1],gamma=x[i,2])\r\n            svr.fit(X_train[idx_train],Y_train[idx_train])\r\n            fs[i] += np.sqrt(np.square(svr.predict(X_train[idx_valid])-Y_train[idx_valid]).mean())\r\n        fs[i] *= 1./nfold\r\n    return fs\r\n```\r\n\r\n\r\nwould not work with multiple cores. The array of x passed in would have shape only (1,3) at each iteration. Similarly, the \"train\" function I defined will not be passed in a (num_cores x 3) shape array, so parallel evaluation is not possible. How should one write custom objectives like this so that the demo \r\n\r\n\r\n```\r\n# --- Run the optimization (may take a few seconds)                         # evaluation budget\r\nBO_demo_parallel.run_optimization(max_iter,                                 # Number of iterations\r\n                                acqu_optimize_method = 'fast_random',       # method to optimize the acq. function\r\n                                n_inbatch = n_cores,                        # size of the collected batches (= number of cores)\r\n                                n_procs  = n_cores,                         # size of the collected batches (= number of cores)\r\n                                batch_method='lp',                          # method to collected the batches (maximization-penalization) \r\n                                acqu_optimize_restarts = 1000,              # number of local optimizers\r\n                                eps = 1e-6) \r\n\r\n```\r\nworks?\r\n\r\n"}}
{"actor":{"display_login":"ab07"}}