In this video, I have explained derivation of least square estimation for a constant and how we can use the power of Matrix to find the final estimate
x_hat = (HT * H )-1 * H*y this is the formula for calculating best estimate
y - measurement Matrix
H - one dimensional matrix consist of 1 in this problem
x_hat gives same as average of all measurement,
---------------------------------------------------------------
Python Implementation
you can copy and paste below code, it would run
def measurement_generator(mu, sigma, k):
s1 = np.random.normal(mu, sigma, k)
resistor_s = 40 + s1
return resistor_s
def x_hat_cal(meas, k):
H Matrix definition
h_matrix = np.transpose(np.ones(k))
Y(measurement) Matrix definition
y_matrix = meas
hth = (np.matmul(np.transpose(h_matrix), h_matrix))
h_y = np.matmul(h_matrix, y_matrix)
x_hat = (1 / hth) * h_y
return x_hat
if _name_ == "__main__":
mean, std_dvt = 0, 2
meas_no = 100
measurement = measurement_generator(mean,std_dvt,meas_no)
x_hat_least_square = x_hat_cal(measurement,meas_no)
x_hat_average = np.average(measurement)
print('x_hat_least_square - ',x_hat_least_square)
print('x_hat_average - ',x_hat_average)
*I hope this video is useful for anyone try to figure out Least Square Estimation