From: <ku...@us...> - 2010-02-16 01:08:48
|
Revision: 2042 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=2042&view=rev Author: kurzum Date: 2010-02-16 00:17:05 +0000 (Tue, 16 Feb 2010) Log Message: ----------- almost finished DescriptionSubsumptionTree, still a NullPointer somewhere... Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/scripts/tiger/TestIterativeLearning.java trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentCollector.java trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentConfig.java trunk/src/dl-learner/org/dllearner/utilities/experiments/IteratedConfig.java trunk/src/dl-learner/org/dllearner/utilities/experiments/Table.java trunk/src/dl-learner/org/dllearner/utilities/experiments/TableRowColumn.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/utilities/datastructures/DescriptionSubsumptionTree.java Modified: trunk/src/dl-learner/org/dllearner/scripts/tiger/TestIterativeLearning.java =================================================================== --- trunk/src/dl-learner/org/dllearner/scripts/tiger/TestIterativeLearning.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/scripts/tiger/TestIterativeLearning.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -47,8 +47,8 @@ import org.dllearner.utilities.experiments.ExperimentCollector; import org.dllearner.utilities.experiments.IteratedConfig; import org.dllearner.utilities.experiments.Jamon; +import org.dllearner.utilities.experiments.Table; -import com.jamonapi.MonKey; import com.jamonapi.MonKeyImp; import com.jamonapi.Monitor; @@ -114,7 +114,7 @@ } folds = 2; - iterations = 1; + iterations = 2; long n = System.currentTimeMillis(); passiveNoZU(); // passiveWithZu(); @@ -144,25 +144,27 @@ // ExMakerCrossFolds.printFolds(folds); List<IteratedConfig> configs = getConfigs(); for (IteratedConfig experimentConfig : configs) { - logger.warn("next: passiveNoZU."+experimentConfig.label); + experimentConfig.init(mks); + logger.warn("next: passiveNoZU."+experimentConfig.experimentName); int i = 1; for (Examples examples : folds) { - - for(MonKeyImp m : mks){ - experimentConfig.init(m); - } - logger.warn("beginning fold: "+(i++)); conductExperiment( examples, experimentConfig); + } + Table t = new Table(); + t.addTableRowColumn(experimentConfig.getTableRows()); + t.sortByLabel(); + JamonMonitorLogger.writeHTMLReport("/tmp/tiger.html"); + System.out.println(t.getGnuPlotAsColumn()); if (true) { System.exit(0); } - eColl_passiveNoZU.addExperimentConfig(experimentConfig); +// eColl_passiveNoZU.addExperimentConfig(experimentConfig); logger.info(experimentConfig); - eColl_passiveNoZU.write(iterations); +// eColl_passiveNoZU.write(iterations); } @@ -192,7 +194,7 @@ List<IteratedConfig> configs = getConfigs(); for (IteratedConfig experimentConfig : configs) { - logger.warn("next: passiveWithZu."+experimentConfig.label); + logger.warn("next: passiveWithZu."+experimentConfig.experimentName); int i=1; for (Examples examples : runs) { logger.warn("beginning run: "+(i++)); @@ -259,6 +261,17 @@ for(int i = 0 ; config.stopCondition(i, precision, recall, fmeasure, lastConcept) ;i++ ) { Monitor iterationTime = JamonMonitorLogger.getTimeMonitor(TestIterativeLearning.class, "iterationTime").start(); Monitor literationTime = config.start(logIterationTime, i); +// try { +// Thread.sleep(2000); +// } catch (InterruptedException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// literationTime.stop(); +// System.out.println(literationTime); +// if (true) { +// System.exit(0); +// } /*LEARNING*/ Monitor lLearningTime = config.start(logLearningTime, i); Added: trunk/src/dl-learner/org/dllearner/utilities/datastructures/DescriptionSubsumptionTree.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/datastructures/DescriptionSubsumptionTree.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/utilities/datastructures/DescriptionSubsumptionTree.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -0,0 +1,127 @@ +package org.dllearner.utilities.datastructures; + +import java.util.Collection; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.dllearner.core.EvaluatedDescription; +import org.dllearner.core.ReasonerComponent; +import org.dllearner.core.owl.Description; +import org.dllearner.learningproblems.EvaluatedDescriptionPosNeg; + +public class DescriptionSubsumptionTree { + public class Node { + public Node parent; + public double accuracy; + + //by length? + public SortedSet<EvaluatedDescription> equivalents = new TreeSet<EvaluatedDescription>(); + + //by accuracy + public SortedSet<Node> subClasses = new TreeSet<Node>(); + + public Node(EvaluatedDescription ed){ + if(ed!=null) {equivalents.add(ed);}; + accuracy = ed.getAccuracy(); + } + + //happens only if n is sure to be a subclass + public void insert(Node n){ + if(subClasses.isEmpty()){ + subClasses.add(n); + }else{ + SortedSet<Node> toBeRemoved = new TreeSet<Node>(); + for (Node sub : subClasses) { + if(rc.isSuperClassOf(getDesc(), sub.getDesc())){ + //subClass of subclass + sub.insert(n); + n.parent = sub; + }else if(rc.isEquivalentClass(getDesc(), sub.getDesc())){ + //EquivalentClass of subclass + sub.equivalents.add(n.getEvalDesc()); + }else{ + //superclass of subclass + n.parent = this; + n.subClasses.add(sub); + toBeRemoved.add(sub); + } + } + //needs to be done outside, concurrent exception + for (Node node : toBeRemoved) { + subClasses.remove(node); + } + } + } + + + public boolean isRoot(){ + return (parent == null); + } + + public EvaluatedDescription getEvalDesc(){ + return equivalents.first(); + } + public Description getDesc(){ + return equivalents.first().getDescription(); + } + @Override + public String toString(){ + return getEvalDesc().toString(); + } + + public String _toString(String tab){ + String ret = (isRoot())?"Thing\n":""; + + if(subClasses.isEmpty()){ + ret+= this+"\n"; + } + tab+=" "; + for (Node sub : subClasses) { + ret += sub.toString()+"\n"; + } + return ret; + } + + + } + private Node root; + + private final ReasonerComponent rc; + + public DescriptionSubsumptionTree(ReasonerComponent rc){ + this.rc = rc; + this.root = new Node(null); + this.root.parent = null; + } + + public static void main(String[] args) { + + } + + public void insert(Collection<EvaluatedDescription> evaluatedDescriptions){ + for (EvaluatedDescription evaluatedDescription : evaluatedDescriptions) { + System.out.println("Adding: "+evaluatedDescription.toString()); + Node n = new Node(evaluatedDescription); + this.root.insert(n); + } + } + public void insertEdPosNeg(Collection<EvaluatedDescriptionPosNeg> evaluatedDescriptions, int limit){ + int i=0; + for (EvaluatedDescription evaluatedDescription : evaluatedDescriptions) { + + System.out.println("Adding: "+evaluatedDescription.toString()); + Node n = new Node(evaluatedDescription); + this.root.insert(n); + if(i>limit){break;} + i++; + } + } + + @Override + public String toString(){ + return root._toString(""); + } + + + +} Modified: trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentCollector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentCollector.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentCollector.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -20,6 +20,8 @@ public static DecimalFormat dfhuman = new DecimalFormat("##.##%"); public static DecimalFormat dfRuntime = new DecimalFormat("####."); List<IteratedConfig> experimentConfigs = new ArrayList<IteratedConfig>(); + + public ExperimentCollector(String filePrefix) { details = dir + filePrefix + "_" + "details"; @@ -42,7 +44,7 @@ String headerGNU = "\t"; String headerLatex = "\t&\t"; for (IteratedConfig ec : experimentConfigs) { - headerGNU += ec.label + "\t"; + headerGNU += ec.experimentName + "\t"; Files.appendFile(new File(details), ec.toString()); } for (int i = 0; i < iterations; i++) { @@ -67,7 +69,7 @@ } for (IteratedConfig ec : experimentConfigs) { - String label = ec.label ; + String label = ec.experimentName ; String learningTimeLatex = label+" learn"+ "\t&\t"; String totalTimeLatex = label+" total"+ "\t&\t"; String fmeasureLatex = label+ "\t&\t"; @@ -83,7 +85,7 @@ } for (IteratedConfig ec : experimentConfigs) { - String label = ec.label; + String label = ec.experimentName; String learningTimeHuman = label+" learn" + "\t&\t"; String totalTimeHuman = label+" total" + "\t&\t"; String fmeasureHuman = label + "\t&\t"; Modified: trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentConfig.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentConfig.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/utilities/experiments/ExperimentConfig.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -15,8 +15,8 @@ public class ExperimentConfig { private static final Logger logger = Logger.getLogger(ExperimentConfig.class); - public final String label; - public final int iterations; + public final String experimentName; + public final int sizeOfResultVector; protected List<MonitorComposite> mcs = new ArrayList<MonitorComposite>(); protected Map<String,MonitorComposite> mcsMap = new HashMap<String, MonitorComposite>(); @@ -25,47 +25,89 @@ public ExperimentConfig(String label){ this(label,1); } - public ExperimentConfig(String label, int iterations){ - this.label = label; - this.iterations = iterations; + public ExperimentConfig(String experimentName, int sizeOfResultVector){ + this.experimentName = experimentName; + this.sizeOfResultVector = sizeOfResultVector; } @Override public String toString(){ - return this.label+" with "+iterations+" iterations"; + return this.experimentName+" with "+sizeOfResultVector+" iterations"; } public List<TableRowColumn> getTableRows(){ List<TableRowColumn> l = new ArrayList<TableRowColumn>(); + if(sizeOfResultVector == 1) { + Monitor[] monitors = new Monitor[mcs.size()]; +// TableRowColumn trc = + for (int i = 0; i < monitors.length; i++) { + monitors[i] = mcs.get(i).getMonitors()[0]; + } + l.add(new TableRowColumn(monitors, experimentName, "")); + + }else{ + for(MonitorComposite mc :mcs){ + l.add(new TableRowColumn(mc.getMonitors(), experimentName, getRev(mc))); + } + } + return l; } - public void init(MonKeyImp monkey){ - Monitor[] marr = new Monitor[iterations]; - for (int i = 0; i < iterations; i++) { - marr[i] = MonitorFactory.getMonitor(mon(monkey, i)); + private MonitorComposite get(MonKeyImp m){ + return mcsMap.get(mon(m).getLabel()); + } + private String getRev(MonitorComposite mc){ + return mcsMapRev.get(mc); + } + + private void put(MonKeyImp m ,MonitorComposite mc ){ + mcsMap.put(mon(m).getLabel(), mc); + } + private void putRev(MonitorComposite mc , MonKeyImp m ){ + mcsMapRev.put( mc, m.getLabel()); + } + + public void init(List<MonKeyImp> monkeys){ + for (MonKeyImp monKeyImp : monkeys) { + init(monKeyImp); } +// JamonMonitorLogger.writeHTMLReport("/tmp/tiger.html"); + } + + public void init(MonKeyImp oldMonkey){ + Monitor[] marr = new Monitor[sizeOfResultVector]; + for (int i = 0; i < sizeOfResultVector; i++) { + MonKeyImp newMonKey = mon(oldMonkey, i); + if(newMonKey.getUnits().equals(Jamon.MS)){ + marr[i] = MonitorFactory.getTimeMonitor(newMonKey); + }else{ + marr[i] = MonitorFactory.getMonitor(newMonKey); + } + } MonitorComposite m = new MonitorComposite(marr); mcs.add(m); - mcsMap.put( monkey.getLabel(),m); - mcsMapRev.put(m, monkey.getLabel()); + put( oldMonkey,m); + putRev(m, oldMonkey); + } protected MonKeyImp mon(MonKeyImp monkey){ - return (monkey.getLabel().startsWith(label))?monkey:new MonKeyImp(label+monkey.getLabel(), monkey.getUnits()); + MonKeyImp m = (monkey.getLabel().startsWith(experimentName))?monkey:new MonKeyImp(experimentName+"_"+monkey.getLabel(), monkey.getUnits()); + return m; } - protected MonKeyImp mon(MonKeyImp monkey, int index){ + protected MonKeyImp mon(MonKeyImp oldMonkey, int index){ //narrensicher - MonKeyImp l = mon(monkey); - return (iterations==1)?monkey:new MonKeyImp(l.getLabel()+"_"+index, l.getUnits()) ; + MonKeyImp newMonkey = mon(oldMonkey); + return new MonKeyImp(newMonkey.getLabel()+"_"+index, newMonkey.getUnits()) ; } public void add(MonKeyImp monkey, int index, double value){ try{ - mcsMap.get(monkey.getLabel()).getMonitors()[index].add(value); + get(monkey).getMonitors()[index].add(value); }catch (Exception e) { e.printStackTrace(); logger.error("index too big, max = "+index); @@ -73,7 +115,7 @@ } public Monitor start(MonKeyImp monkey, int index){ - return mcsMap.get(monkey.getLabel()).getMonitors()[index].start(); + return get(monkey).getMonitors()[index].start(); } // public static boolean higher(Monitor[] a, double current){ Modified: trunk/src/dl-learner/org/dllearner/utilities/experiments/IteratedConfig.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/experiments/IteratedConfig.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/utilities/experiments/IteratedConfig.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -43,7 +43,7 @@ // if(higher(iterationRecall, recall)){highestRecall=concept;} // if(higher(iterationFmeasure, fmeasure)){highestFMeasure=concept;} - boolean condIter = (iteration<this.iterations); + boolean condIter = (iteration<this.sizeOfResultVector); boolean condPrec = fmeasure <=1.0d; if(!condIter){ logger.info("iterations reached, stopping"); Modified: trunk/src/dl-learner/org/dllearner/utilities/experiments/Table.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/experiments/Table.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/utilities/experiments/Table.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.SortedSet; +import java.util.TreeSet; import org.apache.log4j.Logger; import org.dllearner.utilities.JamonMonitorLogger; @@ -19,6 +21,11 @@ LATEX, GNUPLOT }; + +// private Map<String, TableRowColumn> m = new HashMap<String, TableRowColumn>(); + private SortedSet<String> experimentNames = new TreeSet<String>(); + private SortedSet<String> labels = new TreeSet<String>(); + private List<TableRowColumn> tableRowColumns = new ArrayList<TableRowColumn>(); private int length; @@ -43,8 +50,8 @@ } // System.out.println("avg: " + m[a].getAvg()); } - TableRowColumn trc = new TableRowColumn(m, "entry_" + i); - trc.deleteAll(); + TableRowColumn trc = new TableRowColumn(m, "Test","entry_" + i); +// trc.deleteAll(); trc.useStdDev=false; t.addTableRowColumn(trc); } @@ -58,11 +65,19 @@ JamonMonitorLogger.writeHTMLReport("log/tiger.html"); } + public void addTableRowColumn(List<TableRowColumn> trcs) { + for (TableRowColumn tableRowColumn : trcs) { + labels.add(tableRowColumn.getLabel()); + experimentNames.add(tableRowColumn.getExperimentName()); + addTableRowColumn(tableRowColumn); + } + } + public void addTableRowColumn(TableRowColumn trc) { try{ trc.toLatexRow(); }catch (NullPointerException e) { - logger.error("TableRowColumn was not initialized, ignoring it, label: "+trc.label); + logger.error("TableRowColumn was not initialized, ignoring it: "+trc); e.printStackTrace(); } @@ -73,7 +88,7 @@ if (trc.size() != length) { logger.error("Added TableRowColumn does not match previous set length (" + length + ") but has size " - + trc.size() + "), \nignoring it, label: "+trc.label+", value: " + trc.toLatexRow()); + + trc.size() + "), \nignoring it: "+trc); } @@ -116,13 +131,13 @@ boolean first = (i==1); switch (f) { case LATEX: - rows[0] += (first?trc.label+TableRowColumn.latexSep:""); + rows[0] += (first?trc.getHeader()+TableRowColumn.latexSep:""); rows[i] += (firstColumn&&addNumbersInFront?i+TableRowColumn.latexSep:""); rows[i] += trc.getLatexEntry(i-1) + ((last) ? TableRowColumn.latexSep : TableRowColumn.latexSep); break; case GNUPLOT: - rows[0] += (first?"#"+trc.label+"\t":""); + rows[0] += (first?"#"+trc.getHeader()+"\t":""); rows[i] += (firstColumn&&addNumbersInFront?i+"\t":""); rows[i] += trc.getGnuPlotEntry(i-1) + ((last) ?"" : "\t"); break; @@ -152,5 +167,45 @@ } return (replaceCommaByPoints)?ret.replace(",","."):ret; } + + public void sortByExperimentName(){ + _sortByLabel(); + _sortByExperimentName(); + + } + public void sortByLabel(){ + _sortByExperimentName(); + _sortByLabel(); + } + + private void _sortByLabel(){ + List<String> l = new ArrayList<String>(labels); + List<TableRowColumn> newTrc = new ArrayList<TableRowColumn>(); + + for (String s : l) { + for (TableRowColumn trc : tableRowColumns) { + if(trc.getLabel().equals(s)){ + newTrc.add(trc); + } + } + } + tableRowColumns = newTrc; + } + private void _sortByExperimentName(){ + List<String> l = new ArrayList<String>(experimentNames); + List<TableRowColumn> newTrc = new ArrayList<TableRowColumn>(); + + for (String s : l) { + for (TableRowColumn trc : tableRowColumns) { + if(trc.getExperimentName().equals(s)){ + newTrc.add(trc); + } + } + } + tableRowColumns = newTrc; + } + + + } Modified: trunk/src/dl-learner/org/dllearner/utilities/experiments/TableRowColumn.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/experiments/TableRowColumn.java 2010-02-15 18:40:49 UTC (rev 2041) +++ trunk/src/dl-learner/org/dllearner/utilities/experiments/TableRowColumn.java 2010-02-16 00:17:05 UTC (rev 2042) @@ -5,7 +5,6 @@ import org.dllearner.utilities.JamonMonitorLogger; import com.jamonapi.Monitor; -import com.jamonapi.MonitorFactory; public class TableRowColumn { @@ -16,12 +15,13 @@ public static String latexSep = "\t&\t"; public static String latexEnd = "\\\\"; - String label = ""; + private final String label ; + private final String experimentName; Monitor[] monitors; boolean useStdDev = false; - DecimalFormat dfGnuPlotDefault = new DecimalFormat("#######.######"); + DecimalFormat dfGnuPlotDefault = new DecimalFormat("######0.00####"); // DecimalFormat dfStdDevLatex = new DecimalFormat("##.##%"); DecimalFormat dfLatexDefault = new DecimalFormat("####.####"); @@ -30,9 +30,10 @@ // public TableRowColumn(Monitor[] monitors){ // this.monitors = monitors; // } - public TableRowColumn(Monitor[] monitors, String label) { + public TableRowColumn(Monitor[] monitors, String experimentName, String label) { this.monitors = monitors; this.label = label; + this.experimentName = experimentName; } @@ -44,10 +45,19 @@ public void deleteAll(){ for (int i = 0; i < monitors.length; i++) { - MonitorFactory.remove(monitors[i].getMonKey()); +// MonitorFactory.remove(monitors[i].getMonKey()); } } + @Override + public String toString(){ + return experimentName+" "+label+" "+toGnuPlotRow(); + } + + public String getHeader(){ + return experimentName+" "+label; + } + public int size() { return monitors.length; } @@ -59,13 +69,17 @@ public String getLabel() { return label; } + + public String getExperimentName() { + return experimentName; + } public String toGnuPlotRow() { return toRow(Formats.GNUPLOT); } private String toRow(Formats f) { - String ret = label; + String ret = experimentName+ " "+ label; for (int i = 0; i < monitors.length; i++) { boolean last = (i + 1 == monitors.length); switch (f) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |