@Override public Object clone() throws CloneNotSupportedException { return new CELOE(this); }
@Override public String toString() { return getShortDescription(null); }
@Override public OWLClassExpression getExpression() { return getDescription(); }
public PCELOE(PCELOE celoe){ setReasoner(celoe.reasoner); setLearningProblem(celoe.learningProblem); setAllowedConcepts(celoe.getAllowedConcepts()); setAllowedObjectProperties(celoe.getAllowedObjectProperties()); setAllowedDataProperties(celoe.getAllowedDataProperties()); setIgnoredConcepts(celoe.ignoredConcepts); setIgnoredObjectProperties(celoe.getIgnoredObjectProperties()); setIgnoredDataProperties(celoe.getIgnoredDataProperties()); setExpandAccuracy100Nodes(celoe.expandAccuracy100Nodes); setFilterDescriptionsFollowingFromKB(celoe.filterDescriptionsFollowingFromKB); setHeuristic(celoe.heuristic); setMaxClassExpressionTests(celoe.maxClassExpressionTests); setMaxClassExpressionTestsAfterImprovement(celoe.maxClassExpressionTestsAfterImprovement); setMaxDepth(celoe.maxDepth); setMaxExecutionTimeInSeconds(celoe.maxExecutionTimeInSeconds); setMaxExecutionTimeInSecondsAfterImprovement(celoe.maxExecutionTimeInSecondsAfterImprovement); setMaxNrOfResults(celoe.maxNrOfResults); setNoisePercentage(celoe.noisePercentage); setOperator(op); setReuseExistingDescription(celoe.reuseExistingDescription); setSingleSuggestionMode(celoe.singleSuggestionMode); setStartClass(celoe.startClass); setStopOnFirstDefinition(celoe.stopOnFirstDefinition);
@Override public double getNodeScore(OENode node) { // accuracy as baseline double score = node.getAccuracy(); // being better than the parent gives a bonus; if(!node.isRoot()) { double accuracyGain = node.getAccuracy() - node.getParent().getAccuracy(); score += accuracyGain * gainBonusFactor; // the root node also gets a bonus to possibly spawn useful disjunctions } else { score += startNodeBonus; } // penalty for horizontal expansion score -= node.getHorizontalExpansion() * expansionPenaltyFactor; // penalty for having many child nodes (stuck prevention) score -= node.getRefinementCount() * nodeRefinementPenalty; return score; }
private OENode getNextNodeToExpand() { // we expand the best node of those, which have not achieved 100% accuracy // already and have a horizontal expansion equal to their length // (rationale: further extension is likely to add irrelevant syntactical constructs) synchronized (searchTree) { Iterator<OENode> it = searchTree.descendingIterator(); while(it.hasNext()) { OENode node = it.next(); if (currentlyProcessedNodes.contains(node)) continue; if (isExpandAccuracy100Nodes() && node.getHorizontalExpansion() < OWLClassExpressionUtils.getLength(node.getDescription())) { currentlyProcessedNodes.add(node); return node; } else { if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < OWLClassExpressionUtils.getLength(node.getDescription())) { currentlyProcessedNodes.add(node); return node; } } } } // this should practically never be called, since for any reasonable learning // task, we will always have at least one node with less than 100% accuracy return null;//nodes.last(); }
private OENode getNextNodeToExpand() { // we expand the best node of those, which have not achieved 100% accuracy // already and have a horizontal expansion equal to their length // (rationale: further extension is likely to add irrelevant syntactical constructs) Iterator<OENode> it = searchTree.descendingIterator(); if (logger.isTraceEnabled()) { for (OENode N:searchTree.getNodeSet()) { logger.trace(sparql_debug,"`getnext:"+N); } } while(it.hasNext()) { OENode node = it.next(); logger.trace(sparql_debug,"``"+node+node.getAccuracy()); if (isExpandAccuracy100Nodes() && node.getHorizontalExpansion() < OWLClassExpressionUtils.getLength(node.getDescription())) { return node; } else { if(node.getAccuracy() < 1.0 || node.getHorizontalExpansion() < OWLClassExpressionUtils.getLength(node.getDescription())) { return node; } } } // this should practically never be called, since for any reasonable learning // task, we will always have at least one node with less than 100% accuracy throw new RuntimeException("CELOE could not find any node with lesser accuracy."); }
private void updateMinMaxHorizExp(OENode node) { int newHorizExp = node.getHorizontalExpansion(); double scoreThreshold = heuristic.getNodeScore(node) + 1 - node.getAccuracy(); if(n.getHorizontalExpansion() == minHorizExp) {
private TreeSet<OWLClassExpression> refineNode(LengthLimitedRefinementOperator operator, OENode node) { MonitorFactory.getTimeMonitor("refineNode").start(); // we have to remove and add the node since its heuristic evaluation changes through the expansion // (you *must not* include any criteria in the heuristic which are modified outside of this method, // otherwise you may see rarely occurring but critical false ordering in the nodes set) searchTree.updatePrepare(node); int horizExp = node.getHorizontalExpansion(); TreeSet<OWLClassExpression> refinements = (TreeSet<OWLClassExpression>) operator.refine(node.getDescription(), horizExp+1); // System.out.println("refinements: " + refinements); node.incHorizontalExpansion(); node.setRefinementCount(refinements.size()); // System.out.println("refined node: " + node); searchTree.updateDone(node); MonitorFactory.getTimeMonitor("refineNode").stop(); return refinements; }
private void showIfBetterSolutionsFound() { if(!singleSuggestionMode && bestEvaluatedDescriptions.getBestAccuracy() > currentHighestAccuracy) { currentHighestAccuracy = bestEvaluatedDescriptions.getBestAccuracy(); expressionTestCountLastImprovement = expressionTests; timeLastImprovement = System.nanoTime(); long durationInMillis = getCurrentRuntimeInMilliSeconds(); String durationStr = getDurationAsString(durationInMillis); logger.info("more accurate (" + dfPercent.format(currentHighestAccuracy) + ") class expression found after " + durationStr + ": " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); } }
private void showIfBetterSolutionsFound() { if(!singleSuggestionMode && bestEvaluatedDescriptions.getBestAccuracy() > currentHighestAccuracy) { currentHighestAccuracy = bestEvaluatedDescriptions.getBestAccuracy(); expressionTestCountLastImprovement = expressionTests; timeLastImprovement = System.nanoTime(); long durationInMillis = getCurrentRuntimeInMilliSeconds(); String durationStr = getDurationAsString(durationInMillis); // track new best accuracy if enabled if(keepTrackOfBestScore) { runtimeVsBestScore.put(getCurrentRuntimeInMilliSeconds(), currentHighestAccuracy); } logger.info("more accurate (" + dfPercent.format(currentHighestAccuracy) + ") class expression found after " + durationStr + ": " + descriptionToString(bestEvaluatedDescriptions.getBest().getDescription())); } }
@Override public OWLClassExpression getCurrentlyBestDescription() { EvaluatedDescription<? extends Score> ed = getCurrentlyBestEvaluatedDescription(); return ed == null ? null : ed.getDescription(); }
@Override public Object clone() throws CloneNotSupportedException { return new PCELOE(this); }
private boolean terminationCriteriaSatisfied() { return stop || (maxClassExpressionTestsAfterImprovement != 0 && (expressionTests - expressionTestCountLastImprovement >= maxClassExpressionTestsAfterImprovement)) || (maxClassExpressionTests != 0 && (expressionTests >= maxClassExpressionTests)) || (maxExecutionTimeInSecondsAfterImprovement != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSecondsAfterImprovement* 1000000000L))) || (maxExecutionTimeInSeconds != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSeconds* 1000000000L))) || (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)) || (stopOnFirstDefinition && (getCurrentlyBestAccuracy() >= 1)); }
private boolean terminationCriteriaSatisfied() { return stop || (maxClassExpressionTestsAfterImprovement != 0 && (expressionTests - expressionTestCountLastImprovement >= maxClassExpressionTestsAfterImprovement)) || (maxClassExpressionTests != 0 && (expressionTests >= maxClassExpressionTests)) || (maxExecutionTimeInSecondsAfterImprovement != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSecondsAfterImprovement* 1000000000L))) || (maxExecutionTimeInSeconds != 0 && ((System.nanoTime() - nanoStartTime) >= (maxExecutionTimeInSeconds* 1000000000L))) || (terminateOnNoiseReached && (100*getCurrentlyBestAccuracy()>=100-noisePercentage)) || (stopOnFirstDefinition && (getCurrentlyBestAccuracy() >= 1)); }
@Override public OWLClassExpression getCurrentlyBestDescription() { EvaluatedDescription<? extends Score> ed = getCurrentlyBestEvaluatedDescription(); return ed == null ? null : ed.getDescription(); }
@Override public double getNodeScore(OENode node) { double score = node.getAccuracy(); if(!node.isRoot()) { double accuracyGain = node.getAccuracy() - node.getParent().getAccuracy(); score += accuracyGain * gainBonusFactor; score -= node.getHorizontalExpansion() * expansionPenaltyFactor; score -= node.getRefinementCount() * nodeRefinementPenalty; OWLClassExpression expression = node.getExpression();//System.out.println(expression);
private void updateMinMaxHorizExp(OENode node) { int newHorizExp = node.getHorizontalExpansion(); double scoreThreshold = heuristic.getNodeScore(node) + 1 - node.getAccuracy(); if(n.getHorizontalExpansion() == minHorizExp) {
public String getShortDescription(String baseURI) { return getShortDescription(baseURI, null); }
@Override public int compare(OENode node1, OENode node2) { return ComparisonChain.start() .compare(getNodeScore(node1), getNodeScore(node2)) .compare(node1.getDescription(), node2.getDescription()) .result(); }