function [estimate] = bamboo(train, test)

# The following is code for preliminary testing of the BAMBOO algorithm for linear time instance selection.
# BAMBOO is meant to be used as both a learner and preprocessor, but in this example it will be used exclusively as a learner.

# Calculations done for later
data = load(train);
[rows, cols] = size(data);

# Step 0: Log the Data (Excluding the class, assumes class is last column of data)
# data0 = [];
# for i = 1 : rows
#	for j = 1 : cols
#		if(j == cols)
#			data0(i,j) = data(i,j);
#		else
#			data0(i,j) = log(data(i,j));
#		end
#	end
# end 
# data = data0;
# Step 0 was removed because it was generating NaN errors in further steps of execution.

# Step 1: Discretize the Data using modified Fayyad-Irani discretization on variance
data = eats(data);
cols = cols + 1;

# Step 2: Sort the range descending by variance they select
[junk, indices] = sort(data(:,cols));
data = data(indices,:);

# Step 3: Delete rows containing the top ranked ranges until you have N^B number of rows
# where B = some number (eg .5)
keep = floor(power(rows,.5));
data = data(keep:rows,:);
[rows,cols] = size(data);

test = load(test);
# Step 4: Sort the surviving rows in ascending order by their distance to test instance (Euclidean distance)
for i = 1 : rows
	distance = 0;
	for j = 1 : cols - 2
		distance = distance + power(data(i,j)-test(1,j),2);
	end
	data(i,cols+1) = distance;
end
[rows,cols] = size(data);
[junk, indices] = sort(data(:,cols));
data = data(indices,:);

# Step 5: Run over rows until variance increases
done = 0;
doneAt = 1;
oldVariance = data(1,cols-1);
for i = 1 : rows
	if (data(i,cols-1) > oldVariance && done != 1)
		done = 1;
		doneAt = i;
	end
	if (done == 0)
		oldVariance = data(i,cols-1);
	end
end

# Step 6: Return the median of the selected rows
estimate = median(data(1:doneAt,cols-2));

# Step 7: Calculate error (only for testing purposes)
# [rows,cols] = size(test);
# error = (test(1,cols) - estimate) / test(1,cols);