lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

31
CS 188: Artificial Intelligence CSPs II + Local Search Prof. Scott Niekum The University of Texas at Austin [These slides based on those of Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at http://ai.berkeley.edu.]

Transcript of lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Page 1: 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.]

Page 2: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Lasttime:CSPs

▪ CSPs:▪ Variables▪ Domains▪ Constraints

▪ Implicit(providecodetocompute)▪ Explicit(providealistofthelegaltuples)▪ Unary/Binary/N-ary

▪ Goals:▪ Here:findanysolution▪ Also:findall,findbest,etc.

Page 3: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Lasttime:Backtracking

Page 4: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Lasttime:ArcConsistencyofanEntireCSP

▪ Asimpleformofpropagationmakessureallarcsareconsistent:

▪ Important:IfXlosesavalue,neighborsofXneedtoberechecked!▪ Arcconsistencydetectsfailureearlierthanforwardchecking▪ Canberunasapreprocessororaftereachassignment▪ What’sthedownsideofenforcingarcconsistency?

Remember:Deletefromthetail!

WA SA

NT Q

NSW

V

Page 5: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

LimitationsofArcConsistency

▪ Afterenforcingarcconsistency:▪ Canhaveonesolutionleft▪ Canhavemultiplesolutionsleft

▪ Canhavenosolutionsleft(andnotknowit)

▪ Arcconsistencystillrunsinsideabacktrackingsearch! Whatwent

wronghere?

Page 6: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

ImprovingBacktracking

▪ General-purposeideasgivehugegainsinspeed▪ …butit’sallstillNP-hard

▪ Filtering:Canwedetectinevitablefailureearly?

▪ Ordering:▪ Whichvariableshouldbeassignednext?(MRV)▪ Inwhatordershoulditsvaluesbetried?(LCV)

▪ Structure:Canweexploittheproblemstructure?

Page 7: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Structure

Page 8: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

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

Page 9: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Tree-StructuredCSPs

▪ Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)time▪ ComparetogeneralCSPs,whereworst-casetimeisO(dn)

▪ Thispropertyalsoappliestoprobabilisticreasoning(later):anexampleoftherelationbetweensyntacticrestrictionsandthecomplexityofreasoning

Page 10: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

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?)

Page 11: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

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

Page 12: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

NearlyTree-StructuredCSPs

▪ Conditioning:instantiateavariable,pruneitsneighbors'domains

▪ Cutsetconditioning:instantiate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree

▪ CutsetsizecgivesruntimeO((dc)(n-c)d2),veryfastforsmallc

Page 13: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

CutsetConditioning

Instantiatethecutset(allpossibleways)

ComputeresidualCSPforeachassignment

SolvetheresidualCSPs(treestructured),removinganyinconsistentdomainvaluesw.r.t.

cutsetassignment

Chooseacutset

SA

SA SA SA dc

(n-c)d2

Page 14: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

CutsetQuiz

▪ Findthesmallestcutsetforthegraphbelow.

Page 15: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

IterativeImprovement

Page 16: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

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)

Page 17: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Example:4-Queens

▪ States:4queensin4columns(44=256states)▪ Operators:movequeenincolumn▪ Goaltest:noattacks▪ Evaluation:c(n)=numberofattacks

Page 18: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

VideoofDemoIterativeImprovement–nQueens

Page 19: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

PerformanceofMin-Conflicts

▪ Runtimeofmin-conflictsisonn-queensisroughlyindependentofproblemsize!▪ Why??Solutionsaredenselydistributedinstatespace

▪ Givenrandominitialstate,cansolven-queensinalmostconstanttimeforarbitrarynwithhighprobability(e.g.,n=10,000,000)in~50steps!

▪ Thesameappearstobetrueforanyrandomly-generatedCSPexceptinanarrowrangeoftheratio

Page 20: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Summary:CSPs

▪ CSPsareaspecialkindofsearchproblem:▪ Statesarepartialassignments▪ Goaltestdefinedbyconstraints

▪ Basicsolution:backtrackingsearch

▪ Speed-ups:▪ Ordering▪ Filtering▪ Structure

▪ Iterativemin-conflictsisofteneffectiveinpractice

Page 21: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

LocalSearch

Page 22: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

LocalSearch

▪ Treesearchkeepsunexploredalternativesonthefringe(ensurescompleteness)

▪ Localsearch:improveasingleoptionuntilyoucan’tmakeitbetter(nofringe!)

▪ Newsuccessorfunction:localchanges

▪ Generallymuchfasterandmorememoryefficient(butincompleteandsuboptimal)

Page 23: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

HillClimbing

▪ Simple,generalidea:▪ Startwherever▪ Repeat:movetothebestneighboringstate▪ Ifnoneighborsbetterthancurrent,quit

▪ What’sbadaboutthisapproach?▪ Complete?▪ Optimal?

▪ What’sgoodaboutit?

Page 24: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

HillClimbingDiagram

Page 25: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

HillClimbingQuiz

StartingfromX,wheredoyouendup? StartingfromY,wheredoyouendup?

StartingfromZ,wheredoyouendup?

Page 26: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

SimulatedAnnealing

▪ Idea:Escapelocalmaximabyallowingdownhillmoves▪ Butmakethemrarerastimegoeson

!26

Shake!

Shake!

Page 27: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

SimulatedAnnealing

▪ Theoreticalguarantee:▪ IfTdecreasedslowlyenough, willconvergetooptimalstate!

▪ Isthisaninterestingguarantee?

▪ Soundslikemagic,butrealityisreality:▪ Themoredownhillstepsyouneedtoescapealocaloptimum,thelesslikelyyouaretoevermakethemallinarow

Page 28: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

BeamSearch

▪ Likegreedyhillclimbingsearch,butkeepKstatesatalltimes:

▪ Variables:beamsize,encouragediversity?▪ ThebestchoiceinMANYpracticalsettings▪ Complete?Optimal?▪ Whydowestillneedoptimalmethods?

Greedy Search Beam Search

Page 29: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

GradientMethods

▪ Continuousstatespaces▪ Problem!Cannotselectoptimalsuccessor

▪ Discretizationorrandomsampling▪ Choosefromafinitenumberofchoices

▪ Continuousoptimization:Gradientascent▪ Takeastepalongthegradient(vectorofpartialderivatives)

▪ Whatifyoucan’tcomputegradient?▪ i.e.maybeyoucanonlysamplethefunction▪ Estimategradientfromsamples!▪ “Stochasticgradientdescent”▪ Wewillreturntothisinneuralnetworks/deeplearning

Page 30: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

GeneticAlgorithms

▪ Geneticalgorithmsuseanaturalselectionmetaphor▪ KeepbestNhypothesesateachstep(selection)basedonafitnessfunction▪ Alsohavepairwisecrossoveroperators,withoptionalmutationtogivevariety

▪ Possiblythemostmisunderstood,misapplied(andevenmaligned)techniquearound

Page 31: lecture6 · 2019. 8. 29. · Title: lecture6 Created Date: 9/19/2018 2:20:42 AM

Example:N-Queens

▪ Whydoescrossovermakesensehere?▪ Whenwouldn’titmakesense?▪ Whatwouldmutationbe?▪ Whatwouldagoodfitnessfunctionbe?