private static void Test_BPM_Sparse_Shared( int nClass, int totalFeatures, double noisePrec, int maxItemsInBatch, int nChunks, string trainingFile, int[][] xIndicesTest, double[][] xValuesTest) { Console.WriteLine("\n------- BPM Sparse Shared -------"); BPMSparse_Shared bpmSparseShared = new BPMSparse_Shared(nClass, totalFeatures, noisePrec, nChunks, 1); bpmSparseShared.TrainingEngine.ShowProgress = false; bpmSparseShared.TestEngine.ShowProgress = false; Gaussian[][] wInferred = new Gaussian[nClass][]; for (int c = 0; c < nClass; c++) { wInferred[c] = new Gaussian[totalFeatures]; } for (int pass = 0; pass < 5; pass++) { int LocToStart = 0; for (int c = 0; c < nChunks; c++) { int[][][] xIndices; double [][][] xValues = DataFromFile.Read(trainingFile, nClass, maxItemsInBatch, ref LocToStart, out xIndices); wInferred = bpmSparseShared.Train(xIndices, xValues, c); } } #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 = bpmSparseShared.Test(xIndicesTest, xValuesTest, 0); foreach (Discrete pred in predictions) Console.WriteLine(pred); Console.WriteLine(); }
/// <summary> /// Print the means of a 2-D array of Gaussians to the console /// </summary> /// <param name="matrix"></param> private static void printMatrixToConsole(Gaussian[,] matrix) { for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) Console.Write("{0,5:0.00}\t", matrix[i, j].GetMean()); Console.WriteLine(""); } }
/// <summary> /// Print the means of a 1-D array of Gaussians to the console /// </summary> /// <param name="matrix"></param> private static void printVectorToConsole(Gaussian[] vector) { for (int i = 0; i < vector.GetLength(0); i++) Console.Write("{0,5:0.00}\t", vector[i].GetMean()); Console.WriteLine(""); }
/// <summary> /// Mean absolute row means /// </summary> /// <param name="matrix"></param> /// <returns></returns> private static double[] meanAbsoluteRowMeans(Gaussian[,] matrix) { double[] mam = new double[matrix.GetLength(0)]; double mult = 1.0 / ((double)matrix.GetLength(1)); for (int i = 0; i < matrix.GetLength(0); i++) { double sum = 0.0; for (int j = 0; j < matrix.GetLength(1); j++) sum += Math.Abs(matrix[i, j].GetMean()); mam[i] = mult * sum; } return mam; }