Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
patches to svdd-l1 reflecting scikit-learn#14286, scikit-learn#16530, s…
  • Loading branch information
ivannz committed Feb 25, 2021
1 parent 201547d commit 840dad5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions sklearn/svm/_classes.py
Expand Up @@ -1556,7 +1556,7 @@ class SVDD(OutlierMixin, BaseLibSVM):
>>> clf = SVDD(gamma='auto').fit(X)
>>> clf.predict(X)
array([-1, 1, 1, 1, -1])
>>> clf.score_samples(X) # doctest: +ELLIPSIS
>>> clf.score_samples(X)
array([0.5298..., 0.8047..., 0.8056..., 0.8061..., 0.4832...])
References
Expand All @@ -1573,7 +1573,7 @@ class SVDD(OutlierMixin, BaseLibSVM):

_impl = 'svdd_l1'

def __init__(self, kernel='rbf', degree=3, gamma='scale',
def __init__(self, *, kernel='rbf', degree=3, gamma='scale',
coef0=0.0, tol=1e-3, nu=0.5, shrinking=True, cache_size=200,
verbose=False, max_iter=-1):

Expand Down
11 changes: 6 additions & 5 deletions sklearn/svm/src/libsvm/svm.cpp
Expand Up @@ -1832,14 +1832,14 @@ static void solve_nu_svr(

static void solve_svdd_l1(
const PREFIX(problem) *prob, const svm_parameter *param,
double *alpha, Solver::SolutionInfo* si)
double *alpha, Solver::SolutionInfo* si, BlasFunctions *blas_functions)
{
int l = prob->l;
int i, j;

double r_square;

ONE_CLASS_Q Q = ONE_CLASS_Q(*prob, *param);
ONE_CLASS_Q Q = ONE_CLASS_Q(*prob, *param, blas_functions);

if(param->nu < 1) {
// case \nu < 1: the dual problem is
Expand Down Expand Up @@ -1981,7 +1981,7 @@ static decision_function svm_train_one(
break;
case SVDD_L1:
si.upper_bound = Malloc(double,prob->l);
solve_svdd_l1(prob,param,alpha,&si);
solve_svdd_l1(prob,param,alpha,&si,blas_functions);
break;
}

Expand Down Expand Up @@ -2929,7 +2929,7 @@ double PREFIX(predict_values)(const PREFIX(model) *model, const PREFIX(node) *x,

if(model->param.svm_type == SVDD_L1)
{
double K_xx = NAMESPACE::Kernel::k_function(x,x,model->param) / 2;
double K_xx = NAMESPACE::Kernel::k_function(x,x,model->param,blas_functions) / 2;
for(int i=0;i<model->l;i++)
sum -= sv_coef[i] * K_xx;
}
Expand Down Expand Up @@ -3247,7 +3247,8 @@ const char *PREFIX(check_parameter)(const PREFIX(problem) *prob, const svm_param
if(svm_type == C_SVC ||
svm_type == EPSILON_SVR ||
svm_type == NU_SVR ||
svm_type == ONE_CLASS)
svm_type == ONE_CLASS ||
svm_type == SVDD_L1)
{
PREFIX(problem) newprob;
// filter samples with negative and null weights
Expand Down

0 comments on commit 840dad5

Please sign in to comment.