Derivative of 1D Gaussian w.r.t mean and w.r.t x

108 Views Asked by At

The three formulas (1D Gaussian, derivative w.r.t x, derivative w.r.t mean) are:

One-dimensional Gaussian curve:

formula

One-dimensional Gaussian curve derivative w.r.t mean:

another

One-dimensional Gaussian curve derivative w.r.t x:

another

When I plot the curves using a Python program (given below) using the above formulas for mean = 0 and sigma = 1, I get the following curves:

enter image description here

QUESTION: I can understand the derivative of Gaussian w.r.t x. We have varied the values of x and the derivative w.r.t x represents how the curves change w.r.t x. But I am not able to understand why we get the same trend for the derivative of Gaussian w.r.t mean. The value of mean is constant for every computed point of the Gaussian curve so, the derivate w.r.t mean should not represent any change/dependence. Why are we getting the same rate of change trend w.r.t x as well as mean?

import numpy as np
import matplotlib.pyplot as plt

# Define the range of x values
x_range = np.linspace(-8, 8, 100)

# Define the mean and standard deviation (sigma) for the Gaussian curve
mean = 0
sigma = 1

# Calculate the Gaussian values for the original Gaussian curve
gaussian_values = (1 / (sigma * np.sqrt(2 * np.pi))) * np.exp(-0.5 * ((x_range - mean) / sigma) ** 2)

# Calculate the derivative of the Gaussian curve with respect to the mean
derivative_mean = -gaussian_values * (x_range - mean) / (sigma ** 2)

# Calculate the derivative of the Gaussian curve with respect to x
derivative_x = (-1 / sigma) * gaussian_values * (x_range - mean)

# Create a plot to visualize the Gaussian curve and its derivatives
plt.figure(figsize=(8, 6))

plt.plot(x_range, gaussian_values, label='Gaussian Curve', color='blue')
plt.plot(x_range, derivative_mean, label='Derivative w.r.t. Mean', color='red', linestyle='--')
plt.plot(x_range, derivative_x, label='Derivative w.r.t. X', color='green', linestyle=':')
plt.xlabel('X')
plt.ylabel('Values')
plt.title('Gaussian Curve and Its Derivatives')
plt.legend()
plt.grid(True)

# Show the plot
plt.show()

print('done')