A transductive SVM (Joachims, 1999) adds a penalty on unlabeled points that pushes them away from the decision boundary. For a linear score f(x) = w^T x + b, the objective is
J = 0.5 ||w||^2 + C * sum_l max(0, 1 - y_l f(x_l)) + C_u * sum_u max(0, 1 - |f(x_u)|).
The unlabeled term is zero when a point lies at least margin 1 from the boundary, whichever side it is on, so it rewards separation and not a particular label.
Implement s3vm_objective(w, b, X_l, y_l, X_u, C, C_u) and return J as a float.
w is 1-D. X_l is (n_l, d), y_l holds values in {-1, +1}, and X_u is (n_u, d).C and C_u must be nonnegative.-1 and +1 raise ValueError.ValueError.X_u may be empty, in which case its term is zero.Use np.maximum(0, 1 - y * f) for the labeled hinge and np.maximum(0, 1 - np.abs(f)) for the unlabeled one.
No results yet
Run your code to check it against the examples, or submit to run every test.