001/** 002 * Copyright (C) 2007-2011, Jens Lehmann 003 * 004 * This file is part of DL-Learner. 005 * 006 * DL-Learner is free software; you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation; either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * DL-Learner is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 018 */ 019 020package org.dllearner.experiments; 021 022import java.io.Serializable; 023import java.text.DecimalFormat; 024 025import org.dllearner.utilities.JamonMonitorLogger; 026 027import com.jamonapi.Monitor; 028 029public class TableRowColumn implements Serializable{ 030 private static final long serialVersionUID = 1252924374566004540L; 031 032 enum Formats { 033 LATEX, GNUPLOT 034 } 035 036 public enum Display { 037 AVG, HITS, TOTAL 038 } 039 040 public static boolean useStdDevWithPercentageUnit = true; 041 042 public static String latexSep = "\t&\t"; 043 public static String latexEnd = "\\\\"; 044 045 private final String label ; 046 private final String experimentName; 047 048// final Monitor[] monitors; 049 final FinalizedMonitor[] monitors; 050 boolean useStdDev = false; 051 052 Display display = Display.AVG; 053 054 DecimalFormat dfGnuPlotDefault = new DecimalFormat("######0.00####"); 055 056// DecimalFormat dfStdDevLatex = new DecimalFormat("##.##%"); 057 DecimalFormat dfLatexDefault = new DecimalFormat("####.####"); 058 DecimalFormat dfPercentage = new DecimalFormat("##.##%"); 059 060 // public TableRowColumn(Monitor[] monitors){ 061 // this.monitors = monitors; 062 // } 063 public TableRowColumn(Monitor[] monitors, String experimentName, String label) { 064 this.monitors = new FinalizedMonitor[monitors.length]; 065 for (int i = 0; i < monitors.length; i++) { 066 this.monitors[i] = new FinalizedMonitor(monitors[i]); 067 } 068 this.label = label; 069 this.experimentName = experimentName; 070 } 071 072 073 074 public static void main(String[] args) { 075 // double d = 0.05d; 076 // System.out.println(new TableRowColumn().dfStdDevLatex.format(d)); 077 } 078 079 public void deleteAll(){ 080 for (FinalizedMonitor monitor : monitors) { 081// MonitorFactory.remove(monitors[i].getMonKey()); 082 } 083 } 084 085 @Override 086 public String toString(){ 087 return experimentName+" "+label+" "+toGnuPlotRow(); 088 } 089 090 public int size() { 091 return monitors.length; 092 } 093 094 public String toLatexRow() { 095 return toRow(Formats.LATEX); 096 } 097 098 public String getLabel() { 099 return label; 100 } 101 102 public String getExperimentName() { 103 return experimentName; 104 } 105 106 public String toGnuPlotRow() { 107 return toRow(Formats.GNUPLOT); 108 } 109 110 private String toRow(Formats f) { 111 String ret = experimentName+ " "+ label; 112 for (int i = 0; i < monitors.length; i++) { 113 boolean last = (i + 1 == monitors.length); 114 switch (f) { 115 case LATEX: 116 ret += latexSep + getLatexEntry(i) + (last?latexEnd:""); 117 break; 118 case GNUPLOT: 119 ret += "\t" + getGnuPlotEntry(i); 120 break; 121 default: 122 break; 123 } 124 } 125// System.out.println(ret); 126 return ret; 127 128 } 129 130 public String toGnuPlotRow(int rowNumber) { 131 return rowNumber + "\t" + toGnuPlotRow(); 132 } 133 134 public String getLatexEntry(int i) { 135 return latexFormat(monitors[i], getValue(i)) + " "+getLatexStdDev(i) ; 136 } 137 private String getLatexStdDev(int i){ 138 String tex = "(\\pm"+latexFormat(monitors[i], monitors[i].getStdDev()) + ") "; 139 if(useStdDev){ 140 return tex; 141 } 142 143 if(useStdDevWithPercentageUnit && monitors[i].getUnits().equals(JamonMonitorLogger.PERCENTAGE)){ 144 return tex; 145 } 146 147 return ""; 148 149 } 150 151 public String getGnuPlotEntry(int i) { 152 return dfGnuPlotDefault.format(getValue(i)) + ""; 153 } 154 155 public void setDisplay(Display d){ 156 display = d; 157 } 158 159 private double getValue(int i){ 160// return monitors[i].getAvg(); 161 switch(display){ 162 case AVG: return monitors[i].getAvg(); 163 case HITS: return monitors[i].getHits(); 164 case TOTAL: return monitors[i].getTotal(); 165 } 166 return monitors[i].getAvg(); 167 } 168 169 private String latexFormat(FinalizedMonitor monitors, double value){ 170 if(monitors.getUnits().equals(JamonMonitorLogger.PERCENTAGE)){ 171 return dfPercentage.format(value).replace("%", "\\%").replace("_", "\\_"); 172 }else{ 173 return dfLatexDefault.format(value); 174 } 175 } 176}