| 58 | } |
| 59 | |
| 60 | public static void main(String[] args) throws Exception { |
| 61 | LangDescriptor[] languages = new LangDescriptor[] { |
| 62 | // QUORUM_DESCR, |
| 63 | ANTLR4_DESCR, |
| 64 | JAVA_DESCR, |
| 65 | JAVA8_DESCR, |
| 66 | JAVA_GUAVA_DESCR, |
| 67 | JAVA8_GUAVA_DESCR, |
| 68 | SQLITE_CLEAN_DESCR, |
| 69 | TSQL_CLEAN_DESCR, |
| 70 | }; |
| 71 | |
| 72 | int maxNumFiles = 30; |
| 73 | int trials = 50; |
| 74 | Map<String,float[]> results = new HashMap<>(); |
| 75 | for (LangDescriptor language : languages) { |
| 76 | float[] medians = getMedianErrorRates(language, maxNumFiles, trials); |
| 77 | results.put(language.name, medians); |
| 78 | } |
| 79 | String python = |
| 80 | "#\n"+ |
| 81 | "# AUTO-GENERATED FILE. DO NOT EDIT\n" + |
| 82 | "# CodeBuff <version> '<date>'\n" + |
| 83 | "#\n"+ |
| 84 | "import numpy as np\n"+ |
| 85 | "import matplotlib.pyplot as plt\n\n" + |
| 86 | "fig = plt.figure()\n"+ |
| 87 | "ax = plt.subplot(111)\n"+ |
| 88 | "N = <maxNumFiles>\n" + |
| 89 | "sizes = range(1,N+1)\n" + |
| 90 | "<results:{r |\n" + |
| 91 | "<r> = [<rest(results.(r)); separator={,}>]\n"+ |
| 92 | "ax.plot(range(1,len(<r>)+1), <r>, label=\"<r>\", marker='<markers.(r)>', color='<colors.(r)>')\n" + |
| 93 | "}>\n" + |
| 94 | "ax.yaxis.grid(True, linestyle='-', which='major', color='lightgrey', alpha=0.5)\n" + |
| 95 | "ax.set_xlabel(\"Number of training files in sample corpus subset\", fontsize=14)\n"+ |
| 96 | "ax.set_ylabel(\"Median Error rate for <trials> trials\", fontsize=14)\n" + |
| 97 | "ax.set_title(\"Effect of Corpus size on Median Leave-one-out Validation Error Rate\")\n"+ |
| 98 | "plt.legend()\n" + |
| 99 | "plt.tight_layout()\n" + |
| 100 | "fig.savefig('images/subset_validator.pdf', format='pdf')\n"+ |
| 101 | "plt.show()\n"; |
| 102 | ST pythonST = new ST(python); |
| 103 | pythonST.add("results", results); |
| 104 | pythonST.add("markers", LeaveOneOutValidator.nameToGraphMarker); |
| 105 | pythonST.add("colors", LeaveOneOutValidator.nameToGraphColor); |
| 106 | pythonST.add("version", version); |
| 107 | pythonST.add("date", new Date()); |
| 108 | pythonST.add("trials", trials); |
| 109 | pythonST.add("maxNumFiles", maxNumFiles); |
| 110 | List<String> corpusDirs = map(languages, l -> l.corpusDir); |
| 111 | String[] dirs = corpusDirs.toArray(new String[languages.length]); |
| 112 | String fileName = "python/src/subset_validator.py"; |
| 113 | Utils.writeFile(fileName, pythonST.render()); |
| 114 | System.out.println("wrote python code to "+fileName); |
| 115 | } |
| 116 | |
| 117 | public static float[] getMedianErrorRates(LangDescriptor language, int maxNumFiles, int trials) throws Exception { |