Aleš Erjavec avatar Aleš Erjavec committed 365165a

Added an explicit check for subset size reduction.

Fixes #1243

Comments (0)

Files changed (1)

source/orange/tdidt_simple.cpp

 				*ex_ge++ = *ex;
 			}
 
-		node->type = ContinuousNode;
-		node->split_attr = best_attr;
-		node->split = best_split;
-		node->children_size = 2;
-		ASSERT(node->children = (SimpleTreeNode **)calloc(2, sizeof *node->children));
+		/*
+		 * Check there was an actual reduction of size in the the two subsets.
+		 * This test fails when all best_attr's (the only attr) values  are
+		 * the same (and equal best_split) so the data is split in 0 | n size
+		 * subsets and recursing would lead to an infinite recursion.
+		 */
+		if ((ex_lt - examples_lt) < size && (ex_ge - examples_ge) < size) {
+			node->type = ContinuousNode;
+			node->split_attr = best_attr;
+			node->split = best_split;
+			node->children_size = 2;
+			ASSERT(node->children = (SimpleTreeNode **)calloc(2, sizeof *node->children));
 
-		node->children[0] = build_tree(examples_lt, ex_lt - examples_lt, depth + 1, node, args);
-		node->children[1] = build_tree(examples_ge, ex_ge - examples_ge, depth + 1, node, args);
+			node->children[0] = build_tree(examples_lt, ex_lt - examples_lt, depth + 1, node, args);
+			node->children[1] = build_tree(examples_ge, ex_ge - examples_ge, depth + 1, node, args);
+		} else {
+			node = make_predictor(node, examples, size, args);
+		}
 
 		free(examples_lt);
 		free(examples_ge);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.