<commit_before>package org.extratrees;

import java.util.Set;

/**
 * All subclasses should have their generic argument equal to itself, 
 * i.e. X extends AbstractBinaryTree<X>.
 * Otherwise getItself() will break. 
 * 
 * @author jaak
 *
 * @param <T>
 */
public abstract class AbstractBinaryTree <T extends AbstractBinaryTree<T, D>, D> {
	/** tree for elements below threshold.
	 * if left==null, it is a leaf node
     * if left!=null, not a leaf
	 *  */
	public T left;
	/** tree for elements equal or above threshold. */
	public T right;

	/** number of elements in the tree */
	public int    nSuccessors;
	/** feature ID used for cutting */
	public int    column=-1;
	/** threshold of cutting */
	public double threshold; 

	/** tasks that are active in this thread */
	Set<Integer> tasks;
	
	/** @return value of current node */
	public abstract D getValue();
	public abstract D getNA();
	
	
	/**
	 * @param input the vector of input values
	 * @return the leaf node (BinaryTree) for the input
	 */
	public T getLeaf(double[] input) {
		if (left==null) {
			return getItself();
		}
		if (Double.isNaN(input[column])) {
			return null;
		}
		if (input[column]<threshold) {
			return left.getLeaf(input);
		}
		return right.getLeaf(input);
	}
	
	public D getValue(double[] input) {
		T leaf = getLeaf(input);
		if (leaf == null) return null;
		return leaf.getValue();
	}
	
	/**
	 * @param x
	 * @param task
	 * @return return multitask value for given input and task
	 */
	public T getLeafMT(double[] input, int task) {
		if (left==null) {
			return getItself();
		}
		if (column < 0) {
			// task cut:
			if (left.tasks.contains(task)) {
				return left.getLeafMT(input, task);
			}
			return right.getLeafMT(input, task);
		}
		if (Double.isNaN(input[column])) {
			return null;
		}
		// feature cut<commit_msg>fix NA return bug<commit_after>package org.extratrees;

import java.util.Set;

/**
 * All subclasses should have their generic argument equal to itself, 
 * i.e. X extends AbstractBinaryTree<X>.
 * Otherwise getItself() will break. 
 * 
 * @author jaak
 *
 * @param <T>
 */
public abstract class AbstractBinaryTree <T extends AbstractBinaryTree<T, D>, D> {
	/** tree for elements below threshold.
	 * if left==null, it is a leaf node
     * if left!=null, not a leaf
	 *  */
	public T left;
	/** tree for elements equal or above threshold. */
	public T right;

	/** number of elements in the tree */
	public int    nSuccessors;
	/** feature ID used for cutting */
	public int    column=-1;
	/** threshold of cutting */
	public double threshold; 

	/** tasks that are active in this thread */
	Set<Integer> tasks;
	
	/** @return value of current node */
	public abstract D getValue();
	public abstract D getNA();
	
	
	/**
	 * @param input the vector of input values
	 * @return the leaf node (BinaryTree) for the input
	 */
	public T getLeaf(double[] input) {
		if (left==null) {
			return getItself();
		}
		if (Double.isNaN(input[column])) {
			return null;
		}
		if (input[column]<threshold) {
			return left.getLeaf(input);
		}
		return right.getLeaf(input);
	}
	
	public D getValue(double[] input) {
		T leaf = getLeaf(input);
		if (leaf == null) return getNA();
		return leaf.getValue();
	}
	
	/**
	 * @param x
	 * @param task
	 * @return return multitask value for given input and task
	 */
	public T getLeafMT(double[] input, int task) {
		if (left==null) {
			return getItself();
		}
		if (column < 0) {
			// task cut:
			if (left.tasks.contains(task)) {
				return left.getLeafMT(input, task);
			}
			return right.getLeafMT(input, task);
		}
		if (Double.isNaN(input[column])) {
			return null;
		}
		// feature cut
{'fraction_non_alphanumeric': 0.13058984910836763, 'fraction_numerical': 0.0010973936899862826, 'mean_word_length': 3.087443946188341, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1785982', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1166, 'n_words': 400}