/// <summary> /// Runs the BPM using sparse features. /// </summary> /// <param name="numClasses">The number of classes</param> /// <param name="noisePrecision">The noise precision</param> /// <param name="numFeatures">The number of features</param> /// <param name="trainingSetFile">The file containing the training set</param> /// <param name="testSetIndices">The test set feature indices</param> /// <param name="testSetValues">The test set feature values</param> private static void RunSparseBPM(int numClasses, double noisePrecision, int numFeatures, string trainingSetFile, bool labelAtEnd, bool addBias, int[][] testSetIndices, double[][] testSetValues) { Console.WriteLine("\n------- Sparse BPM -------"); int[] labels; int[][] indices; double[][] values = DataUtils.Read(trainingSetFile, labelAtEnd, addBias, out labels, out indices); BPMSparse bpmSparse = new BPMSparse(numClasses, noisePrecision, numFeatures); Gaussian[][] posteriorWeights = bpmSparse.Train(indices, values, labels); #if ShowWeights Console.WriteLine("Weights=" + StringUtil.ArrayToString(posteriorWeights)); #endif Console.WriteLine("\nPredictions:"); Discrete[] predictions = bpmSparse.Test(testSetIndices, testSetValues); foreach (Discrete prediction in predictions) Console.WriteLine(prediction); Console.WriteLine(); }
private static void Test_BPM_Sparse( int nClass, int totalFeatures, double noisePrec, string trainingFile, int[][] xIndicesTest, double[][] xValuesTest) { Console.WriteLine("\n------- BPM Sparse -------"); Gaussian[][] wInferred; int[][][] xIndices; double[][][] xValues = DataFromFile.Read(trainingFile, nClass, out xIndices); BPMSparse bpmSparse = new BPMSparse(nClass, totalFeatures, noisePrec); bpmSparse.TrainingEngine.ShowProgress = false; bpmSparse.TestEngine.ShowProgress = false; //if want to see the Browser, uncomment this line // bpmSparse.TrainingEngine.BrowserMode = BrowserMode.Always; wInferred = bpmSparse.Train(xIndices, xValues); #if ShowWeights for (int i = 0; i < wInferred.GetLength(0); i++) { for (int j = 0; j < wInferred[i].Length; j++) { Console.WriteLine(wInferred[i][j].ToString()); } } #endif Console.WriteLine("\nPredictions:"); Discrete[] predictions = bpmSparse.Test(xIndicesTest, xValuesTest); foreach (Discrete pred in predictions) Console.WriteLine(pred); Console.WriteLine(); }