Skip to content

Commit

Permalink
Merge pull request #3 from drkrillo/sequential_minimum_optimization_a…
Browse files Browse the repository at this point in the history
…dd_doctests

Add doctest to _rbf Kernel func
  • Loading branch information
drkrillo committed Sep 18, 2024
2 parents fb58570 + 308fbe4 commit 9d7532a
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 9d7532a

Please sign in to comment.