-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
81 lines (73 loc) · 2.37 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
conf_file = argv(){1};
source(conf_file);
warning("off");
epochs = {};
if (random_weights==true)
cols = size(input_data,2);
for i=1:length(layers)
if(layers{i}.random_weights)
layers{i}.weights = unifrnd(layers{i}.rand_min, layers{i}.rand_max, layers{i}.neurons, cols+1);
printf('Wylosowane wagi warstwy %d:\n', i);
layers{i}.weights
endif
cols=layers{i}.neurons;
layers{i}.epoch = 0;
epochs{i} = 0;
end
endif
%input_data = input_data/norm(input_data)
% calculate
answers = [];
input_rows = size(input_data, 1);
answers=input_data;
for step=1:learn_steps
if (strcmp(layers{1}.type,'bp')==1)
if(find(stages==step))
stage = find(stages==step);
printf("layer %d epoch=%d\n",i,stage);
endif
answers = bp(input_data, expected, stage);
else
answers = input_data;
for i=1:length(layers)
layer = layers{i};
if(find(layers{i}.epochs==step))
epochs{i} = find(layer.epochs==step);
printf("layer %d epoch=%d\n",i,epochs{i});
print = true;
endif
if (strcmp(layer.type,'normal')==1)
answers = layer.activation_function([layer.bias*ones(input_rows,1) answers]*layer.weights');
elseif (strcmp(layer.type,'kohonen')==1)
answers = kohonen(i,answers,step,epochs{i});
if(print)
answers
print = false;
endif
elseif (strcmp(layer.type,'grossberg')==1)
answers = grossberg(i,answers,expected,epochs{i});
if(print)
answers
print = false;
endif
endif
end
endif
end
% show answers
input_data
answers
layers{1}.weights
%layers{2}.weights
answers-expected
if (size(input_data,1)==size(expected,1))
printf('Błąd: %0.4f\n', sqrt(mean(sum((answers-expected).^2, 2))));
endif
% plot chart if 2 inputs and 1 output
if (size(input_data,2)==2 && size(expected,2)==1 && size(input_data,1)==size(expected,1))
x=linspace(0,1,50);
y=linspace(0,1,50);
[xx,yy]=meshgrid(x,y);
meshc(xx,yy,double(reshape( nn(layers, [xx(:) yy(:)]), size(xx))) )
pause
endif