SlideShare a Scribd company logo
1 of 31
A giant python swallows an alligator in Everglades National Park, Fla..
      Paul Zenk/PBS Nature “Invasion of the Giant Pythons” (yesterday’s New York Times)




cs1120 Fall 2011
David Evans
                                               Class 28:
28 October 2011                                Entropy
Plan
Story so Far: Liberal Arts Recap
Reversing in Python
Shannon’s Information Theory: Entropy
Returning Quiz 3, PS5, etc.




                                        2
Ch 1: Computing
                               Ch 2: Language




Analysis
                                                    Synthesis


                               Ch 3: Programming

                               Ch 4: Procedures

                               Ch 5: Data
            Ch 6: Machines

                 Ch 7: Cost

             Ch 8: Sorting and Searching
                        PS5, Ch 9: State
                 You are      PS6, Ch 10: Objects
                                                      Course Roadmap




                  here
                PS7, Ch 11: Interpreters

      Ch 12: Computability
                           PS8, 9
              Intractability
cs1120 Main Topics
Language: How to describe information processes by
  defining procedures (Chapters 3, 4, 5, 9, 10)
   Programming with procedures, lists, recursion (PS1-4)
   Programming with state (PS5), objects (PS6), languages (PS7)
Logic: How to predict properties about information
  processes (Chapter 6, 7, 8)
   Predicting how running time grows with input size
   Are there problems which can’t be solved by algorithms? (Ch 12)
Machines: How to efficiently implement information
 processes (Chapter 6) (not much on this)
   Machines, Digital Logic
   How to implement a Scheme interpreter (Ch 11, PS7)
From Lecture 1:
Grammar: study of meaning in                  BNF, RTN, rules of
               written expression                        evaluation for meaning
Trivium

             Rhetoric: comprehension of verbal             Interfaces between
                                                               components
               and written discourse                     (PS6), evaluation rules

             Logic: argumentative discourse for          Rules of evaluation, if,
                                                          recursive definitions
               discovering truth
             Arithmetic: understanding                     adding with logic,
                                                         representing numbers
               numbers
Quadrivium




                                                         Curves as procedures,
             Geometry: quantification of space               fractals (PS3)

             Music: number in time                         Ada, GEB Chapter

             Astronomy                                          Nothing!
                                         But…read the Neil DeGrasse Tyson essay!
Lists (Tuples) in Python
     Scheme (list)             Python (tuple)
> (define p (list 1 2 3))   >>> p = (1, 2, 3)
> (car p)                   >>> p[0]
1                           1
> (cdr p)                   >>> p[1:]
(2 3)                       (2, 3)
> (cdr (cdr (cdr p)))       >>> p[1:][1:][1:]
null                        ()

                                                7
Python Shortcuts
>>> p = (1, 2, 3)
>>> p[2]
3          list[i]
>>> p[3:]  Evaluates to ith (counting from
             0) element of tuple/list
()
           Runs in (approximately)
>>> p[:2] constant time!
(1, 2)
Mutable Lists (Lists) in Python
Scheme (mutable list)             Python [List]
 > (define p (mlist 1 2 3))   >>> p = [1, 2, 3]
 > (mcar p)                   >>> p[0]
 1                            1
 > (mcdr p)                   >>> p[1:]
 (2 3)                        (2, 3)
 > (mcdr (mcdr (mcdr p)))     >>> p[1:][1:][1:]
 null                         ()

                                                  9
Using Mutable Lists
>>> p = [1, 2, 3]   Scheme Application:
>>> p[0]            (<verb> <operands>)
1                   Python procedure call:
>>> p[0] = 2        <verb>(<operand>)
>>> p               Method call:
[2, 2, 3]           <object>.<verb>(<parameters>)
>>> p.append(4) Note: this is different from mappend!
>>> p             It take a single element, not a list.
[2, 2, 3, 4]
Trick Question

>>> p = (1, 2, 3)
>>> p[0] = 2
Traceback (most recent call last):
 File "<pyshell#23>", line 1, in <module>
  p[0] = 2
TypeError: 'tuple' object does not
support item assignment
Reversing a Mutable List

Scheme:      p:

                   1           2   3




Python:
             p:

                   1   2   3
mlist-reverse!
(define (mlist-reverse! p)
 (if (null? (mcdr p))
    (void)
    (let ((rest (mcdr p))
          (carp (mcar p)))
      (mlist-reverse! rest)
      (set-mcar! p (mcar rest))
      (set-mcdr! p (mcdr rest))
      (mlist-append! p (mcons carp null)))))
Literal Translation
(define (mlist-reverse! p)
 (if (null? (mcdr p))
    (void)
    (let ((rest (mcdr p))
          (carp (mcar p)))
      (mlist-reverse! rest)
      (set-mcar! p (mcar rest))
      (set-mcdr! p (mcdr rest))
      (mlist-append!
         p
         (mcons carp null)))))
Literal Translation
(define (mlist-reverse! p)                 def sreverse(p):
 (if (null? (mcdr p))                        if len(p) == 1:
    (void)
                                                return
    (let ((rest (mcdr p))
          (carp (mcar p)))                   else:
      (mlist-reverse! rest)                     rest = p[1:]
      (set-mcar! p (mcar rest))                 first = p[0]
      (set-mcdr! p (mcdr rest))                 sreverse(rest)
      (mlist-append!
                                                p[0] = rest[0]
         p
         (mcons carp null)))))                  p[1:] = rest[1:]
                                                p.append(first)
                                                          >>> p=[1,2,3]
          This is correct, but no sane Python             >>> sreverse(p)
          programmer would do it this way!                >>> p
                                                          [3, 2, 1]
Python for
Statement ::=                  (define (loop index result test update proc)
  for Varible in Expression:    (if (test index)
                                    (loop (update index)
    Block                                  (proc index result)
                                           test update proc)
                                    result))
def gaussSum (n):
  sum = 0                      (define (gauss-sum n)
                                 (loop 1 0 (lambda (i) (<= i n))
  for i in range(1, n+1):                  (lambda (i) (+ i 1))
                                           (lambda (i sum) (+ i sum))))
       sum = sum + i
  return sum
Reverse in Python
                   p:

                                    1     2     3




      Note: there is a built-in list method, p.reverse().
int(len(p) / 2)    len(p) >> 1
def reverse(p):
  for i in range(0, len(p) >> 1):
    p[i], p[len(p) – 1 - i] = p[len(p) – 1 - i], p[i]
Information Theory




                     19
Entropy




H = - pi log2 pi
                   20
flickr cc:Daniel Dale


 (Ideal) Coin Toss

H = - pi log2 pi




                                       21
Nucleotide
               N      {A, C, G, T}
Intuition: need two bits to distinguish four possible values
               00 = A, 01 = C, 10 = G, 11 = T


          H = - pi log2 pi


                                                               22
23
Real
   Coin
   Toss?

Claude Shannon’s
Juggling W. C. Fields
                        24
Real Coin Toss
According to Susan Holmes, 51% of the time, a
coin will land same way it started. [link]

           H = - pi log2 pi



                                                25
26
Are Randall Munroe’s entropy estimates correct?
Left for course blog discussion.
                                                  27
0.9880135796356116381290864023063602427958811193759308857790...




                            Class Sorting using “Odette”
           Assuming alphabet
             randomly
             distributed: O is
             15th out of 26
             letters in alphabet



                                              = 0.988…
                                                                  28
0.9880135796356116381290864023063602427958811193759308857790...




                             Class Sorting using “Odette”
           The real class: 41 out
             of 49 students have
             names before
             “Odette”!


         -((41/49) * log_2 (41/49) + (7/49) * log_2 (7/49))
         = 0.6162235892609252


                                                                  29
Better Class Sorting
         Front of Class

crm Caroline    Hannah – Li-
  - Gregory       Chang
 Anthony -      mdc Michael
  Casey           - Yuan
                               30
Charge
Office hours:
  Peter – right now
  Sunday, 1-6pm
  Everyone should be making progress on PS6
Monday:
  Trick-or-Treat Protocols!
  Inheritance

More Related Content

What's hot

Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & howlucenerevolution
 
CPSC 125 Ch 1 sec 4
CPSC 125 Ch 1 sec 4CPSC 125 Ch 1 sec 4
CPSC 125 Ch 1 sec 4David Wood
 
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrainsit-people
 
Hash presentation
Hash presentationHash presentation
Hash presentationomercode
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrisonComputer Science Club
 
SPU Optimizations-part 1
SPU Optimizations-part 1SPU Optimizations-part 1
SPU Optimizations-part 1Naughty Dog
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerRoman Elizarov
 
A Proposition for Business Process Modeling
A Proposition for Business Process ModelingA Proposition for Business Process Modeling
A Proposition for Business Process ModelingAng Chen
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasOswald Campesato
 
A born-again programmer's odyssey
A born-again programmer's odysseyA born-again programmer's odyssey
A born-again programmer's odysseyIgor Rivin
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talkJohn Stevenson
 

What's hot (20)

Beyond tf idf why, what & how
Beyond tf idf why, what & howBeyond tf idf why, what & how
Beyond tf idf why, what & how
 
CPSC 125 Ch 1 sec 4
CPSC 125 Ch 1 sec 4CPSC 125 Ch 1 sec 4
CPSC 125 Ch 1 sec 4
 
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
«Отладка в Python 3.6: Быстрее, Выше, Сильнее» Елизавета Шашкова, JetBrains
 
Hash presentation
Hash presentationHash presentation
Hash presentation
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison20130928 automated theorem_proving_harrison
20130928 automated theorem_proving_harrison
 
Lec1
Lec1Lec1
Lec1
 
SPU Optimizations-part 1
SPU Optimizations-part 1SPU Optimizations-part 1
SPU Optimizations-part 1
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 
The theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmerThe theory of concurrent programming for a seasoned programmer
The theory of concurrent programming for a seasoned programmer
 
Lec22
Lec22Lec22
Lec22
 
Lec9
Lec9Lec9
Lec9
 
A Proposition for Business Process Modeling
A Proposition for Business Process ModelingA Proposition for Business Process Modeling
A Proposition for Business Process Modeling
 
Lec4
Lec4Lec4
Lec4
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
Ch2
Ch2Ch2
Ch2
 
A born-again programmer's odyssey
A born-again programmer's odysseyA born-again programmer's odyssey
A born-again programmer's odyssey
 
Clojure made simple - Lightning talk
Clojure made simple - Lightning talkClojure made simple - Lightning talk
Clojure made simple - Lightning talk
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 

Similar to Class 28: Entropy

matlab-python-xref.pdf
matlab-python-xref.pdfmatlab-python-xref.pdf
matlab-python-xref.pdfssuserf07225
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxjovannyflex
 
Frsa
FrsaFrsa
Frsa_111
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programmingAlberto Labarga
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014PyData
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Charles Martin
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexityshowkat27
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ssRuo Ando
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptxKokilaK25
 

Similar to Class 28: Entropy (20)

R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
matlab-python-xref.pdf
matlab-python-xref.pdfmatlab-python-xref.pdf
matlab-python-xref.pdf
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Lecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptxLecture 5 – Computing with Numbers (Math Lib).pptx
Lecture 5 – Computing with Numbers (Math Lib).pptx
 
Frsa
FrsaFrsa
Frsa
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
Matlab python-
Matlab python-Matlab python-
Matlab python-
 
Real Time Big Data Management
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
 
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
Pythran: Static compiler for high performance by Mehdi Amini PyData SV 2014
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3Applied machine learning for search engine relevance 3
Applied machine learning for search engine relevance 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
19. algorithms and-complexity
19. algorithms and-complexity19. algorithms and-complexity
19. algorithms and-complexity
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Otter 2016-11-28-01-ss
Otter 2016-11-28-01-ssOtter 2016-11-28-01-ss
Otter 2016-11-28-01-ss
 
Stack of Tasks Course
Stack of Tasks CourseStack of Tasks Course
Stack of Tasks Course
 
Alg1
Alg1Alg1
Alg1
 
lecture 1
lecture 1lecture 1
lecture 1
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 

More from David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeDavid Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in BitcoinDavid Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm ConfirmationsDavid Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting TransactionsDavid Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in ParadiseDavid Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key SignaturesDavid Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to CryptographyDavid Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the MassesDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinDavid Evans
 

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Class 28: Entropy

  • 1. A giant python swallows an alligator in Everglades National Park, Fla.. Paul Zenk/PBS Nature “Invasion of the Giant Pythons” (yesterday’s New York Times) cs1120 Fall 2011 David Evans Class 28: 28 October 2011 Entropy
  • 2. Plan Story so Far: Liberal Arts Recap Reversing in Python Shannon’s Information Theory: Entropy Returning Quiz 3, PS5, etc. 2
  • 3. Ch 1: Computing Ch 2: Language Analysis Synthesis Ch 3: Programming Ch 4: Procedures Ch 5: Data Ch 6: Machines Ch 7: Cost Ch 8: Sorting and Searching PS5, Ch 9: State You are PS6, Ch 10: Objects Course Roadmap here PS7, Ch 11: Interpreters Ch 12: Computability PS8, 9 Intractability
  • 4. cs1120 Main Topics Language: How to describe information processes by defining procedures (Chapters 3, 4, 5, 9, 10) Programming with procedures, lists, recursion (PS1-4) Programming with state (PS5), objects (PS6), languages (PS7) Logic: How to predict properties about information processes (Chapter 6, 7, 8) Predicting how running time grows with input size Are there problems which can’t be solved by algorithms? (Ch 12) Machines: How to efficiently implement information processes (Chapter 6) (not much on this) Machines, Digital Logic How to implement a Scheme interpreter (Ch 11, PS7)
  • 6. Grammar: study of meaning in BNF, RTN, rules of written expression evaluation for meaning Trivium Rhetoric: comprehension of verbal Interfaces between components and written discourse (PS6), evaluation rules Logic: argumentative discourse for Rules of evaluation, if, recursive definitions discovering truth Arithmetic: understanding adding with logic, representing numbers numbers Quadrivium Curves as procedures, Geometry: quantification of space fractals (PS3) Music: number in time Ada, GEB Chapter Astronomy Nothing! But…read the Neil DeGrasse Tyson essay!
  • 7. Lists (Tuples) in Python Scheme (list) Python (tuple) > (define p (list 1 2 3)) >>> p = (1, 2, 3) > (car p) >>> p[0] 1 1 > (cdr p) >>> p[1:] (2 3) (2, 3) > (cdr (cdr (cdr p))) >>> p[1:][1:][1:] null () 7
  • 8. Python Shortcuts >>> p = (1, 2, 3) >>> p[2] 3 list[i] >>> p[3:] Evaluates to ith (counting from 0) element of tuple/list () Runs in (approximately) >>> p[:2] constant time! (1, 2)
  • 9. Mutable Lists (Lists) in Python Scheme (mutable list) Python [List] > (define p (mlist 1 2 3)) >>> p = [1, 2, 3] > (mcar p) >>> p[0] 1 1 > (mcdr p) >>> p[1:] (2 3) (2, 3) > (mcdr (mcdr (mcdr p))) >>> p[1:][1:][1:] null () 9
  • 10. Using Mutable Lists >>> p = [1, 2, 3] Scheme Application: >>> p[0] (<verb> <operands>) 1 Python procedure call: >>> p[0] = 2 <verb>(<operand>) >>> p Method call: [2, 2, 3] <object>.<verb>(<parameters>) >>> p.append(4) Note: this is different from mappend! >>> p It take a single element, not a list. [2, 2, 3, 4]
  • 11. Trick Question >>> p = (1, 2, 3) >>> p[0] = 2 Traceback (most recent call last): File "<pyshell#23>", line 1, in <module> p[0] = 2 TypeError: 'tuple' object does not support item assignment
  • 12. Reversing a Mutable List Scheme: p: 1 2 3 Python: p: 1 2 3
  • 13. mlist-reverse! (define (mlist-reverse! p) (if (null? (mcdr p)) (void) (let ((rest (mcdr p)) (carp (mcar p))) (mlist-reverse! rest) (set-mcar! p (mcar rest)) (set-mcdr! p (mcdr rest)) (mlist-append! p (mcons carp null)))))
  • 14. Literal Translation (define (mlist-reverse! p) (if (null? (mcdr p)) (void) (let ((rest (mcdr p)) (carp (mcar p))) (mlist-reverse! rest) (set-mcar! p (mcar rest)) (set-mcdr! p (mcdr rest)) (mlist-append! p (mcons carp null)))))
  • 15. Literal Translation (define (mlist-reverse! p) def sreverse(p): (if (null? (mcdr p)) if len(p) == 1: (void) return (let ((rest (mcdr p)) (carp (mcar p))) else: (mlist-reverse! rest) rest = p[1:] (set-mcar! p (mcar rest)) first = p[0] (set-mcdr! p (mcdr rest)) sreverse(rest) (mlist-append! p[0] = rest[0] p (mcons carp null))))) p[1:] = rest[1:] p.append(first) >>> p=[1,2,3] This is correct, but no sane Python >>> sreverse(p) programmer would do it this way! >>> p [3, 2, 1]
  • 16. Python for Statement ::= (define (loop index result test update proc) for Varible in Expression: (if (test index) (loop (update index) Block (proc index result) test update proc) result)) def gaussSum (n): sum = 0 (define (gauss-sum n) (loop 1 0 (lambda (i) (<= i n)) for i in range(1, n+1): (lambda (i) (+ i 1)) (lambda (i sum) (+ i sum)))) sum = sum + i return sum
  • 17. Reverse in Python p: 1 2 3 Note: there is a built-in list method, p.reverse().
  • 18. int(len(p) / 2) len(p) >> 1 def reverse(p): for i in range(0, len(p) >> 1): p[i], p[len(p) – 1 - i] = p[len(p) – 1 - i], p[i]
  • 20. Entropy H = - pi log2 pi 20
  • 21. flickr cc:Daniel Dale (Ideal) Coin Toss H = - pi log2 pi 21
  • 22. Nucleotide N {A, C, G, T} Intuition: need two bits to distinguish four possible values 00 = A, 01 = C, 10 = G, 11 = T H = - pi log2 pi 22
  • 23. 23
  • 24. Real Coin Toss? Claude Shannon’s Juggling W. C. Fields 24
  • 25. Real Coin Toss According to Susan Holmes, 51% of the time, a coin will land same way it started. [link] H = - pi log2 pi 25
  • 26. 26
  • 27. Are Randall Munroe’s entropy estimates correct? Left for course blog discussion. 27
  • 28. 0.9880135796356116381290864023063602427958811193759308857790... Class Sorting using “Odette” Assuming alphabet randomly distributed: O is 15th out of 26 letters in alphabet = 0.988… 28
  • 29. 0.9880135796356116381290864023063602427958811193759308857790... Class Sorting using “Odette” The real class: 41 out of 49 students have names before “Odette”! -((41/49) * log_2 (41/49) + (7/49) * log_2 (7/49)) = 0.6162235892609252 29
  • 30. Better Class Sorting Front of Class crm Caroline Hannah – Li- - Gregory Chang Anthony - mdc Michael Casey - Yuan 30
  • 31. Charge Office hours: Peter – right now Sunday, 1-6pm Everyone should be making progress on PS6 Monday: Trick-or-Treat Protocols! Inheritance