CM10228 / Programming Ib:   Lecture 12

Applications of Search: Artificial Intelligence

-I.  Housekeeping

  1. Coursework Marking:
    1. I'm glad some students are getting their programs working for the first time here.
      1. Unfortunately, we can't give you extra marks for that, this is the second semester of programming.
      2. We mark CW 1 very strictly, because that's how it's going to be for the rest of your 3 year course / life.
        1. Code needs to be well formatted and commented to be useful, for you or for others.
        2. You need to be able to conform to a spec / requirements.
    2. Nobody should have less than 40% on all of their courseworks!
      1. Remember you can hand in coursework late and get up to that point.
      2. If you have 40% for your coursework mark you only need 40% on the exam to pass.  If you have 0 on your coursework mark you need 80% on the exam.  That will be hard to get, particularly for people who don't understand programming.
    3. Appeal procedure on marking:
      1. Go to the TAs.
      2. If it can't be resolved, sign up for my office hours using this link (see also my Contact page.)
      3. I almost never remark myself without checking again with the TAs, because we have to keep a uniform standard.  cf How marking in second semester programming works, an essay from 2014.
  2. How to handle coursework marking complaints.
    1. First, go to lab.
      1. Remember, it may very well be marked correctly. What you are doing is asking about a mark you don't understand.
      2. If you still want it remarked after you achieve understanding, ask a TA to remark it. Note that they are free to mark down as well as up, and that will be your new mark.
    2. Second (if necessary), come to me.
      1. There are two main reasons to come to me:  if you are having problems the tutors can't solve (e.g. problems with the tutors) or if you find broken links on the course pages.
      2. Note, extensions are not given by lecturers, they are given by the Director of Studies.
  3. Marks from tutors are preliminary & do not include late marks etc.
    1. Initial moderation will have taken place before you see the marks.
    2. In addition, I moderate coursework marks after term (when I everything late is handed in & we know how the term went.)
    3. Then all marks can be moderated again by the department in the exam / unit boards.
    4. However, most moderation is done on the marks before you see them (e.g. agreement between tutors.)

I.  Are your Gamebots Intelligent?

  1. What would an intelligent machine be able to do?
    1. Is a robot that can play chess intelligent? 
    2. Many robots run linux, and therefore come with gnu chess.
  2. Intelligence is the ability to generate appropriate behaviour in response to an unpredictable environment.
    1. Note that by this definition, plants are intelligent!
      1. An agent is anything that effects change in an environment, e.g. chemical agents create reactions.  Intelligence is more than agency.
      2. Also not that interested in defining a ball rolling down hill as intelligent.  Laws of physics alone are not usually enough for a an intelligent response, but are always part of it.
    2. The amount of intelligence is generally considered proportional to the ability to generate novel behaviour quickly, but this is difficult to quantify.
  3. Behaviour is the interaction between an intelligent agent and its environment.
    1. Spiders look smart in webs, stupid in bath tubs.
    2. When a robot looks stupid, is the problem the mind, the body, or the connection between them?
    3. When people look stupid, they are often doing things we're just bad at:  e.g. math, playing chess.  But we are incredible at recognising faces, learning language, walking on two legs.  How many muscles are you controlling when you talk or walk?  Why is it different if you juggle too?
  4. Another way to think about intelligence is action selection,
    1. the on-going problem of deciding what to do next
    2. depends on having a set of "what"s one can do
    3. not doing anything is also an option ? exactly when you act can be determined by certainty, motivation, the environment...
  5. There are two basic processes to AI:  generate and test.
    1. If you can generate perfectly, you don't need to test.
    2. If you can test really quickly, you can generate random garbage.
  6. People normally do what is instinctive or habit, but once in a while we think.
    1. When we think, we consider just a small subset of possible behaviours. 
      1. You don't think about edge pieces on the football pitch.
    2. Where does this subset come from?
      1. Previous experience.
      2. Stuff you've seen other people do.
      3. Elaboration (generation) based on a seed of one or more of the above.
        1. Generation is often hacking on known solutions.
    3. Testing is done either by reasoning / imagining / running models, or by actually trying.
  7. People often fail to realize they are doing or acheiving AI.
    1. A calculator would seem completely freaky to people 150 years ago, but no one thinks of it as AI now.
    2. Turing test.
    3. King Kong was so realistic people fainted in 1930s, now shown to children.
      1. How do you do on this test?
    4. Thermostats & Chinese Room
    5. Like all systems, intelligence has many components.
    6. We can now do with computers many things that people do -- some better, some not as well (apparently).
      1. People (and other animals) though are amazingly good at combining information streams probabalistically, so we may not actually be as good as we seem to be at any one approach.
      2. e.g. more likely to recognise someone you expect to see.
    7. Some of human intelligence may not be that different from your game bots (even if they don't do much.)

II. What is the Complexity of Intelligence?

  1. Note that both generation and testing can be thought of as search!
  2. We'll start out by thinking about a simple game.
    1. Games aren't what intelligence was developed for.
    2. But they are a representation of the kinds of reasoning & competitions we do in social domains.
    3. Often used traditionally in AI, somewhat controversial now (more about this at the end.)
    4. Good intuition pumps.
  3. Tic-tac-toe (noughts & crosses)  draw
    1. Initial board is empty.
    2. First player can choose one of 9 places to go.
    3. Next player can choose one of 8 places to go
    4. Game can't take more than 9 steps.
    5. Object is to get three characters in a row --- many games no one wins.
    6. Web pages with pictures:,
  4. Complexity is vaguely exponential!
  5. Think about chess -- that's really exponential...
  6. Most AI problems are in NP
    1. Non-polynomial --- essentially computationally intractable to find (best/optimal) solution.
    2. But if you do find a solution, you can prove it's correct in polynomial time.
      1. This makes NP different from EXP, for example.
      2. Complexity class fun for the masochists:  The Complexity Zoo.
    3. Worse class of problems is when you can't recognize when you've happened to find a solution!
  7. Empirically, many problems we work on seem similar to NP.
    1. How long would it have taken you to invent quick sort?
    2. How long did it take you to understand that it would work?
    3. The answer to question 1 might actually be shorter than you think, or sometimes even shorter than question 2, see section on expertise below.
  8. If a problem is polynomial time or easier, we assume we can usually write a conventional algorithm to solve the problem. 
    1. In the 1990s, you couldn't do an AI dissertation until you proved the problem you were working on was at least NP-hard.
    2. But now we realise that there may be systems engineering reasons for using AI even when conventional algorithms might exist.
      1. Sometimes AI is used to find the solution, but then the solution is recoded deterministically.
      2. Like when you bookmark a page you found on Google.
      3. Which you won't bother doing if finding it was really easy.

III. Depth First vs. Breadth First Search

  1. Depth first search looks all the way down a tree's branches until it finds a solution.
    1. start at the root
    2. look for your answer
    3. if not found
      1. for each child
        1. depth first search
  2. Breadth first search looks across the tree at one depth, and then on to the next level
    1. breadth-first-search (list)  // initially list only contains the root
    2. for each thing in the list
      1. look for the answer
      2. if not found
        1. append item's children to the end of list
  3. Depth first search is faster, because it doesn't store as much state. 
    1. But you can't know if you have the best answer (least amount of steps) unless you look at the whole tree!
  4. Breadth first search guarantees the shortest answer,
    1. but is impossible in cases like chess --- requires more memory than atoms in the universe.
  5. But depth first has another problem --- may enter an infinite loop!
    1. e.g. in chess -- can move a rook back & forth forever.
  6. Here's a picture (from Ralph Morelli's AI Lecture notes):

    Consider the following graph:

    a search

    Depth First Search examines the nodes in the following order:

      A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U, D, I, Q, J, R

    Breadth First Search examines the nodes in the following order:

      A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U

IV. Heuristic Search

  1. We want ways to prune the tree -- make there be less branches.
  2. If you are playing an opponent, assume that each player will avoid losing games, ignore those branches.
    1. This is called "mini-max search" because you alternately minimize & maximize your own expected outcome as you go through the tree.  (demo on tic-tac-toe tree).
  3. Estimate the value of branches & go down the ones that look most profitable.
    1. Estimates are based on heuristics, rules that are often but not always right.
      1. E.g. you might guess that the shortest way across town on the map is the fastest, but really the fastest way depends on traffic, width of streets, tourists, shops etc.
      2. In chess, a common heuristic is to count how many pieces you have left, giving extra value to more powerful pieces.
    2. A* search is kind of like breadth first search, but you keep sorting the list, & keep going down the shortest / cheapest path you've found so far, based on a heuristic estimate of cost.
      1. A*-search (list)  // initially list only contains the root
      2. for the cheapest thing in the list
        1. check if you have the solution, if so use it
        2. take item off list, remembering the cost associated with it,
        3. estimate cost of all children, summing their cost with parent's cost.
        4. sort children into your existing list
      3. If you can guarantee that your heuristic never underestimates the cost of performing the action (overestimating is OK) then this will find the optimal solution.
      4. A* search is used in almost all VR computer games for navigation:  choosing how to get to a goal location (at least while you are looking at the characters.)
        1. While you aren't looking, characters magically warp where they were going to go, to save CPU cycles.
        2. See the Game AI Page: Pathfinding.  Rats, that's gone now, but here's a Game AI page that covers a lot of path planning.
  4. Unfortunately, search is still slow if you have to search too many things, even with pruning.
    1. Here's a real world example showing that some problems are even harder than NP -- like Air Travel Planning.
    2. That shows the type of analysis people do once they notice they have hit a hard problem, so they can understand exactly how hard it is, and try to work around it.
    3. Actually, the point of that talk was to excite & recruit smart PhD students.  ITA software (like Google) hires lisp programmers.

V. Summary

  1. Intelligence is a similar problem whether natural or artificial.
  2. A lot of what we do (with our brains as well as our computers) can be thought of as search.
  3. Games are a "toy domain", but can help us understand why search is hard, and how we might be solving other problems.
  4. Next lectures: learning, concurrency

page author: Joanna Bryson
12 March 2015