Course Content
Probability Theory Basics
Probability Theory Basics
Geometrical Probability
In the previous chapter, we considered the classic rule for counting probabilities. Due to this rule, the probability is calculated as the ratio of the number of outcomes of interest to us to the number of all possible outcomes. But what can we do if the number of outcomes cannot be counted?
For example, assume you are randomly shooting at a target and you want to determine the probability of hitting the center area of this target.
In this case, you can’t just count all the possible outcomes because number of points that you can hit is infinite. As a result, we will have to use geometric probability.
The principle of calculating geometric probabilities is similar to the classical rule - we still assume that all possible elementary outcomes of the experiment are equally probable, but instead of counting the number of outcomes, we consider their geometric measure.
The geometric measure is determined based on the dimension of the space of elementary events:
- if the space is one-dimensional (line), then the length of the line is used as a measure;
- if two-dimensional (plane), then the area of the figure on the plane is used as a measure;
- if three-dimensional (a figure in space), then we use volume as a measure.
Thus, to solve the problem with a target, we can use the ratio of the areas of the area of interest to us and the entire target. Suppose the entire target is a circle with a radius of 2 and the region of interest is a circle in the center with a radius of 1. Then the probability of hitting the central region can be found as follows:
import numpy as np import matplotlib.pyplot as plt # Define the radii of the circles r_large = 2 # Radius of the larger circle r_small = 1 # Radius of the smaller circle # Calculate the areas area_large = np.pi * r_large**2 # Area of the larger circle area_small = np.pi * r_small**2 # Area of the smaller circle # Calculate the probability probability = area_small / area_large # Probability of shooting into the smaller circle # Plot the circles fig, ax = plt.subplots() # Create a new figure and axis object circle_large = plt.Circle((0, 0), r_large, color='blue', alpha=0.3) # Create a circle representing the larger circle circle_small = plt.Circle((0, 0), r_small, color='red', alpha=0.5) # Create a circle representing the smaller circle ax.add_artist(circle_large) # Add the larger circle to the plot ax.add_artist(circle_small) # Add the smaller circle to the plot ax.set_aspect('equal') # Set the aspect ratio of the plot to be equal ax.set_xlim(-r_large-1, r_large+1) # Set the x-axis limits ax.set_ylim(-r_large-1, r_large+1) # Set the y-axis limits ax.set_xlabel('X') # Set the x-axis label ax.set_ylabel('Y') # Set the y-axis label ax.set_title('Probability of Shooting into the Circle') # Set the title of the plot plt.legend(['Target', 'Area to shoot']) # Add a legend to the plot plt.grid(True) # Add a grid to the plot plt.show() # Display the plot print(f'The probability of shooting into the smaller circle is {probability:.4f}') # Print the probability
Thanks for your feedback!