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

09.03.2024 MT-401

09.03.2024 MT-401

بواسطة - Анна Ануфриева
عدد الردود: 0

points = [
1 1; #I
1 5;
3 1;
4 4;

-1 1; #II
-1 5;
-4 1;
-5 5;

-1 -1; #III
-1 -3;
-4 -1;
-4 -2;

1 -1; #IV
4 -1;
1 -5;
3 -5;
];

ht = size(points)(1);
wd = size(points)(2);

H1 = zeros(wd + 1, ht);

for i = 1 : size(H1)(2)
H1(3, i) = 1;
endfor

for i = 1 : (size(H1)(1) - 1)
for j = 1 : size (H1)(2)
H1(i, j) = points(j, i);
endfor
endfor

W = ones(4, 3);

Z2 = W * H1;

function resMatrix = softmax(matrix);
ht = size(matrix)(1);
wd = size(matrix)(2);
massum = zeros(1, wd);
for j = 1 : wd
for i = 1 : ht
massum(1, j) = massum(1, j) + exp(matrix(i, j));
endfor
endfor

for i = 1 : ht
for j = 1 : wd
resMatrix(i, j) = exp(matrix(i, j)) / massum(1, j);
endfor
endfor

#return resMatrix;
endfunction

H2 = softmax(Z2)

#hold on;

#X = -10 : 0.01 : 10;
#Y = -10 : 0.01 : 10;

#plot(X, 0, 'k');
#plot(0, Y, 'k');
#plot(x = -10 : 0.05 : 10, 0, y = 0, "-k");
#plot(0, y = -10 : 0.05 : 10, x = 0, "-k");
#X = linspace(-10, 0.1, 10);
#Y = linspace(-10, 0.1, 10)

#X = -10:0.1:10;
#Y = -10:0.1:10;

#plot(X, 0, y = 0, 'b-');
#plot(0, Y , x = 0, 'b-');


#for i = 1 : size(points)(1)
# if points(i, 1) > 0 && points(i, 2) > 0
# plot(points(i, 1), points(i, 2), 'r*');
# elseif points(i, 1) > 0 && points(i, 2) < 0
# plot(points(i, 1), points(i, 2), 'b*');
# elseif points(i, 1) < 0 && points(i, 2) < 0
# plot(points(i, 1), points(i, 2), 'g*');
# elseif points(i, 1) < 0 && points(i, 2) > 0
# plot(points(i, 1), points(i, 2), 'm*');
# endif
#endfor

#hold off;