//Notes: This isn't beautiful code, but it works. It takes a weights matrix and //the dimension of the matrix (which could be tested for insteadof passed in). It //also takes the name of a file. I generated the filename using seconds past midnight //as a unique timestamp, and then tagged on to that an integer which indicates the //kth weights .ppm file generated //Java 1.1 code // //Also, the gaussian squashing function is perhaps not the best way to squash //the weights. Alternate suggestions are happily accepted. public void printWeightsToFile(double [][] weights, int rows, int cols, String fn) { //Prints to stdout the ppm file of selected image (per ppm format in man ppm) FileWriter fw = null; PrintWriter pw = null; try { fw = new FileWriter(fn); pw = new PrintWriter(fw); } catch (IOException e) { System.err.println("IO Exception: " + e); } String s = ""; s = s +"P3\n"; s = s +""+ rows + " " + cols + " 256\n"; s = s +"# Weight space graph autogenerated by PerceptronLearner\n"; pw.print(s + "\n"); for (int i=0;i0) s = s + "0 " + ((int)(Math.round(256*(2/(1.0 + Math.exp(-2 * Math.abs(curr)))-1)))) + " 0 "; else s = s + ((int)(Math.round(256*(2/(1.0 + Math.exp(-2 * Math.abs(curr)))-1)))) + " 0 0 "; } pw.print(s + "\n"); } pw.close(); } }