SlideShare uma empresa Scribd logo
1 de 72
PLAYING GO
WITH CLOJURE

   Zach Tellman
    @ztellman
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
RULES OF GO
SHALL WE PLAY A GAME?
MY QUALIFICATIONS


• I’m    a mediocre Go player

•I   think this stuff is pretty cool

• I’ve   written performance-oriented Clojure before
THE GAME TREE



          X           X       X
                                  …



X O   X       O   X
                  O       …
THE GAME TREE



          X           X       X
                                  …



X O   X       O   X
                  O       …
THE GAME TREE



   a cooperative or single-player game, we only need to
• in
 search for victory

• in   a competitive game, we need to optimize for victory
MINIMAX


• assign   a value to each leaf node

       the parent the maximal child value if it’s our turn,
• assign
 or the minimal child value if it’s our opponent’s turn

• ascend    one level, and repeat
MINIMAX


• plays   a perfect game

• requires   traversing the entire tree

• there   are ~9! possible tic-tac-toe games
EVALUATION FUNCTIONS


• construct    a shallow game tree

       each leaf node a value based on our best guess at
• assign
 the outcome

• apply    minimax to these values
THE TROUBLE
             WITH HEURISTICS

• difficult   to quantify

• depth   vs. quality

• understanding a function vs. understanding its repeated,
 recursive application
THE TROUBLE
                     WITH GO


• lots   of breadth

• lots   of depth
HISTORICAL APPROACHES



• programmers     who are professional-level players

• shallow   and narrow searches, heavy evaluation functions
MONTE CARLO SIMULATION
MONTE CARLO SIMULATION

             (defn inside-circle? [x y]
               (>= 1 (+ (* x x) (* y y))))

             (defn sample []
               (inside-circle? (rand) (rand)))
1




    (0,0)
MONTE CARLO SIMULATION

             (defn inside-circle? [x y]
               (>= 1 (+ (* x x) (* y y))))

             (defn sample []
               (inside-circle? (rand) (rand)))
1




             (repeatedly 1e6 sample)
    (0,0)
MONTE CARLO SIMULATION
MONTE CARLO EVALUATION


• thestrength of a position is how often one side wins,
 given repeated, naive playouts by both sides

• possible   playouts vs plausible playouts

• eachnew playout gives us additional information about
 what is plausible
MULTI-ARMED BANDIT
MULTI-ARMED BANDIT


• multiple   levers to pull, each with an unknown expected
  reward

• exploitation   vs exploration

• if
   the search space is stable over time, we expect to
  converge on a solution
MONTE CARLO TREE SEARCH
SIMULATING GO
                WITH CLOJURE

• select   a move

• check    for suicide

• make     move

• check    for capture

• repeat
SIMULATING GO
               WITH CLOJURE

• select   a move

•   check for suicide

• make     move

•   check for capture

• repeat
INCREMENTAL STATE




           4
INCREMENTAL STATE


           6
INCREMENTAL STATE


        8
INCREMENTAL STATE


        6

        2
INCREMENTAL STATE


• we  keep track of the pseudo-liberties, but also the
  neighbor sum and sum-of-squares

• ifsum × sum = psudeo-liberties × sum-of-squares,
  there’s only one real liberty

• proof   is left as an exercise for the reader
A LITTLE ARITHMETIC

• select   a move        1 second
                         / 10,000 games per second
• check    for suicide

• make     move

• check    for capture

• repeat
A LITTLE ARITHMETIC

• select   a move        1 second
                         / 10,000 games per second
• check    for suicide   / 100 moves per game

• make     move

• check    for capture

• repeat
A LITTLE ARITHMETIC

• select   a move        1 second
                         / 10,000 games per second
• check    for suicide   / 100 moves per game

• make     move

• check    for capture

• repeat                 = 1μs per move
A MILLION TIMES
         A SECOND

(assoc {} :a 1, :b 2, :c 3, :d 4, :e 5)



(reduce + (range 10))



(set (range 5))
execute typical instruction           1 ns

fetch from L1 cache memory          0.5 ns

branch misprediction                  5 ns

fetch from L2 cache memory            7 ns

mutex lock/unlock                   25 ns

fetch from main memory             100 ns



     “Teach Yourself Programming in Ten Years”
                           Peter Norvig, 2001
execute typical instruction           1 ns

fetch from L1 cache memory          0.5 ns

branch misprediction                  5 ns

fetch from L2 cache memory            7 ns

mutex lock/unlock                   25 ns

fetch from main memory             100 ns



     “Teach Yourself Programming in Ten Years”
                           Peter Norvig, 2001
A QUICK DESCENT
      INTO
   INSANITY
 PERFORMANCE
NOT YOUR DAY JOB


• not   latency bound

• faster   is smarter

• diminishing   returns not within reach
MUTABLE STATE


“They are for experts only - if the semantics and
 implications of :volatile-mutable or :unsynchronized-
 mutable are not immediately apparent to you, you
 should not be using them.”


                                      Rich Hickey,
                         the docstring for deftype
MUTABLE STATE
MUTABLE STATE


• if
   a value is only used on a single thread, it can be
  unsynchronized

• for   everything else, use volatile

• unsynchronized     is roughly 2x faster
MUTABLE STATE
(deftype Mutable
  [^:unsynchronized-mutable ^long counter]

  IMutable
  (get-counter [_]
    counter)
  (set-counter [_ val]
    (set! counter val)))
MUTABLE STATE
(deftype Mutable
  [^:unsynchronized-mutable ^long counter]

  IMutable
  (get-counter [_]
    counter)
  (set-counter [_ val]
    (set! counter val)))

(defn add [^Mutable m ^long val]
  (set-counter m (+ (get-counter m) val)))
MUTABLE STATE
(deftype Mutable
  [^:unsynchronized-mutable ^long counter]

  IMutable
  (get-counter [_]
    counter)
  (set-counter [_ val]
    (set! counter val))
  (add [_ val]
    (set! counter (+ counter val))))
MEASURE TWICE,
            CODE ONCE
user> (bench (assoc {} :a 1, :b 2, :c 3, :d 4, :e 5))

Evaluation count : 46619100 in 60 samples of 776985 calls.

           Execution time mean   :   1.286463   us
  Execution time std-deviation   :   4.220920   ns
 Execution time lower quantile   :   1.280215   us ( 2.5%)
 Execution time upper quantile   :   1.295557   us (97.5%)

Found 4 outliers in 60 samples (6.6667 %)
    low-severe   1 (1.6667 %)
    low-mild     2 (3.3333 %)
    high-mild    1 (1.6667 %)
 Variance from outliers : 1.6389 %
CRITERIUM


• one   of the many great libraries from Hugo Duncan

• use   it at the REPL, and in your tests

• tends   to exaggerate cache coherency

• minimum     resolution appears to be ~15ns
BOTTOM-UP PERFORMANCE


• measure   each piece of your code

• measure   them when used together

• buildan intuition for how long something should take,
 and investigate when you’re wrong
INDIRECTION


“Any performance problem can be solved
 by removing a layer of indirection.”

                            Unattributed
INDIRECTION


     =                    count



==       identical?   Array/getLength
INDIRECTION
PUT IT ALL TOGETHER
> lein test pushkin.test.simulator :benchmark

-----
 random 9x9 playout
-----

Evaluation count : 501120 in 60 samples of 8352 calls.
             Execution time mean : 121.293385 us
    Execution time std-deviation : 2.534460 us
   Execution time lower quantile : 119.685345 us ( 2.5%)
   Execution time upper quantile : 128.150772 us (97.5%)

Found 8 outliers in 60 samples (13.3333 %)
    low-severe   3 (5.0000 %)
    low-mild     5 (8.3333 %)
 Variance from outliers : 9.4036 %
PUT IT ALL TOGETHER
> lein test pushkin.test.simulator :benchmark

-----
 random 9x9 playout
-----

Evaluation count : 501120 in 60 samples of 8352 calls.
             Execution time mean : 121.293385 us
    Execution time std-deviation : 2.534460 us
   Execution time lower quantile : 119.685345 us ( 2.5%)
   Execution time upper quantile : 128.150772 us (97.5%)

Found 8 outliers in 60 samples (13.3333 %)
    low-severe   3 (5.0000 %)
    low-mild     5 (8.3333 %)
 Variance from outliers : 9.4036 %
PLUMBING THE DEPTHS
      OF PERFORMANCE
          INSANITY
• simulating   C-style structs with ByteBuffers

• mimicking    C compiler offset calculation with local analysis

• creating   a bridge to heterogeneous computing
Exploitation             Strong AIs




               Pushkin
Exploration
           Possible          Plausible




    http://github.com/ztellman/pushkin
QUESTIONS?

Mais conteúdo relacionado

Semelhante a Playing Go with Clojure

Research overview Oct. 2018
Research overview Oct. 2018Research overview Oct. 2018
Research overview Oct. 2018XavierDevroey
 
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)Universitat Politècnica de Catalunya
 
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchSimulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchOlivier Teytaud
 
Optimization of water distribution systems design parameters using genetic al...
Optimization of water distribution systems design parameters using genetic al...Optimization of water distribution systems design parameters using genetic al...
Optimization of water distribution systems design parameters using genetic al...Tanay Kulkarni
 
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory AccessAccelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory AccessIgor Sfiligoi
 
Introduction to Alphago Zero
Introduction to Alphago ZeroIntroduction to Alphago Zero
Introduction to Alphago ZeroChia-Ching Lin
 
Volumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the FallenVolumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the FallenBenjamin Glatzel
 
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIATypes Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIADheeraj Kataria
 
PR-252: Making Convolutional Networks Shift-Invariant Again
PR-252: Making Convolutional Networks Shift-Invariant AgainPR-252: Making Convolutional Networks Shift-Invariant Again
PR-252: Making Convolutional Networks Shift-Invariant AgainHyeongmin Lee
 
Market Basket Analysis in SQL Server Machine Learning Services
Market Basket Analysis in SQL Server Machine Learning ServicesMarket Basket Analysis in SQL Server Machine Learning Services
Market Basket Analysis in SQL Server Machine Learning ServicesLuca Zavarella
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Thinkful
 
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"Lviv Startup Club
 
Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Acunu
 
Score based Generative Modeling through Stochastic Differential Equations
Score based Generative Modeling through Stochastic Differential EquationsScore based Generative Modeling through Stochastic Differential Equations
Score based Generative Modeling through Stochastic Differential EquationsSungchul Kim
 
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"YeChan(Paul) Kim
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine LearningPranav Ainavolu
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)Tech in Asia ID
 

Semelhante a Playing Go with Clojure (20)

Research overview Oct. 2018
Research overview Oct. 2018Research overview Oct. 2018
Research overview Oct. 2018
 
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)
Optimization (DLAI D4L1 2017 UPC Deep Learning for Artificial Intelligence)
 
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy SearchSimulation-based optimization: Upper Confidence Tree and Direct Policy Search
Simulation-based optimization: Upper Confidence Tree and Direct Policy Search
 
Optimization of water distribution systems design parameters using genetic al...
Optimization of water distribution systems design parameters using genetic al...Optimization of water distribution systems design parameters using genetic al...
Optimization of water distribution systems design parameters using genetic al...
 
Games.4
Games.4Games.4
Games.4
 
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory AccessAccelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
Accelerating Key Bioinformatics Tasks 100-fold by Improving Memory Access
 
Introduction to Alphago Zero
Introduction to Alphago ZeroIntroduction to Alphago Zero
Introduction to Alphago Zero
 
Volumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the FallenVolumetric Lighting for Many Lights in Lords of the Fallen
Volumetric Lighting for Many Lights in Lords of the Fallen
 
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIATypes Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
 
PR-252: Making Convolutional Networks Shift-Invariant Again
PR-252: Making Convolutional Networks Shift-Invariant AgainPR-252: Making Convolutional Networks Shift-Invariant Again
PR-252: Making Convolutional Networks Shift-Invariant Again
 
Market Basket Analysis in SQL Server Machine Learning Services
Market Basket Analysis in SQL Server Machine Learning ServicesMarket Basket Analysis in SQL Server Machine Learning Services
Market Basket Analysis in SQL Server Machine Learning Services
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
 
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"
Dmytro Panchenko "Cracking Kaggle: Human Protein Atlas"
 
Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!
 
Microchip Mfg. problem
Microchip Mfg. problemMicrochip Mfg. problem
Microchip Mfg. problem
 
Optimization
OptimizationOptimization
Optimization
 
Score based Generative Modeling through Stochastic Differential Equations
Score based Generative Modeling through Stochastic Differential EquationsScore based Generative Modeling through Stochastic Differential Equations
Score based Generative Modeling through Stochastic Differential Equations
 
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"
pycon2018 "RL Adventure : DQN 부터 Rainbow DQN까지"
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
 

Último

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Último (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Playing Go with Clojure

  • 1. PLAYING GO WITH CLOJURE Zach Tellman @ztellman
  • 20. SHALL WE PLAY A GAME?
  • 21. MY QUALIFICATIONS • I’m a mediocre Go player •I think this stuff is pretty cool • I’ve written performance-oriented Clojure before
  • 22. THE GAME TREE X X X … X O X O X O …
  • 23. THE GAME TREE X X X … X O X O X O …
  • 24. THE GAME TREE a cooperative or single-player game, we only need to • in search for victory • in a competitive game, we need to optimize for victory
  • 25. MINIMAX • assign a value to each leaf node the parent the maximal child value if it’s our turn, • assign or the minimal child value if it’s our opponent’s turn • ascend one level, and repeat
  • 26. MINIMAX • plays a perfect game • requires traversing the entire tree • there are ~9! possible tic-tac-toe games
  • 27. EVALUATION FUNCTIONS • construct a shallow game tree each leaf node a value based on our best guess at • assign the outcome • apply minimax to these values
  • 28. THE TROUBLE WITH HEURISTICS • difficult to quantify • depth vs. quality • understanding a function vs. understanding its repeated, recursive application
  • 29. THE TROUBLE WITH GO • lots of breadth • lots of depth
  • 30. HISTORICAL APPROACHES • programmers who are professional-level players • shallow and narrow searches, heavy evaluation functions
  • 32. MONTE CARLO SIMULATION (defn inside-circle? [x y] (>= 1 (+ (* x x) (* y y)))) (defn sample [] (inside-circle? (rand) (rand))) 1 (0,0)
  • 33. MONTE CARLO SIMULATION (defn inside-circle? [x y] (>= 1 (+ (* x x) (* y y)))) (defn sample [] (inside-circle? (rand) (rand))) 1 (repeatedly 1e6 sample) (0,0)
  • 35. MONTE CARLO EVALUATION • thestrength of a position is how often one side wins, given repeated, naive playouts by both sides • possible playouts vs plausible playouts • eachnew playout gives us additional information about what is plausible
  • 37. MULTI-ARMED BANDIT • multiple levers to pull, each with an unknown expected reward • exploitation vs exploration • if the search space is stable over time, we expect to converge on a solution
  • 39. SIMULATING GO WITH CLOJURE • select a move • check for suicide • make move • check for capture • repeat
  • 40. SIMULATING GO WITH CLOJURE • select a move • check for suicide • make move • check for capture • repeat
  • 41.
  • 46. INCREMENTAL STATE • we keep track of the pseudo-liberties, but also the neighbor sum and sum-of-squares • ifsum × sum = psudeo-liberties × sum-of-squares, there’s only one real liberty • proof is left as an exercise for the reader
  • 47. A LITTLE ARITHMETIC • select a move 1 second / 10,000 games per second • check for suicide • make move • check for capture • repeat
  • 48. A LITTLE ARITHMETIC • select a move 1 second / 10,000 games per second • check for suicide / 100 moves per game • make move • check for capture • repeat
  • 49. A LITTLE ARITHMETIC • select a move 1 second / 10,000 games per second • check for suicide / 100 moves per game • make move • check for capture • repeat = 1μs per move
  • 50. A MILLION TIMES A SECOND (assoc {} :a 1, :b 2, :c 3, :d 4, :e 5) (reduce + (range 10)) (set (range 5))
  • 51. execute typical instruction 1 ns fetch from L1 cache memory 0.5 ns branch misprediction 5 ns fetch from L2 cache memory 7 ns mutex lock/unlock 25 ns fetch from main memory 100 ns “Teach Yourself Programming in Ten Years” Peter Norvig, 2001
  • 52. execute typical instruction 1 ns fetch from L1 cache memory 0.5 ns branch misprediction 5 ns fetch from L2 cache memory 7 ns mutex lock/unlock 25 ns fetch from main memory 100 ns “Teach Yourself Programming in Ten Years” Peter Norvig, 2001
  • 53. A QUICK DESCENT INTO INSANITY PERFORMANCE
  • 54. NOT YOUR DAY JOB • not latency bound • faster is smarter • diminishing returns not within reach
  • 55. MUTABLE STATE “They are for experts only - if the semantics and implications of :volatile-mutable or :unsynchronized- mutable are not immediately apparent to you, you should not be using them.” Rich Hickey, the docstring for deftype
  • 57. MUTABLE STATE • if a value is only used on a single thread, it can be unsynchronized • for everything else, use volatile • unsynchronized is roughly 2x faster
  • 58. MUTABLE STATE (deftype Mutable [^:unsynchronized-mutable ^long counter] IMutable (get-counter [_] counter) (set-counter [_ val] (set! counter val)))
  • 59. MUTABLE STATE (deftype Mutable [^:unsynchronized-mutable ^long counter] IMutable (get-counter [_] counter) (set-counter [_ val] (set! counter val))) (defn add [^Mutable m ^long val] (set-counter m (+ (get-counter m) val)))
  • 60. MUTABLE STATE (deftype Mutable [^:unsynchronized-mutable ^long counter] IMutable (get-counter [_] counter) (set-counter [_ val] (set! counter val)) (add [_ val] (set! counter (+ counter val))))
  • 61. MEASURE TWICE, CODE ONCE user> (bench (assoc {} :a 1, :b 2, :c 3, :d 4, :e 5)) Evaluation count : 46619100 in 60 samples of 776985 calls. Execution time mean : 1.286463 us Execution time std-deviation : 4.220920 ns Execution time lower quantile : 1.280215 us ( 2.5%) Execution time upper quantile : 1.295557 us (97.5%) Found 4 outliers in 60 samples (6.6667 %) low-severe 1 (1.6667 %) low-mild 2 (3.3333 %) high-mild 1 (1.6667 %) Variance from outliers : 1.6389 %
  • 62. CRITERIUM • one of the many great libraries from Hugo Duncan • use it at the REPL, and in your tests • tends to exaggerate cache coherency • minimum resolution appears to be ~15ns
  • 63. BOTTOM-UP PERFORMANCE • measure each piece of your code • measure them when used together • buildan intuition for how long something should take, and investigate when you’re wrong
  • 64. INDIRECTION “Any performance problem can be solved by removing a layer of indirection.” Unattributed
  • 65. INDIRECTION = count == identical? Array/getLength
  • 67. PUT IT ALL TOGETHER > lein test pushkin.test.simulator :benchmark ----- random 9x9 playout ----- Evaluation count : 501120 in 60 samples of 8352 calls. Execution time mean : 121.293385 us Execution time std-deviation : 2.534460 us Execution time lower quantile : 119.685345 us ( 2.5%) Execution time upper quantile : 128.150772 us (97.5%) Found 8 outliers in 60 samples (13.3333 %) low-severe 3 (5.0000 %) low-mild 5 (8.3333 %) Variance from outliers : 9.4036 %
  • 68. PUT IT ALL TOGETHER > lein test pushkin.test.simulator :benchmark ----- random 9x9 playout ----- Evaluation count : 501120 in 60 samples of 8352 calls. Execution time mean : 121.293385 us Execution time std-deviation : 2.534460 us Execution time lower quantile : 119.685345 us ( 2.5%) Execution time upper quantile : 128.150772 us (97.5%) Found 8 outliers in 60 samples (13.3333 %) low-severe 3 (5.0000 %) low-mild 5 (8.3333 %) Variance from outliers : 9.4036 %
  • 69. PLUMBING THE DEPTHS OF PERFORMANCE INSANITY • simulating C-style structs with ByteBuffers • mimicking C compiler offset calculation with local analysis • creating a bridge to heterogeneous computing
  • 70. Exploitation Strong AIs Pushkin Exploration Possible Plausible http://github.com/ztellman/pushkin
  • 71.

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n