A mean is a numerical location parameter representing the average or central value of a probability distribution. For a Bernoulli random variable with success probability θ, E[X] = θ. section 2.1.1
The mean appears in several computational roles:
- Estimate an expected value by averaging function evaluations over samples drawn from a distribution. section 2.2
- Measure expected portfolio return while comparing portfolios by their risk, represented by standard deviation. section 9.2.2
- Relate a Bernoulli distribution's central value to its variance: E[X] = θ and Var(X) = θ(1 − θ). section 2.1.1
Monte Carlo estimate of π
Draw uniform points in a square, mark whether each lies inside a circle, and average the resulting area contributions. Dividing that empirical mean by the squared radius estimates π; increasing the sample count improves accuracy, with standard error σ/√N. section 2.2
Listing 2.1 Pi estimator
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42) #1
def pi_est(radius=1, num_iter=int(1e4)): #2
X = np.random.uniform(-radius,+radius,num_iter)
Y = np.random.uniform(-radius,+radius,num_iter)
R2 = X**2 + Y**2
inside = R2 < radius**2
outside = ~inside
samples = (2*radius)*(2*radius)*inside
I_hat = np.mean(samples)
pi_hat = I_hat/radius ** 2 #3
pi_hat_se = np.std(samples)/np.sqrt(num_iter) #4
print("pi est: {} +/- {:f}".format(pi_hat, pi_hat_se))
plt.figure()
plt.scatter(X[inside],Y[inside], c='b', alpha=0.5)
plt.scatter(X[outside],Y[outside], c='r', alpha=0.5)
plt.show()
if __name__ == "__main__":
pi_est()
Shows a NumPy implementation that computes an empirical mean and standard error while estimating π from random samples. section 2.2




























