/// <summary> /// Send a request to the process to get the learning/prediction results. /// The process has to be set up before performing this method. /// The process will automatically terminate after this method was performed. /// </summary> /// <param name="predictedConfigurations">The configurations that were used to predict the nfp values by the learner.</param> /// <param name="writer">Writer to write the prediction results into a csv File.</param> public void getLearningResult(List <Configuration> predictedConfigurations, PythonPredictionWriter writer) { while (!waitForNextReceivedLine().Equals(FINISHED_LEARNING)) { } passLineToApplication(REQUESTING_LEARNING_RESULTS); printNfpPredictionsPython(waitForNextReceivedLine(), predictedConfigurations, writer); }
private void printNfpPredictionsPython(string pythonList, List <Configuration> predictedConfigurations, PythonPredictionWriter writer) { string[] separators = new String[] { "," }; string[] predictions = pythonList.Split(separators, StringSplitOptions.RemoveEmptyEntries); if (predictedConfigurations.Count != predictions.Length) { GlobalState.logError.log("number of predictions using a python learner does not match with number of configurations"); } if ((predictions[0].ToLower()).StartsWith("error")) { GlobalState.logError.log("There was a error running the Python script."); StringBuilder errMessage = new StringBuilder(); foreach (string errInfo in predictions) { errMessage.Append(errInfo); } GlobalState.logError.log("Error message: " + errMessage.ToString()); } else { writer.writePredictions("Configuration;MeasuredValue;PredictedValue\n"); for (int i = 0; i < predictedConfigurations.Count; i++) { writer.writePredictions(predictedConfigurations[i].ToString().Replace(";", "_") + ";" + Math.Round(predictedConfigurations[i].GetNFPValue(), 4) + ";" + Math.Round(Convert.ToDouble(predictions[i]), 4) + "\n"); } } }
/// <summary> /// This method prints the predictions in the specified file and returns the error rate. /// </summary> /// <param name="pythonList">The predictions from python.</param> /// <param name="predictedConfigurations">The configurations that were predicted.</param> /// <param name="writer">The writer object for the file.</param> /// <returns></returns> private double printNfpPredictionsPython(string pythonList, List <Configuration> predictedConfigurations, PythonPredictionWriter writer, out List <Configuration> predictedByPython) { predictedByPython = new List <Configuration>(); string[] separators = new String[] { "," }; string[] predictions = pythonList.Split(separators, StringSplitOptions.RemoveEmptyEntries); if (predictedConfigurations.Count != predictions.Length) { GlobalState.logError.log("number of predictions using a python learner does not match with number of configurations"); } if ((predictions[0].ToLower()).StartsWith("error")) { GlobalState.logError.log("There was a error running the Python script."); StringBuilder errMessage = new StringBuilder(); foreach (string errInfo in predictions) { errMessage.Append(errInfo); } GlobalState.logError.log("Error message: " + errMessage.ToString()); return(Double.NaN); } else { double error = 0; writer.writePredictions("Configuration;MeasuredValue;PredictedValue\n"); for (int i = 0; i < predictedConfigurations.Count; i++) { writer.writePredictions(predictedConfigurations[i].ToString().Replace(";", "_") + ";" + Math.Round(predictedConfigurations[i].GetNFPValue(), 4) + ";" + Math.Round(Convert.ToDouble(predictions[i]), 4) + "\n"); error += Math.Abs(predictedConfigurations[i].GetNFPValue() - Convert.ToDouble(predictions[i])) / predictedConfigurations[i].GetNFPValue(); var copy = predictedConfigurations[i].Copy(); copy.setMeasuredValue(GlobalState.currentNFP, predictedConfigurations[i].GetNFPValue()); predictedByPython.Add(copy); } error /= predictedConfigurations.Count; return(error); } }