Skip to content

Instantly share code, notes, and snippets.

View MariaLavrovskaya's full-sized avatar

Maria MariaLavrovskaya

  • London, United Kingdom
View GitHub Profile
tic
[xPD, fPD, _, _, infoPD] = PrimalDual(F, ineqConstraint, eqConstraint, x0, lambda0, nu0, mu, tol, tol, maxIter, optsBT);
toc
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')
% 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;
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
%% 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;
% 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
@MariaLavrovskaya
MariaLavrovskaya / svm-upload.m
Created October 18, 2021 08:52
svm-upload.m
% % 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);
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
@MariaLavrovskaya
MariaLavrovskaya / dockerselenium_.idea_.gitignore
Created June 11, 2020 09:18
Distributed extraction of comments in Instagram
# Default ignored files
/workspace.xml
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:')