One AI Algorithm

All Programmers Should Know

https://OneAIAlgorithm-confoo.azurewebsites.net/

Barry S. Stahl - @bsstahl - http://www.CognitiveInheritance.com

About Me

I think it is noteworthy that I am the type of person who has both favorite physicists and favorite mathematicians - @bsstahl 16 Apr 2017

Favorite Physicists Favorite Mathematicians
Harold "Hal" Stahl Ada Lovelace
Carl Sagan Alan Turing
Neil Degrasse Tyson Johannes Kepler
Nikola Tesla Rene Descartes
Marie Curie Isaac Newton
Richard Feynman Leonardo Fibonacci
Albert Einstein George Boole

Other notables: Niels Bohr, Galileo Galilei, Michael Faraday, Blaise Pascal, Johann Gauss, Grace Hopper, Stephen Hawking, Marvin Minsky, Daphne Koller, Benoit Mandelbrot

Some OSS Projects I Run

  • Liquid Victor
    • [Experimental] The media tracking and aggregation system that was used to assemble this presentation
  • Prehensile Pony-Tail
    • A blogging platform that produces plain HTML5/CSS output for ultimate scalability.
  • IntentBot
    • A microservices framework for creating conversational bots on top of Bot Framework.
  • LiquidNun
    • A library of abstractions and their implementations that help create loosely-coupled applications.
  • Toastmasters Agenda
    • A c# library and website for generating agenda's for Toastmasters meetings.

GiveCamp

International Headquarters: http://givecamp.org

A weekend event where software creators come together to create great software for some amazing local charities

Artificial Intelligence

A Computational System that Behaves Rationally

Rationality

A system is rational if it attempts to make the best possible decision​ based on the best available understanding of the problem (model)​ and of the state of the domain (data)​.

Intelligent Agents

Intelligent Agents.png

Knapsack Problems

Knapsack Problem.png

Memoization

Slide7_1200x600.jpg

Memoization

Slide8_1200x600.jpg

Memoization

Slide9_1200x600.jpg

Memoization

Slide10_1200x600.jpg

Memoization

Slide11_1200x600.jpg

Memoization

Slide12_1200x600.jpg

Memoization

Slide13_1200x600.jpg

Memoization

Slide14_1200x600.jpg

Memoization

Slide15_1200x600.jpg

Memoization

Slide16_1200x600.jpg

Memoization

Slide17_1200x600.jpg

Memoization

Slide18_1200x600.jpg

Memoization

Slide19_1200x600.jpg

Memoization

Slide20_1200x600.jpg

Memoization

Slide21_1200x600.jpg

Memoization

Slide22_1200x600.jpg

Memoization

Slide23_1200x600.jpg

Memoization

Slide24_1200x600.jpg

Memoization

Slide25_1200x600.jpg

Memoization

Slide26_1200x600.jpg

Memoization

Slide27_1200x600.jpg

Memoization

Slide28_1200x600.jpg

Memoization

Slide29_1200x600.jpg

Dynamic Programming

A mathematical optimization technique

  • Best for solving problems that can be described recursively.​
  • Breaks the problem into smaller sub-problems​
  • Solves each small problem only once​
  • Guarantees an optimal solution​

Optimization Problems

  • Find the best values for a set of decision variables that​
    • Satisfies all constraints
    • Maximizes the features we want​
    • Minimizes the features we don’t want

Simple Example - Chutes and Ladders

Chutes and Ladders 3.gif Linear Array.jpg

Chutes and Ladders - Greedy Algorithm

  • Start at the 1st space on the board​
  • While we haven't reached the last space​
    • Add the space to the current path​
    • If the current space has a ladder​
      • Add the end of the ladder to the path​
      • Make that space the current space​
    • Move to the next space on the board​
  • Return the completed path through the board
Greedy Algorithm.jpg

Dynamic Programming - Step 1

DetermineDistance(s,d)

  • Call DetermineDistance(space[0], 0)
  • If shorter​ than previously found
    • Set DistanceFromStart property
    • If this space starts a chute or ladder​
      • DetermineDistance(endOfNavigation, distanceFromStart+1​)
    • If not at the end of board​
      • DetermineDistance(nextSpace, distanceFromStart+1)
  • Return all spaces with their DistanceFromStart property populated
Determine Distance from Start.png

Dynamic Programming - Step 2

  • Start at the last space on the board​
  • While we are still on the board​
    • Add the current space to the path​
    • Set the current space to a space that is a neighbor of the current space and whose DistanceFromStart is space.DistanceFromStart-1​
  • Reverse the direction of the path​
Retrace Path - Smaller.png

Memoization

Memoization.gif

Shortest Path

Slide79_1000x475.jpg

Shortest Path

Slide80_1000x475.jpg

Shortest Path

Slide81_1000x475.jpg

Shortest Path

Slide82_1000x475.jpg

Shortest Path

Slide83_1000x475.jpg

Shortest Path

Slide84_1000x475.jpg

Shortest Path

Slide85_1000x475.jpg

Shortest Path

Slide86_1000x475.jpg

Shortest Path

Slide87_1000x475.jpg

Shortest Path

Slide88_1000x475.jpg

Shortest Path

Slide89_1000x475.jpg

Shortest Path

Slide90_1000x475.jpg

Summary - Dynamic Programming

  • Populate the cache​
    • Simple calculations​
    • Build from the ground-up​
  • Use the cached data to determine the answer(s)​
    • Work backwards through the cache​
  • Guaranteed Optimality​
    • A fully populated cache means all options are explored​
    • Works in any number of dimensions​
  • Works with any graph (nodes & edges)​
    • Works best when​
      • Problems can be described recursively​
      • 1 or more axis are limited in scope

Resources