MCPcopy Index your code
hub / github.com/ddbourgin/numpy-ml / test_radial_basis_kernel

Function test_radial_basis_kernel

numpy_ml/tests/test_utils.py:76–97  ·  view source on GitHub ↗
(N=1)

Source from the content-addressed store, hash-verified

74
75
76def test_radial_basis_kernel(N=1):
77 np.random.seed(12345)
78 i = 0
79 while i < N:
80 N = np.random.randint(1, 100)
81 M = np.random.randint(1, 100)
82 C = np.random.randint(1, 1000)
83 gamma = np.random.rand()
84
85 X = np.random.rand(N, C)
86 Y = np.random.rand(M, C)
87
88 # sklearn (gamma) <-> mine (sigma) conversion:
89 # gamma = 1 / (2 * sigma^2)
90 # sigma = np.sqrt(1 / 2 * gamma)
91
92 mine = RBFKernel(sigma=np.sqrt(1 / (2 * gamma)))(X, Y)
93 gold = sk_rbf(X, Y, gamma=gamma)
94
95 np.testing.assert_almost_equal(mine, gold)
96 print("PASSED")
97 i += 1
98
99
100#######################################################################

Callers

nothing calls this directly

Calls 1

RBFKernelClass · 0.90

Tested by

no test coverage detected