4.3) In(k!) shows up everywhere in math. So most math library have 1gamma function to compute this very fast. For example, math.1gamma (5) == math.log(math.factorial(4)) Your job for this problem is to implement P(k; X) using log-exp trick. If you do it right, P(k = 1000; µ = 1000) 0.0126146 1 [ ] [ ] 4.4) Now here is the fun part. Suppose that λ = 987.6(this is not true). Find the probability that Ply will sell all his 1000 apples. (Remember if 2000 people want Ply's apple, he his apple will also be sold out). And No, summing up to infinity is not practical. 1 4.5) Recall the information that After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days. Find the value for \ to a decent accuracy(< ±0.1) 1 4.6) Using \ you found in 4.5). Ply bounght apple for 20 Baht each and he sell it for 50 Baht each. Which means that for each apple he sells he make a profit of 30 baht. But, at the end of each day Ply has to trash all unsold Apples(taking a loss of 20 Baht each). If Ply bought 1000 apples a day, what would be his expected profit(remember expected value from discrete math/stat/quantum?). 1 [ ] 4.7) Using A you found in 4.5) Find the number of apple Ply should buy in a day to maximize his expected profit. 1 [ ] Python Python Python Python Python Problem 4 Ply quit programming and decide to be a Apple(fruit) shop owner. He bought 1000 apples everyday and try to sell it. The probability k customer want Ply's apple(one each) is given by Poisson distribution: Where X is an parameter that represent the mean of number of people that want Ply's apple each day. After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days. The goal for this problem is to figure out how he should change the number of apples he bought in a day. Ak exp(-x) P(k; λ) = = k! • In case you are curious https://en.wikipedia.org/wiki/Poisson_distribution. The true distribution of this selling apple process should be binomial distribution but with large enough customer and low enough probability of an individual buying an apple this is an excellent approximatoin. 4.1) You may find that if you try to code poisson distribution directly. It will not work with large number. Explain briefly why python complains 1 import math 2 3 | def bad poisson (1md, k): return pow(1md,k)*math.exp(-1md)/math.factorial(k) 4 # bad_poisson (1000,1000) # uncomment to see it breaks ] ✓ 0.0s 4.2) A very useful trick to avoid this problem is to take log and exponentiate. That is First, show that 1 X* exp(-λ) P(k; λ) k! xp (In [** exp(-)]) k! P(k; λ) = exp ln(P(k; λ)) = (… …. ln(… . .) — . . .) — ln(k!) Python Python
4.3) In(k!) shows up everywhere in math. So most math library have 1gamma function to compute this very fast. For example, math.1gamma (5) == math.log(math.factorial(4)) Your job for this problem is to implement P(k; X) using log-exp trick. If you do it right, P(k = 1000; µ = 1000) 0.0126146 1 [ ] [ ] 4.4) Now here is the fun part. Suppose that λ = 987.6(this is not true). Find the probability that Ply will sell all his 1000 apples. (Remember if 2000 people want Ply's apple, he his apple will also be sold out). And No, summing up to infinity is not practical. 1 4.5) Recall the information that After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days. Find the value for \ to a decent accuracy(< ±0.1) 1 4.6) Using \ you found in 4.5). Ply bounght apple for 20 Baht each and he sell it for 50 Baht each. Which means that for each apple he sells he make a profit of 30 baht. But, at the end of each day Ply has to trash all unsold Apples(taking a loss of 20 Baht each). If Ply bought 1000 apples a day, what would be his expected profit(remember expected value from discrete math/stat/quantum?). 1 [ ] 4.7) Using A you found in 4.5) Find the number of apple Ply should buy in a day to maximize his expected profit. 1 [ ] Python Python Python Python Python Problem 4 Ply quit programming and decide to be a Apple(fruit) shop owner. He bought 1000 apples everyday and try to sell it. The probability k customer want Ply's apple(one each) is given by Poisson distribution: Where X is an parameter that represent the mean of number of people that want Ply's apple each day. After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days. The goal for this problem is to figure out how he should change the number of apples he bought in a day. Ak exp(-x) P(k; λ) = = k! • In case you are curious https://en.wikipedia.org/wiki/Poisson_distribution. The true distribution of this selling apple process should be binomial distribution but with large enough customer and low enough probability of an individual buying an apple this is an excellent approximatoin. 4.1) You may find that if you try to code poisson distribution directly. It will not work with large number. Explain briefly why python complains 1 import math 2 3 | def bad poisson (1md, k): return pow(1md,k)*math.exp(-1md)/math.factorial(k) 4 # bad_poisson (1000,1000) # uncomment to see it breaks ] ✓ 0.0s 4.2) A very useful trick to avoid this problem is to take log and exponentiate. That is First, show that 1 X* exp(-λ) P(k; λ) k! xp (In [** exp(-)]) k! P(k; λ) = exp ln(P(k; λ)) = (… …. ln(… . .) — . . .) — ln(k!) Python Python
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
%matplotlib inline
import math
import numpy as np
from matplotlib import pyplot as plt
def bad_poisson(lmd, k):
return pow(lmd,k)*math.exp(-lmd)/math.factorial(k)
# bad_poisson(1000,1000) # uncomment to see it breaks
![4.3) In(k!) shows up everywhere in math. So most math library have 1gamma function to compute this very fast. For example,
math.1gamma (5) == math.log(math.factorial(4))
Your job for this problem is to implement P(k; X) using log-exp trick.
If you do it right, P(k = 1000; µ = 1000)
0.0126146
1
[ ]
[ ]
4.4) Now here is the fun part. Suppose that λ = 987.6(this is not true). Find the probability that Ply will sell all his 1000 apples. (Remember if 2000 people want Ply's apple, he his apple will also be sold out).
And No, summing up to infinity is not practical.
1
4.5) Recall the information that
After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days.
Find the value for \ to a decent accuracy(< ±0.1)
1
4.6) Using \ you found in 4.5).
Ply bounght apple for 20 Baht each and he sell it for 50 Baht each. Which means that for each apple he sells he make a profit of 30 baht. But, at the end of each day Ply has to trash all unsold Apples(taking a loss of 20 Baht each).
If Ply bought 1000 apples a day, what would be his expected profit(remember expected value from discrete math/stat/quantum?).
1
[ ]
4.7) Using A you found in 4.5) Find the number of apple Ply should buy in a day to maximize his expected profit.
1
[ ]
Python
Python
Python
Python
Python](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff97c0725-689e-40d7-87a0-46553d65cfc3%2Fc9f3b75d-ce18-4964-a52d-c6c4fcb49ab6%2Fcqcxdge_processed.png&w=3840&q=75)
Transcribed Image Text:4.3) In(k!) shows up everywhere in math. So most math library have 1gamma function to compute this very fast. For example,
math.1gamma (5) == math.log(math.factorial(4))
Your job for this problem is to implement P(k; X) using log-exp trick.
If you do it right, P(k = 1000; µ = 1000)
0.0126146
1
[ ]
[ ]
4.4) Now here is the fun part. Suppose that λ = 987.6(this is not true). Find the probability that Ply will sell all his 1000 apples. (Remember if 2000 people want Ply's apple, he his apple will also be sold out).
And No, summing up to infinity is not practical.
1
4.5) Recall the information that
After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days.
Find the value for \ to a decent accuracy(< ±0.1)
1
4.6) Using \ you found in 4.5).
Ply bounght apple for 20 Baht each and he sell it for 50 Baht each. Which means that for each apple he sells he make a profit of 30 baht. But, at the end of each day Ply has to trash all unsold Apples(taking a loss of 20 Baht each).
If Ply bought 1000 apples a day, what would be his expected profit(remember expected value from discrete math/stat/quantum?).
1
[ ]
4.7) Using A you found in 4.5) Find the number of apple Ply should buy in a day to maximize his expected profit.
1
[ ]
Python
Python
Python
Python
Python
![Problem 4
Ply quit programming and decide to be a Apple(fruit) shop owner. He bought 1000 apples everyday and try to sell it. The probability k customer want Ply's apple(one each) is given by Poisson distribution:
Where X is an parameter that represent the mean of number of people that want Ply's apple each day.
After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days.
The goal for this problem is to figure out how he should change the number of apples he bought in a day.
Ak exp(-x)
P(k; λ) =
=
k!
• In case you are curious https://en.wikipedia.org/wiki/Poisson_distribution. The true distribution of this selling apple process should be binomial distribution but with large enough customer and low enough probability of an individual buying an apple this is an excellent approximatoin.
4.1) You may find that if you try to code poisson distribution directly. It will not work with large number.
Explain briefly why python complains
1 import math
2
3 |
def bad poisson (1md, k):
return pow(1md,k)*math.exp(-1md)/math.factorial(k)
4 # bad_poisson (1000,1000) # uncomment to see it breaks
]
✓ 0.0s
4.2) A very useful trick to avoid this problem is to take log and exponentiate. That is
First, show that
1
X* exp(-λ)
P(k; λ)
k!
xp (In [** exp(-)])
k!
P(k; λ) = exp
ln(P(k; λ)) = (… …. ln(… . .) — . . .) — ln(k!)
Python
Python](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff97c0725-689e-40d7-87a0-46553d65cfc3%2Fc9f3b75d-ce18-4964-a52d-c6c4fcb49ab6%2F6a44fdo_processed.png&w=3840&q=75)
Transcribed Image Text:Problem 4
Ply quit programming and decide to be a Apple(fruit) shop owner. He bought 1000 apples everyday and try to sell it. The probability k customer want Ply's apple(one each) is given by Poisson distribution:
Where X is an parameter that represent the mean of number of people that want Ply's apple each day.
After selling apples for 2000 days Ply found that his 1000 apples a day are sold out 600 days out of 2000 days.
The goal for this problem is to figure out how he should change the number of apples he bought in a day.
Ak exp(-x)
P(k; λ) =
=
k!
• In case you are curious https://en.wikipedia.org/wiki/Poisson_distribution. The true distribution of this selling apple process should be binomial distribution but with large enough customer and low enough probability of an individual buying an apple this is an excellent approximatoin.
4.1) You may find that if you try to code poisson distribution directly. It will not work with large number.
Explain briefly why python complains
1 import math
2
3 |
def bad poisson (1md, k):
return pow(1md,k)*math.exp(-1md)/math.factorial(k)
4 # bad_poisson (1000,1000) # uncomment to see it breaks
]
✓ 0.0s
4.2) A very useful trick to avoid this problem is to take log and exponentiate. That is
First, show that
1
X* exp(-λ)
P(k; λ)
k!
xp (In [** exp(-)])
k!
P(k; λ) = exp
ln(P(k; λ)) = (… …. ln(… . .) — . . .) — ln(k!)
Python
Python
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 2 images

Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education