Last active
August 27, 2021 17:11
-
-
Save junqueira/d8a32bb7df28523e2e59d6fd376991bc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#brew install octave | |
# impl regressão logistica binaria (sem dimensão y) | |
# return w-> pesos(x: 'matriz input', y: 'quant desejada') | |
# n -> num amostras | |
# ne -> num entradas / atributos | |
pt=100 | |
x = [0.5*rand(pt,2);2+0.5*rand(pt,2)] | |
plot(x(:,1),x(:,2),'*') | |
y = [ones(pt,1);-ones(pt,1)] | |
plot(y,'*') | |
function w=rlogb(x, y) | |
[n, ne]= size(x) | |
x= [ones(n,1), x] | |
w= rand(ne+1, 1) | |
e= 1/n * sum(log(1+exp(-(x*w).*y))) | |
Emin= 1e-3 | |
nit= 1000 | |
it= 0 | |
lamb= 0.7 #taxa aprendizado | |
while e>Emin & it<nit | |
#increment interação | |
it = it+1 | |
#calcula gradiente | |
dEw=zeros(ne+1,1) | |
for j=1:ne+1 #atributo | |
for n=1:n #num padrao / amostra | |
dEw(j,1)= dEw(j,1) + y(n,1)*x(n,j) / (1 * exp(y(n,1)*x(n,:)*w)) | |
end; | |
end; | |
dEw = -dEw/n | |
#atualiza w | |
w = w -lamb * dEw | |
#calcula erro | |
e = 1/n * sum(log(1+exp(-(x*w).*y))) | |
pause(2) | |
end; | |
end; | |
rlogb(x,y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment