private void estimateBuildParams() {
		ArrayList<CostData> costs = new ArrayList<CostData>();

		int sampleSize = (int) (sampleFraction * data.length);
		int testSampleSize = Math.min(sampleSize / 10, 1000);

		if (testSampleSize < 10) {
			// return LinearIndexParams();
		}

		// We use a fraction of the original dataset to speedup the autotune
		// algorithm.
		sampledData = Utils.randomSample(data, sampleSize, false);
		testData = Utils.randomSample(sampledData, testSampleSize, true);

		// We compute the ground truth using linear search.
		System.out.println("Computing ground truth...");
		gtMatches = new int[testData.length][1];

		StopWatch timer = new StopWatch();
		int repeats = 0;
		timer.reset();
		while (timer.getTime() / 1000.0f < 0.2f) {
			repeats++;
			timer.start();
			// computeGroundTruth(sampledData, testData, gtMatches, 0, metric);
			timer.stop();
		}

		CostData linearCost = new CostData();
		linearCost.searchTimeCost = timer.getTime() / 1000.0f / repeats;
		linearCost.buildTimeCost = 0;
		linearCost.memoryCost = 0;
		costs.add(linearCost);

		// Start parameter autotune process.
		System.out.println("Autotuning parameters...");

		optimizeKMeans(costs);
		optimizeKDTree(costs);

		float bestTimeCost = costs.get(0).buildTimeCost * buildWeight
				+ costs.get(0).searchTimeCost;
		for (int i = 0; i < costs.size(); i++) {
			float timeCost = costs.get(i).buildTimeCost * buildWeight
					+ costs.get(i).searchTimeCost;
			if (timeCost < bestTimeCost) {
				bestTimeCost = timeCost;
			}
		}

		bestBuildParams = costs.get(0).params;
		if (bestTimeCost > 0) {
			float bestCost = (costs.get(0).buildTimeCost * buildWeight + costs
					.get(0).searchTimeCost) / bestTimeCost;
			for (int i = 0; i < costs.size(); i++) {
				float crtCost = (costs.get(i).buildTimeCost * buildWeight + costs
						.get(i).searchTimeCost)
						/ bestTimeCost
						+ memoryWeight
						* costs.get(i).memoryCost;
				if (crtCost < bestCost) {
					bestCost = crtCost;
					bestBuildParams = costs.get(i).params;
				}
			}
		}
	}