public static void classificationTestsVariableK(String pathToTrainingFiles,String pathToClassificationFiles, int mapWidth, int k,int tieBreakingParam)
    {
	// Training and Validation Data
	String tDataPath = "/Users/rob/git/JBO-Pulsar-Classifier/JBO Pulsar Classifier Tool/Resources/training_set_mod.pat";
	String vDataPath = "/Users/rob/git/JBO-Pulsar-Classifier/JBO Pulsar Classifier Tool/Resources/validation_set.pat";

	// The path that the temporary neural net is saved to.
	String savedNetworkPath = "/Users/rob/DELETEMENETWORK.xml";
	String outputFilePathRubbish = "/Users/rob/DELETEMEFILEPATH.txt";

	// The path to write results to
	String outputFilePath = "/Users/rob/RESULTS/READ.txt";

	// The test data patterns to classify
	String patternsDirectory = pathToClassificationFiles;

	// The file to write result statistics to.
	String stats_output_file = "/Users/rob/RESULTS/STATS_knn_btr.txt";
	// The headers for the CSV statistics file.
	String[] headers = {"STATS","TEST","FILE","TP","FP","TN","FN","Recall","Precision","F-Score","Specificity","NPV","MCC","Accuracy"};

	// Add this information to the input object, usually
	// used to process command line information. It 
	// is not actually used here.
	CommandLineInputData input = new CommandLineInputData();
	input.setPathToTrainingFile(tDataPath);
	input.setPathToValidationFile(vDataPath);
	input.setNetworkSavePath(savedNetworkPath);
	input.setPathToSavedNetwork(savedNetworkPath);
	input.setPathToOutputFile(outputFilePathRubbish);
	input.setClassifier(0);// Doesn't matter
	input.setDesiredNetworkAccuracy(90);

	// The paths to the training files to use.
	String[] classificationFiles = Common.getFilePaths(patternsDirectory);

	String[] trainingFiles = Common.getFilePaths(pathToTrainingFiles);

	if(trainingFiles.length < 1)
	{
	    System.out.println("No training files!");
	    System.exit(0);
	}

	// The class used to train the neural network.
	AutoTrainerController trainer;

	// The test data to be classified.
	I_DataSet classification_data;

	for(int kloop = 23 ; kloop < 28; kloop++)
	    if( kloop % 2 != 0)
	    {
		for(int z = 0; z < trainingFiles.length ; z++) // For each training file
		{
		    if(!trainingFiles[z].toString().endsWith(".pat"))
			continue;

		    input.setPathToTrainingFile(trainingFiles[z]); // Update path to the training file

		    for(int f = 0; f < classificationFiles.length;f++)// for each file of data to be classified
		    {
			if(!classificationFiles[f].toString().endsWith(".pat"))
			    continue;

			// Get the data
			classification_data = new PatternFileProcessor().process(classificationFiles[f]);

			for(int t=0; t < 1; t++)// do a number of tests
			{
			    for(int s = 0; s < 10; s++)
			    {
				// Delete any existing saved neural network.
				Common.fileDelete(input.getPathToSavedNetwork());
				// Train the network.
				input.setMapSize(mapWidth);
				trainer = new AutoTrainerController(input);
				trainer.run();

				// Load the trained Map back in.
				SOMClassifier classifier = (SOMClassifier)SOMClassifier.read(input.getPathToSavedNetwork());
				classifier.stats.calculate(); // get the performance statistics of the network.

				// Create an object to store the statistics collected during this test.
				ClassifierStatistics testStats = new ClassifierStatistics();

				//classify the data
				for(int r = 0; r < classification_data.getRows(); r++) // For each pattern to be classified.
				{
				    // Classify the pattern.
				    Object[] results = classifier.discreetKNNClassify(classification_data.getDataRow(r),kloop,tieBreakingParam);
				    String classification = (String) results[0].toString();

				    // Here we classify the pattern using the classify, but we already know the class a priori.
				    // So we check the classification given, with the actual class.
				    //  CLASSIFICATION APPLIED --------------------------------- ACTUAL CLASS
				    if( classification.equals(Constants.PULSAR) && classification_data.getDataRow(r).getClassMembership().equals(Constants.PULSAR))
					testStats.incrementTP(); // True Positive
				    else if(classification.equals(Constants.PULSAR) && classification_data.getDataRow(r).getClassMembership().equals(Constants.RFI))
					testStats.incrementFP(); // False positive
				    else if(classification.equals(Constants.RFI) && classification_data.getDataRow(r).getClassMembership().equals(Constants.PULSAR))
					testStats.incrementFN(); // False negative
				    else
					testStats.incrementTN(); // True negative
				}

				// Causes the statistics object to calculate its internal metrics (i.e. F-score, precision, recall etc).
				testStats.calculate();

				// Write the output to a file.

				// Describe test: 
				String test = "Test[ td =" + StringOps.getFileNameFromPath(trainingFiles[z]) + "][k="+kloop+"][ file = " + f + "][ test = " + t + "][ mapsize test (12)= " + s + "]," + StringOps.getFileNameFromPath(classificationFiles[f]) + ",";

				// Provide statistics: TP, FP, TN, FN, RECALL, PRECISION, FSCORE, SPECIFICITY, NPV, MCC, ACCURACY, 
				String stats = testStats.getTP() + "," + testStats.getFP() + "," + testStats.getTN() + "," + testStats.getFN() + "," + testStats.getRecall() + "," +
					testStats.getPrecision() + ","+testStats.getfScore() + "," + testStats.getSpecificity() + "," +testStats.getNegativePredictiveValue() + "," +
					testStats.getMatthewsCorrelation() + "," + testStats.getAccuracy() + ",\n";

				String text = test + stats;// Simply add two parts together.
				Writer.write(outputFilePath,text);

				//clean up variables.
				trainer = null;
				classifier = null;
			    }

			    // Create a new object that converts the statistics collected in to CSV format.
			    StatsDataSet statsDataSet = new StatsDataSet(outputFilePath); // Read neural network output file.
			    String summaryStats = statsDataSet.printAsCSVWithStats(headers);

			    // Write the CSV format to file.
			    Writer.write(stats_output_file, summaryStats);

			    // Delete the neural net output file, as these results have now
			    // been written to a statistics file.
			    Common.fileDelete(outputFilePath);
			    Common.fileCreate(outputFilePath);
			    System.gc();
			}

			// Explicit cleanup.
			classification_data = null;
			System.gc();
		    }
		}
		System.gc();
	    }
    }