001 package aima.learning.knowledge; 002 003 import java.util.List; 004 005 import aima.logic.fol.kb.FOLKnowledgeBase; 006 import aima.logic.fol.kb.data.Clause; 007 008 /** 009 * Artificial Intelligence A Modern Approach (2nd Edition): Figure 19.2, page 681. 010 * 011 * <code> 012 * function CURRENT-BEST-LEARNING(examples) returns a hypothesis 013 * 014 * H <- any hypothesis consistent with the first example in examples. 015 * for each remaining example in examples do 016 * if e is false positive for H then 017 * H <- choose a specialization of H consistent with examples 018 * else if e is false negative for H then 019 * H <- choose a generalization of H consistent with examples 020 * if no consistent specialization/generalization can be found then fail 021 * return H 022 * </code> 023 * 024 * Figure 19.2 The current-best-hypothesis learning algorithm. It searches for a consistent 025 * hypothesis and backtracks when no consistent specialization/generalization can be found. 026 */ 027 028 /** 029 * @author Ciaran O'Reilly 030 * 031 */ 032 public class CurrentBestLearning { 033 private FOLDataSetDomain folDSDomain = null; 034 private FOLKnowledgeBase kbForLearning = null; 035 036 // 037 // PUBLIC METHODS 038 // 039 public CurrentBestLearning(FOLDataSetDomain folDSDomain, FOLKnowledgeBase kbForLearning) { 040 this.folDSDomain = folDSDomain; 041 this.kbForLearning = kbForLearning; 042 } 043 044 // * function CURRENT-BEST-LEARNING(examples) returns a hypothesis 045 public Hypothesis currentBestLearning(List<FOLExample> examples) { 046 047 // TODO-use the default from pg 679 for now. 048 String c1 = "patrons(v,Some)"; 049 String c2 = "patrons(v,Full) AND (hungry(v) AND type(v,French))"; 050 String c3 = "patrons(v,Full) AND (hungry(v) AND (type(v,Thai) AND fri_sat(v)))"; 051 String c4 = "patrons(v,Full) AND (hungry(v) AND type(v,Burger))"; 052 String sh = "FORALL v (will_wait(v) <=> ("+c1+" OR ("+c2+" OR ("+c3+" OR ("+c4+")))))"; 053 054 Hypothesis H = new Hypothesis(kbForLearning.tell(sh)); 055 056 // TODO 057 // * H <- any hypothesis consistent with the first example in examples. 058 // * for each remaining example in examples do 059 // * if e is false positive for H then 060 // * H <- choose a specialization of H consistent with examples 061 // * else if e is false negative for H then 062 // * H <- choose a generalization of H consistent with examples 063 // * if no consistent specialization/generalization can be found then 064 // fail 065 // * return H 066 return H; 067 } 068 069 // 070 // PRIVATE METHODS 071 // 072 }