-
Notifications
You must be signed in to change notification settings - Fork 1
/
Neuron.m
54 lines (36 loc) · 1.41 KB
/
Neuron.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
classdef Neuron < matlab.mixin.Copyable
properties (SetAccess = private, GetAccess = public)
noInputs; % number of inputs into neuron
arrWeights; % weights for each input
end
properties (SetAccess = public)
sigmoidOut; % output after sigmoid.
sigmoidPre; % pre sigmoid output.
end
methods
function NEURON = Neuron(noinputs)
NEURON.noInputs = noinputs;
% initialize weights:
for i=1:NEURON.noInputs+1 % include the BIAS weight.
% for good initialisation,
% initialize the random number between -1/sqrt(
NEURON.arrWeights(i) = clampedRandom();
end
end
function UpdateWeight(NEURON, wNo, val)
NEURON.arrWeights(wNo) = val;
%NEURON.arrWeights(wNo) = 0;
end
function printDebug(NEURON)
fprintf('s:%f x:%f\n', NEURON.sigmoidPre, NEURON.sigmoidOut);
for i=1:NEURON.noInputs+1
fprintf('w:%f', NEURON.arrWeights(i));
if (i==NEURON.noInputs+1)
fprintf(' (bias)\n');
else
fprintf('\n');
end
end
end
end
end