// Path: src/main/java/org/extratrees/data/Array2D.java
// public interface Array2D {
// 	public double get(int row, int col);
// 	public int ncols();
// 	public int nrows();
// 	public Row getRow(int row);
// }
// 
// Path: src/main/java/org/extratrees/data/Row.java
// public interface Row {
// 	public double get(int col);
// }


import java.util.ArrayList;
import java.util.Set;
import org.extratrees.data.Array2D;
import org.extratrees.data.Row;
package org.extratrees;



public class QuantileExtraTrees extends ExtraTrees {

	public QuantileExtraTrees(Array2D input, double[] output) {
		super(input, output);
	}
	
	/**
	 * 
	 * @param input
	 * @param quantile a value between 0.0 and 1.0. For median use 0.5
	 * @return return quantiles for each input row. 
	 */
	public double[] getQuantiles(Array2D input, double k) {
		double[] quantileValues = new double[input.nrows()];
		ArrayList<Double> leafValues = new ArrayList<Double>(this.trees.size());
		for (int row=0; row<input.nrows(); row++) {
			getLeafValues(input.getRow(row), leafValues);
			// doing quickselect:
			quantileValues[row] = QuickSelect.quickSelect(leafValues, k);
		}
		return quantileValues;
	}
	
	/**
	 * Clears ArrayList {@code values} and adds leaf values of {@code input} to it.
	 * @param input
	 * @param values 
	 */
// Path: src/main/java/org/extratrees/data/Array2D.java
// public interface Array2D {
// 	public double get(int row, int col);
// 	public int ncols();
// 	public int nrows();
// 	public Row getRow(int row);
// }
// 
// Path: src/main/java/org/extratrees/data/Row.java
// public interface Row {
// 	public double get(int col);
// }


// Path: src/main/java/org/extratrees/QuantileExtraTrees.java
import java.util.ArrayList;
import java.util.Set;
import org.extratrees.data.Array2D;
import org.extratrees.data.Row;

package org.extratrees;



public class QuantileExtraTrees extends ExtraTrees {

	public QuantileExtraTrees(Array2D input, double[] output) {
		super(input, output);
	}
	
	/**
	 * 
	 * @param input
	 * @param quantile a value between 0.0 and 1.0. For median use 0.5
	 * @return return quantiles for each input row. 
	 */
	public double[] getQuantiles(Array2D input, double k) {
		double[] quantileValues = new double[input.nrows()];
		ArrayList<Double> leafValues = new ArrayList<Double>(this.trees.size());
		for (int row=0; row<input.nrows(); row++) {
			getLeafValues(input.getRow(row), leafValues);
			// doing quickselect:
			quantileValues[row] = QuickSelect.quickSelect(leafValues, k);
		}
		return quantileValues;
	}
	
	/**
	 * Clears ArrayList {@code values} and adds leaf values of {@code input} to it.
	 * @param input
	 * @param values 
	 */
	public void getLeafValues(Row input, ArrayList<Double> values) {