{"action":"created","comment":{"url":"https://api.github.com/repos/apache/ignite/pulls/comments/231516853","pull_request_review_id":172485551,"id":231516853,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMTUxNjg1Mw==","diff_hunk":"@@ -0,0 +1,373 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * the License.  You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.ignite.ml.trainers;\n+\n+import java.io.Serializable;\n+import org.apache.ignite.lang.IgniteBiPredicate;\n+import org.apache.ignite.ml.Model;\n+import org.apache.ignite.ml.composition.ModelsComposition;\n+import org.apache.ignite.ml.composition.predictionsaggregator.PredictionsAggregator;\n+import org.apache.ignite.ml.dataset.Dataset;\n+import org.apache.ignite.ml.dataset.DatasetBuilder;\n+import org.apache.ignite.ml.dataset.PartitionContextBuilder;\n+import org.apache.ignite.ml.dataset.PartitionDataBuilder;\n+import org.apache.ignite.ml.dataset.UpstreamTransformerChain;\n+import org.apache.ignite.ml.environment.LearningEnvironment;\n+import org.apache.ignite.ml.environment.logging.MLLogger;\n+import org.apache.ignite.ml.environment.parallelism.Promise;\n+import org.apache.ignite.ml.math.functions.IgniteBiFunction;\n+import org.apache.ignite.ml.math.functions.IgniteFunction;\n+import org.apache.ignite.ml.math.functions.IgniteSupplier;\n+import org.apache.ignite.ml.math.functions.IgniteTriFunction;\n+import org.apache.ignite.ml.math.primitives.vector.Vector;\n+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;\n+import org.apache.ignite.ml.trainers.transformers.BaggingUpstreamTransformer;\n+import org.apache.ignite.ml.util.Utils;\n+\n+import java.util.*;\n+import java.util.stream.Collectors;\n+import java.util.stream.IntStream;\n+\n+/**\n+ * Class containing various trainer transformers.\n+ */\n+public class TrainerTransformers {\n+    /** Relatively big prime used in seeding. */\n+    private static final int MAGIC_PRIME = 953851;\n+\n+    /**\n+     * Add bagging logic to a given trainer.\n+     *\n+     * @param ensembleSize Size of ensemble.\n+     * @param subsampleRatio Subsample ratio to whole dataset.\n+     * @param aggregator Aggregator.\n+     * @param <M> Type of one model in ensemble.\n+     * @param <L> Type of labels.\n+     * @return Bagged trainer.\n+     */\n+    public static <M extends Model<Vector, Double>, L> DatasetTrainer<ModelsComposition, L> makeBagged(\n+        DatasetTrainer<M, L> trainer,\n+        int ensembleSize,\n+        double subsampleRatio,\n+        PredictionsAggregator aggregator) {\n+        return makeBagged(trainer, ensembleSize, subsampleRatio, -1, -1, aggregator, new Random().nextLong());\n+    }\n+\n+    /**\n+     * Add bagging logic to a given trainer.\n+     *\n+     * @param ensembleSize Size of ensemble.\n+     * @param subsampleRatio Subsample ratio to whole dataset.\n+     * @param aggregator Aggregator.\n+     * @param <M> Type of one model in ensemble.\n+     * @param <L> Type of labels.\n+     * @return Bagged trainer.\n+     */\n+    public static <M extends Model<Vector, Double>, L> DatasetTrainer<ModelsComposition, L> makeBagged(\n+        DatasetTrainer<M, L> trainer,\n+        int ensembleSize,\n+        double subsampleRatio,\n+        int featureVectorSize,\n+        int maxFeaturesCntPerMdl,\n+        PredictionsAggregator aggregator,\n+        Long transformationSeed) {\n+        return new DatasetTrainer<ModelsComposition, L>() {\n+            @Override\n+            public <K, V> ModelsComposition fit(\n+                DatasetBuilder<K, V> datasetBuilder,\n+                IgniteBiFunction<K, V, Vector> featureExtractor,\n+                IgniteBiFunction<K, V, L> lbExtractor) {\n+                datasetBuilder.upstreamTransformersChain().setSeed(\n+                    transformationSeed == null\n+                        ? new Random().nextLong()\n+                        : transformationSeed);\n+\n+                return runOnEnsemble(\n+                    (db, i, fe) -> (() -> trainer.fit(db, fe, lbExtractor)),\n+                    datasetBuilder,\n+                    ensembleSize,\n+                    subsampleRatio,\n+                    featureVectorSize,\n+                    maxFeaturesCntPerMdl,\n+                    featureExtractor,\n+                    aggregator,\n+                    environment);\n+            }\n+\n+            @Override\n+            protected boolean checkState(ModelsComposition mdl) {","path":"modules/ml/src/main/java/org/apache/ignite/ml/trainers/TrainerTransformers.java","position":113,"original_position":113,"commit_id":"66e5977a0f2f539b3d5488bfedb65a1fad1cc55e","original_commit_id":"66e5977a0f2f539b3d5488bfedb65a1fad1cc55e","user":{"login":"dmitrievanthony","id":1028969,"node_id":"MDQ6VXNlcjEwMjg5Njk=","avatar_url":"https://avatars3.githubusercontent.com/u/1028969?v=4","gravatar_id":"","url":"https://api.github.com/users/dmitrievanthony","html_url":"https://github.com/dmitrievanthony","followers_url":"https://api.github.com/users/dmitrievanthony/followers","following_url":"https://api.github.com/users/dmitrievanthony/following{/other_user}","gists_url":"https://api.github.com/users/dmitrievanthony/gists{/gist_id}","starred_url":"https://api.github.com/users/dmitrievanthony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmitrievanthony/subscriptions","organizations_url":"https://api.github.com/users/dmitrievanthony/orgs","repos_url":"https://api.github.com/users/dmitrievanthony/repos","events_url":"https://api.github.com/users/dmitrievanthony/events{/privacy}","received_events_url":"https://api.github.com/users/dmitrievanthony/received_events","type":"User","site_admin":false},"body":"`@Override` on the wrong line and missed javadoc here and next method too.","created_at":"2018-11-07T14:10:25Z","updated_at":"2018-11-07T14:22:01Z","html_url":"https://github.com/apache/ignite/pull/5058#discussion_r231516853","pull_request_url":"https://api.github.com/repos/apache/ignite/pulls/5058","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/apache/ignite/pulls/comments/231516853"},"html":{"href":"https://github.com/apache/ignite/pull/5058#discussion_r231516853"},"pull_request":{"href":"https://api.github.com/repos/apache/ignite/pulls/5058"}}},"pull_request":{"url":"https://api.github.com/repos/apache/ignite/pulls/5058","id":225023410,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI1MDIzNDEw","html_url":"https://github.com/apache/ignite/pull/5058","diff_url":"https://github.com/apache/ignite/pull/5058.diff","patch_url":"https://github.com/apache/ignite/pull/5058.patch","issue_url":"https://api.github.com/repos/apache/ignite/issues/5058","number":5058,"state":"open","locked":false,"title":"IGNITE-8867: Bagging","user":{"login":"artemmalykh","id":26772992,"node_id":"MDQ6VXNlcjI2NzcyOTky","avatar_url":"https://avatars2.githubusercontent.com/u/26772992?v=4","gravatar_id":"","url":"https://api.github.com/users/artemmalykh","html_url":"https://github.com/artemmalykh","followers_url":"https://api.github.com/users/artemmalykh/followers","following_url":"https://api.github.com/users/artemmalykh/following{/other_user}","gists_url":"https://api.github.com/users/artemmalykh/gists{/gist_id}","starred_url":"https://api.github.com/users/artemmalykh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemmalykh/subscriptions","organizations_url":"https://api.github.com/users/artemmalykh/orgs","repos_url":"https://api.github.com/users/artemmalykh/repos","events_url":"https://api.github.com/users/artemmalykh/events{/privacy}","received_events_url":"https://api.github.com/users/artemmalykh/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-23T12:44:36Z","updated_at":"2018-11-07T14:22:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca3a9baeb47463c931ef8c3d62ceafb6fabc9666","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/ignite/pulls/5058/commits","review_comments_url":"https://api.github.com/repos/apache/ignite/pulls/5058/comments","review_comment_url":"https://api.github.com/repos/apache/ignite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/ignite/issues/5058/comments","statuses_url":"https://api.github.com/repos/apache/ignite/statuses/66e5977a0f2f539b3d5488bfedb65a1fad1cc55e","head":{"label":"gridgain:ignite-8867","ref":"ignite-8867","sha":"66e5977a0f2f539b3d5488bfedb65a1fad1cc55e","user":{"login":"gridgain","id":803592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwMzU5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/803592?v=4","gravatar_id":"","url":"https://api.github.com/users/gridgain","html_url":"https://github.com/gridgain","followers_url":"https://api.github.com/users/gridgain/followers","following_url":"https://api.github.com/users/gridgain/following{/other_user}","gists_url":"https://api.github.com/users/gridgain/gists{/gist_id}","starred_url":"https://api.github.com/users/gridgain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gridgain/subscriptions","organizations_url":"https://api.github.com/users/gridgain/orgs","repos_url":"https://api.github.com/users/gridgain/repos","events_url":"https://api.github.com/users/gridgain/events{/privacy}","received_events_url":"https://api.github.com/users/gridgain/received_events","type":"Organization","site_admin":false},"repo":{"id":32432793,"node_id":"MDEwOlJlcG9zaXRvcnkzMjQzMjc5Mw==","name":"apache-ignite","full_name":"gridgain/apache-ignite","private":false,"owner":{"login":"gridgain","id":803592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgwMzU5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/803592?v=4","gravatar_id":"","url":"https://api.github.com/users/gridgain","html_url":"https://github.com/gridgain","followers_url":"https://api.github.com/users/gridgain/followers","following_url":"https://api.github.com/users/gridgain/following{/other_user}","gists_url":"https://api.github.com/users/gridgain/gists{/gist_id}","starred_url":"https://api.github.com/users/gridgain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gridgain/subscriptions","organizations_url":"https://api.github.com/users/gridgain/orgs","repos_url":"https://api.github.com/users/gridgain/repos","events_url":"https://api.github.com/users/gridgain/events{/privacy}","received_events_url":"https://api.github.com/users/gridgain/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/gridgain/apache-ignite","description":"Mirror of Apache Ignite","fork":true,"url":"https://api.github.com/repos/gridgain/apache-ignite","forks_url":"https://api.github.com/repos/gridgain/apache-ignite/forks","keys_url":"https://api.github.com/repos/gridgain/apache-ignite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gridgain/apache-ignite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gridgain/apache-ignite/teams","hooks_url":"https://api.github.com/repos/gridgain/apache-ignite/hooks","issue_events_url":"https://api.github.com/repos/gridgain/apache-ignite/issues/events{/number}","events_url":"https://api.github.com/repos/gridgain/apache-ignite/events","assignees_url":"https://api.github.com/repos/gridgain/apache-ignite/assignees{/user}","branches_url":"https://api.github.com/repos/gridgain/apache-ignite/branches{/branch}","tags_url":"https://api.github.com/repos/gridgain/apache-ignite/tags","blobs_url":"https://api.github.com/repos/gridgain/apache-ignite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gridgain/apache-ignite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gridgain/apache-ignite/git/refs{/sha}","trees_url":"https://api.github.com/repos/gridgain/apache-ignite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gridgain/apache-ignite/statuses/{sha}","languages_url":"https://api.github.com/repos/gridgain/apache-ignite/languages","stargazers_url":"https://api.github.com/repos/gridgain/apache-ignite/stargazers","contributors_url":"https://api.github.com/repos/gridgain/apache-ignite/contributors","subscribers_url":"https://api.github.com/repos/gridgain/apache-ignite/subscribers","subscription_url":"https://api.github.com/repos/gridgain/apache-ignite/subscription","commits_url":"https://api.github.com/repos/gridgain/apache-ignite/commits{/sha}","git_commits_url":"https://api.github.com/repos/gridgain/apache-ignite/git/commits{/sha}","comments_url":"https://api.github.com/repos/gridgain/apache-ignite/comments{/number}","issue_comment_url":"https://api.github.com/repos/gridgain/apache-ignite/issues/comments{/number}","contents_url":"https://api.github.com/repos/gridgain/apache-ignite/contents/{+path}","compare_url":"https://api.github.com/repos/gridgain/apache-ignite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gridgain/apache-ignite/merges","archive_url":"https://api.github.com/repos/gridgain/apache-ignite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gridgain/apache-ignite/downloads","issues_url":"https://api.github.com/repos/gridgain/apache-ignite/issues{/number}","pulls_url":"https://api.github.com/repos/gridgain/apache-ignite/pulls{/number}","milestones_url":"https://api.github.com/repos/gridgain/apache-ignite/milestones{/number}","notifications_url":"https://api.github.com/repos/gridgain/apache-ignite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gridgain/apache-ignite/labels{/name}","releases_url":"https://api.github.com/repos/gridgain/apache-ignite/releases{/id}","deployments_url":"https://api.github.com/repos/gridgain/apache-ignite/deployments","created_at":"2015-03-18T02:19:44Z","updated_at":"2018-10-23T14:17:55Z","pushed_at":"2018-11-07T14:14:44Z","git_url":"git://github.com/gridgain/apache-ignite.git","ssh_url":"git@github.com:gridgain/apache-ignite.git","clone_url":"https://github.com/gridgain/apache-ignite.git","svn_url":"https://github.com/gridgain/apache-ignite","homepage":"","size":381938,"stargazers_count":20,"watchers_count":20,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"archived":false,"open_issues_count":18,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":7,"open_issues":18,"watchers":20,"default_branch":"sprint-2"}},"base":{"label":"apache:master","ref":"master","sha":"6f9c702cd764963208c8962d7ef35b2c340dbc08","user":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":31006158,"node_id":"MDEwOlJlcG9zaXRvcnkzMTAwNjE1OA==","name":"ignite","full_name":"apache/ignite","private":false,"owner":{"login":"apache","id":47359,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ3MzU5","avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/apache/ignite","description":"Mirror of Apache Ignite","fork":false,"url":"https://api.github.com/repos/apache/ignite","forks_url":"https://api.github.com/repos/apache/ignite/forks","keys_url":"https://api.github.com/repos/apache/ignite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/ignite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/ignite/teams","hooks_url":"https://api.github.com/repos/apache/ignite/hooks","issue_events_url":"https://api.github.com/repos/apache/ignite/issues/events{/number}","events_url":"https://api.github.com/repos/apache/ignite/events","assignees_url":"https://api.github.com/repos/apache/ignite/assignees{/user}","branches_url":"https://api.github.com/repos/apache/ignite/branches{/branch}","tags_url":"https://api.github.com/repos/apache/ignite/tags","blobs_url":"https://api.github.com/repos/apache/ignite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/ignite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/ignite/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/ignite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/ignite/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/ignite/languages","stargazers_url":"https://api.github.com/repos/apache/ignite/stargazers","contributors_url":"https://api.github.com/repos/apache/ignite/contributors","subscribers_url":"https://api.github.com/repos/apache/ignite/subscribers","subscription_url":"https://api.github.com/repos/apache/ignite/subscription","commits_url":"https://api.github.com/repos/apache/ignite/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/ignite/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/ignite/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/ignite/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/ignite/contents/{+path}","compare_url":"https://api.github.com/repos/apache/ignite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/ignite/merges","archive_url":"https://api.github.com/repos/apache/ignite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/ignite/downloads","issues_url":"https://api.github.com/repos/apache/ignite/issues{/number}","pulls_url":"https://api.github.com/repos/apache/ignite/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/ignite/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/ignite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/ignite/labels{/name}","releases_url":"https://api.github.com/repos/apache/ignite/releases{/id}","deployments_url":"https://api.github.com/repos/apache/ignite/deployments","created_at":"2015-02-19T08:00:05Z","updated_at":"2018-11-07T11:31:39Z","pushed_at":"2018-11-07T14:06:54Z","git_url":"git://github.com/apache/ignite.git","ssh_url":"git@github.com:apache/ignite.git","clone_url":"https://github.com/apache/ignite.git","svn_url":"https://github.com/apache/ignite","homepage":"","size":296582,"stargazers_count":2060,"watchers_count":2060,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1077,"mirror_url":null,"archived":false,"open_issues_count":1392,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":1077,"open_issues":1392,"watchers":2060,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/ignite/pulls/5058"},"html":{"href":"https://github.com/apache/ignite/pull/5058"},"issue":{"href":"https://api.github.com/repos/apache/ignite/issues/5058"},"comments":{"href":"https://api.github.com/repos/apache/ignite/issues/5058/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/ignite/pulls/5058/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/ignite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/ignite/pulls/5058/commits"},"statuses":{"href":"https://api.github.com/repos/apache/ignite/statuses/66e5977a0f2f539b3d5488bfedb65a1fad1cc55e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"dmitrievanthony"}}