Example #1
0
    def test_cache_speedup(self):
        skip_if_no_external('shogun', ver_dep='shogun:rev', min_version=4455)

        ck = sgSVM(kernel=CachedKernel(kernel=RbfSGKernel(sigma=2)), C=1)
        sk = sgSVM(kernel=RbfSGKernel(sigma=2), C=1)

        cv_c = CrossValidation(ck, NFoldPartitioner())
        cv_s = CrossValidation(sk, NFoldPartitioner())

        #data = datasets['uni4large']
        P = 5000
        data = normal_feature_dataset(snr=2,
                                      perlabel=200,
                                      nchunks=10,
                                      means=np.random.randn(2, P),
                                      nfeatures=P)

        t0 = time()
        ck.params.kernel.compute(data)
        cachetime = time() - t0

        t0 = time()
        cached_err = cv_c(data)
        ccv_time = time() - t0

        t0 = time()
        norm_err = cv_s(data)
        ncv_time = time() - t0

        assert_almost_equal(np.asanyarray(cached_err), np.asanyarray(norm_err))
        ok_(cachetime < ncv_time)
        ok_(ccv_time < ncv_time)
        #print 'Regular CV time: %s seconds'%ncv_time
        #print 'Caching time: %s seconds'%cachetime
        #print 'Cached CV time: %s seconds'%ccv_time

        speedup = ncv_time / (ccv_time + cachetime)
        #print 'Speedup factor: %s'%speedup

        # Speedup ideally should be 10, though it's not purely linear
        self.failIf(speedup < 2, 'Problem caching data - too slow!')
Example #2
0
        bad_classifiers.append('gnpp')

    for impl in sg.SVM._KNOWN_IMPLEMENTATIONS:
        # Uncomment the ones to disable
        if impl in bad_classifiers:
            continue
        clfswh += [
            sg.SVM(descr="sg.LinSVM(C=def)/%s" % impl, svm_impl=impl),
            sg.SVM(C=-10.0,
                   descr="sg.LinSVM(C=10*def)/%s" % impl,
                   svm_impl=impl),
            sg.SVM(C=1.0, descr="sg.LinSVM(C=1)/%s" % impl, svm_impl=impl),
        ]
        if not impl in ['svmocas']:  # inherently linear only
            clfswh += [
                sg.SVM(kernel=RbfSGKernel(),
                       descr="sg.RbfSVM()/%s" % impl,
                       svm_impl=impl),
                #            sg.SVM(kernel=RbfSGKernel(),
                #                   descr="sg.RbfSVM(gamma=0.1)/%s"
                #                    % impl, svm_impl=impl, gamma=0.1),
                #           sg.SVM(descr="sg.SigmoidSVM()/%s"
                #                   % impl, svm_impl=impl, kernel=SigmoidSGKernel(),),
            ]

    _optional_regressions = []
    if externals.exists(
            'shogun.krr') and externals.versions['shogun'] >= '0.9':
        _optional_regressions += ['krr']
    for impl in ['libsvr'] + _optional_regressions:  # \
        # XXX svrlight sucks in SG -- dont' have time to figure it out