Skip to content

Commit 86839a6

Browse files
authored
Fix RBF kernel length scale calculation
This commit fixes the implementation of the RBF kernel function to correctly match the standard mathematical definition. Previously, the length scale parameter ls was used without squaring, resulting in a kernel formula of exp(- (1/(2*ls)) * ||x1 - x2||^2 ). The corrected implementation now uses ls**2 in the denominator, so the kernel is computed as exp(- (1/(2*ls**2)) * ||x1 - x2||^2 ), which is consistent with the conventional RBF kernel definition.
1 parent 23d7a5a commit 86839a6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

chapter_gaussian-processes/gp-priors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ We illustrate this process in the figure below.
117117
```{.python .input}
118118
def rbfkernel(x1, x2, ls=4.): #@save
119119
dist = distance_matrix(np.expand_dims(x1, 1), np.expand_dims(x2, 1))
120-
return np.exp(-(1. / ls / 2) * (dist ** 2))
120+
return np.exp(-(1. / ls**2 / 2) * (dist ** 2))
121121
122122
x_points = np.linspace(0, 5, 50)
123123
meanvec = np.zeros(len(x_points))

0 commit comments

Comments
 (0)