Sunday, September 2, 2018

Depth-first search (DFS)

Depth-first search (DFS)

  • Description:
    • DFS progresses by expanding the first child node of the search tree that appears and thus going deeper and deeper until a goal node is found, or until it hits a node that has no children. Then the search backtracks, returning to the most recent node it hasn’t finished exploring.
    • Order in which nodes are expanded
  • Performance Measure:
    • Completeness: 
      • DFS is not complete, to convince yourself consider that our search start expanding the left sub tree of the root for so long path (may be infinite) when different choice near the root could lead to a solution, now suppose that the left sub tree of the root has no solution, and it is unbounded, then the search will continue going deep infinitely, in this case we say that DFS is not complete.
    • Optimality:
      • Consider the scenario that there is more than one goal node, and our search decided to first expand the left sub tree of the root where there is a solution at a very deep level of this left sub tree, in the same time the right sub tree of the root has a solution near the root, here comes the non-optimality of DFS that it is not guaranteed that the first goal to find is the optimal one, so we conclude that DFS is not optimal.
    • Time Complexity:
      • Consider a state space that is identical to that of BFS, with branching factor b, and we start the search from the root.
      • In the worst case that goal will be in the shallowest level in the search tree resulting in generating all tree nodes which are O(bm).
    • Space Complexity:
      • Unlike BFS, our DFS has a very modest memory requirements, it needs to story only the path from the root to the leaf node, beside the siblings of each node on the path, remember that BFS needs to store all the explored nodes in memory.
      • DFS removes a node from memory once all of its descendants have been expanded.
      • With branching factor b and maximum depth m, DFS requires storage of only bm + 1 nodes which are O(bm) compared to the O(bd+1) of the BFS.
  • Conclusion:
    • DFS may suffer from non-termination when the length of a path in the search tree is infinite, so we perform DFS to a limited depth which is called Depth-limited Search.

Iterative deepening depth-first search (IDS)

Iterative deepening depth-first search (IDS)

  • Description:
    • It is a search strategy resulting when you combine BFS and DFS, thus combining the advantages of each strategy, taking the completeness and optimality of BFS and the modest memory requirements of DFS.
    • IDS works by looking for the best search depth d, thus starting with depth limit 0 and make a BFS and if the search failed it increase the depth limit by 1 and try a BFS again with depth 1 and so on – first d = 0, then 1 then 2 and so on – until a depth d is reached where a goal is found.
  • Performance Measure:
    • Completeness:
      • IDS is like BFS, is complete when the branching factor b is finite.
    • Optimality:
      • IDS is also like BFS optimal when the steps are of the same cost.
    • Time Complexity:
      • One may find that it is wasteful to generate nodes multiple times, but actually it is not that costly compared to BFS, that is because most of the generated nodes are always in the deepest level reached, consider that we are searching a binary tree and our depth limit reached 4, the nodes generated in last level = 24 = 16, the nodes generated in all nodes before last level = 20 + 21 + 22 + 23= 15
      • Imagine this scenario, we are performing IDS and the depth limit reached depth d, now if you remember the way IDS expands nodes, you can see that nodes at depth d are generated once, nodes at depth d-1 are generated 2 times, nodes at depth d-2 are generated 3 times and so on, until you reach depth 1 which is generated d times, we can view the total number of generated nodes in the worst case as:
        • N(IDS) = (b)d + (d – 1)b2 + (d – 2)b3 + …. + (2)bd-1 + (1)bd = O(bd)
      • If this search were to be done with BFS, the total number of generated nodes in the worst case will be like:
        • N(BFS) = b + b2 + b3 + b4 + …. bd + (bd + 1 – b) = O(bd + 1)
      • If we consider a realistic numbers, and use b = 10 and d = 5, then number of generated nodes in BFS and IDS will be like
        • N(IDS) = 50 + 400 + 3000 + 20000 + 100000 = 123450
        • N(BFS) = 10 + 100 + 1000 + 10000 + 100000 + 999990 = 1111100
        • BFS generates like 9 time nodes to those generated with IDS.
    • Space Complexity:
      • IDS is like DFS in its space complexity, taking O(bd) of memory.
  • Conclusion:
    • We can conclude that IDS is a hybrid search strategy between BFS and DFS inheriting their advantages.
    • IDS is faster than BFS and DFS.
    • It is said that “IDS is the preferred uniformed search method when there is a large search space and the depth of the solution is not known”.

COMPARISONS BETWEEN SEARCH STRATEGIES


AI BY Patrick Henry Winston

HEURISTIC SEARCH

STRUCTURE OF AGENTS


The Structure of Agents
An intelligent agent is a combination of Agent Program and Architecture.
Intelligent Agent = Agent Program + Architecture
Agent Program is a function that implements the agent mapping from percepts to actions. There exists a variety of basic agent program designs, reflecting the kind of information made explicit and used in the decision process. The designs vary in efficiency, compactness, and flexibility. The appropriate design of the agent program depends on the nature of the environment.
Architecture is a computing device used to run the agent program.
To perform the mapping task four types of agent programs are there. They are                
1. Simple reflex agents
2. Model-based reflex agents
3. Goal-based agents
4. Utility-based agents
We then explain in general terms how to convert all these into learning agents.
1.Simple reflex agents
The simplest kind of agent is the simple reflex agent. It responds directly to percepts i.e. these agent select actions on the basis of the current percept, ignoring the rest of the percept history.
An agent describes about how the condition  action rules allow the agent to make the connection from percept to action.
   Condition  action rule: if condition then action
   Rectangle  to denote the current internal state of the agents decision process.
Oval  to represent the background information in the process.
The agent program, which is also very simple, is shown in the following figure.
function SIMPLE-REFLEX-AGENT (percept) returns an action
static: rules, a set of condition-action rules
state ← INTERPRET – INPUT(percept)
rule ← RULE – MATCH(state, rules)
action ← RULE – ACTION[rule]
return action
INTERRUPT-INPUT – function generates an abstracted description of the current state from the percept.
RULE-MATCH – function returns the first rule in the set of rules that matches the given state description.
RULE-ACTION – the selected rule is executed as action of the given percept.
The agent in figure will work only ―if the correct decision can be made on the basis of only the current percept – that is, only if the environment is fully observable‖.
Example: Medical diagnosis system
            if the patient has reddish brown spots then start the treatment for measles.
2. Model-based reflex agents (Agents that keep track of the world)
The most effective way to handle partial observability is for the agent ―to keep track of the part of the world it cant see now. That is, the agent which combines the current percept with the old internal state to generate updated description of the current state.
The current percept is combined with the old internal state and it derives a new current state is updated in the state description is also. This updation requires two kinds of knowledge in the agent program. First, we need some information about how the world evolves independently of the agent. Second, we need some information about how the agents own actions affect the world.
The above two knowledge implemented in simple Boolean circuits or in complete scientific theories  is called a model of the world. An agent that uses such a model is called a model- based agent.
The above figure shows the structure of the reflex agent with internal state, showing how the current percept id combined with the old internal state to generate the updated description of the current state.
function REFLEX-AGENT-WITH-STATE (percept) returns an action
static: state, a description of the current world state
rules, a set of condition-action rules
action, the most recent action, initially none
state ← UPDATE-STATE(state, action, percept)
rule ← RULE-MATCH(state, rules)
action ← RULE-ACTION[rule]
return action
A model-based reflex agent. It keeps track of the current state of the world using an internal model. It then chooses an action in the same way as the reflex agent.
UPDATE-STATE – This is responsible for creating the new internal state description by combining percept and current state description.
3. Goal-based agents
An agent knows the description of current state and also needs some sort of goal information that describes situations that are desirable. The action matches with the current state is selected depends on the goal state.
The goal based agent is more flexible for more than one destination also. After identifying one destination, the new destination is specified, goal based agent is activated to come up with a new behavior. Search and Planning are the subfields of AI devoted to finding action sequences that achieve the agents goals.
The goal-based agent appears less efficient, it is more flexible because the knowledge that supports its decisions is represented explicitly and can be modified. The goal-based agent‘s behavior can easily be changed to go to a different location.
4. Utility-based agents (Utility – refers to ― the quality of being useful‖)
An agent generates a goal state with high – quality behavior (utility) that is, if more than one sequence exists to reach the goal state then the sequence with more reliable, safer, quicker and cheaper than others to be selected.
A utility function maps a state (or sequence of states) onto a real number, which describes the associated degree of happiness. The utility function can be used for two different cases: First, when there are conflicting goals, only some of which can be achieved (for e.g., speed and safety), the utility function specifies the appropriate tradeoff. Second, when the agent aims for several goals, none of which can be achieved with certainty, then the success can be weighted up against the importance of the goals.
Learning agents
The learning task allows the agent to operate in initially unknown environments and to become more competent than its initial knowledge.
A learning agent can be divided into four conceptual components, .
Learning element – This is responsible for making improvements. It uses the feedback from the critic on how the agent is doing and determines how the performance element should be modified to do better in the future.
Performance element – which is responsible for selecting external actions and it is equivalent to agent: it takes in percepts and decides on actions.
Critic – It tells the learning element how well the agent is doing with respect to a fixed performance standard.
Problem generator – It is responsible for suggesting actions that will lead to new and informative experiences.
  In summary, agents have a variety of components, and those components can be represented in many ways within the agent program, so there appears to be great variety among learning methods. Learning in intelligent agents can be summarized as a process of modification of each component of the agent to bring the components into closer agreement with the available feedback information, thereby improving the overall performance of the agent (All agents can improve their performance through learning).

INTELLIGENT AGENT