<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.insightml.models.trees;

import java.util.function.IntFunction;
import java.util.function.Supplier;

import com.insightml.math.statistics.IStats;
import com.insightml.math.statistics.MutableStatistics;

public final class ThresholdSplitFinder implements IntFunction<Split> {
	public static final double VALUE_MISSING = Double.NEGATIVE_INFINITY;

	private final SplitFinderContext context;
	private final boolean[] subset;
	private final int samples;
	private final SplitCriterion splitCriterion;
	private final int minObs;
	private final Supplier<MutableStatistics> statisticsFactory;

	public ThresholdSplitFinder(final SplitFinderContext context, final boolean[] subset, final int samples,
			final SplitCriterion splitCriterion, final int minObs,
			final Supplier<MutableStatistics> statisticsFactory) {
		this.context = context;
		this.subset = subset;
		this.samples = samples;
		this.splitCriterion = splitCriterion;
		this.minObs = minObs;
		this.statisticsFactory = statisticsFactory;
	}

	public static ThresholdSplitFinder createThresholdSplitFinder(final SplitFinderContext context,<commit_msg>ThresholdSplitFinder: require enough samples to perform a split<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.insightml.models.trees;

import java.util.function.IntFunction;
import java.util.function.Supplier;

import com.insightml.math.statistics.IStats;
import com.insightml.math.statistics.MutableStatistics;

public final class ThresholdSplitFinder implements IntFunction<Split> {
	public static final double VALUE_MISSING = Double.NEGATIVE_INFINITY;

	private final SplitFinderContext context;
	private final boolean[] subset;
	private final int samples;
	private final SplitCriterion splitCriterion;
	private final int minObs;
	private final Supplier<MutableStatistics> statisticsFactory;

	public ThresholdSplitFinder(final SplitFinderContext context, final boolean[] subset, final int samples,
			final SplitCriterion splitCriterion, final int minObs,
			final Supplier<MutableStatistics> statisticsFactory) {
		this.context = context;
		this.subset = subset;
		this.samples = samples;
		this.splitCriterion = splitCriterion;
		this.minObs = minObs;
		this.statisticsFactory = statisticsFactory;

		if (samples < minObs * 2) {
			throw new IllegalArgumentException(
					"Requires at least " + minObs * 2 + " samples to find a split, but only got " + samples);
		}
	}

	public static ThresholdSplitFinder createThresholdSplitFinder(final SplitFinderContext context,
{'fraction_non_alphanumeric': 0.07012278308321965, 'fraction_numerical': 0.0049113233287858115, 'mean_word_length': 5.079601990049751, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6202810', 'n_tokens_mistral': 1014, 'n_tokens_neox': 961, 'n_words': 359}