lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM
Transcript of lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM
CS188:ArtificialIntelligenceCSPsII+LocalSearch
Prof.ScottNiekum
TheUniversityofTexasatAustin
[TheseslidesbasedonthoseofDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]
Lasttime:CSPs
▪ CSPs:▪ Variables▪ Domains▪ Constraints
▪ Implicit(providecodetocompute)▪ Explicit(providealistofthelegaltuples)▪ Unary/Binary/N-ary
▪ Goals:▪ Here:findanysolution▪ Also:findall,findbest,etc.
Lasttime:Backtracking
Lasttime:ArcConsistencyofanEntireCSP
▪ Asimpleformofpropagationmakessureallarcsareconsistent:
▪ Important:IfXlosesavalue,neighborsofXneedtoberechecked!▪ Arcconsistencydetectsfailureearlierthanforwardchecking▪ Canberunasapreprocessororaftereachassignment▪ What’sthedownsideofenforcingarcconsistency?
Remember:Deletefromthetail!
WA SA
NT Q
NSW
V
LimitationsofArcConsistency
▪ Afterenforcingarcconsistency:▪ Canhaveonesolutionleft▪ Canhavemultiplesolutionsleft
▪ Canhavenosolutionsleft(andnotknowit)
▪ Arcconsistencystillrunsinsideabacktrackingsearch! Whatwent
wronghere?
ImprovingBacktracking
▪ General-purposeideasgivehugegainsinspeed▪ …butit’sallstillNP-hard
▪ Filtering:Canwedetectinevitablefailureearly?
▪ Ordering:▪ Whichvariableshouldbeassignednext?(MRV)▪ Inwhatordershoulditsvaluesbetried?(LCV)
▪ Structure:Canweexploittheproblemstructure?
Structure
ProblemStructure
▪ Extremecase:independentsubproblems▪ Example:Tasmaniaandmainlanddonotinteract
▪ Independentsubproblemsareidentifiableasconnectedcomponentsofconstraintgraph
▪ Supposeagraphofnvariablescanbebrokenintosubproblemsofonlycvariables:▪ Worst-casesolutioncostisO((n/c)(dc)),linearinn▪ E.g.,n=80,d=2,c=20▪ 280=4billionyearsat10millionnodes/sec▪ (4)(220)=0.4secondsat10millionnodes/sec
Tree-StructuredCSPs
▪ Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)time▪ ComparetogeneralCSPs,whereworst-casetimeisO(dn)
▪ Thispropertyalsoappliestoprobabilisticreasoning(later):anexampleoftherelationbetweensyntacticrestrictionsandthecomplexityofreasoning
Tree-StructuredCSPs
▪ Algorithmfortree-structuredCSPs:▪ Order:Choosearootvariable,ordervariablessothatparentsprecedechildren
▪ Removebackward:Fori=n:2,applyRemoveInconsistent(Parent(Xi),Xi)▪ Assignforward:Fori=1:n,assignXiconsistentlywithParent(Xi)
▪ Runtime:O(nd2)(why?)
Tree-StructuredCSPs
▪ Claim1:Afterbackwardpass,allroot-to-leafarcsareconsistent▪ Proof:EachX→YwasmadeconsistentatonepointandY’sdomaincouldnothavebeen
reducedthereafter(becauseY’schildrenwereprocessedbeforeY)
▪ Claim2:Ifroot-to-leafarcsareconsistent,forwardassignmentwillnotbacktrack▪ Proof:Inductiononposition
▪ Whydoesn’tthisalgorithmworkwithcyclesintheconstraintgraph?
▪ Note:we’llseethisbasicideaagainwithBayes’nets
NearlyTree-StructuredCSPs
▪ Conditioning:instantiateavariable,pruneitsneighbors'domains
▪ Cutsetconditioning:instantiate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree
▪ CutsetsizecgivesruntimeO((dc)(n-c)d2),veryfastforsmallc
CutsetConditioning
Instantiatethecutset(allpossibleways)
ComputeresidualCSPforeachassignment
SolvetheresidualCSPs(treestructured),removinganyinconsistentdomainvaluesw.r.t.
cutsetassignment
Chooseacutset
SA
SA SA SA dc
(n-c)d2
CutsetQuiz
▪ Findthesmallestcutsetforthegraphbelow.
IterativeImprovement
IterativeAlgorithmsforCSPs
▪ Localsearchmethodstypicallyworkwith“complete”states,i.e.,allvariablesassigned
▪ ToapplytoCSPs:▪ Takeanassignmentwithunsatisfiedconstraints▪ Operatorsreassignvariablevalues▪ Nofringe!Liveontheedge.
▪ Algorithm:Whilenotsolved,▪ Variableselection:randomlyselectanyconflictedvariable▪ Valueselection:min-conflictsheuristic:
▪ Chooseavaluethatviolatesthefewestconstraints▪ I.e.,hillclimbwithh(n)=totalnumberofviolatedconstraints
▪ Cangetstuckinlocalminima(we’llcomebacktothisideainafewslides)
Example:4-Queens
▪ States:4queensin4columns(44=256states)▪ Operators:movequeenincolumn▪ Goaltest:noattacks▪ Evaluation:c(n)=numberofattacks
VideoofDemoIterativeImprovement–nQueens
PerformanceofMin-Conflicts
▪ Runtimeofmin-conflictsisonn-queensisroughlyindependentofproblemsize!▪ Why??Solutionsaredenselydistributedinstatespace
▪ Givenrandominitialstate,cansolven-queensinalmostconstanttimeforarbitrarynwithhighprobability(e.g.,n=10,000,000)in~50steps!
▪ Thesameappearstobetrueforanyrandomly-generatedCSPexceptinanarrowrangeoftheratio
Summary:CSPs
▪ CSPsareaspecialkindofsearchproblem:▪ Statesarepartialassignments▪ Goaltestdefinedbyconstraints
▪ Basicsolution:backtrackingsearch
▪ Speed-ups:▪ Ordering▪ Filtering▪ Structure
▪ Iterativemin-conflictsisofteneffectiveinpractice
LocalSearch
LocalSearch
▪ Treesearchkeepsunexploredalternativesonthefringe(ensurescompleteness)
▪ Localsearch:improveasingleoptionuntilyoucan’tmakeitbetter(nofringe!)
▪ Newsuccessorfunction:localchanges
▪ Generallymuchfasterandmorememoryefficient(butincompleteandsuboptimal)
HillClimbing
▪ Simple,generalidea:▪ Startwherever▪ Repeat:movetothebestneighboringstate▪ Ifnoneighborsbetterthancurrent,quit
▪ What’sbadaboutthisapproach?▪ Complete?▪ Optimal?
▪ What’sgoodaboutit?
HillClimbingDiagram
HillClimbingQuiz
StartingfromX,wheredoyouendup? StartingfromY,wheredoyouendup?
StartingfromZ,wheredoyouendup?
SimulatedAnnealing
▪ Idea:Escapelocalmaximabyallowingdownhillmoves▪ Butmakethemrarerastimegoeson
!26
Shake!
Shake!
SimulatedAnnealing
▪ Theoreticalguarantee:▪ IfTdecreasedslowlyenough, willconvergetooptimalstate!
▪ Isthisaninterestingguarantee?
▪ Soundslikemagic,butrealityisreality:▪ Themoredownhillstepsyouneedtoescapealocaloptimum,thelesslikelyyouaretoevermakethemallinarow
BeamSearch
▪ Likegreedyhillclimbingsearch,butkeepKstatesatalltimes:
▪ Variables:beamsize,encouragediversity?▪ ThebestchoiceinMANYpracticalsettings▪ Complete?Optimal?▪ Whydowestillneedoptimalmethods?
Greedy Search Beam Search
GradientMethods
▪ Continuousstatespaces▪ Problem!Cannotselectoptimalsuccessor
▪ Discretizationorrandomsampling▪ Choosefromafinitenumberofchoices
▪ Continuousoptimization:Gradientascent▪ Takeastepalongthegradient(vectorofpartialderivatives)
▪ Whatifyoucan’tcomputegradient?▪ i.e.maybeyoucanonlysamplethefunction▪ Estimategradientfromsamples!▪ “Stochasticgradientdescent”▪ Wewillreturntothisinneuralnetworks/deeplearning
GeneticAlgorithms
▪ Geneticalgorithmsuseanaturalselectionmetaphor▪ KeepbestNhypothesesateachstep(selection)basedonafitnessfunction▪ Alsohavepairwisecrossoveroperators,withoptionalmutationtogivevariety
▪ Possiblythemostmisunderstood,misapplied(andevenmaligned)techniquearound
Example:N-Queens
▪ Whydoescrossovermakesensehere?▪ Whenwouldn’titmakesense?▪ Whatwouldmutationbe?▪ Whatwouldagoodfitnessfunctionbe?