{"action":"created","comment":{"url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/comments/37634145","id":37634145,"diff_hunk":"@@ -0,0 +1,109 @@\n+import numpy as np\n+\n+from openmdao.surrogate_models.nn_interpolators.nn_base import NNBase\n+from six.moves import range\n+\n+\n+class LinearInterpolator(NNBase):\n+    \"\"\"\n+    Interpolates values by forming a hyperplane between the points closest to\n+    the prescribed inputs.\n+    \"\"\"\n+\n+    def _find_hyperplane(self, nloc):\n+        # Extra Inputs for Finding the normal are found below\n+        # Number of row vectors needed always dimensions - 1\n+        indep_dims = self.indep_dims\n+        dep_dims = self.dep_dims\n+\n+        # Number of Prediction Points\n+        nppts = nloc.shape[0]\n+\n+        # Preallocate storage\n+        pc = np.empty((nppts, dep_dims), dtype='float')\n+        normal = np.empty((nppts, indep_dims + 1, dep_dims), dtype='float')\n+        nvect = np.empty((nppts, indep_dims, indep_dims + 1), dtype='float')\n+        trnd = np.concatenate((self.tp[nloc, :],\n+                               self.tv[nloc, 0].reshape(nppts, indep_dims + 1, 1)),\n+                              axis=2)\n+        nvect[:, :, :-1] = trnd[:, 1:, :-1] - trnd[:, :-1, :-1]\n+\n+        for i in range(dep_dims):\n+            # Planar vectors need both dep and ind dimensions\n+            trnd[:, :, -1] = self.tv[nloc, i]\n+\n+            # Go through each neighbor\n+            # Creates array[neighbor, dimension] from NN results\n+            nvect[:, :, -1] = trnd[:, 1:, -1] - trnd[:, :-1, -1]\n+\n+            # Normal vector is in the null space of nvect.\n+            # Since nvect is of size indep x (indep + 1),\n+            # the normal vector will be the last entry in\n+            # V in the U, Sigma, V = svd(nvect).\n+            normal[:, :, i] = np.linalg.svd(nvect)[2][:, -1, :]\n+\n+            # Use the point of the closest neighbor to\n+            # solve for pc - the constant of the n-dimensional plane.\n+            pc[:, i] = np.einsum('ij,ij->i', trnd[:, 0, :], normal[:, :, i])\n+\n+        return normal, pc\n+\n+    def __call__(self, prediction_points):\n+        # This method uses linear interpolation by defining a plane with\n+        # a set number of nearest neighbors to the predicted\n+\n+        if len(prediction_points.shape) == 1:\n+            # Reshape vector to n x 1 array\n+            prediction_points.shape = (1, prediction_points.shape[0])\n+\n+        normalized_pts = (prediction_points - self.tpm) / self.tpr\n+\n+        # Linear interp only uses as many neighbors as it has dimensions\n+        points_needed = self.indep_dims + 1\n+\n+        # KData query takes (data, #ofneighbors) to determine closest\n+        # training points to predicted data\n+        ndist, nloc = self.KData.query(normalized_pts.real, points_needed)\n+\n+        normal, pc = self._find_hyperplane(nloc)\n+\n+        # Set all predictions from values on plane\n+        predictions = np.einsum('ij,ijk->ik', normalized_pts,","path":"openmdao/surrogate_models/nn_interpolators/linear_interpolator.py","position":71,"original_position":71,"commit_id":"049a52cbebd55f8d334be932add8e542d2989030","original_commit_id":"24f3f5d3da3b7cf05d9a3ef60acf44191ff69dbb","user":{"login":"Kenneth-T-Moore","id":867917,"avatar_url":"https://avatars.githubusercontent.com/u/867917?v=3","gravatar_id":"","url":"https://api.github.com/users/Kenneth-T-Moore","html_url":"https://github.com/Kenneth-T-Moore","followers_url":"https://api.github.com/users/Kenneth-T-Moore/followers","following_url":"https://api.github.com/users/Kenneth-T-Moore/following{/other_user}","gists_url":"https://api.github.com/users/Kenneth-T-Moore/gists{/gist_id}","starred_url":"https://api.github.com/users/Kenneth-T-Moore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kenneth-T-Moore/subscriptions","organizations_url":"https://api.github.com/users/Kenneth-T-Moore/orgs","repos_url":"https://api.github.com/users/Kenneth-T-Moore/repos","events_url":"https://api.github.com/users/Kenneth-T-Moore/events{/privacy}","received_events_url":"https://api.github.com/users/Kenneth-T-Moore/received_events","type":"User","site_admin":false},"body":"I looked this over and didn't see anything that jumped out at me in terms of design of style, so it gets my vote for merge.","created_at":"2015-08-21T13:37:31Z","updated_at":"2015-08-21T13:37:31Z","html_url":"https://github.com/OpenMDAO/OpenMDAO/pull/278#discussion_r37634145","pull_request_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278","_links":{"self":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/comments/37634145"},"html":{"href":"https://github.com/OpenMDAO/OpenMDAO/pull/278#discussion_r37634145"},"pull_request":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278"}}},"pull_request":{"url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278","id":42865836,"html_url":"https://github.com/OpenMDAO/OpenMDAO/pull/278","diff_url":"https://github.com/OpenMDAO/OpenMDAO/pull/278.diff","patch_url":"https://github.com/OpenMDAO/OpenMDAO/pull/278.patch","issue_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/278","number":278,"state":"open","locked":false,"title":"Nearest Neighbour Interpolators","user":{"login":"dwmunster","id":3619157,"avatar_url":"https://avatars.githubusercontent.com/u/3619157?v=3","gravatar_id":"","url":"https://api.github.com/users/dwmunster","html_url":"https://github.com/dwmunster","followers_url":"https://api.github.com/users/dwmunster/followers","following_url":"https://api.github.com/users/dwmunster/following{/other_user}","gists_url":"https://api.github.com/users/dwmunster/gists{/gist_id}","starred_url":"https://api.github.com/users/dwmunster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwmunster/subscriptions","organizations_url":"https://api.github.com/users/dwmunster/orgs","repos_url":"https://api.github.com/users/dwmunster/repos","events_url":"https://api.github.com/users/dwmunster/events{/privacy}","received_events_url":"https://api.github.com/users/dwmunster/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-19T21:23:01Z","updated_at":"2015-08-21T13:37:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b3d18031cda82aa79b75831fe8006f6cc979e0dc","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278/commits","review_comments_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278/comments","review_comment_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/278/comments","statuses_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/statuses/049a52cbebd55f8d334be932add8e542d2989030","head":{"label":"dwmunster:nn_interp","ref":"nn_interp","sha":"049a52cbebd55f8d334be932add8e542d2989030","user":{"login":"dwmunster","id":3619157,"avatar_url":"https://avatars.githubusercontent.com/u/3619157?v=3","gravatar_id":"","url":"https://api.github.com/users/dwmunster","html_url":"https://github.com/dwmunster","followers_url":"https://api.github.com/users/dwmunster/followers","following_url":"https://api.github.com/users/dwmunster/following{/other_user}","gists_url":"https://api.github.com/users/dwmunster/gists{/gist_id}","starred_url":"https://api.github.com/users/dwmunster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwmunster/subscriptions","organizations_url":"https://api.github.com/users/dwmunster/orgs","repos_url":"https://api.github.com/users/dwmunster/repos","events_url":"https://api.github.com/users/dwmunster/events{/privacy}","received_events_url":"https://api.github.com/users/dwmunster/received_events","type":"User","site_admin":false},"repo":{"id":39217803,"name":"OpenMDAO","full_name":"dwmunster/OpenMDAO","owner":{"login":"dwmunster","id":3619157,"avatar_url":"https://avatars.githubusercontent.com/u/3619157?v=3","gravatar_id":"","url":"https://api.github.com/users/dwmunster","html_url":"https://github.com/dwmunster","followers_url":"https://api.github.com/users/dwmunster/followers","following_url":"https://api.github.com/users/dwmunster/following{/other_user}","gists_url":"https://api.github.com/users/dwmunster/gists{/gist_id}","starred_url":"https://api.github.com/users/dwmunster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dwmunster/subscriptions","organizations_url":"https://api.github.com/users/dwmunster/orgs","repos_url":"https://api.github.com/users/dwmunster/repos","events_url":"https://api.github.com/users/dwmunster/events{/privacy}","received_events_url":"https://api.github.com/users/dwmunster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dwmunster/OpenMDAO","description":"","fork":true,"url":"https://api.github.com/repos/dwmunster/OpenMDAO","forks_url":"https://api.github.com/repos/dwmunster/OpenMDAO/forks","keys_url":"https://api.github.com/repos/dwmunster/OpenMDAO/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dwmunster/OpenMDAO/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dwmunster/OpenMDAO/teams","hooks_url":"https://api.github.com/repos/dwmunster/OpenMDAO/hooks","issue_events_url":"https://api.github.com/repos/dwmunster/OpenMDAO/issues/events{/number}","events_url":"https://api.github.com/repos/dwmunster/OpenMDAO/events","assignees_url":"https://api.github.com/repos/dwmunster/OpenMDAO/assignees{/user}","branches_url":"https://api.github.com/repos/dwmunster/OpenMDAO/branches{/branch}","tags_url":"https://api.github.com/repos/dwmunster/OpenMDAO/tags","blobs_url":"https://api.github.com/repos/dwmunster/OpenMDAO/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dwmunster/OpenMDAO/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dwmunster/OpenMDAO/git/refs{/sha}","trees_url":"https://api.github.com/repos/dwmunster/OpenMDAO/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dwmunster/OpenMDAO/statuses/{sha}","languages_url":"https://api.github.com/repos/dwmunster/OpenMDAO/languages","stargazers_url":"https://api.github.com/repos/dwmunster/OpenMDAO/stargazers","contributors_url":"https://api.github.com/repos/dwmunster/OpenMDAO/contributors","subscribers_url":"https://api.github.com/repos/dwmunster/OpenMDAO/subscribers","subscription_url":"https://api.github.com/repos/dwmunster/OpenMDAO/subscription","commits_url":"https://api.github.com/repos/dwmunster/OpenMDAO/commits{/sha}","git_commits_url":"https://api.github.com/repos/dwmunster/OpenMDAO/git/commits{/sha}","comments_url":"https://api.github.com/repos/dwmunster/OpenMDAO/comments{/number}","issue_comment_url":"https://api.github.com/repos/dwmunster/OpenMDAO/issues/comments{/number}","contents_url":"https://api.github.com/repos/dwmunster/OpenMDAO/contents/{+path}","compare_url":"https://api.github.com/repos/dwmunster/OpenMDAO/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dwmunster/OpenMDAO/merges","archive_url":"https://api.github.com/repos/dwmunster/OpenMDAO/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dwmunster/OpenMDAO/downloads","issues_url":"https://api.github.com/repos/dwmunster/OpenMDAO/issues{/number}","pulls_url":"https://api.github.com/repos/dwmunster/OpenMDAO/pulls{/number}","milestones_url":"https://api.github.com/repos/dwmunster/OpenMDAO/milestones{/number}","notifications_url":"https://api.github.com/repos/dwmunster/OpenMDAO/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dwmunster/OpenMDAO/labels{/name}","releases_url":"https://api.github.com/repos/dwmunster/OpenMDAO/releases{/id}","created_at":"2015-07-16T20:04:29Z","updated_at":"2015-07-16T20:04:30Z","pushed_at":"2015-08-20T21:33:49Z","git_url":"git://github.com/dwmunster/OpenMDAO.git","ssh_url":"git@github.com:dwmunster/OpenMDAO.git","clone_url":"https://github.com/dwmunster/OpenMDAO.git","svn_url":"https://github.com/dwmunster/OpenMDAO","homepage":"","size":2420,"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":"OpenMDAO:master","ref":"master","sha":"b2bade0fa12c34dadd72e0875a5367288619108c","user":{"login":"OpenMDAO","id":861615,"avatar_url":"https://avatars.githubusercontent.com/u/861615?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenMDAO","html_url":"https://github.com/OpenMDAO","followers_url":"https://api.github.com/users/OpenMDAO/followers","following_url":"https://api.github.com/users/OpenMDAO/following{/other_user}","gists_url":"https://api.github.com/users/OpenMDAO/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenMDAO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenMDAO/subscriptions","organizations_url":"https://api.github.com/users/OpenMDAO/orgs","repos_url":"https://api.github.com/users/OpenMDAO/repos","events_url":"https://api.github.com/users/OpenMDAO/events{/privacy}","received_events_url":"https://api.github.com/users/OpenMDAO/received_events","type":"Organization","site_admin":false},"repo":{"id":33391296,"name":"OpenMDAO","full_name":"OpenMDAO/OpenMDAO","owner":{"login":"OpenMDAO","id":861615,"avatar_url":"https://avatars.githubusercontent.com/u/861615?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenMDAO","html_url":"https://github.com/OpenMDAO","followers_url":"https://api.github.com/users/OpenMDAO/followers","following_url":"https://api.github.com/users/OpenMDAO/following{/other_user}","gists_url":"https://api.github.com/users/OpenMDAO/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenMDAO/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenMDAO/subscriptions","organizations_url":"https://api.github.com/users/OpenMDAO/orgs","repos_url":"https://api.github.com/users/OpenMDAO/repos","events_url":"https://api.github.com/users/OpenMDAO/events{/privacy}","received_events_url":"https://api.github.com/users/OpenMDAO/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OpenMDAO/OpenMDAO","description":"OpenMDAO is a high-performance computing platform for systems analysis and optimization that enables you to decompose your models, making them easier to build and maintain, while still solving them in a tightly-coupled manner with efficient parallel numerical methods.","fork":false,"url":"https://api.github.com/repos/OpenMDAO/OpenMDAO","forks_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/forks","keys_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/teams","hooks_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/hooks","issue_events_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/events{/number}","events_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/events","assignees_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/assignees{/user}","branches_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/branches{/branch}","tags_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/tags","blobs_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/git/refs{/sha}","trees_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/statuses/{sha}","languages_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/languages","stargazers_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/stargazers","contributors_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/contributors","subscribers_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/subscribers","subscription_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/subscription","commits_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/commits{/sha}","git_commits_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/git/commits{/sha}","comments_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/comments{/number}","issue_comment_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/comments{/number}","contents_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/contents/{+path}","compare_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/merges","archive_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/downloads","issues_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues{/number}","pulls_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls{/number}","milestones_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/milestones{/number}","notifications_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/labels{/name}","releases_url":"https://api.github.com/repos/OpenMDAO/OpenMDAO/releases{/id}","created_at":"2015-04-04T02:15:24Z","updated_at":"2015-08-20T07:12:45Z","pushed_at":"2015-08-21T13:30:35Z","git_url":"git://github.com/OpenMDAO/OpenMDAO.git","ssh_url":"git@github.com:OpenMDAO/OpenMDAO.git","clone_url":"https://github.com/OpenMDAO/OpenMDAO.git","svn_url":"https://github.com/OpenMDAO/OpenMDAO","homepage":"http://openmdao.org","size":3646,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":2,"forks":15,"open_issues":2,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278"},"html":{"href":"https://github.com/OpenMDAO/OpenMDAO/pull/278"},"issue":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/278"},"comments":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/issues/278/comments"},"review_comments":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278/comments"},"review_comment":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/pulls/278/commits"},"statuses":{"href":"https://api.github.com/repos/OpenMDAO/OpenMDAO/statuses/049a52cbebd55f8d334be932add8e542d2989030"}}}}