001/**
002 * Copyright (C) 2007 - 2016, 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 */
019package org.dllearner.algorithms.celoe;
020
021import org.dllearner.core.AbstractHeuristic;
022import org.dllearner.core.ComponentAnn;
023import org.dllearner.core.ComponentInitException;
024import org.dllearner.core.config.ConfigOption;
025
026/**
027 * Search algorithm heuristic for the ontology engineering algorithm. The heuristic
028 * has a strong bias towards short descriptions (i.e. the algorithm is likely to be
029 * less suitable for learning complex descriptions).
030 * 
031 * @author Jens Lehmann
032 *
033 */
034@ComponentAnn(name = "OEHeuristicRuntime", shortName = "celoe_heuristic", version = 0.5)
035public class OEHeuristicRuntime extends AbstractHeuristic{
036        
037        
038        @ConfigOption(description = "penalty for long descriptions (horizontal expansion) (strong by default)", defaultValue = "0.1")
039        private double expansionPenaltyFactor = 0.1;
040        @ConfigOption(description = "bonus for being better than parent node", defaultValue = "0.3")
041        private double gainBonusFactor = 0.3;
042        @ConfigOption(description = "penalty if a node description has very many refinements since exploring such a node is computationally very expensive",
043                        defaultValue = "0.0001")
044        private double nodeRefinementPenalty = 0.0001;
045        
046        @ConfigOption(defaultValue="0.1")
047        private double startNodeBonus = 0.1;
048        
049        public OEHeuristicRuntime() {
050
051        }
052        
053        @Override
054        public void init() throws ComponentInitException {
055
056                initialized = true;
057        }
058
059        @Override
060        public double getNodeScore(OENode node) {
061                // accuracy as baseline
062                double score = node.getAccuracy();
063
064                // being better than the parent gives a bonus;
065                if(!node.isRoot()) {
066                        double accuracyGain = node.getAccuracy() - node.getParent().getAccuracy();
067                        score += accuracyGain * gainBonusFactor;
068                // the root node also gets a bonus to possibly spawn useful disjunctions
069                } else {
070                        score += startNodeBonus;
071                }
072
073                // penalty for horizontal expansion
074                score -= (node.getHorizontalExpansion() - 1) * expansionPenaltyFactor;
075
076                // penalty for having many child nodes (stuck prevention)
077                score -= node.getRefinementCount() * nodeRefinementPenalty;
078
079                return score;
080        }
081
082        public double getExpansionPenaltyFactor() {
083                return expansionPenaltyFactor;
084        }
085
086        public double getGainBonusFactor() {
087                return gainBonusFactor;
088        }
089
090        public void setGainBonusFactor(double gainBonusFactor) {
091                this.gainBonusFactor = gainBonusFactor;
092        }
093
094        public double getNodeRefinementPenalty() {
095                return nodeRefinementPenalty;
096        }
097
098        public void setNodeRefinementPenalty(double nodeRefinementPenalty) {
099                this.nodeRefinementPenalty = nodeRefinementPenalty;
100        }
101
102        public void setExpansionPenaltyFactor(double expansionPenaltyFactor) {
103                this.expansionPenaltyFactor = expansionPenaltyFactor;
104        }
105
106        public double getStartNodeBonus() {
107                return startNodeBonus;
108        }
109
110        public void setStartNodeBonus(double startNodeBonus) {
111                this.startNodeBonus = startNodeBonus;
112        }
113
114}