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
tic | |
[xPD, fPD, _, _, infoPD] = PrimalDual(F, ineqConstraint, eqConstraint, x0, lambda0, nu0, mu, tol, tol, maxIter, optsBT); | |
toc |
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
alphas = find(xPD>0.0001); | |
W=sum(xPD(alphas,:).*y(alphas,:).*x(alphas,:)) | |
bias =mean( y(alphas,:) - x(alphas,:)*W') | |
% Xsupport=x((find(xPD~=0)),:); | |
% Ysupport=y((find(xPD~=0)),:); | |
Xsupport=x(alphas,:); | |
Ysupport=y(alphas,:); | |
hold on | |
scatter(x(y==1,1),x(y==1,2),'b') |
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
% Backtracking line search until constraints are met. We decompose deltaY | |
deltaX = deltaY(1:n); | |
deltaL = deltaY(n+1:n+m); | |
deltaN = deltaY(n+m+1:end); %delta nu | |
s_max = 1; | |
s = s_max; | |
nIterBT = 0; | |
stopCondBackTrack = false; |
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
function [xMin, fMin, t, nIter, infoPD] = PrimalDual(F, ineqConstraint, eqConstraint, x0, lambda0, nu0, mu, tol, tolFeas, maxIter, opts) | |
% Initilize the structures | |
nIter = 0; | |
stopCond = false; | |
x_k = x0; %k stands for current iteration | |
lambda_k = lambda0; %k stands for current iteration | |
nu_k = nu0; %k stands for current iteration | |
infoPD.xs = x_k; %all the interations | |
infoPD.lambdas = lambda0; %all the iterations of lambdas | |
infoPD.nus = nu0; %all iterations of nus |
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
%% Parameters | |
% Set parameters | |
mu = 10; % in (3, 100); | |
t = 1; | |
tol = 1e-12; | |
maxIter = 200; | |
% Backtracking options | |
optsBT.maxIter = 30; | |
optsBT.alpha = 0.1; %1e-4; %0.1; |
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
% Finding D | |
D = zeros(length(x)); | |
for i = 1: length(x) | |
for j = 1:length(x) | |
D(i,j) = y(i)*y(j)*x(i, 1:2)*x(j, 1:2)'; | |
end | |
end | |
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
% % For unseparable data | |
x = readtable(''); %add your path to the file | |
y = readtable(''); %add your path to the file | |
x = table2array(x); | |
y = table2array(y); |
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
f = @(x) x.^2; %objective | |
f1 = @(x) 1-x; %inequality constraint | |
L = @(x,lambda) f(x) + lambda.*f1(x); %lagrangian | |
g = @(lambda) -1/4*lambda.^2 + lambda; %dual function | |
%% | |
[X,Lambda] = meshgrid((-1:0.01:1), (-0.5:0.01:1.5)); | |
alpha = 3; %scale x | |
beta = 4; %scale lambda |
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
# Default ignored files | |
/workspace.xml |
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
from sklearn.model_selection import train_test_split | |
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1) | |
#Linear | |
from sklearn.svm import SVC | |
from sklearn import metrics | |
svc=SVC() #Default hyperparameters | |
svc.fit(X_train,y_train) | |
y_pred=svc.predict(X_test) | |
print('Accuracy Score:') |
NewerOlder