private EvaluatedDescription<? extends Score> computePartialSolution() { log.info("computing next partial solution..."); la.start(); EvaluatedDescription<? extends Score> partialSolution = la.getCurrentlyBestEvaluatedDescription(); return partialSolution; }
/** * Returns a fraction of class descriptions with sufficiently high accuracy. * @param accuracyThreshold Only return solutions with this accuracy or higher. * @return Return value is getCurrentlyBestDescriptions(Integer.MAX_VALUE, accuracyThreshold, false). */ public synchronized List<? extends EvaluatedDescription<? extends Score>> getCurrentlyBestEvaluatedDescriptions(double accuracyThreshold) { return getCurrentlyBestEvaluatedDescriptions(Integer.MAX_VALUE, accuracyThreshold, false); }
/** * @see #getCurrentlyBestEvaluatedDescriptions(int) * @param nrOfDescriptions Limit for the number or returned descriptions. * @return The best class descriptions found by the learning algorithm so far. */ @Override public synchronized List<OWLClassExpression> getCurrentlyBestDescriptions(int nrOfDescriptions) { return getCurrentlyBestDescriptions(nrOfDescriptions, false); }
@Override public void run() { if(la.isRunning()){ System.out.println(la.getCurrentlyBestEvaluatedDescriptions()); } }
private void updateLearningProblem(EvaluatedDescription<? extends Score> partialSolution) { // get individuals covered by the solution SortedSet<OWLIndividual> coveredExamples = la.getReasoner().getIndividuals(partialSolution.getDescription()); // remove from pos examples as those are already covered currentPosExamples.removeAll(coveredExamples); // remove from neg examples as those will always be covered in the combined solution currentNegExamples.removeAll(coveredExamples); // update the learning problem itself // TODO do we need some re-init of the lp afterwards? if(lp instanceof PosNegLP) { ((PosNegLP) la.getLearningProblem()).setPositiveExamples(currentPosExamples); ((PosNegLP) la.getLearningProblem()).setNegativeExamples(currentNegExamples); } else if(lp instanceof PosOnlyLP) { ((PosOnlyLP) la.getLearningProblem()).setPositiveExamples(currentPosExamples); } else if(lp instanceof ClassLearningProblem){ // TODO } }
la.init(); la.start(); timer.cancel(); List<? extends EvaluatedDescription> currentlyBestEvaluatedDescriptions = la.getCurrentlyBestEvaluatedDescriptions(0.8); System.out.println(currentlyBestEvaluatedDescriptions);
/** * Returns a list of JSON encoded description including extra information * (which partially depends on the learning problem) such as the accuracy * of the learned description. * * @param id The session ID. * @param limit Maximum number of results desired. * @return A JSON string encoding learned descriptions. * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public String learnDescriptionsEvaluatedLimit(int id, int limit) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); List<? extends EvaluatedDescription> descriptions = state.getLearningAlgorithm().getCurrentlyBestEvaluatedDescriptions(limit); String json = "{"; int count = 1; for(EvaluatedDescription description : descriptions) { if (count>1) json += ",\"solution" + count + "\" : " + description.asJSON(); else json += "\"solution" + count + "\" : " + description.asJSON(); count++; } json+="}"; return json; }
cela.start(); cela.getReasoner().releaseKB(); celaTimeMills = System.currentTimeMillis() - celaTimeMills; NavigableSet<? extends EvaluatedDescription> evaluatedDescriptions = cela.getCurrentlyBestEvaluatedDescriptions(); if (cela.getLearningProblem() instanceof ClassLearningProblem) { try { finalOntology = replaceDummyClass(finalOntology, learnedAxioms);
try { lp.init(); la.setLearningProblem(lp); la.init(); } catch (ComponentInitException e) { la.start(); long algorithmDuration = System.nanoTime() - algorithmStartTime; runtime.addNumber(algorithmDuration/(double)1000000000); OWLClassExpression concept = la.getCurrentlyBestDescription();
cela.start(); celaTimeMills = System.currentTimeMillis() - celaTimeMills; NavigableSet<? extends EvaluatedDescription> evaluatedDescriptions = cela.getCurrentlyBestEvaluatedDescriptions(); if (cela.getLearningProblem() instanceof ClassLearningProblem) { finalOntology = replaceSuperClass(finalOntology, bestRevision.getLearnedAxioms()); } else {
@Override public void run() { la.start(); } });
/** * Starts the learning algorithm and returns the best concept found. This * method will block until learning is completed. * * @param id Session ID. * @param format The format of the result string: "manchester", "kb", "dl". * @return The best solution found. * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public String learn(int id, String format) throws ClientNotKnownException { ClientState state = getState(id); state.getLearningAlgorithm().start(); OWLClassExpression solution = state.getLearningAlgorithm().getCurrentlyBestDescription(); switch (format) { case "manchester": return OWLAPIRenderers.toManchesterOWLSyntax(solution); case "kb": return OWLAPIRenderers.toManchesterOWLSyntax(solution); default: return solution.toString(); } }
protected String getSolutionString() { int current = 1; String str = ""; for(EvaluatedDescription<? extends Score> ed : getCurrentlyBestEvaluatedDescriptions().descendingSet()) { String descriptionString = descriptionToString(description); if(learningProblem instanceof PosNegLP) { Set<OWLIndividual> positiveExamples = ((PosNegLP)learningProblem).getPositiveExamples();
/** * @param la the basic learning algorithm */ public DisjunctiveCELA(AbstractCELA la) { this.la = la; this.lp = la.getLearningProblem(); }
/** * 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(); }
/** * @see #getCurrentlyBestEvaluatedDescription() * @return The best class OWLClassExpression found by the learning algorithm so far. */ public OWLClassExpression getCurrentlyBestDescription() { return getCurrentlyBestEvaluatedDescription().getDescription(); }
/** * * @param id The session ID. * @return * @throws ClientNotKnownException Thrown if client (session ID) is not known. */ @WebMethod public boolean isAlgorithmRunning(int id) throws ClientNotKnownException { return getState(id).getLearningAlgorithm().isRunning(); }
la.init(); la.start(); System.out.println(la.getCurrentlyBestEvaluatedDescriptions(10, 0.8, true));