Форум для обсуждения курса

23 03 2022 МТ 401

23 03 2022 МТ 401

Артем Маковецкий -
回帖数:0

# p1 = (1, 1)
# p2 = (3, 3)
# p3 = (5, 1)
# p4 = (2, 8)

# p5 = (-5, 1)
# p6 = (-7, 3)
# p7 = (-1, 1)
# p8 = (-17, 1)

# p9 = (1, -4)
# p10 = (3, -12)
# p11 = (12, -1)
# p12 = (1, -5)

# p13 = (-4, -1)
# p14 = (-5, -5)
# p15 = (-12, -3)
# p16 = (-2, -7)

H1 = [1,1,1;
3,3,1;
5,1,1;
2,8,1;

-5,1,1;
-7,3,1;
-1,1,1;
-17,1,1;

1,-4,1;
3,-12,1;
12,-1,1;
1,-5,1;

-4,-1,1;
-5,-5,1;
-12,-3,1;
-2,-7,1;
];

Y = [0,0;
0,0;
0,0;
0,0;

0,1;
0,1;
0,1;
0,1;

1,0;
1,0;
1,0;
1,0;

1,1;
1,1;
1,1;
1,1;
];
Y=Y';
H1=H1';
#disp(h1);
W = [1,1;
1,1;
1,1];
W=W';

Z2=W*H1;

str1=Z2(1,:);
str2=Z2(2,:);

 

#disp(str2);

function HI = softmax(Z2)
ht=size(Z2)(1);
wd=size(Z2)(2);
sum=zeros(1,wd);

for i=1:wd;
sum(i)+=exp(Z2(1,i)) + exp(Z2(2,i));
endfor;

for i=1:ht;
for j=1:wd;
HI(i,j)=exp(Z2(i,j))/sum(j);
endfor;
endfor;
endfunction;

H2=softmax(Z2);

J_0=norm(H2-Y)**2;
Dlt = (H2-Y).*(H2.*(1-H2));
Grd_0 = Dlt*(H1');

lambda = 0.0000001;
W1 = W - lambda*Grd_0;
Z2_1 = W1*H1;
H2_1 = softmax(Z2_1);
J_1 = norm(H2_1-Y)**2;
disp(Grd_0);

#for i=1:16;
#str2_sum+=exp(str2(i));
#endfor;

#for j=1:16;
#str1_h(j)=exp(str1(j))/str1_sum;
#endfor;

#for j=1:16;
#str2_h(j)=exp(str2(j))/str2_sum;
#endfor;

#H2 = [str1_h; str2_h];
#Y=Y';
#disp(Y);