Docsity

fundamentals of artificial intelligence, Appunti di Tecniche Di Intelligenza Artificiale

Toggle sidebar
bg1
Search Problem
Many AI problems can be solved by exploring the solution space: it contains all possible sequence of
actions that might be applied by an agent. some of these sequences lead to a solution
The agent examines alternative sequence of actions that lead to know state and chooses the best
one, this procces is called Search.
The search process can be seen as a tree whose node are states and branches are operators or
actions.
A search alorithm take as input a probelm and returns a solution in form of a sequence of actions.
In general we use constructive algorithm: we expand the current state until we found a solution.
Once the solution is found, the action found can be performed. this is called execution
usually search done off-line, before execution
terminology
1. expansion: one starts from a state and apply all the operators to generate new state
2. Search strategy choose which state to expand
3. Serch tree: it rapresent the expansion of all states starting from the inital state, the root of the
tree
SEARCH TREE
it is an off-line simulated exploration obtained by expanding states that have been already explored.
the final leaf of the tree can be a failure state or a goal state
The strategy of search depend on how we select a node to expand
PROBLEM FORMULATION
1. Initial state the root of the tree, the first state to be expanded
2. A set of actions or operators
3. Successor functions set of action-state pairs, return the new state after performing an action
4. Goal state, and the test to find them
5. Cost of the path the sum of the operator cost present in the path, each actions in the problem
has associated a cost.
A solution is a sequence of actions that lead from the inital state to the goal
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f

Anteprima parziale del testo

Scarica fundamentals of artificial intelligence e più Appunti in PDF di Tecniche Di Intelligenza Artificiale solo su Docsity!

Search Problem

Many AI problems can be solved by exploring the solution space: it contains all possible sequence of actions that might be applied by an agent. some of these sequences lead to a solution The agent examines alternative sequence of actions that lead to know state and chooses the best one, this procces is called Search. The search process can be seen as a tree whose node are states and branches are operators or actions. A search alorithm take as input a probelm and returns a solution in form of a sequence of actions. In general we use constructive algorithm: we expand the current state until we found a solution. Once the solution is found, the action found can be performed. this is called execution usually search done off-line, before execution terminology

  1. expansion : one starts from a state and apply all the operators to generate new state
  2. Search strategy choose which state to expand
  3. Serch tree : it rapresent the expansion of all states starting from the inital state, the root of the tree SEARCH TREE it is an off-line simulated exploration obtained by expanding states that have been already explored. the final leaf of the tree can be a failure state or a goal state The strategy of search depend on how we select a node to expand PROBLEM FORMULATION
  4. Initial state the root of the tree, the first state to be expanded
  5. A set of actions or operators
  6. Successor functions set of action-state pairs, return the new state after performing an action
  7. Goal state , and the test to find them
  8. Cost of the path the sum of the operator cost present in the path, each actions in the problem has associated a cost. A solution is a sequence of actions that lead from the inital state to the goal

In general to solve a seach problem we need to define the state, all possible operators that can be performed and its associated cost, the inital state and the goal states. NODE Each node in the search tree corresponds to a data structure contains:

  1. the state
  2. the parent ndoe
  3. the operator which has been applite to obtain the node
  4. the depth of the node
  5. the cost of the path from the current initial state to the node SEARCH STRATEGY The choice on how to expand a search tree is called strategy. two possibilities:
  6. Non informed strategies Do not use any domain knowledge and do an exhaustive search.
  7. Informed strategies : use domain knowledge, applyng rules following heuristics. if the heuristics is optimal then we do not need to search. We can evaluate a strategy according to 4 criteria:
  8. completeness the search strategy always find a solution if it exists.
  9. optimality the solution found is the solution of minimum path cost
  10. Space complexity memoery needed to perform the search
  11. Time complexity how does long take to find a solution Space and complexity are expressed using big-O notation, and it depends on:
  12. b : the branching factor, the number of operators that can be applied to a ndoe
  13. d : the depth of the first solution found by the seach strategy
  14. m : the total depth of the tree. depth : the depth of the root is 0, the depth of any other node is the depth of its parent plus 1. BREADH-FIRST Always expand less deep node. so the tree is expanded level by level. before expand the next level we have the guarantee that the current level is all expanded. in order to implement breadh first is used a simple FIFO queue.

time: , is the maximum deoth parameter Memory ITERATIVE DEEPENING perfrom iteratively a limited depth search starting with maximum depth=0 and adding 1 at each new search performed. There are nodes in the tree that are expanded multiple time due to ther estarting of the search. but asymptotically has the same time of breadh-first combine the memory advantege of depth first, and the completeness of the breadth first Complete: yes Optimal: yes if step cost equal one Space: Time: BIDIRECTIONAL SEARCH start a forward search strategy from the inital state and a backward search strategy from the goal state. stop when the fringe in the backward part is equal or is a subset of the fringe of the froward part. Complete: if both direction use breadh first strategy Optimal: if both direction use breadh first strategy and step unit costs. time and memory:

Informed search strategy

Use knowledge about the problem in order to reduce the combinatorial explosion. In order to selct which nodes to expand we use an evaluation function. evaluation functions : evaluation function that gives a computational estimate of the effort to reach the final state.

the time use to evaluate a node should reduce the size of the space to explore, usually there is rade off between time to compute the heuristics and the time it takes to solve the problem. we have to consider that the time spent to compute the hueristcs could be used to search for the solution, this is the trade off. Evaluation function: estimate the cost from the given node to the goal BEST SEARCH Expand the node with smaller evaluation function value. the choice of the evaluation function. usually the evaluation function contains a component calld heuristic functions = estimate of the chepaest path from the current state n to the goal state. if n is a goal state, then the heuristics must be 0. the informed best search strategy depends on the evaluation function used to elect the ndoe to expand. GREEDY BEST-FIRST The evaluation function is composed only by the heuristics function, expan node that seem closer to the goal Optimal: no, try to find as soon as possible a node with 0 evaluation functions, and not the node with lowest path cost. Complete: no, like deepth first, can be stucked in loop time and complexity: , but can be drastically reduced by the heuristic function A STAR ALGORITHM the evaluation function is composed by the path cost to reach the node and the heuristic function admissible heuristics an heuristics is admissible if the estimated cost is less then the true cost.

the heursitc is consistent if for each node n1 and any succesr n2 genrerted by an action a: if n is a goal state If the heurstic is consitent then the A star on graph is optimal. the tree search for A star is optimal if the heuristic is admissible, whule the graph version is optimal if the heuristic is consistent A consistent heuristc implies an admissible heuristc, consistency is a much stronger property.

Local Search

Local search algorithms start from the initial solution (can be unfeasible) and iteratively try to improve it through local moves, defined in a neighborhood. Local search is done when the path to reach a goal is not important and when we can determine if state is solution or not by looking at its description. Neighborhood structure Assigns to every a set of neighbors. is called neighborhood. neighborhood graph : graph that depend on local move you are using, define the solution that you can obtain from current state with one local move. HILL CLIMBING Very basic local search algorithm. A move is performed only if the solution it produces is better than the current solution. It stops as soon as it finds a local minimum. This one of its main drawbacks, as it doesn't effectively explore the search space. Moreover, it doesn't remember the states already reached. It's like " climbing Everest in a thick fog with amnesia ".There are severial variants. it is dependent from the starting point. A local optima is a solution such that it is the best one among any other solutions belonging to its neighborhood. when we solve optmization problem we want to find the global optimum. The larger the neighbourhood the higher quality is the solution. A problem with local optima is that it represents the best solution in the neighborhood but it could be worst than other local optima. We can also incur in plateaus , flat regions where the states have the same value: in this case we don't know in which direction to move. Ridges are ... (ask prof ??? )

META HEURISTICS

A metaheuristic is a high-level problem-independent algorithmic framework that guides the search process. Two major components of any metaheuristic algorithms are: intensification and diversification. Diversification means to generate diverse solutions so as to explore the search space on a global scale, while intensification means to focus the search in a local region knowing that a current good solution is found in this region. Intensification ensures that solutions will be near an optimum, while diversification via randomization allows the search to espace from local optima and, at the same time, increases the diversity of solutions. metaheurstic is not an exact method, usually finds good enough solution in relative small amount of time, that would not be find by exact method due the complexity of the problem. meta-heuristcs overcome probelm of classic local search method like get stuck in local optima. metaheuristc can be dividid in:

  1. local search metaheuristcs , find good solutions by iteratively making changes to a single current solution. this change are called moves and are typically based on the neighborhood of the current solution. usually this metahueristic try to improve the current solution, but once we find the local optimum the metaheurstic use a strategy to escape from them. Example: simultaed annnaling, tabu search, iterated local search
  2. Population based Metaheuristics find good solutions by evolving existing solution from a set, called population. example: genetic algorithm
  3. Swarm intelligence : SI systems typically consists of a population of simple agents interacting locally with one another and their environment. usually a global behabior emerge in order to find the best solution. (particular type of population based Metaheuristics) Simlulated Annealing is a meta heuristic that allows moves of worse quality than the current solution. The probability of doing such a move is decresed gradually during search. Such probability can be represented as a temperature T, which can be varied in different ways: logarithmic, where the optimal solution can be reached with probability 1, but actually is not suitable in pratical setting for being too slow geometric, where the temperature is decreased by constant factor alpha in [0,1] non-monotonic, where the temperature is descreased and then increased again High temperature favorite diversification, while low temperature favorite intensification.

Population based metaheuristics are inspired by natural processes like natural evolution and social insects foraging behaviors. It's based on the basic principle of learning correlations between good solution components, achieved by evolving a set of points in the search space. Genetic Algorithms are inspired by evolution. There are three key components: adaptation: organisms are suited to their habitats inheritance: offspring resemble their parents. The fittest individuals have a higher chance of having numerous offspring. Children are similar, not equal to their parents. The traits characterizing the fittest individuals spread across the population, generation by generation. natural selection: new, adapted types of organisms emerge and those that fail to change adequately are subject to extinction. GAs are not meant to simulate the biological evolutionary processes, but rather aimed at exploiting these key concepts for problem solving. A population is the set of individuals or solutions, individuals are also called genotypes. Genotypes are made of units calledd genes , the domain of a vlaue of a gende is composed of alles The offspring creation phase uses multiple operators:

  1. Recombination, also known as crossover , combines the genetic material of the parents. This operation can combine good parts from good solutions, as well as achieving the opposite effect.
  2. Mutation introduces variability and diversity in the genotypes (individuals), by mutating each gene with a certain probability.
  3. Selection selects the parents to be combined during the crossover, and it's usually implemented in proportional to each individual's fitness value, in order to drive population toward high fitness
  4. Generational replacement creates the new generation replacing the old one. It can be done in different ways, like entirely replacing the old one with the new one, but this can exclude good solutions previously found. So an alternative could be to keep the n individuals from the old one and add the new population (or any variant of this scheme).

Genetical Algorithms can result in a good strategy for many problems for its simplicity and its general purpose design, but sometimes its genetic operators are too simple. Local search-based algorithms are preferred when :

  1. neighborhood structures creaate a correlated search graph ( ??? )
  2. when the computational cost of a move is low
  3. when inventing moves is easy ( ??? ). Population-based approaches are preferrable when:
  4. solutions can be encoded as composition of good building blocks, like binary string representation, where for good we mean building blocks on which mutation and crossover can be defined and applied on easily.
  5. when computational cost of moves in a local search is high or when the search space is huge.
  6. Difficult to design a neighborhood structure

Swarm Intelligence

Swarm Intelligence is an artificial intelligence technique based on the study of many individuals that coordinate using decentralized control and self-organization. SI systems typically consists of a population of simple agents interacting locally with one another and their environment. Although there is normally no centralized control dictating how each individual agent should behave, local interactions between such agents often lead to the emergence of a global behaviour. human inspiration There is a theory stating that human intelligence is the result of social interactions, as we evaluate, compare and imitate other individuals, learn from experience emulating the successful behaviour of others, enabling us to adapt to complex environments and situations through the discovery of optimal patterns, belief and behaviors. Thus, culture and cognition could be considered as consequences of human social choices, where a culture emerges when individuals become similar through a process of social learning. Propertis The typical swarm intelligence system has the following properties:

  1. it is ocmpose of many simple individuals with limited capacities, they are not aware of the system in its global view

ant colony is a sthocastic process on a fully connected graph called construction graph :

  1. vertex are partial solution componet
  2. arcs are connections between partial solution component
  3. A solution is a complete path on the algorithm builds solution in an incremental way. Connection and vertex have the following information:
  4. Phermone used to comunicate throught the enviroment
  5. Heuristc value to guide the seach, it rapresents the prior knowledge about the problem A set of ants is put on each vertex Solution construction Ants build possible solutions following a path on the construction graph based on a transition rules, that depends on the value of the phermone and the value of the heuristic transition rules starting from a node i, we choose the next node to visit in a probabilistic way that depends on the phermone and on the heuristics (only concistent node are take into account). we use to parameter:
  6. alpha control the intensities of the phermone
  7. beta control the intensities of the heuristic Phermone update The aim of the pheromone update is to increase the pheromone values associated with good solutions, and to decrease those that are associated with bad ones. Usually, this is achieved (i) by decreasing all the pheromone values through pheromone evaporation , and (ii) by increasing the pheromone levels associated with a chosen set of good solutions After performing a transition the phermone are update based on an evaporation rate and the number of ants that used the arc selected. ants can also update backward (after having found the solution) the phermone of component used during the building of the solution in base of the quality of the overall solution Once solutions have been constructed, and before updating the pheromone values, often some problem specific actions may be required. These are often called daemon actions, and can be used to implement problem specific and/or centralized actions, which cannot be performed by single ants. The most used daemon action consists in the application of local search to the constructed solutions: the locally optimized solutions are then used to decide which pheromone values to update.

Evaporation is applied both time: after ceratin time step, the current phermone become less intense. Deamon actions Centralized actions, that can not be performed by the ants, usually a local search is done on the solution in order to decide to leave additional phermone to guide the search from a gloabal perspective

HONEY BEE COLONY

The model consists of three essential components: employed and unemployed foraging bees, and food sources. The first two components, employed and unemployed foraging bees, search for rich food sources, which is the third component, close to their hive. The model also defines two leading modes of behaviour which are necessary for self-organizing and collective intelligence: recruitment of foragers to rich food sources resulting in positive feedback and abandonment of poor sources by foragers causing negative feedback. the artificial bees randomly discover a population of initial solution vectors and then iteratively improve them by employing the strategies: moving towards better solutions by explore a local neighborhood of the food source while abandoning poor solutions. algorithm there are 3 groups of bees:

  1. employes bees associated with specific food sources (a solution), the number of possible solution is equal to the number of emplyes bees
  2. Onllokers bees watching emplyed bees and decide if explore the source food of a certain employes been based on a probabilistc criteria. More onlockers bees are on the same food source more the intensfication in this area increase.
  3. scout bees seqarching for food sources randomnly Both onlookers and scouts are also called unemployed bees. Initially, all food source positions are discovered by scout bees. Thereafter, the nectar of food sources are exploited by employed bees and onlooker bees, and this continual exploitation will ultimately cause them to become exhausted. Then, the employed bee which was exploiting the exhausted food source becomes a scout bee in search of further food sources once again. In other words, the employed bee whose food source has been exhausted becomes a scout bee. In ABC, the position of a food source represents a possible solution to the problem and the nectar amount of a food source corresponds to the quality (fitness) of the associated solution. The number of employed bees is equal to the number of food sources (solutions) since each employed bee is associated with one and only one food source. initialization phase

In particle swarm optimization, simple software agents, called particles , move in the search space of an optimization problem. The position of a particle represents a candidate solution to the optimization problem at hand. Each particle searches for better positions in the search space by changing its velocity according to rules originally inspired by behavioral models of bird flocking. idea : each individual move and sample the solution space and take infotrmation of the best solutionf found from its neighborhood Exploration is achieved by individual agents that search for the best solution (food source) in their neighborhood, determined by their position, which is initially assigned randomly according to a uniform distribution. The search is performed by the movement of each particle, where the movement is guided by the best position found so far in search space, which is updated when better solutions are discovered. To evaluate each position a fitness function (or cost function) is used. Exploitation is then achieved by taking advantage of other searches toward promising regions, as other successful behaviors influence the search direction of each individual. To avoid getting stuck in a local minimum, the swarm is divided into sub-groups and information is spread only within the sub- group. To guarantee global spread of information each particle is part of more sub-groups. proximity individuals are effected by the best solution found from other individuals that are closer to them. algorithm initialize a population of candidate solutions (paeticles) randomly at each step move each particles in the serach space based on:

  1. the best solution found by the single particle
  2. the best solution of the entire population
  3. velocity of the particle
  4. hyper parameter The first term, called the inertia or momentum serves as a memory of the previous flight direction, preventing the particle from drastically changing direction. The second term, called the cognitive component models the tendency of particles to return to previously found best positions. The third term, called the social component quantifies the performance of a particle relative to its neighbors if a solution is better then spread the information among the particles. In order to evaluate a solution we need a fitness function.

All these swarm intelligence algorithms require an accurate parameter tuning activity, which is a tedious and error prone operation. In fact, it's hard to find the optimal parameter configuration. this method are never complete! no optimal or feasible solution guarantee. All the solution found using local search or population based can be found in the search tree.

Games

Games are multi-agent environment that has to account for the presence of an opponent, and we do not know how the oppenent behave. the player in games can be 2 or more but we do not know haw the opponents behave. we consider only games with following properties:

  1. Two player games (we call them MAX and MIN) in which the moves are alternated and players have complementary objective functions, one win and the other lose.
  2. Games with perfect knowledge of the environments, player have the same informations. (this does not happen in poker or bridge..) The development of a match can be interpreted as a tree in which the root is the starting position and leaves the final positions, the moves at each levels are performed by a different player. The tree encode al possible match that the 2 player can do by starting from a given position. Tree structure:
  3. Node: the state of the game, in case of board game, the node is a rapresentation of the board
  4. Operator: all possible move that a payer can do from the current board
  5. Goal: node in which the game terminate, so the leaf can be labeled as: max win, max lose or tie. We have to construct a tree every time a player has to move, then we explore it until we find the goal state and porpagate the value back, then the player at the root select the best move he can do at level 1. We have to construct a different tree every time playes has to move. we are not interesting in the path but only on the best move that the player has to select. wehn we find a goal state, we assign to it a reward and propagate back the value. so we explore all the tree, propagate back the value until the root, and then the root player selcet the best move for himself.

if the search space is huge we have to prune the tree, we can not explore all the tree, if is the branch and is the depth then the elaf are. we have to apply the min-max algo up to certain node and then apply an evaluation function to the leaf in which we stop. This evaluation function must be fast to compute, else the time i spent to compute the evaluation i could use it for search. If the evaluation function is perfect, i would stop at the first level evaluate the ndoe and oick the best action, but we do not have a perfect evaluation function. What happen if evaluation function of other player is different from my? you have to think that a good move for me is a bad for the opponent. So we consider the evaluation only from one player perspective and if the root node is a max, all the eval function are given by the max eval function because we do not know the eval function of the opponent. the opponent will try to minimize my evaluation function. Stop after few iterations How we decideto expand a node or not? we could set a maximum depth for all the tree or we can explore first the most promising action until a certain depth or until the evaluation function does not change a lot and then search for the not promising action, but stop the search for them until a few iterations sometimes we can also search more for moves that seem complicated, so move that have an high variance in the evalution function, so evalute it with an higer depth, the problem is that this moves can be useless, so we extend the tree for level grater than p, but the search is useless. so in general we explore the tree until a certian level, stop the search, compute the evaluation function on each leaf and propagate the values back. alpha beta cut The type of evaluation we have seen so far consider also moves and nodes that will never occur. If I found a move that is better than all the possible moves i can do in certain node, then i can stop to seach along this path because all the possible moves i can do from the current state will never influence the choice make at root level. We can explot this concept to reduce the search space. idea behind alpha-beta cut: Consider a node in the tree, if the player had a better choice (call it ), in the parent node level or at any point along the current path, then will never be selected, so we cut this path and stop search along this way.

we call alpha the best value found on the path for MAX, and beta the best value found on the path for MIN, the algorithm cut the branch using this two value since there is no way of finding a best value along the current path, no matter which is the evaluation of the node along this path. alpha and beta are values that store the current best value you can chose in a given path rules of cutting

  1. if alpha is greater or equal than beta of a descending node, then stop the genration of the children for the descending node
  2. if beta is smaller or equal than alpjha of a descending ndoe, then stop the geneartion of the children for the descending node So we generate depth-first tree, left to right, until we encounter.aleaf or until a certain depth, then we propagated the value or the estimated value back from the leaf. effectiveness If you always evalute first the worst node, then the best ndoe are always in the search path so there will be no cut, the best case is when we evaluate first the best node, the other will be always cut because we have found the most promsing path. so it is important to selcet the order of the node if we want to cut more, also is important t avoid simmetries to avoid to repeat the search for move that arre symmetric to other. reduce the search space. important alpha beta cut will not cut promising move, it just cuts useless move. the use or not of cuts will no influence the best move selected at root node, it influence the efficency because you save time for evaluate other node that are useless. this does not change completeness and optimality of your algo. we can use the evaluation function to order the node to explore first, trying to maximize the cut that we will do. for the exam the first smaller subtree on the left will always been evaluated, look for simmetric games, we do not need to duplicate moves.