@Override public void run() { try { org.apache.log4j.Logger.getLogger("org.dllearner").setLevel(Level.toLevel(logLevel.toUpperCase())); } catch (Exception e) { logger.warn("Error setting log level to " + logLevel); } lp = context.getBean(AbstractClassExpressionLearningProblem.class); rs = lp.getReasoner(); expression = OWLAPIUtils.classExpressionPropertyExpanderChecked(this.expression, rs, dataFactory, true, logger); if (expression != null) { EvaluatedHypothesis ev = lp.evaluate(expression); if (ev instanceof EvaluatedDescriptionPosNeg) { logger.info("#EVAL# tp: " + ((EvaluatedDescriptionPosNeg) ev).getCoveredPositives().size()); logger.info("#EVAL# fp: " + ((EvaluatedDescriptionPosNeg) ev).getCoveredNegatives().size()); logger.info("#EVAL# tn: " + ((EvaluatedDescriptionPosNeg) ev).getNotCoveredNegatives().size()); logger.info("#EVAL# fn: " + ((EvaluatedDescriptionPosNeg) ev).getNotCoveredPositives().size()); } } else { logger.error("Expression is empty."); throw new RuntimeException("Expression is empty."); } } }
private void evaluateGeneratedDefinition() { double bestScoreVal = Double.NEGATIVE_INFINITY; double tmpScoreVal; ScorePosNeg tmpScore; for (int i=1; i<=maxLength; i++) { for (OWLClassExpression description : generatedDescriptions.get(i)) { tmpScore = (ScorePosNeg) learningProblem.computeScore(description); tmpScoreVal = tmpScore.getScoreValue(); if (tmpScoreVal > bestScoreVal) { bestDescription = description; bestScore = tmpScore; bestScoreVal = tmpScoreVal; } } } } }
private void setReasonerAndUtil(AbstractReasonerComponent reasoner) { if (this.reasoner != reasoner) { if (this.reasoningUtil == null) { this.reasoningUtil = newReasoningUtils(reasoner); } else { this.reasoningUtil.setReasoner(reasoner); } this.reasoningUtil.init(); } this.reasoner = reasoner; }
/** * Initialise all components. * @param id Session ID. * @throws ComponentInitException Thrown if an error occurs during component initialisation. */ @WebMethod public void initAll(int id) throws ClientNotKnownException, ComponentInitException { ClientState state = getState(id); logger.info("Initializing knowledge sources..."); for(AbstractKnowledgeSource ks : state.getKnowledgeSources()) ks.init(); logger.info("Initializing reasoner..."); state.getReasonerComponent().init(); logger.info("Initializing learning problem..."); state.getLearningProblem().init(); logger.info("Initializing learning algorithm..."); state.getLearningAlgorithm().init(); }
private boolean addPartialSolution(EvaluatedDescription<? extends Score> partialSolution) { // check whether partial solution follows criteria (currently only accuracy threshold) if(Double.compare(partialSolution.getAccuracy(), minAccuracyPartialSolution) > 0) { partialSolutions.add(partialSolution); // create combined solution OWLObjectUnionOf combinedCE = dataFactory.getOWLObjectUnionOf( partialSolutions.stream() .map(EvaluatedHypothesis::getDescription) .collect(Collectors.toSet())); // evalute combined solution EvaluatedDescription<? extends Score> combinedSolution = lp.evaluate(combinedCE); bestEvaluatedDescriptions.add(combinedSolution); return true; } return false; }
positiveIndividuals = ((PosOnlyLP) lp).getPositiveExamples(); negativeIndividuals = Sets.difference(lp.getReasoner().getIndividuals(), positiveIndividuals); } else if (lp instanceof ClassLearningProblem) {
/** * Constructs a learning problem using a reasoning service for * querying the background knowledge. It can be used for * evaluating solution candidates. * @param reasoner The reasoning service used as * background knowledge. */ public AbstractClassExpressionLearningProblem(AbstractReasonerComponent reasoner) { setReasonerAndUtil(reasoner); }
double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); logger.trace(sparql_debug, "`acc:"+accuracy); mon.stop();
Set<OWLIndividual> positiveExamples = ((PosNegLP)learningProblem).getPositiveExamples(); Set<OWLIndividual> negativeExamples = ((PosNegLP)learningProblem).getNegativeExamples(); ReasoningUtils reasoningUtil = learningProblem.getReasoningUtil();
output += "-" + new TreeSet<>(neg) + "\n"; try { lp.init(); la.setLearningProblem(lp); la.init();
private void reset() { // set all values back to their default values (used for running // the algorithm more than once) candidates.clear(); trees.clear(); currentSolution.clear(); bestEvaluatedDescription = learningProblem.evaluate(dataFactory.getOWLThing()); // we need to clone in order not to modify the learning problem currentPosExamples = new TreeSet<>(((PosNegLP) getLearningProblem()).getPositiveExamples()); currentNegExamples = new TreeSet<>(((PosNegLP) getLearningProblem()).getNegativeExamples()); startPosExamplesSize = currentPosExamples.size(); // startNegExamplesSize = currentNegExamples.size(); }
@Override public void changeReasonerComponent(AbstractReasonerComponent reasoner) { setReasonerAndUtil(reasoner); }
double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); mon.stop();
lp.init(); la.init(); } catch (ComponentInitException e) {
/** * Adds an class expression to this set. Some kind of lazy evaluation is applied, * i.e. an evaluated description is only generated if the given accuracy * is higher than the accuracy value of the worst evaluated description * contained in this set. * @param description the class expression * @param accuracy the accuracy of the class expression * @param problem the learning problem */ public void add(OWLClassExpression description, double accuracy, AbstractClassExpressionLearningProblem<? extends Score> problem) { // bug // http://sourceforge.net/tracker/?func=detail&atid=986319&aid=3029181&group_id=203619 // -> set should be filled up to max size before we compare acc. with // the worst result if (set.size() < maxSize || getWorst().getAccuracy() <= accuracy) { set.add(problem.evaluate(description)); } // delete the worst element if set is full if (set.size() > maxSize) { set.pollFirst(); } }
@Override @Autowired(required=false) public void setReasoner(AbstractReasonerComponent reasoner) { setReasonerAndUtil(reasoner); }
Score score = learningProblem.computeScore(classExpression, noise);
bestEvaluatedDescription = learningProblem.evaluate(bestDescription); bestEvaluatedDescriptions.add(bestEvaluatedDescription); } else { bestCombinedDescription = dataFactory.getOWLObjectUnionOf(bestEvaluatedDescription.getDescription(), bestDescription); bestEvaluatedDescription = learningProblem.evaluate(bestCombinedDescription); bestEvaluatedDescriptions.add(bestEvaluatedDescription); bestEvaluatedDescription = learningProblem.evaluate(niceDescription);
lp.init(); la.setLearningProblem(lp); la.init();