-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigmoid.cpp
77 lines (74 loc) · 2.57 KB
/
sigmoid.cpp
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
/* including libraries for c++ program */
#include <iostream>
#include <math.h>
#include <time.h>
#include <stdlib.h>
using namespace std; /* using the namespace method */
/*
This is an example program of using Sigmoid function using C++
We will be using Object Oriented Programming methods by creating a Class System of Objects
having pointer functions for neural value processing and mathematical computations.
*/
class SigmoidNeuronExample {
private:
double arrayOfInputs[10];
double arrayOfBiasedValues[10];
double arrayOfWeights[10];
double arrayOfSigmoid[10];
double arrayOfOutputs[10];
public:
double generateInputValues(void) {
/* here we will generate random values for inputs */
/* generating random values by creating a function to create those values */
srand(time(NULL)); // setting time as NULL
double inputSeed = rand() % 100 + 1;
for (int i = 0; i < 10; i++) {
arrayOfInputs[i] = inputSeed;
}
}
double generateBiasValues(void) {
/* here we will generate random bias values */
srand(time(NULL));
double biasValue = rand() % 100 + 1;
for (int i = 0; i < 10; i++) {
arrayOfBiasedValues[i] = biasValue;
}
}
double generateWeightValues(void) {
/* here we will generate random weight values */
srand(time(NULL));
double weightValue = rand() % 100 + 1;
for (int i = 0; i < 10; i++) {
arrayOfWeights[i] = weightValue;
}
}
double sigmoidFunction(void) {
/* generating functional math values using sigmoid function */
for (int i = 0; i < 10; i++) {
/* computing mathematical exponential values */
arrayOfSigmoid[i] = 1 / (1 + exp(-(arrayOfInputs[i] * arrayOfWeights[i] + arrayOfBiasedValues[i])));
}
}
double setComputedValues(void) {
/* initialising generated sigmoid values into the output array */
for (int i = 0; i < 10; i++) {
arrayOfOutputs[i] = arrayOfSigmoid[i];
}
}
void getComputedResults(void) {
cout << "Generated Results> " << endl;
for (int i = 0; i < 10; i++) {
cout << "Computaion >" << arrayOfOutputs[i] << endl;
}
}
};
int main() {
SigmoidNeuronExample sigmoidNeuron;
sigmoidNeuron.generateInputValues();
sigmoidNeuron.generateBiasValues();
sigmoidNeuron.generateWeightValues();
sigmoidNeuron.sigmoidFunction();
sigmoidNeuron.setComputedValues();
sigmoidNeuron.getComputedResults();
return 0;
}