{"action":"created","comment":{"url":"https://api.github.com/repos/Shark-ML/Shark/pulls/comments/81370375","pull_request_review_id":2356575,"id":81370375,"diff_hunk":"@@ -0,0 +1,156 @@\n+//===========================================================================\n+/*!\n+ *\n+ *\n+ * \\brief       General functions for Tree modeling.\n+ *\n+ *\n+ *\n+ * \\author      K. N. Hansen, J. Kremer, J. Wrigley\n+ * \\date        2011-2016\n+ *\n+ *\n+ * \\par Copyright 1995-2015 Shark Development Team\n+ *\n+ * <BR><HR>\n+ * This file is part of Shark.\n+ * <http://image.diku.dk/shark/>\n+ *\n+ * Shark is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Lesser General Public License as published\n+ * by the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * Shark is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU Lesser General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Lesser General Public License\n+ * along with Shark.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+//===========================================================================\n+#ifndef SHARK_ALGORITHMS_TRAINERS_CARTCOMMON_H\n+#define SHARK_ALGORITHMS_TRAINERS_CARTCOMMON_H\n+\n+#include <shark/Models/Trees/General.h>\n+#include <shark/Data/DataView.h>\n+#include <vector>\n+#include <unordered_map>\n+#include <utility>\n+namespace shark {\n+namespace detail {\n+namespace cart {\n+/// ClassVector\n+using ClassVector = UIntVector;\n+\n+\n+struct Attribute {\n+\tdouble value;\n+\tstd::size_t id;\n+\n+\tinline bool operator<(Attribute const &v) const {\n+\t\treturn value < v.value;\n+\t}\n+};\n+\n+\n+class Index {\n+/// attribute table\n+\tusing AttributeTable = std::vector<Attribute>;\n+/// collecting of attribute tables\n+\tusing AttributeTables = std::vector<AttributeTable>;\n+\n+\tstd::size_t m_noInputDimensions, m_noElements;\n+\tAttributeTables m_tables;\n+\n+\texplicit Index(AttributeTables &&tables)\n+\t\t\t: m_noElements(tables[0].size()),\n+\t\t\t  m_noInputDimensions(tables.size()),\n+\t\t\t  m_tables(std::move(tables))\n+\t{}\n+public:\n+\tstruct size_pair{\n+\t\tstd::size_t n_inputDimensions, n_elements;\n+\t\tsize_pair(std::size_t n_inputDimensions, std::size_t n_elements)\n+\t\t\t\t: n_inputDimensions(n_inputDimensions),\n+\t\t\t\t  n_elements(n_elements)\n+\t\t{}\n+\t};\n+\n+/** Creates an index of the dataset\n+ *  A dataset consisting of m input variables has m sorted attribute tables.\n+ *  [attribute | rid ]\n+ */\n+\ttemplate<class Dataset>\n+\texplicit Index(DataView<Dataset const> const &elements)\n+\t\t\t: m_noElements{elements.size()},\n+\t\t\t  m_noInputDimensions{elements[0].input.size()},\n+\t\t\t  m_tables(m_noInputDimensions)\n+\t{\n+\t\tstd::size_t n_elements = m_noElements;\n+\t\t//Each entry in the outer vector is an attribute table\n+\t\t//For each column\n+\t\tfor (std::size_t j = 0; j < m_noInputDimensions; j++) {\n+\t\t\t//m_tables.push_back({});\n+\t\t\tauto &table = m_tables[j];\n+\t\t\ttable.reserve(n_elements);\n+\n+\t\t\t//For each row, store Attribute value, class and rowId\n+\t\t\tfor (std::size_t i = 0; i < n_elements; i++) {\n+\t\t\t\ttable.push_back(Attribute{elements[i].input[j], i});\n+\t\t\t}\n+\t\t\tstd::sort(table.begin(), table.end());\n+\t\t}\n+\t}\n+\n+/**\n+ * Returns two Indices: left and right\n+ * Calculated from splitting tables at (index, valIndex)\n+ */\n+\tstd::pair<Index, Index> split(std::size_t index, std::size_t valIndex) {\n+\t\t//Build a hash table for fast lookup\n+\t\tstd::unordered_map<std::size_t, bool> hash;\n+\t\tfor(std::size_t i = 0, s = m_tables[index].size(); i<s; ++i) {\n+\t\t\thash[m_tables[index][i].id] = (i<=valIndex);\n+\t\t}\n+\n+\t\tAttributeTables RAttributeTables, LAttributeTables;\n+\t\tfor(auto && table : m_tables) {\n+\t\t\tauto begin = table.begin(), end = table.end();\n+\t\t\tauto middle = std::stable_partition(begin,end,[&hash](Attribute const& entry){\n+\t\t\t\treturn hash[entry.id];\n+\t\t\t});\n+\t\t\tRAttributeTables.emplace_back(AttributeTable{middle,end});\n+\t\t\ttable.resize(std::distance(begin,middle));\n+\t\t\tLAttributeTables.emplace_back(std::move(table));\n+\t\t}\n+\t\tm_tables.clear(); m_tables.shrink_to_fit();\n+\t\treturn std::make_pair(Index{std::move(LAttributeTables)},\n+\t\t\t\t\t\t\t  Index{std::move(RAttributeTables)});\n+\t}\n+\n+\tinline size_pair size() const {","path":"include/shark/Algorithms/Trainers/CARTcommon.h","position":134,"original_position":134,"commit_id":"dd7b1d1e7bea9186b2b7040f333ff45746e3e36c","original_commit_id":"dd7b1d1e7bea9186b2b7040f333ff45746e3e36c","user":{"login":"wrigleyster","id":982109,"avatar_url":"https://avatars.githubusercontent.com/u/982109?v=3","gravatar_id":"","url":"https://api.github.com/users/wrigleyster","html_url":"https://github.com/wrigleyster","followers_url":"https://api.github.com/users/wrigleyster/followers","following_url":"https://api.github.com/users/wrigleyster/following{/other_user}","gists_url":"https://api.github.com/users/wrigleyster/gists{/gist_id}","starred_url":"https://api.github.com/users/wrigleyster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wrigleyster/subscriptions","organizations_url":"https://api.github.com/users/wrigleyster/orgs","repos_url":"https://api.github.com/users/wrigleyster/repos","events_url":"https://api.github.com/users/wrigleyster/events{/privacy}","received_events_url":"https://api.github.com/users/wrigleyster/received_events","type":"User","site_admin":false},"body":"Good point, will do.","created_at":"2016-09-30T16:17:58Z","updated_at":"2016-09-30T16:17:58Z","html_url":"https://github.com/Shark-ML/Shark/pull/117#discussion_r81370375","pull_request_url":"https://api.github.com/repos/Shark-ML/Shark/pulls/117","_links":{"self":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/comments/81370375"},"html":{"href":"https://github.com/Shark-ML/Shark/pull/117#discussion_r81370375"},"pull_request":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/117"}}},"pull_request":{"url":"https://api.github.com/repos/Shark-ML/Shark/pulls/117","id":86920615,"html_url":"https://github.com/Shark-ML/Shark/pull/117","diff_url":"https://github.com/Shark-ML/Shark/pull/117.diff","patch_url":"https://github.com/Shark-ML/Shark/pull/117.patch","issue_url":"https://api.github.com/repos/Shark-ML/Shark/issues/117","number":117,"state":"open","locked":false,"title":"Random forests optimization","user":{"login":"wrigleyster","id":982109,"avatar_url":"https://avatars.githubusercontent.com/u/982109?v=3","gravatar_id":"","url":"https://api.github.com/users/wrigleyster","html_url":"https://github.com/wrigleyster","followers_url":"https://api.github.com/users/wrigleyster/followers","following_url":"https://api.github.com/users/wrigleyster/following{/other_user}","gists_url":"https://api.github.com/users/wrigleyster/gists{/gist_id}","starred_url":"https://api.github.com/users/wrigleyster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wrigleyster/subscriptions","organizations_url":"https://api.github.com/users/wrigleyster/orgs","repos_url":"https://api.github.com/users/wrigleyster/repos","events_url":"https://api.github.com/users/wrigleyster/events{/privacy}","received_events_url":"https://api.github.com/users/wrigleyster/received_events","type":"User","site_admin":false},"body":"Includes a number of significant speedups, seeding of random functions, and now properly calculated OOB estimates.\r\n\r\nStill in the merging pipe line:\r\n* All equivalent CART improvements\r\n* Choice of bootstrapping method\r\n* Choice of impurity measure for Classification\r\n* Some cleanup involving the old method for OOB estimates\r\n","created_at":"2016-09-27T12:34:33Z","updated_at":"2016-09-30T16:17:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7727a926e6b91122217ab2c260624ad9cb107858","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Shark-ML/Shark/pulls/117/commits","review_comments_url":"https://api.github.com/repos/Shark-ML/Shark/pulls/117/comments","review_comment_url":"https://api.github.com/repos/Shark-ML/Shark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Shark-ML/Shark/issues/117/comments","statuses_url":"https://api.github.com/repos/Shark-ML/Shark/statuses/dd7b1d1e7bea9186b2b7040f333ff45746e3e36c","head":{"label":"wrigleyster:p","ref":"p","sha":"dd7b1d1e7bea9186b2b7040f333ff45746e3e36c","user":{"login":"wrigleyster","id":982109,"avatar_url":"https://avatars.githubusercontent.com/u/982109?v=3","gravatar_id":"","url":"https://api.github.com/users/wrigleyster","html_url":"https://github.com/wrigleyster","followers_url":"https://api.github.com/users/wrigleyster/followers","following_url":"https://api.github.com/users/wrigleyster/following{/other_user}","gists_url":"https://api.github.com/users/wrigleyster/gists{/gist_id}","starred_url":"https://api.github.com/users/wrigleyster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wrigleyster/subscriptions","organizations_url":"https://api.github.com/users/wrigleyster/orgs","repos_url":"https://api.github.com/users/wrigleyster/repos","events_url":"https://api.github.com/users/wrigleyster/events{/privacy}","received_events_url":"https://api.github.com/users/wrigleyster/received_events","type":"User","site_admin":false},"repo":{"id":53586267,"name":"Shark","full_name":"wrigleyster/Shark","owner":{"login":"wrigleyster","id":982109,"avatar_url":"https://avatars.githubusercontent.com/u/982109?v=3","gravatar_id":"","url":"https://api.github.com/users/wrigleyster","html_url":"https://github.com/wrigleyster","followers_url":"https://api.github.com/users/wrigleyster/followers","following_url":"https://api.github.com/users/wrigleyster/following{/other_user}","gists_url":"https://api.github.com/users/wrigleyster/gists{/gist_id}","starred_url":"https://api.github.com/users/wrigleyster/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wrigleyster/subscriptions","organizations_url":"https://api.github.com/users/wrigleyster/orgs","repos_url":"https://api.github.com/users/wrigleyster/repos","events_url":"https://api.github.com/users/wrigleyster/events{/privacy}","received_events_url":"https://api.github.com/users/wrigleyster/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/wrigleyster/Shark","description":"The Shark Machine Leaning Library. See more:","fork":true,"url":"https://api.github.com/repos/wrigleyster/Shark","forks_url":"https://api.github.com/repos/wrigleyster/Shark/forks","keys_url":"https://api.github.com/repos/wrigleyster/Shark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/wrigleyster/Shark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/wrigleyster/Shark/teams","hooks_url":"https://api.github.com/repos/wrigleyster/Shark/hooks","issue_events_url":"https://api.github.com/repos/wrigleyster/Shark/issues/events{/number}","events_url":"https://api.github.com/repos/wrigleyster/Shark/events","assignees_url":"https://api.github.com/repos/wrigleyster/Shark/assignees{/user}","branches_url":"https://api.github.com/repos/wrigleyster/Shark/branches{/branch}","tags_url":"https://api.github.com/repos/wrigleyster/Shark/tags","blobs_url":"https://api.github.com/repos/wrigleyster/Shark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/wrigleyster/Shark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/wrigleyster/Shark/git/refs{/sha}","trees_url":"https://api.github.com/repos/wrigleyster/Shark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/wrigleyster/Shark/statuses/{sha}","languages_url":"https://api.github.com/repos/wrigleyster/Shark/languages","stargazers_url":"https://api.github.com/repos/wrigleyster/Shark/stargazers","contributors_url":"https://api.github.com/repos/wrigleyster/Shark/contributors","subscribers_url":"https://api.github.com/repos/wrigleyster/Shark/subscribers","subscription_url":"https://api.github.com/repos/wrigleyster/Shark/subscription","commits_url":"https://api.github.com/repos/wrigleyster/Shark/commits{/sha}","git_commits_url":"https://api.github.com/repos/wrigleyster/Shark/git/commits{/sha}","comments_url":"https://api.github.com/repos/wrigleyster/Shark/comments{/number}","issue_comment_url":"https://api.github.com/repos/wrigleyster/Shark/issues/comments{/number}","contents_url":"https://api.github.com/repos/wrigleyster/Shark/contents/{+path}","compare_url":"https://api.github.com/repos/wrigleyster/Shark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/wrigleyster/Shark/merges","archive_url":"https://api.github.com/repos/wrigleyster/Shark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/wrigleyster/Shark/downloads","issues_url":"https://api.github.com/repos/wrigleyster/Shark/issues{/number}","pulls_url":"https://api.github.com/repos/wrigleyster/Shark/pulls{/number}","milestones_url":"https://api.github.com/repos/wrigleyster/Shark/milestones{/number}","notifications_url":"https://api.github.com/repos/wrigleyster/Shark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/wrigleyster/Shark/labels{/name}","releases_url":"https://api.github.com/repos/wrigleyster/Shark/releases{/id}","deployments_url":"https://api.github.com/repos/wrigleyster/Shark/deployments","created_at":"2016-03-10T13:25:32Z","updated_at":"2016-03-10T13:25:36Z","pushed_at":"2016-09-27T12:09:23Z","git_url":"git://github.com/wrigleyster/Shark.git","ssh_url":"git@github.com:wrigleyster/Shark.git","clone_url":"https://github.com/wrigleyster/Shark.git","svn_url":"https://github.com/wrigleyster/Shark","homepage":"http://image.diku.dk/shark","size":25214,"stargazers_count":0,"watchers_count":0,"language":"C++","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":"Shark-ML:master","ref":"master","sha":"1e1b1c26a37ca5fc0086823f4acec6b73c350729","user":{"login":"Shark-ML","id":14577069,"avatar_url":"https://avatars.githubusercontent.com/u/14577069?v=3","gravatar_id":"","url":"https://api.github.com/users/Shark-ML","html_url":"https://github.com/Shark-ML","followers_url":"https://api.github.com/users/Shark-ML/followers","following_url":"https://api.github.com/users/Shark-ML/following{/other_user}","gists_url":"https://api.github.com/users/Shark-ML/gists{/gist_id}","starred_url":"https://api.github.com/users/Shark-ML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shark-ML/subscriptions","organizations_url":"https://api.github.com/users/Shark-ML/orgs","repos_url":"https://api.github.com/users/Shark-ML/repos","events_url":"https://api.github.com/users/Shark-ML/events{/privacy}","received_events_url":"https://api.github.com/users/Shark-ML/received_events","type":"Organization","site_admin":false},"repo":{"id":43938541,"name":"Shark","full_name":"Shark-ML/Shark","owner":{"login":"Shark-ML","id":14577069,"avatar_url":"https://avatars.githubusercontent.com/u/14577069?v=3","gravatar_id":"","url":"https://api.github.com/users/Shark-ML","html_url":"https://github.com/Shark-ML","followers_url":"https://api.github.com/users/Shark-ML/followers","following_url":"https://api.github.com/users/Shark-ML/following{/other_user}","gists_url":"https://api.github.com/users/Shark-ML/gists{/gist_id}","starred_url":"https://api.github.com/users/Shark-ML/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shark-ML/subscriptions","organizations_url":"https://api.github.com/users/Shark-ML/orgs","repos_url":"https://api.github.com/users/Shark-ML/repos","events_url":"https://api.github.com/users/Shark-ML/events{/privacy}","received_events_url":"https://api.github.com/users/Shark-ML/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Shark-ML/Shark","description":"The Shark Machine Leaning Library. See more:","fork":false,"url":"https://api.github.com/repos/Shark-ML/Shark","forks_url":"https://api.github.com/repos/Shark-ML/Shark/forks","keys_url":"https://api.github.com/repos/Shark-ML/Shark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Shark-ML/Shark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Shark-ML/Shark/teams","hooks_url":"https://api.github.com/repos/Shark-ML/Shark/hooks","issue_events_url":"https://api.github.com/repos/Shark-ML/Shark/issues/events{/number}","events_url":"https://api.github.com/repos/Shark-ML/Shark/events","assignees_url":"https://api.github.com/repos/Shark-ML/Shark/assignees{/user}","branches_url":"https://api.github.com/repos/Shark-ML/Shark/branches{/branch}","tags_url":"https://api.github.com/repos/Shark-ML/Shark/tags","blobs_url":"https://api.github.com/repos/Shark-ML/Shark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Shark-ML/Shark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Shark-ML/Shark/git/refs{/sha}","trees_url":"https://api.github.com/repos/Shark-ML/Shark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Shark-ML/Shark/statuses/{sha}","languages_url":"https://api.github.com/repos/Shark-ML/Shark/languages","stargazers_url":"https://api.github.com/repos/Shark-ML/Shark/stargazers","contributors_url":"https://api.github.com/repos/Shark-ML/Shark/contributors","subscribers_url":"https://api.github.com/repos/Shark-ML/Shark/subscribers","subscription_url":"https://api.github.com/repos/Shark-ML/Shark/subscription","commits_url":"https://api.github.com/repos/Shark-ML/Shark/commits{/sha}","git_commits_url":"https://api.github.com/repos/Shark-ML/Shark/git/commits{/sha}","comments_url":"https://api.github.com/repos/Shark-ML/Shark/comments{/number}","issue_comment_url":"https://api.github.com/repos/Shark-ML/Shark/issues/comments{/number}","contents_url":"https://api.github.com/repos/Shark-ML/Shark/contents/{+path}","compare_url":"https://api.github.com/repos/Shark-ML/Shark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Shark-ML/Shark/merges","archive_url":"https://api.github.com/repos/Shark-ML/Shark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Shark-ML/Shark/downloads","issues_url":"https://api.github.com/repos/Shark-ML/Shark/issues{/number}","pulls_url":"https://api.github.com/repos/Shark-ML/Shark/pulls{/number}","milestones_url":"https://api.github.com/repos/Shark-ML/Shark/milestones{/number}","notifications_url":"https://api.github.com/repos/Shark-ML/Shark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Shark-ML/Shark/labels{/name}","releases_url":"https://api.github.com/repos/Shark-ML/Shark/releases{/id}","deployments_url":"https://api.github.com/repos/Shark-ML/Shark/deployments","created_at":"2015-10-09T07:02:53Z","updated_at":"2016-09-28T21:13:38Z","pushed_at":"2016-09-30T14:59:37Z","git_url":"git://github.com/Shark-ML/Shark.git","ssh_url":"git@github.com:Shark-ML/Shark.git","clone_url":"https://github.com/Shark-ML/Shark.git","svn_url":"https://github.com/Shark-ML/Shark","homepage":"http://shark-ml.org/","size":28841,"stargazers_count":105,"watchers_count":105,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":47,"mirror_url":null,"open_issues_count":21,"forks":47,"open_issues":21,"watchers":105,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/117"},"html":{"href":"https://github.com/Shark-ML/Shark/pull/117"},"issue":{"href":"https://api.github.com/repos/Shark-ML/Shark/issues/117"},"comments":{"href":"https://api.github.com/repos/Shark-ML/Shark/issues/117/comments"},"review_comments":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/117/comments"},"review_comment":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Shark-ML/Shark/pulls/117/commits"},"statuses":{"href":"https://api.github.com/repos/Shark-ML/Shark/statuses/dd7b1d1e7bea9186b2b7040f333ff45746e3e36c"}}}}
{"actor":{"display_login":"wrigleyster"}}