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");
                }
            }
        }
Esempio n. 2
0
        /// <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);
            }
        }