protected double kernel(SequenceInput input1, int token1,
			SequenceInput input2, int token2) {
		int idxFtr1 = 0;
		int idxFtr2 = 0;
		int numFtrs1 = input1.getNumberOfInputFeatures(token1);
		int numFtrs2 = input2.getNumberOfInputFeatures(token2);
		double dotProd = 0d;
		while (idxFtr1 < numFtrs1 && idxFtr2 < numFtrs2) {
			int ftrVal1 = input1.getFeature(token1, idxFtr1);
			int ftrVal2 = input2.getFeature(token2, idxFtr2);
			if (ftrVal1 == ftrVal2) {
				dotProd += input1.getFeatureWeight(token1, idxFtr1)
						* input2.getFeatureWeight(token2, idxFtr2);
				++idxFtr1;
				++idxFtr2;
			} else if (ftrVal1 > ftrVal2)
				++idxFtr2;
			else
				++idxFtr1;
		}

		switch (exponent) {
		case 1:
			// Linear kernel.
			return dotProd;
		case 2:
			// Quadratic kernel.
			return dotProd * dotProd;
		case 3:
			// Cubic kernel.
			return dotProd * dotProd * dotProd;
		case 4:
			// Quartic kernel.
			return dotProd * dotProd * dotProd * dotProd;
		}

		return 0d;
	}