/// <summary> /// creates learning curve after learning+deciding about given precentage of pictures according to percent[] /// </summary> /// <param name="folderAll">folder of all images</param> /// <param name="folderTrue">folder of true images</param> /// <param name="learn">data learning object for learning</param> /// <param name="decide">decision making object for deciding</param> /// <param name="percent">percentages to use for learning (percent.length is number of points in learning curve)</param> /// <returns>true if succeeded creating the curve</returns> public static CurvePoint[] LearningCurve(string folderAll, string folderTrue, DataLearning learning, DecisionMaking deciding, int[] percent, out double[] simpleAlgo, Testing.HandleIdenticalMethod identical, bool excludeTrainingSet) { _progress = 0; int itrCount=0; simpleAlgo = new double[3]; //randomLearningCurve = null; const int ITERATIONS_PER_POINT = 5; // Make All, True & False files lists List<string> allFiles, falseFiles, trueFiles; try { allFiles = LoadImages(folderAll).ToList(); trueFiles = LoadImages(folderTrue).ToList(); falseFiles = SubstractListsByFileName(allFiles, trueFiles); trueFiles = SubstractListsByFileName(allFiles, falseFiles); // In order for the path to be via 'allFiles' folder } catch (Exception exc) { MessageBox.Show(exc.Message); return null; } // Handle duplicates ProgressString = "Checking for identicals with different choise"; HandleIdenticalVectorWithDifferentChoise(ref allFiles, ref trueFiles, ref falseFiles, learning.Repository, identical); //create curve of percent.length number of points ProgressString = "Calculating Curves"; CurvePoint[] learningCurve = new CurvePoint[percent.Length]; //for main graph //randomLearningCurve = new CurvePoint[percent.Length]; //for random algorithm graph for (int k = 0; k < percent.Length; k++) { learningCurve[k] = new CurvePoint(percent[k]); // randomLearningCurve[k] = new CurvePoint(percent[k]); for (int itr = 0; itr < ITERATIONS_PER_POINT; itr++) { //get wanted amount of randome images List<string> chosenFiles; do chosenFiles = getRandomImages(allFiles, percent[k]); while (SubstractListsByFileName(chosenFiles, trueFiles).Count == 0 || SubstractListsByFileName(chosenFiles, falseFiles).Count == 0); // incase only true or only false was chosen //get new lists of true and false files (Used for learning in current curve point) List<string> subsetTrueFiles = SubstractListsByFileName(chosenFiles, falseFiles); List<string> subsetFalseFiles = SubstractListsByFileName(chosenFiles, trueFiles); //------------------------------------- //learn from subsets learning.LearnForTesting(chosenFiles, subsetTrueFiles); //------------------------------------- //decide for all files double[] results; deciding.DecideForTesting(allFiles, learning.Repository, out results); //------------------------------------- //make true and false lists according to results List<string> resultsTrue = new List<string>(); List<string> resultsFalse = new List<string>(); for (int i = 0; i < results.Length; i++) if (results[i]>0) //*******here deside for testing*******/ resultsTrue.Add(allFiles[i]); else resultsFalse.Add(allFiles[i]); //------------------------------------- //calculate success precentage CurvePoint.SingleCurvePointCalc currentIteration = new CurvePoint.SingleCurvePointCalc(trueFiles, falseFiles, subsetTrueFiles, subsetFalseFiles, resultsTrue, resultsFalse, excludeTrainingSet); learningCurve[k].AddSingleCurvePointCalc(currentIteration); //------------------------------------- //get simple algorithms calculations double simpleFalseNegative, simpleFalsePositive, simpleSuccess; Testing.SimpleAlgorithm.CalcStatisticalAlgorithm(allFiles.Count, trueFiles.Count, out simpleSuccess, out simpleFalseNegative, out simpleFalsePositive); simpleAlgo[0] = simpleSuccess*100; simpleAlgo[1] = simpleFalseNegative * 100; simpleAlgo[2] = simpleFalsePositive * 100; // Update progress indicators itrCount++; _progress = (int)((itrCount * 100)/(ITERATIONS_PER_POINT * percent.Length)); } } ProgressString = "Done Calculating Curves"; return learningCurve; }
private void threadCalcLearningCurve() { // Make Learning & Deciding objects const string USERNAME = "******"; DataLearning learning; if (_rdoKNN.Checked) { //K = int.Parse(_txtK.Text); K = 1; learning = new DataLearning(USERNAME, LearningAlgorithm.Algorithm.KNN, ParamDictionary, K); } else if (_rdoTree.Checked) { K = 0; learning = new DataLearning(USERNAME, LearningAlgorithm.Algorithm.DecisionTree, ParamDictionary, K); } else // if (_rdoTreeNum.Checked) { K = 0; learning = new DataLearning(USERNAME, LearningAlgorithm.Algorithm.DecisionTreeNumerical, ParamDictionary, K); } DecisionMaking deciding = new DecisionMaking(USERNAME, learning.Algorithm, ParamDictionary); // Load vectors to repository learning.Repository.loadList(); // Scan pictures Testing.scanPicturesIntoReporistory(txtFolderAllTesting3.Text, txtFolderTrueTesting3.Text, learning.Repository, ParamDictionary); // Set X-Axis points for learning curve int nPoints = Convert.ToInt16(txtNumOfPointsTesting3.Text); int[] percent = new int[nPoints]; for (int i = 0; i < nPoints; i++) if (!chkExclude.Checked) percent[i] = (int)(((i + 1) * 100) / (nPoints)); else percent[i] = (int)(((i + 1) * 100) / (nPoints+1)); // Set method for handeling identical vectors with different choice double[] simpleAlgorithm = new double[3]; // Set method for handeling identical vectors with different choice Testing.HandleIdenticalMethod identicalMethod = Testing.HandleIdenticalMethod.Ignore; if (rdoSameRemove.Checked) identicalMethod = Testing.HandleIdenticalMethod.Remove; // Set if training set should be excluded from testing set _excludeTrainingSet = chkExclude.Checked; // Calc learning curves _learningCurve = Testing.LearningCurve(txtFolderAllTesting3.Text, txtFolderTrueTesting3.Text, learning, deciding, percent, out simpleAlgorithm, identicalMethod, _excludeTrainingSet); _statisticAlgoCurve = simpleAlgorithm; _trdTest.Abort(); }
private void MainForm_Load(object sender, EventArgs e) { _timer = new System.Windows.Forms.Timer(); _decision = new DecisionMaking(); _btnBrowseAll.Enabled = false; _btnBrowseTrue.Enabled = false; _btnTrain.Enabled = false; _btnPredict.Enabled = false; _btnBrowsePredict.Enabled = false; _parametersDictionary = new Dictionary<ImageVector.ImageParameters, bool>(); }