private static void Test_BPMIncremental( int nClass, int totalFeatures, double noisePrec, int maxItemsInBatch, int nChunks, string trainingFile, Vector[] testData) { Console.WriteLine("\n------- BPM Train Incremental -------"); VectorGaussian[] wInfer = new VectorGaussian[nClass]; BPM bpmIncremental = new BPM(nClass, totalFeatures, noisePrec); bpmIncremental.TrainingEngine.ShowProgress = false; bpmIncremental.TestEngine.ShowProgress = false; int LocToStart = 0; for (int c = 0; c < nChunks; c++) { List<Vector>[] dataChunks = DataFromFile.Read(trainingFile, nClass, maxItemsInBatch, ref LocToStart); wInfer = bpmIncremental.TrainIncremental(dataChunks); } #if ShowWeights for (int i = 0; i < wInfer.GetLength(0); i++) { Console.WriteLine(wInfer[i].ToString()); } #endif Console.WriteLine("\nPredictions:"); Discrete[] predictions = bpmIncremental.Test(testData); foreach (Discrete pred in predictions) Console.WriteLine(pred); Console.WriteLine(); }
private static void Test_BPM(int nClass, int totalFeatures, double noisePrec, string fileName, Vector[] testData) { Console.WriteLine("\n------- BPM -------"); List<Vector>[] data = DataFromFile.Read(fileName, nClass); BPM bpm = new BPM(nClass, totalFeatures, noisePrec); bpm.TrainingEngine.ShowProgress = false; bpm.TestEngine.ShowProgress = false; VectorGaussian[] wInfer = bpm.Train(data); #if ShowWeights for (int i = 0; i < wInfer.GetLength(0); i++) { Console.WriteLine(wInfer[i].ToString()); } #endif Discrete[] predictions = bpm.Test(testData); Console.WriteLine("\nPredictions:"); foreach (Discrete pred in predictions) Console.WriteLine(pred); Console.WriteLine(); }
/// <summary> /// Runs the BPM using dense features. /// </summary> /// <param name="numClasses">The number of classes</param> /// <param name="noisePrecision">The noise precision</param> /// <param name="trainingSetFile">The file containing the training set</param> /// <param name="testSet">The test set</param> private static void RunBPM(int numClasses, double noisePrecision, string trainingSetFile, bool labelAtEnd, bool addBias, Vector[] testSet) { Console.WriteLine("------- BPM -------"); int[] labels; Vector[] featureVectors = DataUtils.Read(trainingSetFile, labelAtEnd, addBias, out labels); BPM bpm = new BPM(numClasses, noisePrecision); VectorGaussian[] posteriorWeights = bpm.Train(featureVectors, labels); #if ShowWeights Console.WriteLine("Weights=" + StringUtil.ArrayToString(posteriorWeights)); #endif Console.WriteLine("\nPredictions:"); Discrete[] predictions = bpm.Test(testSet); foreach (Discrete prediction in predictions) Console.WriteLine(prediction); Console.WriteLine(); }
/// <summary> /// Runs the BPM using dense features and incremental training. /// </summary> /// <param name="numClasses">The number of classes</param> /// <param name="noisePrecision">The noise precision</param> /// <param name="trainingSetFile">The file containing the training set</param> /// <param name="testSet">The test set</param> /// <param name="maxItemsPerChunk">The maximum number of items per chunk</param> /// <param name="numChunks">The total number of chunks</param> private static void RunIncrementalBPM(int numClasses, double noisePrecision, string trainingSetFile, bool labelAtEnd, bool addBias, Vector[] testSet, int maxItemsPerChunk, int numChunks) { Console.WriteLine("\n------- Incremental BPM -------"); BPM bpm = new BPM(numClasses, noisePrecision); int[] labels; Vector[] featureVectors; VectorGaussian[] posteriorWeights = new VectorGaussian[numClasses]; int locationToStart = 0; for (int c = 0; c < numChunks; c++) { featureVectors = DataUtils.Read(trainingSetFile, maxItemsPerChunk, labelAtEnd, addBias, out labels, ref locationToStart); posteriorWeights = bpm.Train(featureVectors, labels); } #if ShowWeights Console.WriteLine("Weights=" + StringUtil.ArrayToString(posteriorWeights)); #endif Console.WriteLine("\nPredictions:"); Discrete[] predictions = bpm.Test(testSet); foreach (Discrete pred in predictions) Console.WriteLine(pred); Console.WriteLine(); }
private void begin_Click(object sender, EventArgs e) { if (_maxSensitivity < _startSensitivity) { ShowDialog(@"The maximum sensitivity must be greater than or equal to the minimum sensitivity.", "Error", false); return; } if (!_performingCalcs) { //Disable input changes ChangeStatusOfInputs(false); beginButton.Text = @"Cancel"; _bpm = new BPM(_numOfClasses, _noisePrecision); try { _trainingModel = FileUtils.ReadFile(_trainingFilePath, _labelAtStartOfLine, _noOfFeatures, _addBias); _testModel = FileUtils.ReadFile(_testFilePath, _labelAtStartOfLine, _noOfFeatures, _addBias); _writer = new StreamWriter(_resultsFilePath, _appendToFile); _totalRuns = (int) Math.Ceiling(_noOfRuns*(1 + ((_maxSensitivity - _startSensitivity)/_sensitivityIncrement))); _last = DateTime.Now; bw.WorkerReportsProgress = true; bw.WorkerSupportsCancellation = true; bw.DoWork += bw_DoWork; bw.ProgressChanged += bw_ProgressChanged; bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.RunWorkerAsync(); progressBar1.Maximum = _totalRuns; _performingCalcs = true; _prevRem = _totalRuns; } catch (Exception exception) { ShowDialog("Sorry, there was an error reading the input data" + exception.GetType(), "Error", true); beginButton.Text = @"Begin processing"; ChangeStatusOfInputs(true); } } else { bw.CancelAsync(); beginButton.Text = @"Begin processing"; //Tidy up statusLabel.Text = @""; } }