SlideShare a Scribd company logo
1 of 70
Algorithms for More
Intelligent Apps
Frank A. Krueger
for Future Decoded
London
November 2, 2016
Frank A. Krueger
* @praeclarum on Twitter
* Independent mobile app developer (8 years!)
specializing in .NET and Xamarin
- iCircuit, Calca, Continuous
* Open Source Contributor: SQLite-net,
NGraphics, Netjs, …
* Co-host of Merge Conflict podcast with
James Montemagno (http://mergeconflict.fm)
#microsoft
Hiring Manager: Do this thing with a
linked list.
Me: What’s a linked list? 😰
#books
AGENDA
* Linked List Traversal----------------------- NO
* Fuzzy Logic
* Eval
* General Problem Solvers
* Simulated Annealing
(in no particular order)
if temp < desiredTemp
then
setFan(100%)
else
setFan(0%)
“Chatter”
These
can’t be
right
“Chatter” occurs when the fan jumps
from 100% to 0%
when it’s near desiredTemp
0% 100% 0% 100% 0% 100% 0%
temp
desiredTemp
fan
let error = desiredTemp -
temp
if error < 0° then
setFan(0%)
elif error < 10° then
setFan(10%)
elif error < 25° then
setFan(50%)
else
setFan(100%)
More Granularity Fixes All Problems
FUZZY
LOGIC
let error = desiredTemp -
temp
if error < 0° then
setFan(0%)
elif error < 10° then
setFan(10%)
elif error < 25° then
setFan(50%)
else
setFan(100%)
Input Classes
Outputs
Build a Table of Inputs and Outputs
Input | Output
(Error) | (Fan)
============+=========
TooHot | 0%
AlmostThere | 10%
AWaysToGo | 50%
JustStarted | 100%
Input Classes
Output per Class
“Classifiers” are functions
that measure how well an
input matches a class
Trapezoids are good classifiers
True
Input
False
“Fuzzy”
Error = 0 2° 8° 12° 18°
AlmostThere
Classifier
Lots of Classifiers
TooHot
AlmostThere
AWaysToGo
JustStarted
All Inputs are Classified
Some Inputs Have Multiple Classes
Blend The Outputs for Multi-class
Error = 16.5°
Input | Output
============+=========
TooHot | 0%
AlmostThere | 10%
AWaysToGo | 50%
JustStarted | 100%
Fan = 0.25 * 10% +
0.75 * 50%
= 40%
TooHot = 0
AlmostThere = 0.25
AWaysToGo = 0.75
JustStarted = 0
FUZZY LOGIC
* Formalizes a common pattern
* Simplifies problem with classes
- Doesn’t require mathematical models
- Your intuition is usually enough
* Smooth output thanks to blending
* Scales to many inputs and many outputs
A COURSE IN FUZZY SYSTEMS
AND CONTROL by Li Xin-Wang
FUZZY LOGIC LIBRARIES
GameplayKit
GKRuleSystem
Accord.Fuzzy
InferenceSystem
“Fuzzy”
4+ Packages
Eval is an algorithm
for computing anything.
(It’s a virtual computer!)
Program
{}
Eval
...
Value
42°
Abstract Syntax Tree
from Source Code
Pretty Much
Anything
type Syntax =
| Number of float
| Assign of string * Syntax
| Variable of string
| Invoke of Syntax * Syntax[]
| Program of Syntax[]
distance = 101390
velocity = 1000
G = 9.81
angle = 0.5 * asin(G*distance/velocity^2)
Source Code
Syntax Tree
ValueSyntax
Eval is a function that takes
Syntax and produces a Value
NumberNumber
Eval value;
Environment.Set value
Assign
Eval each lineProgram
Variable Environment.Lookup
Friend :-)
Invoke
Eval arguments;
Environment.Set arguments;
Eval body
Eval condition; if true
Eval true syntax, else Eval
false syntax
Conditional
Adding more Syntax is fun & easy
Eval initial; Assign variable;
Eval body; Increment variable;
Check condition; Loop
Loop
Return Closure object
containing Environment and
the function Syntax
Lambda
Recursive Functions of Symbolic Expressions
John McCarthy, 1960
Calca
Frank A. Krueger, 2013
Continuous
Frank A. Krueger, 2016
Why Learn Eval?
* Let users type math when entering numbers
* Add scripting to your app with full sandboxing
* Write Domain Specific Languages
* Write compilers in your spare time
SICP by Abelson & Sussmans
LIBRARIES
System.Linq.Expressions
Expression
Microsoft.CodeAnalysis
“Roslyn”, ISyntax
“Interpreter”
50+ Packages
I have a problem…
* I know roughly what the solution looks
like
* I know how to determine the quality of
a potential solution
* I don’t know how to find the solution
(or it takes too long)
* Layout Circuit Boards
- Know: Components & connections
- Want: Optimal layout
* Plan an Epic Trip
- Know: Cities you want to visit
- Want: Flight & hotel bookings
An algorithm to solve problems:
1. Guess at the solution
2. Randomly change the solution a bit
3. Measure the change in quality
4. If it is better, then accept it
Else, reject it
5. Good enough? DONE
6. GOTO 2
* Greedily looks for a “good” solution,
not the best
- Local minima, not global
“Goodish”
* General purpose
* Intuitive and simple to implement
* A bit slow because it has no knowledge
of the domain
An algorithm to solve problems:
1. Guess at the solution
2. Randomly change the solution a bit
3. Measure the change in quality
4. If it is better, then accept it
Else, reject it
5. Good enough? DONE
6. GOTO 2
Insight: let’s accept
bad changes!
Simulated Annealing
StartWarmHot!Quench!Slowly cool…
Annealed because we gave it time
to try some “bad” configurations
Boltzmann’s Distribution
Even at low
temperatures, high
energy states can exist
An algorithm to solve problems:
1. Guess at the solution
2. Randomly change the solution a bit
3. Measure the change in quality
4. If it is better, then accept it
Else, reject it
5. GOTO 2
Simulated Annealing:
1. Guess at the solution
2. Start with a high temperature
3. Randomly change the solution a bit
4. Measure the change in quality (“energy”)
5. If it is better, then accept it
Else, calculate the change in energy
and the probability of that change
given the temperature
and accept if randomly chosen
6. If it’s been “awhile”, decrease temperature
7. GOTO 3
I want to visit London, Barcelona, Russia, and Japan:
Guess: Tokyo – Moscow – London – Barcelona
Random Change: Barcelona – Moscow – London – Tokyo
Energy = 900 ΔE = -100
Energy = 1000
Random Change: Barcelona – Moscow – London – Tokyo
Energy = 900 ΔE = -100
Random Change: Moscow – Barcelona – London – Tokyo
Energy = 1500 ΔE = 600
Random Change: Moscow – Barcelona – London – Tokyo
Energy = 1500 ΔE = 600
Boltzmann Probability (ΔE, T) = 0.1
*Roll the dice*
NUMERICAL RECIPES in C++ by
Press, et el.
LIBRARIES
LibOptimization
Optimization.clsOptSimulatedAnnealing
How to Solve Problems, Generally
State of the World is a collection of “truths”
Sunny
Outside
Watching a
Presentation
Bags
Unpacked
Happy
Curious
about
Twitter
Hungry
How to Solve Problems, Generally
Action: Pack My Bags
Remove: Bags Unpacked
Add: Bags Packed
Require: In Hotel Room
&& Bags Unpacked
Actions Remove Truths and Add New Ones
How to Solve Problems, Generally
Want: Bags Packed && Checked
into Flight
Problems are described by stating which truths
you want to be true
GPS
Current World State
All Possible Actions
Action 1
Action 2
Action 3
Action 4
Action …
New World State
General Problem Solvers Algorithm
1. Look for an Action that adds the needed state
to the world with all its requirements met
2. If one found, add it to the solution;
DONE!
3. Else, look for an Action that adds the needed
state to the world (requirements not met).
4. If one found, Solve the Sub-problem of meeting
that action’s Requirements. GOTO 1.
5. FAIL! :-(
Recursive
GPS Variations
1. First solution or best solution?
2. What do you mean best?
GPS Criticisms
1. Solution time grows exponentially
2. “Good at solving puzzles”
Looks good to me!
GPS as an Architecture
Where does the data come from?
Make Tile
Street Data
Building Data
Terrain Data
Vector
Data
Terrain
Server
Vector
Server
Route Car
Show Address
async Task<Tile> MakeTile ()
{
var terrain = await GetTerrain();
var vectors = await GetVectors();
var roads = GetRoads(vectors);
var buildings = GetBuildings(vectors);
return ReallyMakeTile(terrain, roads, buildings);
}
How do you handle network errors?
async Task<Tile> TryHarderToMakeTile ()
{
for (var i = 0; i < NumRetries; i++) {
try {
return await MakeTile();
}
catch (NetworkError e) {
// Keep trying after a little wait
await Task.Delay(1000);
}
catch {
throw;
}
}
}
I’m not impressed…
GPS as an Architecture
Possible Truths of the World
Vector
Terrain Network
Streets
Buildings
Define Single Problem Solver Actions
Action: Load Terrain
Add: Terrain
Require: Network
Define Single Problem Solver Actions
Action: Load Streets
Add: Streets
Require: Vector
Define Single Problem Solver Actions
Action: Load Vector
Add: Vector
Require: Network
GPS as an Architecture (Example 1)
Want: Streets && Buildings &&
Terrain
GPS
Network
All Actions
Load Vector
Load Streets
Load Buildings
Load Terrain
GPS as an Architecture (Example 2)
Want: Streets && Buildings &&
Terrain
GPS
Terrain && Vector
All Actions
Load Streets
Load Buildings
GPS as an Architecture (Example 3)
Want: Streets && Buildings &&
Terrain
GPS
Terrain
All Actions
FAIL
(No Network)
GPS Benefits
1. Standardized way of looking at problems
– helps you think!
2. Actions become very specialized doing
one thing very well.
3. Restartable – unlike async methods,
partially solved problems can be
continued.
4. Even the dumbest version of GPS can
help us write better software.
Paradigms of AI Programming
by Norvig
LIBRARIES
“Solver”
0 Packages :-(
Thank you!
* @praeclarum on Twitter and GitHub

More Related Content

Similar to Algorithms - Future Decoded 2016

Lecture01a correctness
Lecture01a correctnessLecture01a correctness
Lecture01a correctnessSonia Djebali
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor ConcurrencyAlex Miller
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 introchidabdu
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapaloozaJenniferBall44
 
Causal inference-for-profit | Dan McKinley | DN18
Causal inference-for-profit | Dan McKinley | DN18Causal inference-for-profit | Dan McKinley | DN18
Causal inference-for-profit | Dan McKinley | DN18DataconomyGmbH
 
DN18 | A/B Testing: Lessons Learned | Dan McKinley | Mailchimp
DN18 | A/B Testing: Lessons Learned | Dan McKinley | MailchimpDN18 | A/B Testing: Lessons Learned | Dan McKinley | Mailchimp
DN18 | A/B Testing: Lessons Learned | Dan McKinley | MailchimpDataconomy Media
 
Priming Java for Speed at Market Open
Priming Java for Speed at Market OpenPriming Java for Speed at Market Open
Priming Java for Speed at Market OpenAzul Systems Inc.
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptGAURAVNAUTIYAL19
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch Eran Shlomo
 
Kaggle - Santa Gift Matching Challenge
Kaggle - Santa Gift Matching ChallengeKaggle - Santa Gift Matching Challenge
Kaggle - Santa Gift Matching ChallengeKnowledgeMavens
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sJay Patel
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deckMikeBegley
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science ChallengeMark Nichols, P.E.
 

Similar to Algorithms - Future Decoded 2016 (20)

Stop that!
Stop that!Stop that!
Stop that!
 
Lecture01a correctness
Lecture01a correctnessLecture01a correctness
Lecture01a correctness
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
Actor Concurrency
Actor ConcurrencyActor Concurrency
Actor Concurrency
 
Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
 
Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
Causal inference-for-profit | Dan McKinley | DN18
Causal inference-for-profit | Dan McKinley | DN18Causal inference-for-profit | Dan McKinley | DN18
Causal inference-for-profit | Dan McKinley | DN18
 
DN18 | A/B Testing: Lessons Learned | Dan McKinley | Mailchimp
DN18 | A/B Testing: Lessons Learned | Dan McKinley | MailchimpDN18 | A/B Testing: Lessons Learned | Dan McKinley | Mailchimp
DN18 | A/B Testing: Lessons Learned | Dan McKinley | Mailchimp
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Priming Java for Speed at Market Open
Priming Java for Speed at Market OpenPriming Java for Speed at Market Open
Priming Java for Speed at Market Open
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
DAA Notes.pdf
DAA Notes.pdfDAA Notes.pdf
DAA Notes.pdf
 
C Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.pptC Programing Arithmetic Operators.ppt
C Programing Arithmetic Operators.ppt
 
Realtime Analytics
Realtime AnalyticsRealtime Analytics
Realtime Analytics
 
Deep learning from scratch
Deep learning from scratch Deep learning from scratch
Deep learning from scratch
 
Kaggle - Santa Gift Matching Challenge
Kaggle - Santa Gift Matching ChallengeKaggle - Santa Gift Matching Challenge
Kaggle - Santa Gift Matching Challenge
 
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal'sGreedy algorithms -Making change-Knapsack-Prim's-Kruskal's
Greedy algorithms -Making change-Knapsack-Prim's-Kruskal's
 
Interview questions slide deck
Interview questions slide deckInterview questions slide deck
Interview questions slide deck
 
Cloudera Data Science Challenge
Cloudera Data Science ChallengeCloudera Data Science Challenge
Cloudera Data Science Challenge
 

More from Frank Krueger

Open Source CLRs - Seattle Mobile .NET
Open Source CLRs - Seattle Mobile .NETOpen Source CLRs - Seattle Mobile .NET
Open Source CLRs - Seattle Mobile .NETFrank Krueger
 
Asynchronous Application Patterns in C# - MonkeySpace
Asynchronous Application Patterns in C# - MonkeySpaceAsynchronous Application Patterns in C# - MonkeySpace
Asynchronous Application Patterns in C# - MonkeySpaceFrank Krueger
 
Programming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveProgramming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveFrank Krueger
 
3 Mobile App Dev Problems - Monospace
3 Mobile App Dev Problems - Monospace3 Mobile App Dev Problems - Monospace
3 Mobile App Dev Problems - MonospaceFrank Krueger
 
How I Made Zoom In and Enhance - Seattle Mobile .NET
How I Made Zoom In and Enhance - Seattle Mobile .NETHow I Made Zoom In and Enhance - Seattle Mobile .NET
How I Made Zoom In and Enhance - Seattle Mobile .NETFrank Krueger
 
Overview of iOS 11 - Seattle Mobile .NET
Overview of iOS 11 - Seattle Mobile .NETOverview of iOS 11 - Seattle Mobile .NET
Overview of iOS 11 - Seattle Mobile .NETFrank Krueger
 
Functional GUIs with F#
Functional GUIs with F#Functional GUIs with F#
Functional GUIs with F#Frank Krueger
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#Frank Krueger
 

More from Frank Krueger (9)

Open Source CLRs - Seattle Mobile .NET
Open Source CLRs - Seattle Mobile .NETOpen Source CLRs - Seattle Mobile .NET
Open Source CLRs - Seattle Mobile .NET
 
Asynchronous Application Patterns in C# - MonkeySpace
Asynchronous Application Patterns in C# - MonkeySpaceAsynchronous Application Patterns in C# - MonkeySpace
Asynchronous Application Patterns in C# - MonkeySpace
 
Programming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveProgramming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin Evolve
 
3 Mobile App Dev Problems - Monospace
3 Mobile App Dev Problems - Monospace3 Mobile App Dev Problems - Monospace
3 Mobile App Dev Problems - Monospace
 
How I Made Zoom In and Enhance - Seattle Mobile .NET
How I Made Zoom In and Enhance - Seattle Mobile .NETHow I Made Zoom In and Enhance - Seattle Mobile .NET
How I Made Zoom In and Enhance - Seattle Mobile .NET
 
Overview of iOS 11 - Seattle Mobile .NET
Overview of iOS 11 - Seattle Mobile .NETOverview of iOS 11 - Seattle Mobile .NET
Overview of iOS 11 - Seattle Mobile .NET
 
Functional GUIs with F#
Functional GUIs with F#Functional GUIs with F#
Functional GUIs with F#
 
Mocast Postmortem
Mocast PostmortemMocast Postmortem
Mocast Postmortem
 
Programming iOS in C#
Programming iOS in C#Programming iOS in C#
Programming iOS in C#
 

Recently uploaded

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Algorithms - Future Decoded 2016

  • 1. Algorithms for More Intelligent Apps Frank A. Krueger for Future Decoded London November 2, 2016
  • 2. Frank A. Krueger * @praeclarum on Twitter * Independent mobile app developer (8 years!) specializing in .NET and Xamarin - iCircuit, Calca, Continuous * Open Source Contributor: SQLite-net, NGraphics, Netjs, … * Co-host of Merge Conflict podcast with James Montemagno (http://mergeconflict.fm)
  • 4. Hiring Manager: Do this thing with a linked list. Me: What’s a linked list? 😰
  • 6. AGENDA * Linked List Traversal----------------------- NO * Fuzzy Logic * Eval * General Problem Solvers * Simulated Annealing (in no particular order)
  • 7.
  • 8.
  • 9. if temp < desiredTemp then setFan(100%) else setFan(0%) “Chatter” These can’t be right
  • 10. “Chatter” occurs when the fan jumps from 100% to 0% when it’s near desiredTemp 0% 100% 0% 100% 0% 100% 0% temp desiredTemp fan
  • 11. let error = desiredTemp - temp if error < 0° then setFan(0%) elif error < 10° then setFan(10%) elif error < 25° then setFan(50%) else setFan(100%) More Granularity Fixes All Problems FUZZY LOGIC
  • 12. let error = desiredTemp - temp if error < 0° then setFan(0%) elif error < 10° then setFan(10%) elif error < 25° then setFan(50%) else setFan(100%) Input Classes Outputs
  • 13. Build a Table of Inputs and Outputs Input | Output (Error) | (Fan) ============+========= TooHot | 0% AlmostThere | 10% AWaysToGo | 50% JustStarted | 100% Input Classes Output per Class
  • 14. “Classifiers” are functions that measure how well an input matches a class
  • 15. Trapezoids are good classifiers True Input False “Fuzzy” Error = 0 2° 8° 12° 18° AlmostThere Classifier
  • 17. All Inputs are Classified
  • 18. Some Inputs Have Multiple Classes
  • 19. Blend The Outputs for Multi-class Error = 16.5° Input | Output ============+========= TooHot | 0% AlmostThere | 10% AWaysToGo | 50% JustStarted | 100% Fan = 0.25 * 10% + 0.75 * 50% = 40% TooHot = 0 AlmostThere = 0.25 AWaysToGo = 0.75 JustStarted = 0
  • 20. FUZZY LOGIC * Formalizes a common pattern * Simplifies problem with classes - Doesn’t require mathematical models - Your intuition is usually enough * Smooth output thanks to blending * Scales to many inputs and many outputs
  • 21. A COURSE IN FUZZY SYSTEMS AND CONTROL by Li Xin-Wang
  • 23.
  • 24. Eval is an algorithm for computing anything. (It’s a virtual computer!)
  • 26. type Syntax = | Number of float | Assign of string * Syntax | Variable of string | Invoke of Syntax * Syntax[] | Program of Syntax[] distance = 101390 velocity = 1000 G = 9.81 angle = 0.5 * asin(G*distance/velocity^2) Source Code Syntax Tree
  • 27. ValueSyntax Eval is a function that takes Syntax and produces a Value
  • 28. NumberNumber Eval value; Environment.Set value Assign Eval each lineProgram Variable Environment.Lookup Friend :-) Invoke Eval arguments; Environment.Set arguments; Eval body
  • 29. Eval condition; if true Eval true syntax, else Eval false syntax Conditional Adding more Syntax is fun & easy Eval initial; Assign variable; Eval body; Increment variable; Check condition; Loop Loop Return Closure object containing Environment and the function Syntax Lambda
  • 30. Recursive Functions of Symbolic Expressions John McCarthy, 1960
  • 33. Why Learn Eval? * Let users type math when entering numbers * Add scripting to your app with full sandboxing * Write Domain Specific Languages * Write compilers in your spare time
  • 34. SICP by Abelson & Sussmans
  • 36.
  • 37. I have a problem… * I know roughly what the solution looks like * I know how to determine the quality of a potential solution * I don’t know how to find the solution (or it takes too long)
  • 38. * Layout Circuit Boards - Know: Components & connections - Want: Optimal layout * Plan an Epic Trip - Know: Cities you want to visit - Want: Flight & hotel bookings
  • 39. An algorithm to solve problems: 1. Guess at the solution 2. Randomly change the solution a bit 3. Measure the change in quality 4. If it is better, then accept it Else, reject it 5. Good enough? DONE 6. GOTO 2
  • 40. * Greedily looks for a “good” solution, not the best - Local minima, not global “Goodish” * General purpose * Intuitive and simple to implement * A bit slow because it has no knowledge of the domain
  • 41. An algorithm to solve problems: 1. Guess at the solution 2. Randomly change the solution a bit 3. Measure the change in quality 4. If it is better, then accept it Else, reject it 5. Good enough? DONE 6. GOTO 2 Insight: let’s accept bad changes!
  • 42. Simulated Annealing StartWarmHot!Quench!Slowly cool… Annealed because we gave it time to try some “bad” configurations
  • 43. Boltzmann’s Distribution Even at low temperatures, high energy states can exist
  • 44. An algorithm to solve problems: 1. Guess at the solution 2. Randomly change the solution a bit 3. Measure the change in quality 4. If it is better, then accept it Else, reject it 5. GOTO 2
  • 45. Simulated Annealing: 1. Guess at the solution 2. Start with a high temperature 3. Randomly change the solution a bit 4. Measure the change in quality (“energy”) 5. If it is better, then accept it Else, calculate the change in energy and the probability of that change given the temperature and accept if randomly chosen 6. If it’s been “awhile”, decrease temperature 7. GOTO 3
  • 46. I want to visit London, Barcelona, Russia, and Japan: Guess: Tokyo – Moscow – London – Barcelona Random Change: Barcelona – Moscow – London – Tokyo Energy = 900 ΔE = -100 Energy = 1000 Random Change: Barcelona – Moscow – London – Tokyo Energy = 900 ΔE = -100 Random Change: Moscow – Barcelona – London – Tokyo Energy = 1500 ΔE = 600 Random Change: Moscow – Barcelona – London – Tokyo Energy = 1500 ΔE = 600 Boltzmann Probability (ΔE, T) = 0.1 *Roll the dice*
  • 47. NUMERICAL RECIPES in C++ by Press, et el.
  • 49.
  • 50. How to Solve Problems, Generally State of the World is a collection of “truths” Sunny Outside Watching a Presentation Bags Unpacked Happy Curious about Twitter Hungry
  • 51. How to Solve Problems, Generally Action: Pack My Bags Remove: Bags Unpacked Add: Bags Packed Require: In Hotel Room && Bags Unpacked Actions Remove Truths and Add New Ones
  • 52. How to Solve Problems, Generally Want: Bags Packed && Checked into Flight Problems are described by stating which truths you want to be true GPS Current World State All Possible Actions Action 1 Action 2 Action 3 Action 4 Action … New World State
  • 53. General Problem Solvers Algorithm 1. Look for an Action that adds the needed state to the world with all its requirements met 2. If one found, add it to the solution; DONE! 3. Else, look for an Action that adds the needed state to the world (requirements not met). 4. If one found, Solve the Sub-problem of meeting that action’s Requirements. GOTO 1. 5. FAIL! :-( Recursive
  • 54. GPS Variations 1. First solution or best solution? 2. What do you mean best?
  • 55. GPS Criticisms 1. Solution time grows exponentially 2. “Good at solving puzzles” Looks good to me!
  • 56. GPS as an Architecture
  • 57. Where does the data come from? Make Tile Street Data Building Data Terrain Data Vector Data Terrain Server Vector Server Route Car Show Address
  • 58. async Task<Tile> MakeTile () { var terrain = await GetTerrain(); var vectors = await GetVectors(); var roads = GetRoads(vectors); var buildings = GetBuildings(vectors); return ReallyMakeTile(terrain, roads, buildings); } How do you handle network errors?
  • 59. async Task<Tile> TryHarderToMakeTile () { for (var i = 0; i < NumRetries; i++) { try { return await MakeTile(); } catch (NetworkError e) { // Keep trying after a little wait await Task.Delay(1000); } catch { throw; } } } I’m not impressed…
  • 60. GPS as an Architecture Possible Truths of the World Vector Terrain Network Streets Buildings
  • 61. Define Single Problem Solver Actions Action: Load Terrain Add: Terrain Require: Network
  • 62. Define Single Problem Solver Actions Action: Load Streets Add: Streets Require: Vector
  • 63. Define Single Problem Solver Actions Action: Load Vector Add: Vector Require: Network
  • 64. GPS as an Architecture (Example 1) Want: Streets && Buildings && Terrain GPS Network All Actions Load Vector Load Streets Load Buildings Load Terrain
  • 65. GPS as an Architecture (Example 2) Want: Streets && Buildings && Terrain GPS Terrain && Vector All Actions Load Streets Load Buildings
  • 66. GPS as an Architecture (Example 3) Want: Streets && Buildings && Terrain GPS Terrain All Actions FAIL (No Network)
  • 67. GPS Benefits 1. Standardized way of looking at problems – helps you think! 2. Actions become very specialized doing one thing very well. 3. Restartable – unlike async methods, partially solved problems can be continued. 4. Even the dumbest version of GPS can help us write better software.
  • 68. Paradigms of AI Programming by Norvig
  • 70. Thank you! * @praeclarum on Twitter and GitHub