-
Notifications
You must be signed in to change notification settings - Fork 2
/
uneuron.pas
101 lines (81 loc) · 2.14 KB
/
uneuron.pas
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
unit uneuron;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils;
type
{ TNeuron }
TActivationFunction = (afSigmoid, afLinear, afBias);
TNeuron = class
private
// error
FError: double;
// wait value
FWaitValue: double;
FActivationFunction: TActivationFunction;
FInputValue: double;
FOutputValue: double;
FWeight: double;
FWeigth: double;
FDelta: double;
function GetInputValue: double;
function GetOutputValue: double;
procedure SetInputValue(AValue: double);
function Sigmoid(AValue: double): double;
function Linear(AValue: double): double;
public
constructor Create(AActivationFunction: TActivationFunction);
procedure Start;
property InputValue: double read GetInputValue write SetInputValue;
property OutputValue: double read GetOutputValue;
property Weight: double read FWeight write FWeigth;
property ActivationFunction: TActivationFunction read FActivationFunction write FActivationFunction default afLinear;
property Error: double read FError write FError;
property WaitValue: double read FWaitValue write FWaitValue;
property Delta: double read FDelta write FDelta;
end;
implementation
{ TNeuron }
procedure TNeuron.SetInputValue(AValue: double);
begin
if FInputValue = AValue then
Exit;
FInputValue := AValue;
end;
function TNeuron.GetInputValue: double;
begin
Result := FInputValue;
if FActivationFunction = afBias then
Result := 1;
end;
function TNeuron.GetOutputValue: double;
begin
Result := FOutputValue;
if FActivationFunction = afBias then
Result := 1;
end;
function TNeuron.Sigmoid(AValue: double): double;
begin
Result := 1 / (1 + exp(-1 * AValue));
end;
function TNeuron.Linear(AValue: double): double;
begin
Result := AValue;
end;
constructor TNeuron.Create(AActivationFunction: TActivationFunction);
begin
// Randomize;
FActivationFunction := AActivationFunction;
end;
procedure TNeuron.Start;
begin
case FActivationFunction of
afSigmoid:
FOutputValue := Sigmoid(FInputValue);
afLinear:
FOutputValue := Linear(FInputValue);
afBias:
FOutputValue := 1;
end;
end;
end.