{"action":"created","comment":{"url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/comments/23071596","id":23071596,"diff_hunk":"@@ -0,0 +1,167 @@\n+# Authors: Giovani Chiachia <giovani.chiachia@gmail.com>\n+#\n+# License: BSD\n+\n+import os\n+import optparse\n+import pprint\n+\n+from scipy import misc\n+from scipy import io\n+\n+import hyperopt\n+\n+from simplehp.opt.base import datasets, learning_algos\n+from simplehp.opt.hp import objective, build_search_space\n+from simplehp.util.util import load_hp\n+\n+speed_thresh = {'seconds': 2.0, 'elements': 4}\n+\n+\n+class WriteAdapter(object):\n+\tdef __init__(self, dataprovider, filename):\n+\t\tsuper(WriteAdapter, self).__init__()\n+\t\tself.provider = dataprovider\n+\t\tself.filename = filename\n+\n+\tdef protocol_imgs(self):\n+\t\treturn self.provider.protocol_imgs()\n+\t\n+\tdef protocol_eval(self, algo, feat_set):\n+\n+\t\tX = feat_set\n+\t\tY = []\n+\n+\t\tif 'protocol_labels' in dir(self.provider):\n+\t\t\tY = self.provider.protocol_labels()\n+\n+\t\tdataset = dict(X = X, Y = Y)\n+\n+\t\tio.savemat(self.filename, dataset, do_compression=True)\n+\t\t#print feat_set.shape\n+\t\t#return self.provider.protocol_eval(algo, feat_set)\n+\n+\tdef hp_imgs(self):\n+\t\treturn self.provider.hp_imgs()\n+\n+\tdef hp_eval(self, algo, feat_set):\n+\t\treturn self.hp_eval(self, algo, feat_set)\n+\n+\n+def protocol_eval(dataset, dataset_path, hp_fname, host, port,\n+                  learning_algo, output_file):\n+\n+    data_obj = dataset(dataset_path)\n+\n+    data_obj = WriteAdapter(data_obj, output_file)\n+\n+    # -- load hp file\n+    hp_space, trials, _ = load_hp(hp_fname, host, port)\n+\n+    # -- best trial\n+    try:\n+        best_trial = trials.best_trial\n+    except Exception, e:\n+        raise ValueError('problem retrieving best trial: %s' % (e))\n+\n+    dataset_info = {'data_obj': data_obj,\n+                    'fn_imgs': 'protocol_imgs',\n+                    'fn_eval': 'protocol_eval'}\n+\n+    search_space = build_search_space(dataset_info,\n+                                      learning_algo,\n+                                      hp_space=hp_space,\n+                                      n_ok_trials=1000000,\n+                                      batched_lmap_speed_thresh=speed_thresh)\n+\n+    ctrl = hyperopt.Ctrl(trials=trials, current_trial=best_trial)\n+    domain = hyperopt.Domain(objective, search_space)\n+\n+    best_hps = hyperopt.base.spec_from_misc(best_trial['misc'])\n+\n+    print 'Extract Features ...'\n+\n+    domain.evaluate(best_hps, ctrl, attach_attachments=True)\n+\n+    print 'Ok'\n+\n+\n+def get_optparser():\n+\n+    dataset_options = ''\n+    for k in sorted(datasets.keys()):\n+      dataset_options +=  (\"     %s - %s \\n\" % (k, datasets[k].__name__))\n+\n+    usage = (\"usage: %prog <DATASET> <DATASET_PATH> <OUTPUT_FILE>\\n\\n\"\n+             \"+ DATASET is an integer corresponding to the following supported \"\n+             \"datasets:\\n\" + dataset_options + '\\n'\n+             \"+ HP_FNAME is the pkl file containing the result of a previous \"\n+             \"hyperparameter optimization.\"\n+            )\n+\n+    parser = optparse.OptionParser(usage=usage)\n+\n+    learn_algo_default = learning_algos['default']\n+    learning_algos.pop('default', None)\n+    learn_algo_opts = ' OPTIONS=%s' % (learning_algos.keys())\n+\n+    parser.add_option(\"--hp_fname\", \"-F\",\n+                      default=None,\n+                      type=\"str\",\n+                      metavar=\"STR\",\n+                      help=(\"Pickle file created by optimization in serial\"\n+                            \"mode. [DEFAULT='%default']\"\n+                            )\n+                        )\n+\n+    parser.add_option(\"--host\", \"-H\",\n+                      default=None,\n+                      type=\"str\",\n+                      metavar=\"STR\",\n+                      help=(\"Host serving MongoDB database created by \"\n+                            \"optimization running in asynchronous, parallel \"\n+                            \"mode. [DEFAULT='%default']\"\n+                            )\n+                        )\n+\n+    parser.add_option(\"--port\", \"-P\",\n+                      default=10921,\n+                      type=\"int\",\n+                      metavar=\"INT\",\n+                      help=(\"MongoDB port at host serving the database. \"\n+                            \"[DEFAULT='%default']\"\n+                            )\n+                        )\n+\n+\n+    return parser\n+\n+\n+def main():\n+    parser = get_optparser()\n+    opts, args = parser.parse_args()\n+\n+    if len(args) != 3 or (opts.hp_fname is None and opts.host is None):\n+        parser.print_help()\n+    else:\n+        try:\n+            dataset = datasets[args[0]]\n+        except KeyError:\n+            raise ValueError('invalid dataset option')\n+\n+        dataset_path = args[1]\n+\toutput_file = args[2]","path":"simplehp/scripts/generate_dataset.py","position":153,"original_position":153,"commit_id":"c5389a1d9f6d288e3b10c5bd26aeab78ed6068c2","original_commit_id":"c5389a1d9f6d288e3b10c5bd26aeab78ed6068c2","user":{"login":"giovanichiachia","id":1382889,"avatar_url":"https://avatars.githubusercontent.com/u/1382889?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanichiachia","html_url":"https://github.com/giovanichiachia","followers_url":"https://api.github.com/users/giovanichiachia/followers","following_url":"https://api.github.com/users/giovanichiachia/following{/other_user}","gists_url":"https://api.github.com/users/giovanichiachia/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanichiachia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanichiachia/subscriptions","organizations_url":"https://api.github.com/users/giovanichiachia/orgs","repos_url":"https://api.github.com/users/giovanichiachia/repos","events_url":"https://api.github.com/users/giovanichiachia/events{/privacy}","received_events_url":"https://api.github.com/users/giovanichiachia/received_events","type":"User","site_admin":false},"body":"is this indentation right?","created_at":"2015-01-16T10:03:58Z","updated_at":"2015-01-16T10:03:58Z","html_url":"https://github.com/giovanichiachia/simple-hp/pull/2#discussion_r23071596","pull_request_url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/comments/23071596"},"html":{"href":"https://github.com/giovanichiachia/simple-hp/pull/2#discussion_r23071596"},"pull_request":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2","id":27248593,"html_url":"https://github.com/giovanichiachia/simple-hp/pull/2","diff_url":"https://github.com/giovanichiachia/simple-hp/pull/2.diff","patch_url":"https://github.com/giovanichiachia/simple-hp/pull/2.patch","issue_url":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/2","number":2,"state":"open","locked":false,"title":"Generate Dataset","user":{"login":"alan-mnix","id":3215952,"avatar_url":"https://avatars.githubusercontent.com/u/3215952?v=3","gravatar_id":"","url":"https://api.github.com/users/alan-mnix","html_url":"https://github.com/alan-mnix","followers_url":"https://api.github.com/users/alan-mnix/followers","following_url":"https://api.github.com/users/alan-mnix/following{/other_user}","gists_url":"https://api.github.com/users/alan-mnix/gists{/gist_id}","starred_url":"https://api.github.com/users/alan-mnix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alan-mnix/subscriptions","organizations_url":"https://api.github.com/users/alan-mnix/orgs","repos_url":"https://api.github.com/users/alan-mnix/repos","events_url":"https://api.github.com/users/alan-mnix/events{/privacy}","received_events_url":"https://api.github.com/users/alan-mnix/received_events","type":"User","site_admin":false},"body":"scripts/generate-dataset.py file to save datasets in the MATLAB/OCTAVE format.","created_at":"2015-01-13T05:14:20Z","updated_at":"2015-01-16T10:03:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"74ddf713c74b6272bea65134838db33d9fb97eb1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2/commits","review_comments_url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2/comments","review_comment_url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/comments/{number}","comments_url":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/2/comments","statuses_url":"https://api.github.com/repos/giovanichiachia/simple-hp/statuses/c5389a1d9f6d288e3b10c5bd26aeab78ed6068c2","head":{"label":"alan-mnix:generate-dataset","ref":"generate-dataset","sha":"c5389a1d9f6d288e3b10c5bd26aeab78ed6068c2","user":{"login":"alan-mnix","id":3215952,"avatar_url":"https://avatars.githubusercontent.com/u/3215952?v=3","gravatar_id":"","url":"https://api.github.com/users/alan-mnix","html_url":"https://github.com/alan-mnix","followers_url":"https://api.github.com/users/alan-mnix/followers","following_url":"https://api.github.com/users/alan-mnix/following{/other_user}","gists_url":"https://api.github.com/users/alan-mnix/gists{/gist_id}","starred_url":"https://api.github.com/users/alan-mnix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alan-mnix/subscriptions","organizations_url":"https://api.github.com/users/alan-mnix/orgs","repos_url":"https://api.github.com/users/alan-mnix/repos","events_url":"https://api.github.com/users/alan-mnix/events{/privacy}","received_events_url":"https://api.github.com/users/alan-mnix/received_events","type":"User","site_admin":false},"repo":{"id":29173907,"name":"simple-hp","full_name":"alan-mnix/simple-hp","owner":{"login":"alan-mnix","id":3215952,"avatar_url":"https://avatars.githubusercontent.com/u/3215952?v=3","gravatar_id":"","url":"https://api.github.com/users/alan-mnix","html_url":"https://github.com/alan-mnix","followers_url":"https://api.github.com/users/alan-mnix/followers","following_url":"https://api.github.com/users/alan-mnix/following{/other_user}","gists_url":"https://api.github.com/users/alan-mnix/gists{/gist_id}","starred_url":"https://api.github.com/users/alan-mnix/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alan-mnix/subscriptions","organizations_url":"https://api.github.com/users/alan-mnix/orgs","repos_url":"https://api.github.com/users/alan-mnix/repos","events_url":"https://api.github.com/users/alan-mnix/events{/privacy}","received_events_url":"https://api.github.com/users/alan-mnix/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alan-mnix/simple-hp","description":"Hyperparameter Optimization made Simple","fork":true,"url":"https://api.github.com/repos/alan-mnix/simple-hp","forks_url":"https://api.github.com/repos/alan-mnix/simple-hp/forks","keys_url":"https://api.github.com/repos/alan-mnix/simple-hp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alan-mnix/simple-hp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alan-mnix/simple-hp/teams","hooks_url":"https://api.github.com/repos/alan-mnix/simple-hp/hooks","issue_events_url":"https://api.github.com/repos/alan-mnix/simple-hp/issues/events{/number}","events_url":"https://api.github.com/repos/alan-mnix/simple-hp/events","assignees_url":"https://api.github.com/repos/alan-mnix/simple-hp/assignees{/user}","branches_url":"https://api.github.com/repos/alan-mnix/simple-hp/branches{/branch}","tags_url":"https://api.github.com/repos/alan-mnix/simple-hp/tags","blobs_url":"https://api.github.com/repos/alan-mnix/simple-hp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alan-mnix/simple-hp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alan-mnix/simple-hp/git/refs{/sha}","trees_url":"https://api.github.com/repos/alan-mnix/simple-hp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alan-mnix/simple-hp/statuses/{sha}","languages_url":"https://api.github.com/repos/alan-mnix/simple-hp/languages","stargazers_url":"https://api.github.com/repos/alan-mnix/simple-hp/stargazers","contributors_url":"https://api.github.com/repos/alan-mnix/simple-hp/contributors","subscribers_url":"https://api.github.com/repos/alan-mnix/simple-hp/subscribers","subscription_url":"https://api.github.com/repos/alan-mnix/simple-hp/subscription","commits_url":"https://api.github.com/repos/alan-mnix/simple-hp/commits{/sha}","git_commits_url":"https://api.github.com/repos/alan-mnix/simple-hp/git/commits{/sha}","comments_url":"https://api.github.com/repos/alan-mnix/simple-hp/comments{/number}","issue_comment_url":"https://api.github.com/repos/alan-mnix/simple-hp/issues/comments/{number}","contents_url":"https://api.github.com/repos/alan-mnix/simple-hp/contents/{+path}","compare_url":"https://api.github.com/repos/alan-mnix/simple-hp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alan-mnix/simple-hp/merges","archive_url":"https://api.github.com/repos/alan-mnix/simple-hp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alan-mnix/simple-hp/downloads","issues_url":"https://api.github.com/repos/alan-mnix/simple-hp/issues{/number}","pulls_url":"https://api.github.com/repos/alan-mnix/simple-hp/pulls{/number}","milestones_url":"https://api.github.com/repos/alan-mnix/simple-hp/milestones{/number}","notifications_url":"https://api.github.com/repos/alan-mnix/simple-hp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alan-mnix/simple-hp/labels{/name}","releases_url":"https://api.github.com/repos/alan-mnix/simple-hp/releases{/id}","created_at":"2015-01-13T05:12:01Z","updated_at":"2015-01-13T05:12:03Z","pushed_at":"2015-01-13T05:13:02Z","git_url":"git://github.com/alan-mnix/simple-hp.git","ssh_url":"git@github.com:alan-mnix/simple-hp.git","clone_url":"https://github.com/alan-mnix/simple-hp.git","svn_url":"https://github.com/alan-mnix/simple-hp","homepage":null,"size":113,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"giovanichiachia:master","ref":"master","sha":"c51ee95a129516f1389cea43917591355832a59c","user":{"login":"giovanichiachia","id":1382889,"avatar_url":"https://avatars.githubusercontent.com/u/1382889?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanichiachia","html_url":"https://github.com/giovanichiachia","followers_url":"https://api.github.com/users/giovanichiachia/followers","following_url":"https://api.github.com/users/giovanichiachia/following{/other_user}","gists_url":"https://api.github.com/users/giovanichiachia/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanichiachia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanichiachia/subscriptions","organizations_url":"https://api.github.com/users/giovanichiachia/orgs","repos_url":"https://api.github.com/users/giovanichiachia/repos","events_url":"https://api.github.com/users/giovanichiachia/events{/privacy}","received_events_url":"https://api.github.com/users/giovanichiachia/received_events","type":"User","site_admin":false},"repo":{"id":25687268,"name":"simple-hp","full_name":"giovanichiachia/simple-hp","owner":{"login":"giovanichiachia","id":1382889,"avatar_url":"https://avatars.githubusercontent.com/u/1382889?v=3","gravatar_id":"","url":"https://api.github.com/users/giovanichiachia","html_url":"https://github.com/giovanichiachia","followers_url":"https://api.github.com/users/giovanichiachia/followers","following_url":"https://api.github.com/users/giovanichiachia/following{/other_user}","gists_url":"https://api.github.com/users/giovanichiachia/gists{/gist_id}","starred_url":"https://api.github.com/users/giovanichiachia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/giovanichiachia/subscriptions","organizations_url":"https://api.github.com/users/giovanichiachia/orgs","repos_url":"https://api.github.com/users/giovanichiachia/repos","events_url":"https://api.github.com/users/giovanichiachia/events{/privacy}","received_events_url":"https://api.github.com/users/giovanichiachia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/giovanichiachia/simple-hp","description":"Hyperparameter Optimization made Simple","fork":false,"url":"https://api.github.com/repos/giovanichiachia/simple-hp","forks_url":"https://api.github.com/repos/giovanichiachia/simple-hp/forks","keys_url":"https://api.github.com/repos/giovanichiachia/simple-hp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/giovanichiachia/simple-hp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/giovanichiachia/simple-hp/teams","hooks_url":"https://api.github.com/repos/giovanichiachia/simple-hp/hooks","issue_events_url":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/events{/number}","events_url":"https://api.github.com/repos/giovanichiachia/simple-hp/events","assignees_url":"https://api.github.com/repos/giovanichiachia/simple-hp/assignees{/user}","branches_url":"https://api.github.com/repos/giovanichiachia/simple-hp/branches{/branch}","tags_url":"https://api.github.com/repos/giovanichiachia/simple-hp/tags","blobs_url":"https://api.github.com/repos/giovanichiachia/simple-hp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/giovanichiachia/simple-hp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/giovanichiachia/simple-hp/git/refs{/sha}","trees_url":"https://api.github.com/repos/giovanichiachia/simple-hp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/giovanichiachia/simple-hp/statuses/{sha}","languages_url":"https://api.github.com/repos/giovanichiachia/simple-hp/languages","stargazers_url":"https://api.github.com/repos/giovanichiachia/simple-hp/stargazers","contributors_url":"https://api.github.com/repos/giovanichiachia/simple-hp/contributors","subscribers_url":"https://api.github.com/repos/giovanichiachia/simple-hp/subscribers","subscription_url":"https://api.github.com/repos/giovanichiachia/simple-hp/subscription","commits_url":"https://api.github.com/repos/giovanichiachia/simple-hp/commits{/sha}","git_commits_url":"https://api.github.com/repos/giovanichiachia/simple-hp/git/commits{/sha}","comments_url":"https://api.github.com/repos/giovanichiachia/simple-hp/comments{/number}","issue_comment_url":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/comments/{number}","contents_url":"https://api.github.com/repos/giovanichiachia/simple-hp/contents/{+path}","compare_url":"https://api.github.com/repos/giovanichiachia/simple-hp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/giovanichiachia/simple-hp/merges","archive_url":"https://api.github.com/repos/giovanichiachia/simple-hp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/giovanichiachia/simple-hp/downloads","issues_url":"https://api.github.com/repos/giovanichiachia/simple-hp/issues{/number}","pulls_url":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls{/number}","milestones_url":"https://api.github.com/repos/giovanichiachia/simple-hp/milestones{/number}","notifications_url":"https://api.github.com/repos/giovanichiachia/simple-hp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/giovanichiachia/simple-hp/labels{/name}","releases_url":"https://api.github.com/repos/giovanichiachia/simple-hp/releases{/id}","created_at":"2014-10-24T12:23:05Z","updated_at":"2014-10-24T12:26:04Z","pushed_at":"2014-10-24T15:55:40Z","git_url":"git://github.com/giovanichiachia/simple-hp.git","ssh_url":"git@github.com:giovanichiachia/simple-hp.git","clone_url":"https://github.com/giovanichiachia/simple-hp.git","svn_url":"https://github.com/giovanichiachia/simple-hp","homepage":null,"size":156,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2"},"html":{"href":"https://github.com/giovanichiachia/simple-hp/pull/2"},"issue":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/2"},"comments":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/giovanichiachia/simple-hp/statuses/c5389a1d9f6d288e3b10c5bd26aeab78ed6068c2"}}}}