Skip to content

Commit

Permalink
Add doctest to _rbf Kernel func
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Pasutti committed Sep 18, 2024
1 parent 94b1403 commit 308fbe4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions machine_learning/sequential_minimum_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,13 @@ def _linear(self, v1, v2):
return np.inner(v1, v2) + self.coef0

def _rbf(self, v1, v2):
"""
>>> from machine_learning.sequential_minimum_optimization import Kernel
>>> kernel = Kernel(kernel='linear')
>>> result = kernel._rbf(np.array([1, 2]), np.array([2, 3]))
>>> round(result, 3)
0.135
"""
return np.exp(-1 * (self.gamma * np.linalg.norm(v1 - v2) ** 2))

def _check(self):
Expand Down

0 comments on commit 308fbe4

Please sign in to comment.