A weighted average combines values while giving each one influence proportional to its assigned weight. Larger weights pull the estimate closer to their measurements. section 6.2.1
Estimating CPU time
For measurements 1.54 at parameter 0.5 and 1.21 at parameter 0.0, an equal average is 0.5 × 1.54 + 0.5 × 1.21 = 1.365. For parameter 0.4, weights 0.8 and 0.2 produce 1.458, favoring the nearer measurement. section 6.2.1
Use weighted averages carefully:
- Make weights sum to 1 so the result remains on the measurements’ scale. section 6.2.1
- In proximity-based estimates, decrease a measurement’s weight as its distance from the query increases. section 6.2.1
Listing 6.3 GPR with a weighted average
class GPR2:
def __init__(self, parameters, measurements, sigma):
self.x = parameters
self.y = np.array(measurements)
self.sigma = sigma
self.mean_y = self.y.mean()
self.y -= self.mean_y #1
def kernel(self, x1, x2): #2
distance_squared = ((x1-x2)**2).sum()
return np.exp( -distance_squared/(2*self.sigma**2) )
def estimate(self, query_parameter):
weights = [
self.kernel(x, query_parameter)
for x in self.x
] #3
weights = np.array(weights)
weights = weights / weights.sum() #4
return self.mean_y + weights @ self.y #5
A NumPy implementation centers measurements, computes squared-exponential kernel weights, normalizes them, and forms a weighted sum. section 6.2.1




