{"action":"created","comment":{"url":"https://api.github.com/repos/all-umass/metric-learn/pulls/comments/79288208","id":79288208,"diff_hunk":"@@ -0,0 +1,124 @@\n+\"\"\"\n+Metric Learning for Kernel Regression (MLKR), Weinberger et al.,\n+\n+MLKR is an algorithm for supervised metric learning, which learns a distance\n+function by directly minimising the leave-one-out regression error. This\n+algorithm can also be viewed as a supervised variation of PCA and can be used\n+for dimensionality reduction and high dimensional data visualization.\n+\"\"\"\n+from __future__ import division\n+import numpy as np\n+from six.moves import xrange\n+from scipy.spatial.distance import pdist, squareform\n+\n+from .base_metric import BaseMetricLearner\n+\n+class MLKR(BaseMetricLearner):\n+    \"\"\"Metric Learning for Kernel Regression (MLKR)\"\"\"\n+    def __init__(self, A0=None, epsilon=0.01, alpha=0.0001):\n+        \"\"\"\n+        MLKR initialization\n+\n+        Parameters\n+        ----------\n+        A0: Initialization of matrix A. Defaults to the identity matrix.\n+        epsilon: Step size for gradient descent.\n+        alpha: Stopping criterion for loss function in gradient descent.\n+        \"\"\"\n+        self.params = {\n+            \"A0\": A0,\n+            \"epsilon\": epsilon,\n+            \"alpha\": alpha\n+        }\n+\n+    def _process_inputs(self, X, y):\n+        self.X = np.array(X, copy=False)\n+        y = np.array(y, copy=False)\n+        if X.ndim == 1:\n+            X = X[:, np.newaxis]\n+        if y.ndim == 1:\n+            y = y[:, np.newaxis]\n+        n, d = X.shape\n+        if y.shape[0] != n:\n+            raise ValueError('Data and label lengths mismatch: %d != %d'\n+                             % (n, y.shape[0]))\n+        return y, n, d\n+\n+    def fit(self, X, y):\n+        \"\"\"\n+        Fit MLKR model\n+\n+        Parameters:\n+        ----------\n+        X : (n x d) array of samples\n+        y : (n) data labels\n+\n+        Returns:\n+        -------\n+        self: Instance of self\n+        \"\"\"\n+        y, n, d = self._process_inputs(X, y)\n+        if self.params['A0'] is None:\n+            A = np.identity(d)  # Initialize A as eye matrix\n+        else:\n+            A = self.params['A0']\n+            assert A.shape == (d, d)\n+        cost = np.Inf\n+        # Gradient descent procedure\n+        while cost > self.params['alpha']:","path":"metric_learn/mlkr.py","position":68,"original_position":68,"commit_id":"1e78faab93a28a7b6e5e894f1fc8650e1317eb79","original_commit_id":"1e78faab93a28a7b6e5e894f1fc8650e1317eb79","user":{"login":"perimosocordiae","id":82855,"avatar_url":"https://avatars.githubusercontent.com/u/82855?v=3","gravatar_id":"","url":"https://api.github.com/users/perimosocordiae","html_url":"https://github.com/perimosocordiae","followers_url":"https://api.github.com/users/perimosocordiae/followers","following_url":"https://api.github.com/users/perimosocordiae/following{/other_user}","gists_url":"https://api.github.com/users/perimosocordiae/gists{/gist_id}","starred_url":"https://api.github.com/users/perimosocordiae/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/perimosocordiae/subscriptions","organizations_url":"https://api.github.com/users/perimosocordiae/orgs","repos_url":"https://api.github.com/users/perimosocordiae/repos","events_url":"https://api.github.com/users/perimosocordiae/events{/privacy}","received_events_url":"https://api.github.com/users/perimosocordiae/received_events","type":"User","site_admin":false},"body":"For efficiency, it's better to get `alpha` from the params dictionary once, rather than every iteration:\r\n```python\r\nalpha = self.params['alpha']\r\nwhile cost > alpha:\r\n    ...\r\n```","created_at":"2016-09-17T17:24:11Z","updated_at":"2016-09-17T17:24:11Z","html_url":"https://github.com/all-umass/metric-learn/pull/28#discussion_r79288208","pull_request_url":"https://api.github.com/repos/all-umass/metric-learn/pulls/28","_links":{"self":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/comments/79288208"},"html":{"href":"https://github.com/all-umass/metric-learn/pull/28#discussion_r79288208"},"pull_request":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/28"}}},"pull_request":{"url":"https://api.github.com/repos/all-umass/metric-learn/pulls/28","id":84727787,"html_url":"https://github.com/all-umass/metric-learn/pull/28","diff_url":"https://github.com/all-umass/metric-learn/pull/28.diff","patch_url":"https://github.com/all-umass/metric-learn/pull/28.patch","issue_url":"https://api.github.com/repos/all-umass/metric-learn/issues/28","number":28,"state":"open","locked":false,"title":"Added MLKR algorithm","user":{"login":"dsquareindia","id":9411999,"avatar_url":"https://avatars.githubusercontent.com/u/9411999?v=3","gravatar_id":"","url":"https://api.github.com/users/dsquareindia","html_url":"https://github.com/dsquareindia","followers_url":"https://api.github.com/users/dsquareindia/followers","following_url":"https://api.github.com/users/dsquareindia/following{/other_user}","gists_url":"https://api.github.com/users/dsquareindia/gists{/gist_id}","starred_url":"https://api.github.com/users/dsquareindia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsquareindia/subscriptions","organizations_url":"https://api.github.com/users/dsquareindia/orgs","repos_url":"https://api.github.com/users/dsquareindia/repos","events_url":"https://api.github.com/users/dsquareindia/events{/privacy}","received_events_url":"https://api.github.com/users/dsquareindia/received_events","type":"User","site_admin":false},"body":"Implements MLKR (sorry I've named the branch mklr :P) algorithm mentioned in #13. @perimosocordiae could you please review once? Sorry for the loops! I'll try to make it more vectorized. I'm also checking if any mathematical mistakes have inadvertently crept in. Also, what could be a good test for this? Should it just be on the lines of `testRCA`? Sorry again for the poor quality of the code. This will surely go through many revisions.","created_at":"2016-09-09T22:16:29Z","updated_at":"2016-09-17T17:44:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"64c2ca8084c9c104c8329bcad1c2413c61c46bd6","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/all-umass/metric-learn/pulls/28/commits","review_comments_url":"https://api.github.com/repos/all-umass/metric-learn/pulls/28/comments","review_comment_url":"https://api.github.com/repos/all-umass/metric-learn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/all-umass/metric-learn/issues/28/comments","statuses_url":"https://api.github.com/repos/all-umass/metric-learn/statuses/1e78faab93a28a7b6e5e894f1fc8650e1317eb79","head":{"label":"dsquareindia:mklr","ref":"mklr","sha":"1e78faab93a28a7b6e5e894f1fc8650e1317eb79","user":{"login":"dsquareindia","id":9411999,"avatar_url":"https://avatars.githubusercontent.com/u/9411999?v=3","gravatar_id":"","url":"https://api.github.com/users/dsquareindia","html_url":"https://github.com/dsquareindia","followers_url":"https://api.github.com/users/dsquareindia/followers","following_url":"https://api.github.com/users/dsquareindia/following{/other_user}","gists_url":"https://api.github.com/users/dsquareindia/gists{/gist_id}","starred_url":"https://api.github.com/users/dsquareindia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsquareindia/subscriptions","organizations_url":"https://api.github.com/users/dsquareindia/orgs","repos_url":"https://api.github.com/users/dsquareindia/repos","events_url":"https://api.github.com/users/dsquareindia/events{/privacy}","received_events_url":"https://api.github.com/users/dsquareindia/received_events","type":"User","site_admin":false},"repo":{"id":67274812,"name":"metric-learn","full_name":"dsquareindia/metric-learn","owner":{"login":"dsquareindia","id":9411999,"avatar_url":"https://avatars.githubusercontent.com/u/9411999?v=3","gravatar_id":"","url":"https://api.github.com/users/dsquareindia","html_url":"https://github.com/dsquareindia","followers_url":"https://api.github.com/users/dsquareindia/followers","following_url":"https://api.github.com/users/dsquareindia/following{/other_user}","gists_url":"https://api.github.com/users/dsquareindia/gists{/gist_id}","starred_url":"https://api.github.com/users/dsquareindia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsquareindia/subscriptions","organizations_url":"https://api.github.com/users/dsquareindia/orgs","repos_url":"https://api.github.com/users/dsquareindia/repos","events_url":"https://api.github.com/users/dsquareindia/events{/privacy}","received_events_url":"https://api.github.com/users/dsquareindia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dsquareindia/metric-learn","description":"Metric learning algorithms in Python","fork":true,"url":"https://api.github.com/repos/dsquareindia/metric-learn","forks_url":"https://api.github.com/repos/dsquareindia/metric-learn/forks","keys_url":"https://api.github.com/repos/dsquareindia/metric-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dsquareindia/metric-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dsquareindia/metric-learn/teams","hooks_url":"https://api.github.com/repos/dsquareindia/metric-learn/hooks","issue_events_url":"https://api.github.com/repos/dsquareindia/metric-learn/issues/events{/number}","events_url":"https://api.github.com/repos/dsquareindia/metric-learn/events","assignees_url":"https://api.github.com/repos/dsquareindia/metric-learn/assignees{/user}","branches_url":"https://api.github.com/repos/dsquareindia/metric-learn/branches{/branch}","tags_url":"https://api.github.com/repos/dsquareindia/metric-learn/tags","blobs_url":"https://api.github.com/repos/dsquareindia/metric-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dsquareindia/metric-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dsquareindia/metric-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/dsquareindia/metric-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dsquareindia/metric-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/dsquareindia/metric-learn/languages","stargazers_url":"https://api.github.com/repos/dsquareindia/metric-learn/stargazers","contributors_url":"https://api.github.com/repos/dsquareindia/metric-learn/contributors","subscribers_url":"https://api.github.com/repos/dsquareindia/metric-learn/subscribers","subscription_url":"https://api.github.com/repos/dsquareindia/metric-learn/subscription","commits_url":"https://api.github.com/repos/dsquareindia/metric-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/dsquareindia/metric-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/dsquareindia/metric-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/dsquareindia/metric-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/dsquareindia/metric-learn/contents/{+path}","compare_url":"https://api.github.com/repos/dsquareindia/metric-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dsquareindia/metric-learn/merges","archive_url":"https://api.github.com/repos/dsquareindia/metric-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dsquareindia/metric-learn/downloads","issues_url":"https://api.github.com/repos/dsquareindia/metric-learn/issues{/number}","pulls_url":"https://api.github.com/repos/dsquareindia/metric-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/dsquareindia/metric-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/dsquareindia/metric-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dsquareindia/metric-learn/labels{/name}","releases_url":"https://api.github.com/repos/dsquareindia/metric-learn/releases{/id}","deployments_url":"https://api.github.com/repos/dsquareindia/metric-learn/deployments","created_at":"2016-09-03T06:21:28Z","updated_at":"2016-09-03T06:21:29Z","pushed_at":"2016-09-17T16:21:48Z","git_url":"git://github.com/dsquareindia/metric-learn.git","ssh_url":"git@github.com:dsquareindia/metric-learn.git","clone_url":"https://github.com/dsquareindia/metric-learn.git","svn_url":"https://github.com/dsquareindia/metric-learn","homepage":null,"size":1069,"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":"all-umass:master","ref":"master","sha":"9f602e66c55d9ab3627d556019426686d0a8dcaf","user":{"login":"all-umass","id":6097358,"avatar_url":"https://avatars.githubusercontent.com/u/6097358?v=3","gravatar_id":"","url":"https://api.github.com/users/all-umass","html_url":"https://github.com/all-umass","followers_url":"https://api.github.com/users/all-umass/followers","following_url":"https://api.github.com/users/all-umass/following{/other_user}","gists_url":"https://api.github.com/users/all-umass/gists{/gist_id}","starred_url":"https://api.github.com/users/all-umass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/all-umass/subscriptions","organizations_url":"https://api.github.com/users/all-umass/orgs","repos_url":"https://api.github.com/users/all-umass/repos","events_url":"https://api.github.com/users/all-umass/events{/privacy}","received_events_url":"https://api.github.com/users/all-umass/received_events","type":"Organization","site_admin":false},"repo":{"id":14063354,"name":"metric-learn","full_name":"all-umass/metric-learn","owner":{"login":"all-umass","id":6097358,"avatar_url":"https://avatars.githubusercontent.com/u/6097358?v=3","gravatar_id":"","url":"https://api.github.com/users/all-umass","html_url":"https://github.com/all-umass","followers_url":"https://api.github.com/users/all-umass/followers","following_url":"https://api.github.com/users/all-umass/following{/other_user}","gists_url":"https://api.github.com/users/all-umass/gists{/gist_id}","starred_url":"https://api.github.com/users/all-umass/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/all-umass/subscriptions","organizations_url":"https://api.github.com/users/all-umass/orgs","repos_url":"https://api.github.com/users/all-umass/repos","events_url":"https://api.github.com/users/all-umass/events{/privacy}","received_events_url":"https://api.github.com/users/all-umass/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/all-umass/metric-learn","description":"Metric learning algorithms in Python","fork":false,"url":"https://api.github.com/repos/all-umass/metric-learn","forks_url":"https://api.github.com/repos/all-umass/metric-learn/forks","keys_url":"https://api.github.com/repos/all-umass/metric-learn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/all-umass/metric-learn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/all-umass/metric-learn/teams","hooks_url":"https://api.github.com/repos/all-umass/metric-learn/hooks","issue_events_url":"https://api.github.com/repos/all-umass/metric-learn/issues/events{/number}","events_url":"https://api.github.com/repos/all-umass/metric-learn/events","assignees_url":"https://api.github.com/repos/all-umass/metric-learn/assignees{/user}","branches_url":"https://api.github.com/repos/all-umass/metric-learn/branches{/branch}","tags_url":"https://api.github.com/repos/all-umass/metric-learn/tags","blobs_url":"https://api.github.com/repos/all-umass/metric-learn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/all-umass/metric-learn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/all-umass/metric-learn/git/refs{/sha}","trees_url":"https://api.github.com/repos/all-umass/metric-learn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/all-umass/metric-learn/statuses/{sha}","languages_url":"https://api.github.com/repos/all-umass/metric-learn/languages","stargazers_url":"https://api.github.com/repos/all-umass/metric-learn/stargazers","contributors_url":"https://api.github.com/repos/all-umass/metric-learn/contributors","subscribers_url":"https://api.github.com/repos/all-umass/metric-learn/subscribers","subscription_url":"https://api.github.com/repos/all-umass/metric-learn/subscription","commits_url":"https://api.github.com/repos/all-umass/metric-learn/commits{/sha}","git_commits_url":"https://api.github.com/repos/all-umass/metric-learn/git/commits{/sha}","comments_url":"https://api.github.com/repos/all-umass/metric-learn/comments{/number}","issue_comment_url":"https://api.github.com/repos/all-umass/metric-learn/issues/comments{/number}","contents_url":"https://api.github.com/repos/all-umass/metric-learn/contents/{+path}","compare_url":"https://api.github.com/repos/all-umass/metric-learn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/all-umass/metric-learn/merges","archive_url":"https://api.github.com/repos/all-umass/metric-learn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/all-umass/metric-learn/downloads","issues_url":"https://api.github.com/repos/all-umass/metric-learn/issues{/number}","pulls_url":"https://api.github.com/repos/all-umass/metric-learn/pulls{/number}","milestones_url":"https://api.github.com/repos/all-umass/metric-learn/milestones{/number}","notifications_url":"https://api.github.com/repos/all-umass/metric-learn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/all-umass/metric-learn/labels{/name}","releases_url":"https://api.github.com/repos/all-umass/metric-learn/releases{/id}","deployments_url":"https://api.github.com/repos/all-umass/metric-learn/deployments","created_at":"2013-11-02T08:29:47Z","updated_at":"2016-09-16T12:21:21Z","pushed_at":"2016-09-17T16:21:48Z","git_url":"git://github.com/all-umass/metric-learn.git","ssh_url":"git@github.com:all-umass/metric-learn.git","clone_url":"https://github.com/all-umass/metric-learn.git","svn_url":"https://github.com/all-umass/metric-learn","homepage":null,"size":1307,"stargazers_count":202,"watchers_count":202,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":50,"mirror_url":null,"open_issues_count":9,"forks":50,"open_issues":9,"watchers":202,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/28"},"html":{"href":"https://github.com/all-umass/metric-learn/pull/28"},"issue":{"href":"https://api.github.com/repos/all-umass/metric-learn/issues/28"},"comments":{"href":"https://api.github.com/repos/all-umass/metric-learn/issues/28/comments"},"review_comments":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/28/comments"},"review_comment":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/all-umass/metric-learn/pulls/28/commits"},"statuses":{"href":"https://api.github.com/repos/all-umass/metric-learn/statuses/1e78faab93a28a7b6e5e894f1fc8650e1317eb79"}}}}
{"actor":{"display_login":"perimosocordiae"}}