Answer To: MSE XXXXXXXXXXExercise 4 Introduction to Bayes Rule with Applications Week of February 11th, 2019...
Abr Writing answered on Feb 20 2021
MSE 2321 - Exercise 4 Introduction to Bayes Rule with Applications
Exercise #1 Conditional Probabilities
Q1.1
Before the eddy current test was performed, the best estimate of the probability that the part had a crack is 0.01 or 1%.
Q1.2
An interesting question is "What is the probability that a part that fails the test actually has a crack?". In terms of probability, we can write the objective as that is we know that the part has failed the eddy current test then what is the probability that there was actually a crack in the part? From the real engineering estimates based on data, the probability of such an conditional event can be calculated as follows.
Let's assume a population of 1,000 parts. 99% of that population does not have a crack and 1% does have a
crack.
• 990 parts with no crack & 10 parts with crack
• Out of the 990 parts with no crack 8% will fail the test
• ~79 (79.2) parts fail but no crack.
• Out of the 10 parts with a crack 90% will fail the test
• 9 part fail with crack
• total # of parts that fail test = 88
• Probability that a part that fails has a crack
Q1.3
Now, we need to find
Let's assume a population of 1,000 parts. 99% of that population does not have a crack and 1% does have a
crack.
• 990 parts with no crack & 10 parts with crack
• Out of the 990 parts with no crack 92% will pass the test
• ~911 (910.8) parts pass but no crack.
• Out of the 10 parts with a crack 10% will pass the test
• 1 part pass with crack
• total # of parts that pass test = 912
• Probability that a part that pass has a crack
Q1.4
Ww know that out od 1000 parts, 990 parts don't have a crack. But because of false positives (8%), parts will be removed from the service even though they don't have a crack.
Q1.5
The probability means that the probability that the part has failed and has crack as well. In the 1000 parts case, we have 10 parts that have a crack and out of these 10 parts 90% will fail the eddy current test. Therefore, the probability is equal to . This can also be calculated using the formal definition of conditional probability:
The probability means that the probability that the part atleast has a crack or has failed the eddy current test.
· Out of 990 parts with no crack, 79 will fail the test
· All the 10 parts that have crack will be under this condition
Therefore,
Exercise #2 Bayes' Rule
Q2.1
The formal definition of conditional probability is given as
Which can also be written as:
On equating the two equations above, we get:
Q2.2
Check the q2_2 function for more details.
Q2.3
rate_false_positives = 0.08;
cracked_fractions = linspace(0, 10)/100;
test_accuracies = linspace(50,100)/100;
surf = @(x,y) q2_2(x, y, 0.08);
Q2.4
fsurf(surf, ...
[min(cracked_fractions), ...
max(cracked_fractions), ...
min(test_accuracies), ...
max(test_accuracies)]);
xlabel('Overall fraction of parts with cracks');
ylabel('Accuracy of the Eddy Current test');
zlabel('P(cracked|failed)');
Exercise #3 Updating our hypthesis with Bayes' rule
Q3.1
%Posterior update biased coin example
clear;
close;
visualize_each_flip=0; %set to zero to only see posterior probability
Distribution for only the final flip. Set to 1 to update the graph each flip. This can take a long time if you are flipping more than 10000 times.
num_flips=50; %this is the number of flips we are going to do.
bias=0.2; %this is the bias of our coin. Do not change keep at 0.2
Initialize a list of possible bias values. We want our bias to go from 0 (alwaysflip tails) to 1 (always flip heads) and everywhere in between. We will consider bias values in 1% (0.01 probability) increments.
bias_values=0:0.01:1;
Initialize our prior probabilities. Since we don't know anything about the coin. Let's start by assuming that all possible bias values are equally likely. This is called a flat prior.
bias_priors=ones(1,101);
The priors are probabilties. That means they need to sum to 1 according to the definition of probability (The probability of the intersection of all...