Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fullung
committed
Jul 14, 2006
1 parent
69cd19a
commit 3b8723a
Showing
7 changed files
with
83 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from numpy.testing import * | ||
import numpy as N | ||
|
||
set_local_path('../..') | ||
from svm.regression import * | ||
from svm.dataset import * | ||
from svm.kernel import LinearKernel | ||
restore_path() | ||
|
||
class test_precomputed(NumpyTestCase): | ||
def check_precomputed(self): | ||
kernel = LinearKernel() | ||
|
||
# this dataset remains constant | ||
y1 = N.random.randn(50) | ||
x1 = N.random.randn(len(y1), 10) | ||
data1 = LibSvmRegressionDataSet(zip(y1, x1)) | ||
pcdata1 = data1.precompute(kernel) | ||
|
||
# in a typical problem, this dataset would be smaller than the | ||
# part that remains constant and would differ for each model | ||
y2 = N.random.randn(5) | ||
x2 = N.random.randn(len(y2), x1.shape[1]) | ||
data2 = LibSvmRegressionDataSet(zip(y2, x2)) | ||
|
||
pcdata12 = pcdata1.combine(data2) | ||
model = LibSvmEpsilonRegressionModel(kernel) | ||
results = model.fit(pcdata12) | ||
|
||
# reference model, calculated without involving the | ||
# precomputed Gram matrix | ||
refy = N.concatenate([y1, y2]) | ||
refx = N.vstack([x1, x2]) | ||
refdata = LibSvmRegressionDataSet(zip(refy, refx)) | ||
model = LibSvmEpsilonRegressionModel(kernel) | ||
refresults = model.fit(refdata) | ||
|
||
self.assertAlmostEqual(results.rho, refresults.rho) | ||
assert_array_almost_equal(results.sv_coef, refresults.sv_coef) | ||
|
||
# XXX sigmas don't match yet. need to find out why. | ||
#self.assertAlmostEqual(results.sigma, refresults.sigma) | ||
|
||
if __name__ == '__main__': | ||
NumpyTest().run() |