-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathann.c
102 lines (86 loc) · 1.63 KB
/
ann.c
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
102
//
// ann.c
// ann
//
// Created by Emre Jılta
#include "ann.h"
#include <math.h>
//Distribution Functions
//Net : weighted sum
//Multiplication
float multiplication(float n, float net[], float threshold[]){
int i = 0;
float weight;
while(i<n){
weight *= (net[i]*threshold[i]);
i++;
}
return weight;
}
//Maximum
float maximum(float net, float threshold){
return fmaxf(net,threshold);
}
//Minimum
float minimum(float net, float threshold){
return fminf(net,threshold);
}
//Sum
float sum(float n, float net[], float threshold[]){
int i = 0;
float weight;
while(i<n){
weight += (net[i]*threshold[i]);
i++;
}
return weight;
}
//Cumulative Distribution
float cumulative(float n, float net[], float threshold[]){
float weight = 0;
int i;
while(i<n){
weight += weight*(net[i]*threshold[i]);
i++;
}
return weight;
}
//Activation Functions
//Sigmoid
float sigmoid(float x){
return 1/(1+pow(M_E,-x));
}
//Linear
float linear(float net){
return net;
}
//ReLU
float relu(float net){
if(net > 1)
return 1;
else if((net > -1) || (net < 1))
return net;
else
return -1;
}
//Step
float step(float net, float threshold){
if(net > threshold)
return 1;
else if(net <= threshold)
return 0;
else
return -1;
}
//Sinusoid
float sinusoid(float net){
return sin(net);
}
//Hyperbolic Tangent
float htan(float net){
return tanh(net);
}
//Hyperbolic Tangent - second version
float htan2(float net){
return (pow(M_E,net)+pow(M_E,-net))/(pow(M_E,net)-pow(M_E,-net));
}