protected RegressionTree buildMinLeafSizeLimitedTree(Instances instances, int limit) {
		RegressionTree tree = new RegressionTree();
		// stats[0]: totalWeights
		// stats[1]: sum
		// stats[2]: weightedMean
		// stats[3]: splitEval
		double[] stats = new double[4];
		Dataset dataset = null;
		if (this.cache != null) {
			dataset = Dataset.create(this.cache, instances);
		} else {
			dataset = Dataset.get(instances);
		}
		Stack<TreeNode> nodes = new Stack<>();
		Stack<Dataset> datasets = new Stack<>();
		tree.root = createNode(dataset, limit, stats);
		nodes.push(tree.root);
		datasets.push(dataset);
		while (!nodes.isEmpty()) {
			TreeNode node = nodes.pop();
			Dataset data = datasets.pop();
			if (!node.isLeaf()) {
				TreeInteriorNode interiorNode = (TreeInteriorNode) node;
				Dataset left = new Dataset(data.instances);
				Dataset right = new Dataset(data.instances);
				split(data, interiorNode, left, right);
				interiorNode.left = createNode(left, limit, stats);
				interiorNode.right = createNode(right, limit, stats);
				nodes.push(interiorNode.left);
				datasets.push(left);
				nodes.push(interiorNode.right);
				datasets.push(right);
			}
		}
		return tree;
	}