Skip to content

Commit

Permalink
print error + test v1
Browse files Browse the repository at this point in the history
  • Loading branch information
lmarzora committed May 8, 2017
1 parent 79458f4 commit e1038ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 6 additions & 4 deletions multilayer_perceptron.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
M = m;
i = 1;
for entry = entries
layer_entry = [-1,entry];
layer_entry{1}(2:end) = [entry];
for m = 2:M
layer_entry = [-1,activation_func(weights{m-1} * layer_entry{m-1}')];
layer_entry{m}(2:end) = activation_func(weights{m-1} * layer_entry{m-1}');
end
output(i) = activation_func(weights{M} * layer_entry{M}');
i = i + 1;
Expand All @@ -28,7 +28,7 @@
%setup
for i = 2:length(neurons_per_layer)
m = m + 1;
weights{m} = rand(neurons_per_layer(i), neurons_per_layer(i-1)+1) .- 0.5;
weights{m} = (rand(neurons_per_layer(i), neurons_per_layer(i-1)+1) .- 0.5)./neurons_per_layer(i-1);
layer_entry{m} = [-1, zeros(1, neurons_per_layer(i-1))];
h{m} = [-1 ,zeros(1, neurons_per_layer(i-1))];
end
Expand Down Expand Up @@ -65,7 +65,9 @@
end
end
%get iteration error
error_per_iteration(iteration) = sum((expected_output - output).^2);
error_per_iteration(iteration) = sum((expected_output - output).^2)/n;
error_per_iteration(iteration)
fflush(1);
if error_per_iteration(iteration) <= tolerance
return
end
Expand Down
15 changes: 10 additions & 5 deletions test.m
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
1;
source multilayer_perceptron.m
terrain = dlmread('terrain/terrain03.data');
[f,fder] = activation_tanh(.5);
[weights,output,mse] = multilayer_perceptron_learn(terrain(:,1:2)',terrain(:,3)',[2,20,1],f,fder,.05,1e5);
x = [-2:0.01:2]
[f,fder] = activation_exp(1);
net = [2,45,50,1];
[weights,output,mse] = multilayer_perceptron_learn(terrain(:,1:2)',terrain(:,3)',net ,f,fder,1,1e4,5e-4);
x = [-3:0.01:3];
y = x;
%dlmwrite('weights.csv',cell2mat(weights));

for i = 1 length(x)
for i = 1:length(x)
for j = 1:length(y)
out = get_output([x(i);y(j)],weights,[2,20,1],f);
out(i,j) = get_output([x(i);y(j)],weights,net,f);
end
end

plot3(terrain(:,1),terrain(:,2),terrain(:,3),'.')
hold on;
surf(x,y,out);
hold off;

0 comments on commit e1038ed

Please sign in to comment.