ai-unit-1-ai-notes
ai-unit-1-ai-notes
ARTIFICIALINTELLIGENCE
Whatisartificialintelligence?
• "Itisabranchofcomputersciencebywhichwecancreateintelligentmachineswhich can
behave like a human, think like humans, and able to make decisions."
• Artificial Intelligence is composed of two words Artificial and Intelligence, where
Artificialdefines"man-made,"andintelligencedefines"thinkingpower",henceAI
means "a man-made thinking power.“
Itiscurrentlyworkingwithavarietyofsubfields,rangingfromgeneraltospecific,such asself-
driving cars, playing chess, proving theorems, playing music, Painting, etc.
GoalsofAI
• ToCreateExpertSystems−Thesystemswhichexhibitintelligentbehavior,learn,
demonstrate, explain, and advice its users.
• ToImplementHumanIntelligenceinMachines−Creatingsystemsthatunderstand,think, learn,
and behave like humans.
ApplicationsofArtificialIntelligence:
1. Gaming − AI plays crucial role in strategic games such as chess, poker, tic-tac-toe, etc.,
where machine can think of large number of possible positions based on heuristic
knowledge.
2. NaturalLanguageProcessing − It is possible to interact with the computer that
understands natural language spoken by humans.
3. ExpertSystems − There are some applications which integrate machine, software, and
special information to impart reasoning and advising.They provide explanation and advice
to the users.
4. VisionSystems − these systems understand, interpret, and comprehend visual input on the
computer. For example,
Aspyingaeroplanetakesphotographs,whichareusedtofigureoutspatialinformationor map of
the areas.
Doctorsuseclinicalexpertsystemtodiagnosethe patient.
Policeusecomputersoftwarethatcanrecognizethefaceofcriminalwiththestored portrait
made by forensic artist.
5. SpeechRecognition − It can handle different accents, slang words, noise in the
background, change in human’s noise due to cold, etc.
6. HandwritingRecognition −thehandwritingrecognitionsoftwarereadsthetextwrittenon paper
by a pen or on screen by a stylus. It can recognize the shapes of the letters and convert it
into editable text.
7. IntelligentRobots − Robots are able to perform the tasks given by a human. They have
sensors to detect physical data from the real world such as light, heat, temperature,
movement, sound, bump, and pressure.
HistoryofAI
MaturationofArtificialIntelligence(1943-1952)
1. Year1943: The first work which is now recognized asAI was done byWarren McCulloch
and Walter pits in 1943. They proposed a model of artificialneurons.
2. Year1949: Donald Hebb demonstrated an updating rule for modifying the connection
strength between neurons. His rule is now called Hebbianlearning.
3. Year1950: The Alan Turing who was an English mathematician and pioneered Machine
learning in 1950. Alan Turing publishes "ComputingMachineryandIntelligence" in
which he proposed a test. The test can check the machine's ability to exhibit intelligent
behavior equivalent to human intelligence, called a Turingtest.
ThebirthofArtificialIntelligence(1952-1956)
1. Year1955: AnAllen Newell and HerbertA. Simon created the "first artificial intelligence
program" Which was named as "LogicTheorist". This program had proved 38 of 52
Mathematics theorems, and find new and more elegant proofs for some theorems.
2. Year1956:Theword"ArtificialIntelligence"firstadoptedbyAmericanComputerscientist John
McCarthy at the Dartmouth Conference. For the first time, AI coined as an academic field.
At that time high-level computer languages such as FORTRAN, LISP, or COBOL were invented.
And the enthusiasm forAI was very high at that time.
Thegoldenyears-Earlyenthusiasm(1956-1974)
1. Year1966: The researchers emphasized developing algorithms which can solve
mathematical problems. Joseph Weizenbaum created the first chatbot in 1966, which was
named as ELIZA.
2. Year1972: The first intelligent humanoid robot was built in Japan which was named as
WABOT-1.
ThefirstAIwinter(1974-1980)
1. The duration between years 1974 to 1980 was the firstAI winter duration.AI winter refers to
the time period where computer scientist dealt with a severe shortage of funding from
government for AI researches.
2. DuringAIwinters,aninterestofpublicityonartificialintelligencewasdecreased.
AboomofAI (1980-1987)
1. Year1980:AfterAIwinterduration,AIcamebackwith"ExpertSystem".Expertsystems were
programmed that emulate the decision-making ability of a human expert.
2. IntheYear1980,thefirstnationalconferenceoftheAmericanAssociationofArtificial
Intelligence washeldatStanfordUniversity.
ThesecondAIwinter(1987-1993)
1. Thedurationbetweentheyears1987to1993wasthesecondAIWinterduration.
2. AgainInvestorsandgovernmentstoppedinfundingforAIresearchasduetohighcostbut not
efficient result. The expert system such as XCON was very cost effective.
Theemergenceofintelligentagents(1993-2011)
1. Year1997:Intheyear1997,IBMDeepBluebeatsworldchesschampion,GaryKasparov, and
became the first computer to beat a world chess champion.
2. Year2002:forthefirsttime,AIenteredthehomeintheformofRoomba,avacuum cleaner.
3. Year2006:AIcameintheBusinessworldtilltheyear2006.CompanieslikeFacebook,
Twitter, and Netflix also started using AI.
Deeplearning,bigdataandartificialgeneralintelligence(2011-present)
1. Year2011: In the year 2011, IBM's Watson won jeopardy, a quiz show, where it had to
solve the complex questions as well as riddles. Watson had proved that it could understand
natural language and can solve tricky questions quickly.
2. Year2012: Google has launched anAndroid app feature "Google now", which was able to
provide information to the user as a prediction.
3. Year2014: In the year 2014, Chatbot "Eugene Goostman" won a competition in the
infamous "Turing test."
4. Year2018: The "Project Debater" from IBM debated on complex topics with two master
debaters and also performed extremely well.
5. Google has demonstrated anAI program "Duplex" which was a virtual assistant and which
had taken hairdresser appointment on call, and lady on other side didn't notice that she was
talking with the machine.
STATEOFART
Agentsandenvironments:
Anagentisanythingthatcanbeviewedasperceivingitsenvironmentthroughsensorsand sensor
acting upon that environment through actuators.
1. Ahuman agent has eyes, ears, and other organs for sensors and hands, legs, mouth, and
other body parts for actuators.
2. Arobotic agent might have cameras and infrared range finders for sensors andvarious
motors for actuators.
3. A software agent receives keystrokes, file contents, and network packets as sensory
inputs and acts on the environment by displaying on the screen, writing files, and
sending network packets.
FIG:AGENTWORKING
Sensor: Sensor is a device which detects the change in the environment and sends the information
to other electronic devices.An agent observes its environment through sensors.
Actuators: Actuators are the component of machines that converts energy into motion. The
actuators are only responsible for moving and controlling a system.An actuator can be an electric
motor, gears, rails, etc.
Effectors: Effectors are the devices which affect the environment. Effectors can be legs, wheels,
arms, fingers, wings, fins, and display screen.
Percept
Weusethetermpercepttorefertotheagent'sperceptualinputsatanygiveninstant. Percept
Sequence
Anagent'sperceptsequenceisthecompletehistoryofeverythingtheagenthasever perceived.
Agentfunction
Mathematicallyspeaking,wesaythatanagent'sbehaviorisdescribedbytheagentfunction
thatmapsanygivenperceptsequencetoanaction.
Agentprogram
Agent function
PerceptSequence Action
[A,Clean] Right
[A,Dirty] Suck
[B,Clean] Left
[B,Dirty] Suck
[A,Clean],[A,Clean] Right
[A,Clean],[A,Dirty] Suck
….. …..
Agent program
functionReflex-VACUUM-AGENT([locations,status])returnsanactionif status = Dirty
thenreturn Suck
elseiflocation=AthenreturnRight
elseiflocation=BthenreturnLeft
IntelligentAgents:
An intelligent agent is an autonomous entity which act upon an environment using sensors and
actuators for achieving goals.An intelligent agent may learn from the environment to achieve their
goals. Athermostat is an example of an intelligent agent.
o Rule1:AnAIagentmusthavethe abilitytoperceivetheenvironment.
o Rule2:Theobservationmust beusedtomakedecisions.
o Rule3:Decisionshouldresultinanaction.
o Rule4:Theaction takenbyanAI agentmustbearationalaction.
StructureofanAIAgent
ThetaskofAIistodesignanagentprogramwhichimplementstheagentfunction.Thestructureof an
intelligent agent is a combination of architecture and agent program. It can be viewed as:
Agent=Architecture+Agent program
Architecture:ArchitectureismachinerythatanAIagentexecuteson.
AgentFunction:Agentfunctionisusedtomapapercepttoanaction.
Agentprogram:Agentprogramisanimplementationofagentfunction.Anagentprogram executes
on the physical architecture to produce function f.
RationalAgent:
GoodBehavior:theconceptofRationality
Rationality:
o Performancemeasurewhichdefinesthesuccesscriterion.
o Agentpriorknowledgeofitsenvironment.
o Bestpossibleactionsthatanagentcanperform.
o Thesequenceof percepts.
Performance measures
1. Aperformance measureembodiesthecriterionforsuccessofanagent'sbehavior.
2. Whenanagentisplunkeddowninanenvironment,itgeneratesasequenceof
actionsaccordingtotheperceptsitreceives.
3. Thissequenceofactionscausesthe environmenttogothroughasequence ofstates.
4. Ifthesequenceisdesirable,thentheagent hasperformedwell.
PEAS Representation
PEAS is a type of model on which an AI agent works upon. When we define an AI agent or
rational agent, then we can group its properties under PEAS representation model. It is made up
of four words:
o P:Performancemeasure
o E:Environment
o A:Actuators
o S:Sensors
Examples:
1) SelfDrivingcar
Performance:Healthypatient,Minimizedcost
Environment: Patient,Hospital,Staff
Actuators: Tests,Treatments
Sensors:Keyboard(Entryofsymptoms)
3) VacuumCleaner
Performance:Cleanness,Efficiency,Batterylife,Security
Environment:Patient,Hospital,Staff
Actuators:Wheels,Brushes,Vacuum,Extractor
Sensors:Camera,Dirtdetectionsensor,Cliffsensor,BumpSensor,InfraredWallSensor
4) Part-pickingRobot
Performance:Percentageofpartsincorrectbins.
Environment: Conveyor belt with parts,Bins
Actuators: Jointed Arms,Hand
Sensors:Camera,Jointanglesensors.
TypesofAgents
Agentscanbegroupedintofourclassesbasedontheirdegreeofperceivedintelligenceandcapability:
• SimpleReflexAgents
• Model-BasedReflexAgents
• Goal-BasedAgents
• Utility-BasedAgents
• Learning Agent
Simplereflexagents
Simple reflex agents ignore the rest of the percept history and act only on the basis of thecurrentpercept.
Theagentfunctionisbasedonthecondition-actionrule.Acondition-actionruleisarulethatmapsastatei.e, condition
to an action. If the condition is true, then the action is taken, else not.
ProblemswithSimplereflexagentsare:
• Verylimitedintelligence.
• Noknowledgeofnon-perceptualpartsofthestate.
• Usuallytoobigtogenerateandstore.
• Ifthereoccursanychangeintheenvironment,thenthecollectionof rulesneedstobeupdated.
Model-basedreflexagents
Itworksbyfindingarulewhoseconditionmatchesthecurrentsituation.Amodel-basedagentcan
Handlepartiallyobservableenvironments bytheuseofamodelabouttheworld.Theagenthastokeeptrack Of the
internalstate which is adjusted by each percept and that depends on the percept history.The current state is
stored inside the agent which maintains some kind of structure describing the part of the world which
cannotbeseen.
Updatingthestaterequiresinformationabout:
• howtheworldevolvesindependentlyfromtheagent,and
• howtheagent’sactionsaffecttheworld.
Goal-basedagents
These kinds of agents take decisions based on how far they are currently from their goal (description of
desirablesituations).Theireveryactionisintendedtoreduceitsdistancefromthegoal.Thisallowstheagenta way to
choose among multiple possibilities, selecting the one which reaches a goal state. The knowledge that supports
its decisions is represented explicitly and can be modified, which makes these agents moreflexible. They
usually require search and planning. The goal-based agent’s behavior can easily be changed.
Utility-basedagents
Theagentswhich aredeveloped having theirendusesasbuildingblocksarecalled utility-based agents.When there
are multiple possible alternatives, then to decide which one is best, utility-based agents are used. They choose
actions based on a preference(utility) for each state. Sometimes achieving the desired goal is not
enough.Wemaylookforaquicker,safer, cheaper triptoreachadestination.Agenthappinessshouldbetaken into
consideration. Utility describes how“happy” the agent is. Because of the uncertainty in the world, a utility
agent chooses the action that maximizes the expected utility.Autility function maps a state onto a real number
which describes the associated degree ofhappiness.
LearningAgent:
Alearning agent inAI is the type of agent that can learn from its past experiences or it has learning
capabilities.Itstartstoactwithbasicknowledgeandthenisabletoactandadaptautomaticallythrough learning.
Alearningagenthasmainlyfourconceptualcomponents,which are:
1. Learningelement:Itisresponsibleformakingimprovementsbylearningfromtheenvironment
2. Critic:Thelearningelementtakesfeedbackfromcriticswhichdescribeshowwelltheagentisdoingwith respect
to a fixed performancestandard.
3. Performanceelement:Itisresponsibleforselectingexternalaction
4. ProblemGenerator:Thiscomponentisresponsibleforsuggestingactionsthatwillleadtonewand
informative experiences.
TheNatureofEnvironments
Anenvironmentiseverythingintheworldwhichsurroundstheagent,butitisnotapartofan agent
itself.An environment can be described as a situation in which an agent is present.
Anenvironmentiseverythingintheworldwhichsurroundstheagent,butitisnotapartofan agent
itself.An environment can be described as a situation in which an agent is present.
1. FullyobservablevsPartially Observable:
1. Ifanagentsensorcansenseoraccessthecompletestateofanenvironmentateachpointof time then
it is afullyobservable environment, else it is partiallyobservable.
2. Afullyobservableenvironmentiseasyasthereisnoneedtomaintaintheinternalstateto keep
track history of the world.
3. Anagentwithnosensorsinallenvironmentsthensuchanenvironmentiscalledas
unobservable.
2. Deterministicvs Stochastic:
1. If the next state of the environment is completely determined by the current state and the
actionexecutedbytheagent,thensuchenvironmentiscalledadeterministicenvironment.
2. Astochasticenvironmentisrandominnatureandcannotbedeterminedcompletelybyan agent.
3. Inadeterministic,fullyobservableenvironment,agentdoesnotneedtoworryabout
uncertainty.
3. Episodicvs Sequential:
1. Inanepisodicenvironment,thereisaseriesofone-shotactions,andonlythecurrent percept
is required for the action.
2. However,inSequentialenvironment,anagentrequiresmemoryofpastactionsto
determine the next best actions.
4. Single-agentvsMulti-agent
1. Ifonlyoneagentisinvolvedinanenvironment,andoperatingbyitselfthensuchan
environment is called single agent environment.
2. However,ifmultipleagentsareoperatinginanenvironment,thensuchanenvironmentis called
a multi-agent environment.
3. Theagentdesignproblemsinthemulti-agentenvironmentaredifferentfromsingleagent
environment.
5. Staticvs Dynamic:
1. Iftheenvironmentcanchangeitselfwhileanagentisdeliberatingthensuchenvironmentis called a
dynamic environment else it is called a static environment.
2. Staticenvironmentsareeasytodealbecauseanagentdoesnotneedtocontinuelookingat the
world while deciding for an action.
3. Howeverfordynamicenvironment,agentsneedtokeeplookingattheworldateachaction.
4. TaxidrivingisanexampleofadynamicenvironmentwhereasCrosswordpuzzlesarean
example of a static environment.
6. Discretevs Continuous:
ProblemSolvingAgents
Problem-solvingagents:
InArtificialIntelligence,Searchtechniquesareuniversalproblem-solvingmethods.RationalagentsorProblem-
solvingagents inAImostlyusedthesesearchstrategiesoralgorithmstosolveaspecific problem and provide the
best result. Problem-solving agents are the goal-based agents and use atomic representation. In this topic, we
will learn various problem-solving search algorithms.
Searchalgorithm
a. SearchSpace:Searchspacerepresentsasetofpossiblesolutions,whichasystemmay have.
b. StartState:Itisastatefrom whereagentbeginsthesearch.
c. Goaltest:Itisafunctionwhichobservethecurrentstateandreturnswhetherthegoalstate is
achieved or not.
2. Searchtree:AtreerepresentationofsearchproblemiscalledSearchtree.Therootofthesearch tree is
the root node which is corresponding to the initial state.
3. Actions:Itgivesthedescriptionofalltheavailableactionstotheagent.
4. Transitionmodel: Adescriptionofwhateachactiondo,canberepresentedasatransitionmodel.
5. PathCost:Itisafunctionwhichassignsanumericcosttoeachpath.
6. Solution:Itisanactionsequencewhichleadsfromthestartnodetothegoalnode.
7. OptimalSolution:Ifasolutionhasthelowestcostamongallsolutions.
PropertiesofSearchAlgorithms:
Followingarethefouressentialpropertiesofsearchalgorithmstocomparetheefficiencyofthese algorithms:
10 Sec
Optimality:Ifasolutionfoundforanalgorithmisguaranteedtobethebestsolution(lowestpathcost) among all
other solutions, then such a solution for is said to be an optimal solution.
SpaceComplexity:Itisthemaximumstoragespacerequiredatanypointduringthesearch,asthe complexity
of the problem.
Stepsproblem-solvinginAI
TheproblemofAIisdirectlyassociatedwiththenatureofhumansandtheiractivities.Soweneeda number of
finite steps to solve a problem which makes human easyworks.
Thesearethefollowingstepswhichrequiretosolveaproblem:
• GoalFormulation:Thisoneisthefirstandsimplestepinproblem-solving.Itorganizesfinitestepsto
formulate a target/goals which require some action to achieve the goal. Today the formulation of the
goal is based on AIagents.
• Problemformulation: It is one of the core steps of problem-solving which decides what action
shouldbetakentoachievetheformulatedgoal.InAIthiscorepartisdependentuponsoftwareagent which
consisted of the following components to formulate the associatedproblem.
Componentstoformulatetheassociatedproblem:
• InitialState: This state requires an initial state for the problem which starts theAI agent towards a
specified goal. In this state new methods also initialize problem domain solving by a specific class.
• Action: Thisstageofproblemformulationworkswithfunctionwitha specific classtakenfromthe initial
state and all possible actions done in thisstage.
• Transition:Thisstageofproblemformulationintegratestheactualactiondonebythepreviousaction stage
and collects the final stage to forward it to their nextstage.
• Goaltest: This stage determines that the specified goal achieved by the integrated transition model or
not, whenever the goal achieves stop the action and forward into the next stage to determines the costto
achieve the goal.
• Pathcosting: This component of problem-solving numerical assigned what will be the cost to achieve
the goal. It requires all hardware software and human workingcos
EXAMPLEPROBLEMS
a. Theproblemsolvingapproachhasbeenappliedtoavastarrayoftaskenvironments.
i. Somebestknownproblemsaresummarizedbelow.
b. Theyaredistinguishedastoyorreal-worldproblems
1. A Toyproblem is intended to illustrate various problem solving
methods.Itcanbeeasilyusedbydifferentresearcherstocomparethe
performance of algorithms.
2. A Realworldproblem is one whose solutions people actually care
about.
TOYPROBLEMS
VacuumWorldExample
VacuumWorldStateSpace
Thestatespaceforthevacuumworld.
Arcsdenoteactions:L=Left,R=Right,S=Suck
8-puzzle:
1. An8-puzzleconsistsofa3x3boardwitheightnumberedtilesandablank space.
2. Atileadjacentto theblankspacecanslideintothespace.Theobjectistoreachthespecific goal state
,as shown in figure
Example:The8-puzzle
Theproblemformulationisasfollows:
8-queensproblem
a. States:Anyarrangementof0to8queensonboardisastate.
b. Initialstate:Noqueenontheboard.
c. Successorfunction:Addaqueentoanyemptysquare.
d. GoalTest:8queensareontheboard,noneattacked.
Inthisformulation,wehave64.63…57=3x1014possiblesequencestoinvestigate.
Abetterformulationwouldprohibitplacingaqueeninanysquarethatisalreadyattacked.:
Thisformulationreducesthe8-queenstatespacefrom3x1014tojust2057,andsolutionsareeasyto find.
a.For the 100 queens the initial formulation has roughly 10400 states whereas the
improvedformulationhasabout1052states.
b.Thisisahugereduction,buttheimprovedstatespaceisstilltoobigforthe algorithms to
handle.
REALWORLDPROBLEMS
1. Arealworldproblemisonewhosesolutionspeopleactuallycareabout.
2. Theytendnottohaveasingleagreedupondescription,butattemptismadetogivegeneralflavor of their
formulation,
Thefollowingarethesomerealworldproblems,
a. RouteFindingProblem
b. TouringProblems
c. TravellingSalesmanProblem
d. RobotNavigation
ROUTE-FINDINGPROBLEM
1. Route-findingproblemisdefinedintermsofspecifiedlocationsandtransitionsalonglinks
between them.
2. Route-findingalgorithmsareusedinavarietyofapplications,suchasrouting incomputer
networks, military operations planning, and air line travel planning systems.
AIRLINETRAVELPROBLEM
Theairlinetravelproblem isspecifiesasfollows:
1. States: Eachisrepresentedbyalocation(e.g.,anairport)andthecurrenttime.
2. Initialstate:Thisisspecifiedbytheproblem.
3. Successorfunction: This returns the states resulting from taking any scheduled flight(further
specified by seat class and location),leaving later than the current time plus the within-airport
transit time,from the current airport to another.
4. GoalTest:Areweatthedestinationbysomeprespecifiedtime?
5. Pathcost: This depends upon the monetary cost,waiting time,flight time,customs and
immigration procedures,seat quality,time of dat,type of air plane,frequent-flyer mileage awards,
and so on.
TOURINGPROBLEMS
1. Touringproblemsarecloselyrelatedtoroute-findingproblems,butwithanimportant
difference.
2. Considerforexample,theproblem, "Visiteverycityatleastonce"asshowninRomaniamap.
3. Aswithroute-findingtheactionscorrespondtotripsbetweenadjacentcities.Thestatespace,
however,is quite different.
4. Initialstatewouldbe"InBucharest;visited{Bucharest}".
5. Intermediatestatewouldbe"InVaslui; visited
a. {Bucharest,Vrziceni,Vaslui}".
6. GoaltestwouldcheckwhethertheagentisinBucharestandall20citieshavebeenvisited.
THETRAVELLINGSALESPERSONPROBLEM(TSP)
1. TSPisatouringprobleminwhicheachcitymustbe visitedexactlyonce.
2. Theaimistofindtheshortesttour.TheproblemisknowntobeNP-hard.
3. EnormouseffortshavebeenexpendedtoimprovethecapabilitiesofTSPalgorithms.
4. Thesealgorithmsarealsousedintaskssuch asplanningmovementsofautomaticcircuit-boarddrills
and of stockingmachines on shop floors.
VLSIlayout
When the robot has arms and legs or wheels that also must be controlled,the search space becomes multi-
dimensional.Advanced techniques are required to make the search space finite.
AUTOMATICASSEMBLYSEQUENCING
The example includes assembly of intricate objects suchaselectric motors.The aim inassemblyproblems is
to find the order in which to assemble the parts ofsome objects. If thewrong order is choosen, there will be
no way to add some part later without undoing somework already done.
Anotherimportantassemblyproblemisproteindesign,inwhichthegoalistofindasequenceof
Amino acids that will be fold into a three-dimensional protein with the right properties to cure some
disease.
INTERNETSEARCHING
In recent years there has been increased demand for software robots that perform Internet searching,
looking for answers to questions, for related information, or for shopping deals.
Thesearchingtechniquesconsiderinternetasagraphofnodes(pages)connectedbylinks.
MEASURINGPROBLEM-SOLVINGPERFORMANCE
The output of problem-solving algorithm is either failure or a solution. (Somealgorithms might struck in an
infinite loop and never return an output.)
Thealgorithm'sperformancecanbemeasuredinfourways :
a. Completeness:Isthealgorithmguaranteedtofindasolutionwhenthereis one?
b. Optinality:Doesthestrategyfindtheoptimalsolution
c. Timecomplexity:Howlongdoesittaketofindasolution?
d. Spacecomplexity:Howmuchmemoryisneededtoperformthesearch
StateSpaces
One general formulation of intelligent action is in terms of a state space.Astate contains all of the
informationnecessarytopredicttheeffectsofanactionandtodeterminewhetherastatesatisfiesthe goal.
AssumptionsofState-spacesearching:
1. Theagenthasperfectknowledgeofthestatespaceandisplanningforthecasewhereit observes
what state it is in: there is full observability.
2. Theagenthasasetofactions thathaveknowndeterministiceffects.
3. Theagentcandeterminewhetherastatesatisfiesthegoal A
state-spaceproblem consists of
1. Asetofstates
2. Adistinguishedstatecalledthe startstate
3. Foreachstate,asetofactionsavailabletotheagentinthatstate
4. anactionfunction that,givenastateandanaction,returnsanewstate
5. AgoalspecifiedasaBooleanfunction,goal(s)goal(s),thatistruewhenstatesssatisfies the goal, in
which case we say that ss is a goalstate
6. Acriterion that specifies the quality of an acceptable solution. For example, any sequence of
actions that gets the agent to the goal state may be acceptable, or there may be costs associated
with actions and the agent may be required to find a sequence that has minimal total cost.A
solutionthatisbestaccordingtosomecriterioniscalledan optimalsolution.Wedonotalways need
anoptimal solution, forexample,we may besatisfiedwithany solution thatiswithin 10% of
optimal.
GraphSearching
1. Theproblemoffindingasequenceofactionstoachieveagoalisabstractedassearchingfor paths in
directed graphs.
2. Tosolveaproblem,firstdefinetheunderlyingsearchspaceandthenapplya search
algorithm to that search space.
3. Manyproblem-solvingtasksaretransformableintotheproblemoffindingapathinagraph.
4. Searchingingraphsprovidesanappropriateabstractmodelofproblemsolving
independent of a particular domain.
AGenericSearchingAlgorithm
Agenericalgorithmtosearchforasolutionpathinagraph.Thealgorithmcallsproceduresthatcan be coded
to implement various search strategies.
FIG:Problemsolvingbygraphsearching
Theintuitiveideabehindthegenericsearchalgorithm,givenagraph,astartnode,andagoalpredicate,isto explore
paths incrementally from the start node. This is done by maintaining a frontier (or fringe) of paths from the
start node. The frontier contains all of the paths that could form initial segments of paths from the start node
to a goal node Initially, the frontier contains the trivial path containing just the start node, and no arcs.As
the search proceeds, the frontier expands into the unexplored nodes until a goal node is encountered.
Different search strategies are obtained by providing an appropriate implementation of the frontier.
1. procedureSearch(G,S,goalG,S,goal)
2: Inputs
3: GG:graphwithnodesNNandarcsAA 4:
ss: start node
5: goal:Booleanfunctionofnodes
6: Output
7: pathfromsstoanodeforwhichgoalistrue 8:
or⊥⊥ iftherearenosolutionpaths
9: Local
10: Frontier:setof paths
11:
Frontier:={⟨s⟩}Frontier:={⟨s⟩}12:
whileFrontier≠{}Frontier≠{}do
13: selectandremove⟨n0,…,nk⟩⟨n0,…,nk⟩ from
Frontier 14: if goal(nk)goal(nk) then
15: return⟨n0,…,nk⟩⟨n0,…,nk⟩
16: Frontier:=Frontier∪{⟨n0,…,nk,n⟩:⟨nk,n⟩∈A}Frontier:=Frontier∪{⟨n0,…,nk,n⟩:⟨nk,n⟩∈A}
17: return⊥⊥
Thisalgorithmhasafewfeatures thatshouldbenoted:
1. Whichpathisselectedatline13definesthesearchstrategy.Theselectionofapathcanaffectthe
efficiency; see the box for more details on the use of “select”.
2. Itisusefultothinkofthe returnatline15asatemporaryreturn,whereacallercan retrythesearchto get another
answer by continuing the while loop.This can be implemented by having a class that keeps
thestateofthesearchanda search()search()method thatreturnsthe next solution.
3. If the procedure returns ⊥⊥ (“bottom”), there are no solutions, or no remaining solutions if
the search has been retried.
4. Thealgorithmonlytestsifapathendsinagoalnode afterthepathhasbeenselectedfromthe frontier, not when
it is added to the frontier.There are two important reasons for this.There could be a costly arc from a
node on the frontier to a goal node. The search should not always return the path with this arc, because a
lower-cost solution may exist. This is crucial when the lowest-cost path is required.Asecond reason is
that it may be expensive to determine whether a node is a goal node, and so this should be delayed in
case the computation is not necessary.
Typesofsearchalgorithms
The uninformed search does not contain any domain knowledge such as closeness, the location of the
goal. It operates in a brute-force way as it only includes information about how to traverse the tree and
how to identify leaf and goal nodes. Uninformed search applies a way in which search tree is searched
withoutanyinformationaboutthesearchspacelikeinitialstateoperatorsandtestforthegoal,soitisalso called
blind search.It examines each node of the tree until it achieves the goal node.
Itcanbedividedintofivemaintypes:
o Breadth-firstsearch
o Uniformcostsearch
o Depth-firstsearch
o Iterativedeepeningdepth-firstsearch
o BidirectionalSearch
Breadth-firstsearch
Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It
starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a ‘search key’), and
exploresalloftheneighbournodesatthepresentdepthpriortomovingontothenodesatthenextdepth level.
BFS expands the leaf node with the lowest path cost so far, and keeps going until a goal node is
generated. If the path cost simply equals the number of links, we can implement this as a simple queue
(“first in, first out”)..
Depth-firstSearch
o Depth-firstsearchisarecursivealgorithmfortraversingatreeorgraphdatastructure.
o Itiscalledthedepth-firstsearchbecauseitstartsfromtherootnodeandfollowseachpathtoits greatest
depth node before moving to the nextpath.
o DFSusesastackdatastructureforitsimplementation.
o TheprocessoftheDFSalgorithmis similartotheBFSalgorithm.
Advantage:
o Thereisthepossibilitythatmanystateskeepre-occurring,andthereisnoguaranteeoffinding the
solution.
o DFSalgorithmgoesfordeepdownsearchingandsometimeitmaygototheinfiniteloop.
TimeComplexity:TimecomplexityofDFSwillbeequivalenttothenodetraversedbythealgorithm.It is given
by:
T(n)=1+n2+n3+.+ nm=O(nm)
Where,m=maximumdepthofanynodeandthiscanbemuchlargerthand(Shallowestsolutiondepth)
SpaceComplexity:DFSalgorithmneedstostoreonlysinglepathfromtherootnode,hencespace complexity
of DFS is equivalent to the size of the fringe set, which is O(bm).
Depth-LimitedSearchAlgorithm:
A depth-limited search algorithm is similar to depth-first search with a predetermined limit. Depth-limited
searchcansolvethe drawbackof theinfinitepathinthe Depth-first search. Inthis algorithm, thenodeat the depth
limit will treat as it has no successor nodes further.
Depth-limitedsearchcanbeterminatedwithtwoConditionsoffailure:
o Standardfailurevalue:Itindicates thatproblemdoesnothaveanysolution.
o Cutofffailurevalue:Itdefinesnosolutionfortheproblemwithinagivendepthlimit.
Advantages:
Depth-limitedsearchisMemoryefficient.
Disadvantages:
o Depth-limitedsearchalsohasadisadvantageofincompleteness.
o Itmaynot beoptimal iftheproblemhas morethanonesolution.
Bidirectionalsearch
Bidirectional search algorithm runs two simultaneous searches, one form initial state called as forward-
search and other from goal node called as backward-search, to find the goal node. Bidirectional search
replaces one single search graph with two small subgraphs in which one starts the search from an initial
vertex and other starts from goal vertex. The search stops when these two graphs intersect each other.
BidirectionalsearchcanusesearchtechniquessuchasBFS,DFS,DLS,etc.
Advantages:
o Bidirectionalsearchisfast.
o Bidirectionalsearchrequireslessmemory
Disadvantages:
Implementationofthebidirectionalsearchtreeisdifficult.
Inbidirectionalsearch,oneshouldknowthegoalstateinadvance.
Completeness:BidirectionalSearchiscompleteifweuseBFSinbothsearches.
TimeComplexity:TimecomplexityofbidirectionalsearchusingBFSis O(bd).
Optimal:Bidirectionalsearchis Optimal.
Uniform-costSearchAlgorithm:
Uniform-cost search is a searching algorithm used for traversing a weighted tree or graph. This algorithm
comes into play when a different cost is available for each edge. The primary goal of the uniform-cost
searchistofindapathtothegoalnodewhichhasthelowestcumulativecost.Uniform-costsearchexpands nodes
according to their path costs form the root node. It can be used to solve any graph/tree where the optimal
cost is in demand.Auniform-cost search algorithm is implemented by the priority queue. It gives maximum
priority to the lowest cumulative cost. Uniform cost search is equivalent to BFS algorithm if the path cost
of all edges is the same
Advantages:
Uniformcostsearchisoptimalbecauseateverystatethepathwiththeleastcostischosen.
Disadvantages:
Itdoesnotcareaboutthenumberofstepsinvolveinsearchingandonlyconcernedaboutpath cost.
Due to which this algorithm may be stuck in an infinite loop.
Best first search
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and
search. Best-first search allows us to take the advantages of both algorithms. With the help of best-first
search, at each step, we can choose the most promising node. In the best first search algorithm, weexpand
the node which is closest to the goalnode and the closest cost is estimated by heuristic function,
i.e.f(n)= g(n).
Bestfirstsearchalgorithm:
o Step1:PlacethestartingnodeintotheOPENlist.
o Step2:IftheOPENlistisempty,Stopandreturnfailure.
o Step3:Removethenoden,fromtheOPENlistwhichhasthelowestvalueofh(n),andplacesit in the
CLOSED list.
o Step4: Expandthenoden, andgeneratethesuccessors ofnoden.
o Step5: Check each successor of node n, and find whether any node is a goal node or not. If any
successor node is goal node, then return success and terminate the search, else proceed to Step 6.
o Step6: For each successor node, algorithm checks for evaluation function f(n), and then check if
the node has been in either OPEN or CLOSED list. If the node has not been in both list, then add
it to the OPEN list.
o Step7: ReturntoStep 2.
TimeComplexity: TheworstcasetimecomplexityofGreedybestfirstsearchisO(bm).
SpaceComplexity: TheworstcasespacecomplexityofGreedybestfirstsearchisO(bm).Where,mis the
maximum depth of the search space.
Complete:Greedybest-firstsearchisalsoincomplete,evenifthegivenstatespaceis finite.
Optimal:Greedybestfirstsearchalgorithmisnotoptimal.
Iterativedeepeningalgorithm
TheiterativedeepeningalgorithmisacombinationofDFSandBFSalgorithms.Thissearchalgorithmfinds out the
best depth limit and does it by gradually increasing the limit until a goal is found.
Thisalgorithmperformsdepth-firstsearchuptoacertain"depthlimit",anditkeepsincreasingthedepth limit after
each iteration until the goal node is found.
ThisSearchalgorithmcombinesthebenefitsofBreadth-firstsearch'sfastsearchanddepth-firstsearch's memory
efficiency.
Theiterativesearchalgorithmisusefuluninformedsearchwhensearchspaceislarge,anddepthofgoal node is
unknown.
Completeness:Thisalgorithmiscompleteisifthebranchingfactoris finite.
TimeComplexity:Let'ssupposebisthebranchingfactoranddepthisdthentheworst-case time
complexity is O(bd).
SpaceComplexity:ThespacecomplexityofIDDFSwillbeO(bd).
InformedSearch
Informed search algorithms use domain knowledge. In an informed search, problem information is
available which can guide the search. Informed search strategies can find a solution more efficiently than
an uninformed search strategy. Informed search is also called a Heuristic search.
Aheuristicisawaywhichmightnotalwaysbeguaranteedforbestsolutionsbutguaranteedtofindagood solution in
reasonable time.
Theinformedsearchalgorithmismoreusefulforlargesearchspace.Informedsearchalgorithmus
estheideaofheuristic,soitisalsocalledHeuristicsearch.
Heuristicsfunction:
Heuristic is a function which is used in Informed Search, and it finds the most promising path. It takes the
current state of the agent as its input and produces the estimation of how close agent is from the goal. The
heuristicmethod,however,might not always givethebestsolution,butitguaranteedtofindagoodsolution
inreasonabletime.Heuristicfunctionestimateshowcloseastateistothegoal.Itisrepresentedbyh(n),and it
calculates the cost of an optimal path between the pair of states. The value of the heuristic function is always
positive.
PureHeuristicSearch:
Pure heuristic search is the simplest form of heuristic search algorithms. It expands nodes based on their
heuristic value h(n). It maintains two lists, OPEN and CLOSED list. In the CLOSED list, it places those
nodes which have already expanded and in the OPEN list, it places nodes which have yet not beenexpanded.
Oneachiteration,eachnodenwiththelowestheuristicvalueisexpandedandgeneratesallitssuccessors and n is
placed to the closed list. The algorithm continues unit a goal state is found.
Intheinformedsearchwewilldiscusstwomainalgorithmswhicharegivenbelow:
o BestFirstSearchAlgorithm(Greedysearch)
o A*SearchAlgorithm
BestFirstSearchAlgorithm(Greedysearch)
Greedy best-first search algorithm always selects the path which appears best at that moment. It is the
combination of depth-first search and breadth-first search algorithms. It uses the heuristic function and
search. Best-first search allows us to take the advantages of both algorithms. With thehelp of best-first
search,ateachstep,wecanchoosethemostpromisingnode.Inthebestfirstsearchalgorithm,weexpand the node
which is closest to the goal node and the closest cost is estimated by heuristic function, i.e.
f(n)=g(n).
Were,h(n)=estimatedcostfromnodentothegoal.
search algorithm:
o Step1:PlacethestartingnodeintotheOPENlist.
o Step2:IftheOPENlistisempty,Stopandreturn failure.
o Step3:Removethenoden,fromtheOPENlistwhichhasthelowestvalueofh(n),andplacesitin the
CLOSED list.
o Step4:Expandthenoden,andgeneratethesuccessorsof noden.
o Step5: Check each successor of node n, and find whether any node is a goal node or not. If any
successor node is goal node, then return success and terminate the search, else proceed to Step 6.
o Step6: For each successor node, algorithm checks for evaluation function f(n), and then check ifthe
node has been in either OPEN or CLOSED list. If the node has not been in both list, then add it to
the OPEN list.
o Step7:ReturntoStep2.
Advantages:
o BestfirstsearchcanswitchbetweenBFSandDFSbygainingtheadvantagesofboththe
algorithms.
o ThisalgorithmismoreefficientthanBFSandDFSalgorithms.
Disadvantages:
o Itcanbehaveasanunguideddepth-firstsearchintheworstcasescenario.
o Itcanget stuckinaloopasDFS.
o Thisalgorithmisnotoptimal.
Example:
ExpandthenodesofSandputintheCLOSEDlistInitialization:
Iteration1:Open[A],Closed[S,B]
Iteration3:Open[I,G,E,A],Closed[S,B,F]
:Open[I,E,A],Closed[S,B,F,G]
Hencethefinalsolutionpathwillbe:S---->B----->F---------->G
TimeComplexity: TheworstcasetimecomplexityofGreedybestfirstsearchisO(bm).
SpaceComplexity:TheworstcasespacecomplexityofGreedybestfirstsearchisO(bm).Where,misthe maximum
depth of the search space.
Complete:Greedybest-firstsearchisalsoincomplete,evenifthegivenstatespaceis finite.
Optimal:Greedybestfirstsearchalgorithmisnotoptimal.
2.)A*SearchAlgorithm:
A* search is the most commonly known form of best-first search. It uses heuristic function h(n), and cost to
reach the node n from the start state g(n). It has combined features of UCS and greedy best-first search, by
which it solve the problem efficiently.A* search algorithm finds the shortest path through the search space
using the heuristic function. This search algorithm expands less search tree and provides optimal result
faster.A* algorithm is similar to UCS except that it uses g(n)+h(n) instead of g(n).
AlgorithmofA*search:
Step1:PlacethestartingnodeintheOPENlist.
Step2:CheckiftheOPENlistisemptyornot,ifthelistisemptythenreturnfailureandstops.
Step3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if
node n is goal node then return success and stop, otherwise
Step4: Expand node n and generate all of its successors, and put n into the closed list. For each successorn',
check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
Step5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back pointer
which reflects the lowest g(n') value.
Step6:ReturntoStep2. Advantages:
o A*searchalgorithmisthebestalgorithmthanothersearchalgorithms.
o A*searchalgorithmisoptimalandcomplete.
o Thisalgorithmcansolveverycomplexproblems.
Disadvantages:
o Itdoesnotalwaysproducetheshortestpathasitmostlybasedonheuristicsandapproximation.
o A*searchalgorithmhassomecomplexityissues.
o ThemaindrawbackofA*ismemoryrequirementasitkeepsallgeneratednodesinthememory,so it is not
practical for various large-scale problems.
Example:
In this example, we will traverse the given graph using theA* algorithm. The heuristic value of all states is
giveninthebelowtablesowewillcalculatethef(n)ofeachstateusingtheformulaf(n)=g(n)+h(n),where g(n) is the
cost to reach any node from start state.
HerewewilluseOPENandCLOSEDlist.
Solution:
Initialization:{(S, 5)}
Iteration1:{(S-->A,4),(S-->G,10)}
Iteration2:{(S-->A-->C,4),(S-->A-->B,7),(S-->G,10)}
Iteration3:{(S-->A-->C--->G,6),(S-->A-->C--->D,11),(S-->A-->B,7),(S-->G,10)}
Iteration4willgivethefinalresult,asS--->A--->C--->G itprovidestheoptimalpathwithcost6.
Pointstoremember:
o A*algorithmreturnsthepathwhichoccurredfirst,anditdoesnotsearchforallremainingpaths.
o TheefficiencyofA*algorithmdependsonthequalityofheuristic.
o A*algorithmexpandsallnodeswhichsatisfytheconditionf(n)<=""li="">
Complete:A*algorithmiscompleteaslongas:
o Branchingfactoris finite.
o Costateveryactionisfixed.
Optimal:A*searchalgorithmisoptimalifitfollowsbelowtwoconditions:
o Admissible:thefirstconditionrequiresforoptimalityisthath(n)shouldbeanadmissibleheuristic forA*
tree search.An admissible heuristic is optimistic in nature.
o Consistency:SecondrequiredconditionisconsistencyforonlyA*graph-search.
Iftheheuristicfunctionisadmissible,thenA*treesearchwillalwaysfindtheleastcostpath.
TimeComplexity: The time complexity of A* search algorithm depends on heuristic function, and the
number of nodes expanded is exponential to the depth of solution d. So the time complexity is O(b^d),
where b is the branching factor.
SpaceComplexity:ThespacecomplexityofA*searchalgorithmis
O(b^d)RecursiveBest-firstSearch(RBFS)
1. Recursivebest-firstsearchisasimplerecursivealgorithmthatattemptstomimicthe
operation of standard best-first search,but using only linearspace.
2. Thealgorithmisshowninbelowfigure.
3. Its structure is similar to that of recursive depth-first search,but rather than continuing
indefinitelydownthecurrentpath,itkeepstrackofthef-valueofthebestalternativepath
available from any ancestor of the current node.
4. If the current node exceeds this limit,the recursion unwinds back to the alternative path.
Astherecursionunwinds,RBFSreplacesthef-valueofeachnodealongthepathwiththe best f-
value of its children.
functionRECURSIVE-BEST-FIRST-SEARCH(problem)returnasolutionorfailure
returnRFBS(problem,MAKE-NODE(INITIAL-STATE[problem]),∞)
RBFSEvaluation:
a.RBFSisabitmoreefficientthan IDA*
i. Stillexcessivenodegeneration(mind changes)
b.Like A*, optimal if h(n) is admissible
c.SpacecomplexityisO(bd).
i.IDA*retains onlyone single number (the current f-cost limit)
d.Time complexity difficult tocharacterize
i.Dependsonaccuracyifh(n)andhowoftenbestpathchanges.
e.IDA*enRBFSsufferfromtoolittlememory.
HeuristicFunctions
Aheuristicfunction or simplya heuristic is a functionthat ranks alternatives in varioussearchalgorithms at
each branching step basing on an available information in order tomake a decision which branch is tobe
followed during asearch
Example:8Puzzle
Aheuristicfunctionforthe8-
puzzleproblemisdefinedbelow:h(n)=Numberofti
lesoutofposition.
So,thereistotalofthreetilesoutofpositioni.e.,6,5and4.Donotcounttheemptytilepresentinthegoal state). i.e.
h(n)=3. Now, we require to minimize the value of h(n)=0.
Wecanconstructastate-spacetreetominimizetheh(n)valueto0,asshownbelow:
It is seen from the above state space tree that the goal state is minimized from h(n)=3 to h(n)=0. However,
we can create and use several heuristic functions as per the reqirement. It is also clear from the above
example that a heuristic function h(n) can be defined as the information required to solve a given problem
moreefficiently.Theinformationcanberelatedtothe
natureofthestate,costoftransformingfromonestatetoanother,goalnodecharacterstics, etc., which is
expressed as a heuristic function.
PropertiesofaHeuristicsearchAlgorithm
Useofheuristicfunctioninaheuristicsearchalgorithmleadstofollowingpropertiesofaheuristicsearch algorithm:
• AdmissibleCondition: Analgorithmissaidtobeadmissible,ifitreturnsanoptimalsolution.
• Completeness:Analgorithmissaidtobecomplete,ifitterminateswithasolution(ifthesolutionexists).
• DominanceProperty:Iftherearetwoadmissibleheuristic
algorithmsA1andA2havingh1andh2heuristicfunctions,then A1issaidtodominateA2ifh1isbetter than h2 for
all the values of node n.
• OptimalityProperty:Ifanalgorithmis complete,admissible,anddominatingotheralgorithms,itwillbe the
best one and will definitely give an optimal solution.
TheEffectiveBranchingfactor
a. Oneway tocharacterizethequalityofaheuristicistheeffectivebranchingfactorb*. If the
total number of nodes generated byA* for a particular problem is N,and the
solutiondepth is d,thenb*is thebranchingfactorthat auniform treeof depthdwould have
to have in order to contain N+1 nodes.Thus,
N+1= 1+b*+ (b*)2+…+(b*)d
*
b.Forexample,if A finds a solution at depth 5 using 52nodes,theneffectivebranching factor is
1.92.
c. Awelldesignedheuristicwould haveavalueofb*closeto1,allowingfailrulargeproblems to be
solved.
d. To test the heuristic functions h 1 and h2,1200 randomproblemsweregeneratedwith solution
lengths from 2 to 24 and solved them with iterativedeepeningsearch andwith A* search
using both h1 and h2.
e. Thefollowingtablegivestheaveragenumberofnodesexpandedbyeachstrategyand
i. theeffectivebranchingfactor.
f. The results suggest that h 2 is better than h1,and is far better than using iterative deepening
search.
g. For a solution length of 14,A* with h 2 is 30,000 times more efficient than uninformed
iterative deepening search.
ComparisonofsearchcostsandeffectivebranchingfactorsfortheITERATIVE-DEEPENING- SEARCH
andA*Algorithms with h1,and h2. Data are average over 100 instances of the 8- puzzle,for various
solution lengths.
HillClimbingAlgorithminArtificialIntelligence
o Hill climbing algorithm is a local search algorithm which continuously moves in the direction of
increasing elevation/value to find the peak of the mountain or best solution to the problem. It
terminates when it reaches a peak value where no neighbor has a higher value.
o Hillclimbingalgorithmisatechniquewhichisusedforoptimizingthemathematicalproblems.One of the
widely discussed examples of Hill climbing algorithm is Traveling-salesman Problem in which we
need to minimize the distance traveled by the salesman.
o It is also called greedy local search as it only looks to its good immediate neighbor state and not
beyond that.
o Anodeofhillclimbingalgorithmhas twocomponentswhicharestateandvalue.
o HillClimbingismostlyusedwhenagoodheuristicisavailable.
o In this algorithm, we don't need to maintain and handle the search tree or graph as it only keeps a
single current state.
FeaturesofHillClimbing:
FollowingaresomemainfeaturesofHillClimbingAlgorithm:
o GenerateandTestvariant: Hill Climbing is the variant of Generate and Test method. The Generate
and Test method produce feedback which helps to decide which direction to move in the search
space.
o Greedyapproach:Hill-climbingalgorithmsearchmovesinthedirectionwhichoptimizesthecost.
o Nobacktracking: It does not backtrack the search space, as it does not remember the previous
states.
State-spaceDiagramforHillClimbing:
The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a
graph between various states of algorithm and Objective function/Cost.
On Y-axis we have taken the function which can be an objective function or cost function, and state-space
on the x-axis. If the function on Y-axis is cost then, the goal of search is to find the global minimum and
local minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the
global maximum and local maximum.
Differentregionsinthestatespacelandscape:
LocalMaximum: Local maximum is a state which is better than its neighbor states, but there is alsoanother
state which is higher than it.
GlobalMaximum:Globalmaximumisthebestpossiblestateofstatespacelandscape.Ithasthehighest value of
objective function.
Currentstate:Itisastateinalandscapediagramwhereanagentiscurrentlypresent.
Shoulder:Itisaplateauregionwhichhasanuphilledge.
TypesofHillClimbingAlgorithm:
o SimplehillClimbing:
o Steepest-Ascenthill-climbing:
o StochastichillClimbing:
1. SimpleHillClimbing:
Simple hill climbing is the simplest way to implement a hill climbing algorithm.
Itonlyevaluatestheneighbornodestateatatimeandselectsthefirstonewhichoptimizescurrentcostandsetita
sacurrentstate. It only checks it's one successor state, and if it finds better than the current state, then move
else be in the same state. This algorithm has the following features:
o Lesstime consuming
o Lessoptimalsolutionandthesolutionisnotguaranteed
AlgorithmforSimpleHillClimbing:
o Step1:Evaluatetheinitialstate,ifitisgoalstatethenreturnsuccessandStop.
o Step2:LoopUntil asolutionisfoundorthereis nonewoperator lefttoapply.
o Step3:Selectandapplyanoperatortothecurrentstate.
o Step4:Checknew state:
1. Ifitisgoalstate,thenreturnsuccessandquit.
2. Elseifitisbetterthanthecurrentstatethenassignnewstateasacurrentstate.
3. Elseifnot betterthanthecurrentstate,thenreturntostep2.
o Step5:Exit.
2. Steepest-Ascenthillclimbing:
The steepest-Ascent algorithm is a variation of simple hill climbing algorithm. This algorithm examines all
the neighboring nodes of the current state and selects one neighbor node which is closest to the goal state.
This algorithm consumes more time as it searches for multiple neighbors
AlgorithmforSteepest-Ascenthillclimbing:
o Step1:Evaluatetheinitialstate,ifitisgoalstatethenreturnsuccessandstop,elsemakecurrent state as
initial state.
o Step2:Loopuntilasolutionis foundorthecurrent statedoesnotchange.
1. LetSUCCbeastatesuchthatanysuccessorofthecurrentstatewillbebetterthanit.
2. Foreachoperatorthatappliestothecurrentstate:
I. Applythenewoperatorandgenerateanewstate.
II. Evaluatethenewstate.
III. Ifitisgoalstate,thenreturnitandquit,elsecompareittotheSUCC.
IV. IfitisbetterthanSUCC,thensetnewstateasSUCC.
V. IftheSUCCisbetterthanthecurrentstate,thensetcurrentstatetoSUCC.
o Step5:Exit.
3. Stochastichillclimbing:
Stochastic hill climbing does not examine for all its neighbor before moving. Rather, this search algorithm
selects one neighbor node at random and decides whether to choose it as a current state or examine another
state.
ProblemsinHillClimbingAlgorithm:
1. LocalMaximum: Alocalmaximumisapeakstateinthelandscapewhichisbetterthaneachofits
neighboring states, but there is another state also present which is higher than the local maximum.
Solution: Backtrackingtechnique can be a solutionof the local maximum in state space landscape. Create a
list of the promising path so that the algorithm can backtrack the search space and explore other paths as
well.
2. Plateau: Aplateau is the flat area of the search space in which all the neighbor states of the current state
contains the same value, because of this algorithm does not find any best direction to move.Ahill-climbing
search might be lost in the plateau area.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to solve the
problem. Randomlyselect a state whichis far awayfrom the current state soit is possible that the algorithm
could find non-plateau region.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is higher than its
surrounding areas, but itself has a slope, and cannot be reached in a single move.
Solution: With the use of bidirectional search, or by moving in different directions, we can improve this
problem.
Simulated Annealing:
A hill-climbing algorithm which never makes a move towards a lower value guaranteed to be incomplete
because it can get stuck on a local maximum. And if algorithm applies a random walk, by moving a
successor, then it may complete but not efficient. SimulatedAnnealing is an algorithm which yields both
efficiency and completeness.
In mechanical term Annealing is a process of hardening a metal or glass to a high temperature then cooling
gradually, so this allows the metal to reach a low-energy crystalline state. The same process is used in
simulated annealing in which the algorithm picks a random move, instead of picking the best move. If the
random move improves the state, then it follows the same path. Otherwise, the algorithm follows the path
which has a probability of less than 1 or it moves downhill and chooses another path.
InventingadmissibleheuristicfunctionsRelax
edproblems
o Aproblemwithfewerrestrictionsontheactionsiscalledarelaxedproblem
o Thecostofanoptimalsolutiontoarelaxed problemisanadmissibleheuristicforthe
original problem
o Iftherulesofthe8-puzzlearerelaxedsothatatilecanmoveanywhere,thenhi(n)gives the
shortest solution
o Iftherulesarerelaxedsothatatilecan movetoanyadjacentsquare,thenh2(n)givesthe shortest
solution
LocalSearchAlgorithmsandOptimizationProblem
Theinformedanduninformedsearchexpandsthenodessystematicallyintwoways:
• keepingdifferentpathsinthememoryand
• selectingthebestsuitablepath,
Which leads to a solution state required to reach the goal node. But beyond these “classical search
algorithms,”wehavesome“localsearchalgorithms”wherethepathcostdoesnotmatters,andonlyfocus on
solution-state needed to reach the goal node.
Alocalsearchalgorithmcompletesitstaskbytraversingonasinglecurrentnoderatherthanmultiplepaths and
following the neighbors of that node generally.
Althoughlocalsearchalgorithmsarenotsystematic,stilltheyhavethefollowingtwo advantages:
• Localsearchalgorithmsuseaverylittleorconstantamountofmemoryastheyoperateonlyona single
path.
• Mostoften,theyfindareasonablesolutioninlargeorinfinitestatespaceswheretheclassicalorsystematic
algorithms do not work.
PUREOPTIMIZEDPROBLEM
WorkingofaLocalsearchalgorithm
Considerthebelowstate-spacelandscapehavingboth:
• Location: Itisdefinedbythe state.
• Elevation:Itisdefinedbythevalueoftheobjectivefunctionorheuristiccostfunction.
Thelocalsearchalgorithmexplorestheabovelandscapebyfindingthefollowingtwopoints:
• GlobalMinimum:Iftheelevationcorrespondstothecost,thenthetaskistofindthelowestvalley,which is known
as GlobalMinimum.
• GlobalMaxima:Iftheelevationcorrespondstoanobjectivefunction,thenitfindsthehighestpeak which is called
as GlobalMaxima. It is the highest point in the valley.
WewillunderstandtheworkingofthesepointsbetterinHill-climbingsearch.
Belowaresomedifferenttypesoflocalsearches:
• Hill-climbingSearch
• SimulatedAnnealing
• LocalBeamSearch
Onlinesearchagents
Online search is a necessary idea for unknown environments, where the agent does not know what states
existorwhatitsactionsdo.Inthisstateofignorance,theagentfacesanexplorationproblemandmustuse its actions
as experiments in order to learn enough to make deliberation
Thecanonicalexampleofonlinesearchisarobotthatisplacedinanewbuildingandmustexploreitto build a map
that it can use for getting fromAto B. Methods for escaping from labyrinths—required knowledge for
aspiring heroes of antiquity—are also examples of online search algorithms
Spatial exploration is not the only form of exploration, however.Consider a newborn baby: it has many
possibleactionsbutknowstheoutcomesofnoneofthem,andithasexperiencedonlyafewofthepossible states that it
can reach. The baby’s gradual discovery of how the world works is, in part, an online search process.
Onlinesearchproblems
An online search problem must be solved by an agent executing actions, rather than by pure
computation.Weassumeadeterministicandfullyobservableenvironment(Chapter17relaxesthese
assumptions), but we stipulate that the agent knows only the following:
• ACTIONS(s),whichreturnsalistofactionsallowedinstates;
• Thestep-costfunctionc(s,a,s)—notethatthiscannotbeuseduntiltheagentknows that s is
the outcome; and
• GOAL-TEST(s).
Noteinparticularthat the agentcannotdetermine RESULT(s, a) exceptby actuallybeingins anddoinga.
Forexample, inthemazeproblem showninFigure4.19, theagentdoesnot knowthat goingUpfrom(1,1)
leadsto(1,2);nor,havingdonethat,doesitknowthatgoingDownwilltakeitbackto(1,1).Thisdegreeof ignorance
can be reduced in some applications—for example, a robot explorer might know how its movement actions
work and be ignorant only of the locations of obstacles