1 Lecture 20 Probabilistic PL the Church Programming Language Ras Bodik Ali and Mangpo Hack Your Language! CS164: Introduction to Programming Languages.

Slides:



Advertisements
Similar presentations
Simulation Examples in EXCEL Montana Going Green 2010.
Advertisements

Probability Chances Are… You can do it! Activity #3.
Health Literacy: how to explain risk? Dr. Keiko Yasukawa University of Technology, Sydney.
Bayes Rule The product rule gives us two ways to factor a joint probability: Therefore, Why is this useful? –Can get diagnostic probability P(Cavity |
Bayesian Classification
Objectives (BPS chapter 12) General rules of probability  Independence and the multiplication rule  The general addition rule  Conditional probability.
Objectives (BPS chapter 12)
Econ 140 Lecture 61 Inference about a Mean Lecture 6.
Processing physical evidence discovering, recognizing and examining it; collecting, recording and identifying it; packaging, conveying and storing it;
Sampling Prepared by Dr. Manal Moussa. Sampling Prepared by Dr. Manal Moussa.
Random variables; discrete and continuous probability distributions June 23, 2004.
Statistics: Unlocking the Power of Data Lock 5 STAT 101 Dr. Kari Lock Morgan Bayesian Inference SECTION 11.1, 11.2 Bayes rule (11.2) Bayesian inference.
Lecture 9: p-value functions and intro to Bayesian thinking Matthew Fox Advanced Epidemiology.
Review: Probability Random variables, events Axioms of probability
Selective Sampling on Probabilistic Labels Peng Peng, Raymond Chi-Wing Wong CSE, HKUST 1.
Calculating Probabilities for Chance Experiments with Equally Likely Outcomes.
Probability and inference General probability rules IPS chapter 4.5 © 2006 W.H. Freeman and Company.
Research in Psychology. Research Basics  All psychological research MUST follow the scientific method  Improves accuracy and validity of findings 
Statistics in Screening/Diagnosis
5.3A Conditional Probability, General Multiplication Rule and Tree Diagrams AP Statistics.
An Intuitive Explanation of Bayes' Theorem By Eliezer Yudkowsky.
Sets, Combinatorics, Probability, and Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProbability.
Multiple Choice Questions for discussion
2 Probability. A. A basketball player shoots three free throws. What are the possible sequences of hits (H) and misses (M)? H H H - HHH M … M M - HHM.
Probability and inference General probability rules IPS chapter 4.5 © 2006 W.H. Freeman and Company.
Chapter 3 Section 3.2 Basic Terms of Probability.
Statistics: Unlocking the Power of Data Lock 5 STAT 101 Dr. Kari Lock Morgan 12/4/12 Bayesian Inference SECTION 11.1, 11.2 More probability rules (11.1)
Quiz 2 - Review. Descriptive Statistics Be able to interpret: -Box Plots and Histograms -Mean, Median, Standard Deviation, and Percentiles.
Level34567 Probability Skills I can use the probability words impossible, certain and even chance to describe the probability of an event occurring. I.
Probability and inference General probability rules IPS chapter 4.5 © 2006 W.H. Freeman and Company.
Imran Ahmad, MD FACP. Consultant Medical Oncologist, KFSH &RC-Jeddah.
Collection of Data Chapter 4. Three Types of Studies Survey Survey Observational Study Observational Study Controlled Experiment Controlled Experiment.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 25 Wednesday, 20 October.
Lung cancer By Hanchu Zhang, Billy Shi and Hongyu Mao.
Kansas State University Department of Computing and Information Sciences CIS 730: Introduction to Artificial Intelligence Lecture 28 of 41 Friday, 22 October.
 Probability: the chance that a particular event will occur.  When do people use probability ◦ Investing in stocks ◦ Gambling ◦ Weather.
Bayesian Inference, Review 4/25/12 Frequentist inference Bayesian inference Review The Bayesian Heresy (pdf)pdf Professor Kari Lock Morgan Duke University.
Lecture: Forensic Evidence and Probability Characteristics of evidence Class characteristics Individual characteristics  features that place the item.
Populations III: evidence, uncertainty, and decisions Bio 415/615.
A psychophysical analysis of the base rate fallacy.
Probability THEORETICAL Theoretical probability can be found without doing and experiment. EXPERIMENTAL Experimental probability is found by repeating.
Review: Probability Random variables, events Axioms of probability Atomic events Joint and marginal probability distributions Conditional probability distributions.
This material was developed by Oregon Health & Science University, funded by the Department of Health and Human Services, Office of the National Coordinator.
5.1 Randomness  The Language of Probability  Thinking about Randomness  The Uses of Probability 1.
Chapter 4(4.1~4.2) Probability and text sampling Parallel embedded system design lab 이청용.
Probability Distributions: Binomial & Normal Ginger Holmes Rowell, PhD MSP Workshop June 2006.
Bell Work/Cronnelly. A= 143 ft 2 ; P= 48 ft A= 2.3 m; P= 8.3 m A= ft 2 ; P= 76 ft 2/12; 1/6 1/12 8/12; 2/3 6/12; 1/2 0/12 4/12; 1/3 5/12 6/12; 1/2.
Simulating Experiments Introduction to Random Variable.
Making Predictions with Theoretical Probability. Warm Up You flip a coin three times. 1.Create a tree diagram to find the sample space. 2.How many outcomes.
CANCER. CANCER IS UNCONTROLLED GROWTH AND REPRODUCTION OF CELLS RESULTING IN DESTRUCTION OF THE HEALTHY TISSUE. MOST COMMON CANCER TYPES ARE BREAST, PROSTATE,
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Classification COMP Seminar BCB 713 Module Spring 2011.
Expected Value and Fair Game S-MD.6 (+) Use probabilities to make fair decisions (e.g., drawing by lots, using a random number generator). S-MD.7 (+) Analyze.
Probability Distribution. Probability Distributions: Overview To understand probability distributions, it is important to understand variables and random.
TOPIC 1.2, RISK. SPECIFICATIONS: RISK 1.18 Analyse and interpret quantitative data on illness and mortality rates to determine health risks (including.
HL2 Math - Santowski Lesson 93 – Bayes’ Theorem. Bayes’ Theorem  Main theorem: Suppose we know We would like to use this information to find if possible.
Probability Probability Day 3 Introduction to Probability Probability of Independent Events.
Introduction to Probabilistic Programming Languages (PPL) Anton Andreev Ingénieur d'études CNRS
LECTURE 13: ONGOING RESEARCH: THE ROLE OF INDIVIDUAL DIFFERENCES April 25, 2016 SDS136: Communicating with Data.
Probability Axioms and Formulas
Sec. 4-5: Applying Ratios to Probability
Quote of the Day …in man there is nothing great but mind. -Sir William Rowan Hamilton.
Optimal Ways to learn about and communicate Evidence Based Medicine
Respiratory Disorders
سرطان الثدي Breast Cancer
الأستاذ المساعد بقسم المناهج وطرق التدريس
Medical Diagnosis Problem
CS 188: Artificial Intelligence Fall 2008
CS 188: Artificial Intelligence Fall 2007
Lecture: Forensic Evidence and Probability Characteristics of evidence
Hypothesis Testing: Two-Sample Inference
Presentation transcript:

1 Lecture 20 Probabilistic PL the Church Programming Language Ras Bodik Ali and Mangpo Hack Your Language! CS164: Introduction to Programming Languages and Compilers, Spring 2013 UC Berkeley

Today Scheme refresher Church is an extension of Scheme Generative Models Conditioning 2

Scheme Refresher 3

Scheme Define symbols (variables) (define x 3) (define y 4) Define functions ;; long way (define f2 (lambda (a b) (expt (+ a b) 3))) ;; short way (define (f1 a b) (expt (+ a b) 3)) 4

Generative Models 5

Random Samples Flip a coin (flip) Flip a biased coin (flip 0.7) Draw a histogram of 1000 samples (hist (repeat 1000 flip) "Flips") 6

A Causal Model for Medical Diagnosis representing causal knowledge: (define lung-cancer (flip 0.01)) (define cold (flip 0.2)) (define cough (or cold lung-cancer)) cough This program generates random conditions for a patient in a doctor's office. It first specifies the base rates of two diseases the patient could have: lung cancer is rare while a cold is common, and there is an independent chance of having each disease. The program then specifies a process for generating a common symptom of these diseases -- an effect with two possible causes: The patient coughs if they have a cold or lung cancer (or both). 7

A more complex model (define lung-cancer (flip 0.01)) (define TB (flip 0.005)) (define cold (flip 0.2)) (define stomach-flu (flip 0.1)) (define other (flip 0.1)) (define cough (or (and cold (flip 0.5)) (and lung-cancer (flip 0.3)) (and TB (flip 0.7)) (and other (flip 0.01)))) (define fever (or (and cold (flip 0.3)) (and stomach-flu (flip 0.5)) (andTB (flip 0.1)) (and other (flip 0.01)))) (define chest-pain (or (and lung-cancer (flip 0.5)) (and TB (flip 0.5))(and other(flip 0.01)))) (define shortness-of-breath (or (and lung-cancer (flip 0.5)) (and TB (flip0.2)) (and other (flip 0.01)))) (list "cough" cough "fever" fever "chest-pain" chest-pain "shortness-of-breath" shortness-of-breath) 8

Modeling coins (define (make-coin weight) (lambda () (if (flip weight) 'h 't))) (define fair-coin (make-coin 0.5)) (define trick-coin (make-coin 0.95)) (define bent-coin (make-coin 0.25)) (hist (repeat 20 fair-coin) "20 fair coin flips") (hist (repeat 20 trick-coin) "20 trick coin flips") (hist (repeat 20 bent-coin) "20 bent coin flips") "done" 9

Bending a coin (define (make-coin weight) (lambda () (if (flip weight) 'h 't))) (define (bend coin) (lambda () (if (equal? (coin) 'h) ( (make-coin 0.7) ) ( (make-coin 0.1) ) ))) (define fair-coin (make-coin 0.5)) (define bent-coin (bend fair-coin)) (hist (repeat 100 bent-coin) "bent coin") "done" 10

Persistent Randomness

Persisting random decisions What is the value of this expression? (equal? (flip) (flip)) And this one? (define (eye-color person) (uniform- draw '(blue green brown))) (list (eye-color 'bob) (eye-color 'alice) (eye-color 'bob) ) 12

Persitence The mem high-order function: (define mem-flip (mem flip)) (equal? (mem-flip) (mem-flip)) The second example (define eye-color (mem (lambda (person) (uniform-draw '(blue green brown))))) (list (eye-color 'bob) (eye-color 'alice) (eye-color 'bob) ) 13

Tug of War (define strength (mem (lambda (person) (if (flip) 10 5)))) (define lazy (lambda (person) (flip (/ 1 3)))) (define (total-pulling team) (apply + (map (lambda (person) (if (lazy person) (/ (strength person) 2)(strength person))) team))) (define (winner team1 team2) (if (< (total-pulling team1) (total-pullingteam2)) team2 team1)) 14

Tug of War … (list "Tournament results:" (winner '(alice bob) '(sue tom)) (winner '(alice bob) '(sue tom)) (winner '(alice sue) '(bob tom)) (winner '(alice sue) '(bob tom)) (winner '(alice tom) '(bob sue)) (winner '(alice tom) '(bob sue))) 15

Conditioning

query (query generative-model what-we-want-to-know what-we-know) 17

Model (define A (if (flip) 1 0)) (define B (if (flip) 1 0)) (define C (if (flip) 1 0)) (define D (+ A B C)) D 18

query (define (take-sample) (rejection-query (define A (if (flip) 1 0)) (define B (if (flip) 1 0)) (define C (if (flip) 1 0)) (define D (+ A B C)) A (equal? D 3) ) ) (hist (repeat 100 take-sample) "Value of A, given that D is 3") 19

Answer this "The probability of breast cancer is 1% for a woman at 40 who participates in a routine screening. If a woman has breast cancer, the probability is 80% that she will have a positive mammography. If a woman does not have breast cancer, the probability is 9.6% that she will also have a positive mammography. A woman in this age group had a positive mammography in a routine screening. What is the probability that she actually has breast cancer?" 20

Model (define samples (mh-query (define breast-cancer (flip 0.01)) (define positive-mammogram (if breast- cancer (flip 0.8) (flip 0.096))) breast-cancer positive-mammogram ) ) (hist samples "breast cancer") 21