This commit is contained in:
Asrın Doğan 2019-12-14 12:50:57 +03:00
parent dc43ce7a29
commit a2614c61c4
1 changed files with 166 additions and 91 deletions

255
main.cpp
View File

@ -35,10 +35,13 @@ float RandomFloat(int min, int max)
Sinaps::Sinaps() Sinaps::Sinaps()
{ {
weight = value = bias = 0.0; // weight = value = bias = 0.0;
this -> weight = RandomFloat(-1, 1);
this -> value = RandomFloat(-1, 1);
this -> bias = RandomFloat(-1, 1);
std::clog << "Create Sinaps: Weight = " << weight std::clog << "Create Sinaps: Weight = " << weight
<< " Value = " << value << " Value = " << value
<< " Bias = " << bias << "\n"; << " Bias = " << bias << "\n" << "\n";
} }
Sinaps::~Sinaps() Sinaps::~Sinaps()
@ -62,18 +65,18 @@ float RandomFloat(int min, int max)
this -> weight = weight; this -> weight = weight;
this -> value = value; this -> value = value;
this -> bias = bias; this -> bias = bias;
std::clog << "Set Sinaps: Weight = " << weight std::clog << "\n" << "Set Sinaps: Weight = " << weight
<< " Value = " << value << " Value = " << value
<< " Bias = " << bias << "\n"; << " Bias = " << bias << "\n";
} }
void Sinaps::SetWeight(float weight) { std::clog << "Set Sinaps Weight: " << weight << "\n"; this -> weight = weight; } void Sinaps::SetWeight(float weight) { std::clog << "\n" << "Set Sinaps Weight: " << weight << "\n"; this -> weight = weight; }
void Sinaps::SetValue(float value) { std::clog << "Set Sinaps Value: " << value << "\n"; this -> value = value; } void Sinaps::SetValue(float value) { std::clog << "\n" << "Set Sinaps Value: " << value << "\n"; this -> value = value; }
void Sinaps::SetBias(float bias) { std::clog << "Set Sinaps Bias: " << bias << "\n"; this -> bias = bias; } void Sinaps::SetBias(float bias) { std::clog << "\n" << "Set Sinaps Bias: " << bias << "\n"; this -> bias = bias; }
float Sinaps::Fire() float Sinaps::Fire()
{ {
float result = weight * value + bias; float result = weight * value + bias;
std::clog << "Return Sinaps Fire: " << weight << " * " << std::clog << "\n" << "Return Sinaps Fire: " << weight << " * " <<
value << " + " << value << " + " <<
bias << " = " << bias << " = " <<
result << "\n"; result << "\n";
@ -111,7 +114,13 @@ float RandomFloat(int min, int max)
bool Noron::SetForwards(Sinaps *newForwards, int size) bool Noron::SetForwards(Sinaps *newForwards, int size)
{ {
std::clog << "SetForwards: Allocating Memory of Size " << size << "\n"; std::clog << "\n" << "SetForwards: Allocating Memory of Size " << size << " Sinapses" << "\n";
if(forwards)
{
delete forwards;
forwards = NULL;
std::clog << "SetForwards: Old Forwards Has Been Deleted!" << "\n";
}
forwards = (Sinaps *)new char[sizeof(Sinaps) * size]; forwards = (Sinaps *)new char[sizeof(Sinaps) * size];
if(!forwards) if(!forwards)
@ -131,7 +140,14 @@ float RandomFloat(int min, int max)
bool Noron::SetIncoming(Sinaps *newIncoming, int size) bool Noron::SetIncoming(Sinaps *newIncoming, int size)
{ {
std::clog << "SetIncoming: Allocating Memory of Size " << size << "\n"; std::clog << "\n" << "SetIncoming: Allocating Memory of Size " << size << " Sinapses" << "\n";
if(incoming)
{
delete incoming;
incoming = NULL;
std::clog << "SetIncoming: Old Incoming Has Been Deleted!" << "\n";
}
incoming = (Sinaps *)new char[sizeof(Sinaps) * size]; incoming = (Sinaps *)new char[sizeof(Sinaps) * size];
if(!incoming) if(!incoming)
@ -159,7 +175,7 @@ float RandomFloat(int min, int max)
for (int i = 0; i < forwardsCount; i++) for (int i = 0; i < forwardsCount; i++)
(forwards + i) -> SetValue(toplam); (forwards + i) -> SetValue(toplam);
std::clog << "Get Noron Status: Sum = " << toplam << "\n"; std::clog << "\n" << "Get Noron Status: Sum = " << toplam << "\n";
return toplam; return toplam;
} }
#pragma endregion #pragma endregion
@ -197,7 +213,7 @@ float RandomFloat(int min, int max)
if(!CreateNoron(size)) if(!CreateNoron(size))
{ {
std::clog << "Error Create Layer: Neurons Couldn't Created!" << "\n"; std::clog << "Error Create Layer: Neurons Couldn't Created!" << "\n";
std::cout << "Katman Oluşturulamadı!"; std::cout << "Katman Oluşturulamadı!" << "\n";
return; return;
} }
@ -209,10 +225,11 @@ float RandomFloat(int min, int max)
Sinaps *Katman::CreateSinapsSet(int size) Sinaps *Katman::CreateSinapsSet(int size)
{ {
std::clog << "\n" << "CreateSinapsSet: Allocating Memory Size of " << size << " Sinapses" << "\n";
Sinaps* sinapses = new Sinaps[size]; Sinaps* sinapses = new Sinaps[size];
if(sinapses) if(sinapses)
std::clog << "Create Sinaps Set: " << size << " Sinapses Has Been Created!" << "\n"; std::clog << "Create Sinaps Set: Memory Size of " << size << " Sinapses Allocated!" << "\n";
else else
std::clog << "Error Create Sinaps Set!" << "\n"; std::clog << "Error Create Sinaps Set!" << "\n";
@ -223,9 +240,9 @@ float RandomFloat(int min, int max)
if(!forward) if(!forward)
return; return;
float weight; float weight = 0;
float value; float value = 0;
float bias; float bias = 0;
int sinapsCount = size * (forward -> GetSize()); int sinapsCount = size * (forward -> GetSize());
for (int i = 0; i < sinapsCount; i++) for (int i = 0; i < sinapsCount; i++)
@ -235,43 +252,54 @@ float RandomFloat(int min, int max)
bias = RandomFloat(-1, 1); bias = RandomFloat(-1, 1);
(layerSinapses + i) -> SetSinaps(weight, value, bias); (layerSinapses + i) -> SetSinaps(weight, value, bias);
std::clog << "Call RandomizeSinapsValues: SetSinaps Called With Values of SetSinaps(" << weight << ", " << value << ", " << bias << ")" << "\n"; std::clog << "RandomizeSinapsValues: SetSinaps d With Values of SetSinaps(" << weight << ", " << value << ", " << bias << ")" << "\n";
} }
} }
void Katman::FireLayer() void Katman::FireLayer()
{ {
std::clog << "Call FireLayer: Number of " << size << " Neurons' GetStatus is Being Called!" << "\n"; std::clog << "\n" << "FireLayer: Number of " << size << " Neurons' GetStatus is Being Called!" << "\n";
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
std::clog << i << ". Neuron Status: " << (neurons + i) -> GetStatus() << "\n"; std::clog << i << ". Neuron Status: " << (neurons + i) -> GetStatus() << "\n";
} }
bool Katman::SetForward(Katman *forward) bool Katman::SetForward(Katman *forward)
{ {
std::clog << "\n" << "SetForward: Called!" << "\n";
Sinaps *sinapses = NULL; // Pointer to store all created sinapses Sinaps *sinapses = NULL; // Pointer to store all created sinapses
Sinaps *newSinapses = NULL; // Temporary Pointer for creating each neurons' s1inapses Sinaps *newSinapses = NULL; // Temporary Pointer for creating each neurons' s1inapses
int forwardSize; int forwardSize = 0;
int sinapsesIndex = 0; if(layerSinapses)
delete layerSinapses; {
delete layerSinapses;
layerSinapses = NULL;
std::clog << "SetForward: Old layerSinapses Has Been Deleted!" << "\n";
}
this -> forward = forward; this -> forward = forward;
if(!forward) if(!forward)
{ {
std::clog << "Call SetForward: Forward is NULL" << "\n"; std::clog << "SetForward: Forward is NULL" << "\n";
return true; return true;
} }
forwardSize = forward -> GetSize(); forwardSize = forward -> GetSize();
std::clog << "Call SetForward: Creating Sinaps Set with Number of " << (size * forwardSize) << "\n"; std::clog << "SetForward: Creating Sinaps Set with Number of " << (size * forwardSize) << "\n";
if(sinapses)
{
delete sinapses;
sinapses = NULL;
std::clog << "SetForward: Old Sinapses Has Been Deleted!" << "\n";
}
sinapses = (Sinaps *)new char[sizeof(Sinaps) * size * forwardSize]; sinapses = (Sinaps *)new char[sizeof(Sinaps) * size * forwardSize];
if(!sinapses) if(!sinapses)
{ {
std::clog << "Error Call SetForward: Couldn't Allocate Memory for Sinapses!" << "\n"; std::clog << "Error SetForward: Couldn't Allocate Memory for Sinapses!" << "\n";
return false; return false;
} }
std::clog << "Call SetForward: Sinapses Set Created!" << "\n"; std::clog << "SetForward: SinapsSet Created!" << "\n";
// Set Forwards of each neuron in the Layer // Set Forwards of each neuron in the Layer
for (int thisCounter = 0; thisCounter < size; thisCounter++) for (int thisCounter = 0; thisCounter < size; thisCounter++)
@ -280,23 +308,24 @@ float RandomFloat(int min, int max)
if(!newSinapses) if(!newSinapses)
{ {
std::clog << "Call SetForward -> CreateSinapsSet: Couldn't Allocate Memory for Sinapses!" << "\n"; std::clog << "SetForward -> CreateSinapsSet: Couldn't Allocate Memory for Sinapses!" << "\n";
return false; return false;
} }
std::clog << "Call SetForward -> CreateSinapsSet: Sinapses Set Created!" << "\n"; std::clog << "SetForward -> CreateSinapsSet: SinapsSet Created!" << "\n";
std::clog << "Call SetForward -> SetForwards: " << std::clog << "SetForward -> SetForwards: " <<
(neurons + thisCounter) -> SetForwards(newSinapses, forwardSize) (neurons + thisCounter) -> SetForwards(newSinapses, forwardSize)
<< "\n";; << "\n";;
// Add each sinaps to the array // Add each sinaps to the array
for (int forwardCounter = 0; forwardCounter < forwardSize; forwardCounter++) for (int forwardCounter = 0; forwardCounter < forwardSize; forwardCounter++)
*(sinapses + (sinapsesIndex++)) = *(newSinapses + forwardCounter); *(sinapses + forwardCounter) = *(newSinapses + forwardCounter);
std::clog << "Call SetForward: Sinapses Are Added to the Array!" << "\n"; std::clog << "SetForward: Sinapses Are Added to the Array!" << "\n";
} }
layerSinapses = sinapses; layerSinapses = sinapses;
std::clog << "Call SetForward: Sinaps Array Has Been Set to the Class' Pointer!" << "\n"; std::clog << "SetForward: Sinaps Array Has Been Set to the Class' Pointer!" << "\n";
// Send the sinapses to the forward layer // Send the sinapses to the forward layer
return forward -> SetIncoming(sinapses, size); return forward -> SetIncoming(sinapses, size);
} }
@ -305,24 +334,30 @@ float RandomFloat(int min, int max)
{ {
Sinaps *sinapses = NULL; Sinaps *sinapses = NULL;
std::clog << "Call SetIncoming: Creating Sinaps Set with Number of " << backwardsNeuronCount << "\n"; std::clog << "\n" << "SetIncoming: Creating Sinaps Set with Number of " << backwardsNeuronCount << "\n";
if(sinapses)
{
delete sinapses;
sinapses = NULL;
std::clog << "SetIncoming: Old Sinapses Has Been Deleted!" << "\n";
}
sinapses = (Sinaps *)new char[sizeof(Sinaps) * backwardsNeuronCount]; sinapses = (Sinaps *)new char[sizeof(Sinaps) * backwardsNeuronCount];
if(!sinapses) if(!sinapses)
{ {
std::clog << "Error Call SetIncoming: Couldn't Allocate Memory for Sinapses!" << "\n"; std::clog << "Error SetIncoming: Couldn't Allocate Memory for Sinapses!" << "\n";
return false; return false;
} }
std::clog << "Call SetIncoming: Sinapses Set Created!" << "\n"; std::clog << "SetIncoming: SinapsSet Created!" << "\n";
for (int thisCounter = 0; thisCounter < size; thisCounter++) for (int thisCounter = 0; thisCounter < size; thisCounter++)
{ {
std::clog << "Call SetIncoming: Sinapses Are Being Added to the Array!" << "\n"; std::clog << "SetIncoming: Sinapses Are Being Added to the Array!" << "\n";
// Add each sinaps to the array // Add each sinaps to the array
for (int incomingCounter = 0; incomingCounter < backwardsNeuronCount; incomingCounter++) for (int incomingCounter = 0; incomingCounter < backwardsNeuronCount; incomingCounter++)
*(sinapses + (size * thisCounter + incomingCounter)) = *(sinapsSet + incomingCounter); *(sinapses + incomingCounter) = *(sinapsSet + (size * thisCounter + incomingCounter));
std::clog << "Call SetIncoming -> Neuron SetIncoming: " << std::clog << "SetIncoming -> Neuron SetIncoming: " <<
(neurons + thisCounter) -> SetIncoming(sinapses, backwardsNeuronCount) (neurons + thisCounter) -> SetIncoming(sinapses, backwardsNeuronCount)
<< "\n"; << "\n";
} }
@ -332,39 +367,50 @@ float RandomFloat(int min, int max)
bool Katman::SetNoron(Noron *newNeurons, int size) bool Katman::SetNoron(Noron *newNeurons, int size)
{ {
std::clog << "Call SetNoron: Creating Neurons with Number of " << size << "\n"; std::clog << "\n" << "SetNoron: Creating Neurons with Number of " << size << "\n";
if(neurons)
{
delete neurons;
neurons = NULL;
std::clog << "SetNoron: Old Neurons Has Been Deleted!" << "\n";
}
neurons = (Noron *) new char[sizeof(Noron) * size]; neurons = (Noron *) new char[sizeof(Noron) * size];
if(!neurons) if(!neurons)
{ {
std::clog << "Error Call SetNoron: Creating Neurons Failed!" << "\n"; std::clog << "Error SetNoron: Creating Neurons Failed!" << "\n";
return false; return false;
} }
std::clog << "Call SetNoron: Neurons Created Successfully!" << "\n"; std::clog << "SetNoron: Neurons Created Successfully!" << "\n";
std::clog << "Call SetNoron: Setting Neurons to the Class' Neurons!" << "\n"; std::clog << "SetNoron: Setting Neurons to the Class' Neurons!" << "\n";
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
*(neurons+i) = *(newNeurons+i); *(neurons+i) = *(newNeurons+i);
std::clog << "Call SetNoron: Neurons are Set Successfully!" << "\n"; std::clog << "SetNoron: Neurons are Set Successfully!" << "\n";
this -> size = size; this -> size = size;
return true; return true;
} }
bool Katman::CreateNoron(int size) bool Katman::CreateNoron(int size)
{ {
std::clog << "Call CreateNoron: Creating Neurons with Number of " << size << "\n"; std::clog << "\n" << "CreateNoron: Creating Neurons with Number of " << size << "\n";
if(neurons)
{
delete neurons;
neurons = NULL;
std::clog << "CreateNoron: Old Neurons Has Been Deleted!" << "\n";
}
neurons = new Noron[size]; neurons = new Noron[size];
if(!neurons) if(!neurons)
{ {
std::clog << "Error Call CreateNoron: Creating Neurons Failed!" << "\n"; std::clog << "Error CreateNoron: Creating Neurons Failed!" << "\n";
return false; return false;
} }
std::clog << "Call CreateNoron: Neurons Created Successfully!" << "\n"; std::clog << "CreateNoron: Neurons Created Successfully!" << "\n";
std::clog << "Call CreateNoron: Neurons are Set Successfully!" << "\n"; std::clog << "CreateNoron: Neurons are Set Successfully!" << "\n";
this -> size = size; this -> size = size;
return true; return true;
} }
@ -381,23 +427,23 @@ float RandomFloat(int min, int max)
void SetValue(int, float); void SetValue(int, float);
}; };
Girdi::Girdi() : Katman() {} Girdi::Girdi() : Katman(1) { std::clog << "\n" << "Create Input Layer: Called!" << "\n"; }
Girdi::Girdi(int size) : Katman(size) {} Girdi::Girdi(int size) : Katman(size) {}
void Girdi::SetValue(int index, float value) void Girdi::SetValue(int index, float value)
{ {
Sinaps *editedSinaps = NULL; Sinaps *editedSinaps = NULL;
int forwardNeuronCount = forward -> GetSize(); int forwardNeuronCount = forward -> GetSize();
std::clog << "Call SetValue: Index of " << index << " Neuron's Sinapses Values are Getting Set to Value of " << value << "\n"; std::clog << "\n" << "SetValue: Index of " << index << " Neuron's Sinapses Values are Getting Set to Value of " << value << "\n";
for (int i = 0; i < forwardNeuronCount; i++) for (int i = 0; i < forwardNeuronCount; i++)
{ {
std::clog << "Call SetValue -> Sinaps SetValue: Index of " << index << " Neuron's " << i << " Sinaps Value is Getting Set to Value of " << value << "\n"; std::clog << "SetValue -> Sinaps SetValue: Index of " << index << " Neuron's " << i << " Sinaps Value is Getting Set to Value of " << value << "\n";
editedSinaps = (layerSinapses + index * forwardNeuronCount + i); editedSinaps = (layerSinapses + index * forwardNeuronCount + i);
editedSinaps -> SetValue(value); editedSinaps -> SetValue(value);
std::clog << "Call SetValue -> Sinaps SetValue: Successfull" << "\n"; std::clog << "SetValue -> Sinaps SetValue: Successfull" << "\n";
} }
std::clog << "Call SetValue: Successfull" << "\n"; std::clog << "SetValue: Successfull" << "\n";
} }
#pragma endregion #pragma endregion
#pragma region Cikti #pragma region Cikti
@ -409,13 +455,14 @@ float RandomFloat(int min, int max)
float GetValue(int); float GetValue(int);
}; };
Cikti::Cikti() : Katman() {} Cikti::Cikti() : Katman(1) { std::clog << "\n" << "Create Output Layer: Called!" << "\n"; }
Cikti::Cikti(int size) : Katman(size) {} Cikti::Cikti(int size) : Katman(size) {}
float Cikti::GetValue(int index) float Cikti::GetValue(int index)
{ {
std::clog << "\n" << "Call GetValue!" << "\n";
float result = (neurons + index) -> GetStatus(); float result = (neurons + index) -> GetStatus();
std::clog << "Call GetValue: " << result << "\n"; std::clog << "GetValue: " << result << "\n";
return result; return result;
} }
#pragma endregion #pragma endregion
@ -444,7 +491,7 @@ float RandomFloat(int min, int max)
NeuralNetwork::NeuralNetwork() NeuralNetwork::NeuralNetwork()
{ {
std::clog << "Create NeuralNetwork: NULL" << "\n"; std::clog << "\n" << "Create NeuralNetwork: NULL" << "\n";
hiddenSize = 0; hiddenSize = 0;
input = NULL; input = NULL;
hiddenLayers = NULL; hiddenLayers = NULL;
@ -453,10 +500,11 @@ float RandomFloat(int min, int max)
NeuralNetwork::NeuralNetwork(int hiddenSize) NeuralNetwork::NeuralNetwork(int hiddenSize)
{ {
std::clog << "\n" << "Create NeuralNetwork: Called" << "\n";
input = new Girdi(); input = new Girdi();
hiddenLayers = new Katman[hiddenSize]; hiddenLayers = new Katman[hiddenSize];
output = new Cikti(); output = new Cikti();
std::clog << "Create NeuralNetwork: New Neural Network Created with " << hiddenSize << " Layers!" << "\n"; std::clog << "\n" << "Create NeuralNetwork: New Neural Network Created with " << hiddenSize << " Layers!" << "\n";
if(!input) if(!input)
{ {
@ -490,75 +538,89 @@ float RandomFloat(int min, int max)
bool NeuralNetwork::SetHiddenLayerNeurons(int index, int size) bool NeuralNetwork::SetHiddenLayerNeurons(int index, int size)
{ {
std::clog << "Call SetHiddenLayerNeurons: Size of " << size << " at Index of " << index << "\n"; bool result;
std::clog << "Call SetHiddenLayerNeurons: Creating " << size << " Neurons!" << "\n"; std::clog << "\n" << "SetHiddenLayerNeurons: Size of " << size << " at Index of " << index << "\n";
std::clog << "SetHiddenLayerNeurons: Allocating Memory Size of " << size << " Neurons!" << "\n";
Noron *neurons = (Noron *) new char[sizeof(Noron) * size]; Noron *neurons = (Noron *) new char[sizeof(Noron) * size];
if(!neurons) if(!neurons)
{ {
std::clog << "Error Call SetHiddenLayerNeurons: Couldn't Allocate Memory for Neurons!" << "\n"; std::clog << "Error SetHiddenLayerNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
return false; return false;
} }
std::clog << "Call SetHiddenLayerNeurons: Neurons Are Created!" << "\n"; std::clog << "SetHiddenLayerNeurons: Memory Allocated!" << "\n";
std::clog << "SetHiddenLayerNeurons -> CreateNoron: Called!" << "\n";
return (hiddenLayers + index) -> SetNoron(neurons, size); result = (hiddenLayers + index) -> CreateNoron(size);
std::clog << "SetHiddenLayerNeurons -> CreateNoron: " << result << "\n";
// if(result)
// return (hiddenLayers + index) -> SetNoron(neurons, size);
return result;
} }
bool NeuralNetwork::SetInputNeurons(int size) bool NeuralNetwork::SetInputNeurons(int size)
{ {
std::clog << "Call SetInputNeurons: Size of " << size << "\n"; bool result;
std::clog << "Call SetInputNeurons: Creating " << size << " Neurons!" << "\n"; std::clog << "\n" << "SetInputNeurons: Size of " << size << "\n";
std::clog << "SetInputNeurons: Allocating Memory Size of " << size << " Neurons!" << "\n";
Noron *neurons = (Noron *) new char[sizeof(Noron) * size]; Noron *neurons = (Noron *) new char[sizeof(Noron) * size];
if(!neurons) if(!neurons)
{ {
std::clog << "Error Call SetInputNeurons: Couldn't Allocate Memory for Neurons!" << "\n"; std::clog << "Error SetInputNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
return false; return false;
} }
std::clog << "Call SetInputNeurons: Neurons Are Created!" << "\n"; std::clog << "SetInputNeurons: Memory Allocated!" << "\n";
std::clog << "SetInputNeurons -> CreateNoron: Called!" << "\n";
return output -> SetNoron(neurons, size); result = input -> CreateNoron(size);
std::clog << "SetInputNeurons -> CreateNoron: " << result << "\n";
// return output -> SetNoron(neurons, size);
return result;
} }
bool NeuralNetwork::SetOutputNeurons(int size) bool NeuralNetwork::SetOutputNeurons(int size)
{ {
std::clog << "Call SetInputNeurons: Size of " << size << "\n"; bool result;
std::clog << "Call SetInputNeurons: Creating " << size << " Neurons!" << "\n"; std::clog << "\n" << "SetOutputNeurons: Size of " << size << "\n";
std::clog << "SetOutputNeurons: Allocating Memory Size of " << size << " Neurons!" << "\n";
Noron *neurons = (Noron *) new char[sizeof(Noron) * size]; Noron *neurons = (Noron *) new char[sizeof(Noron) * size];
if(!neurons) if(!neurons)
{ {
std::clog << "Error Call SetInputNeurons: Couldn't Allocate Memory for Neurons!" << "\n"; std::clog << "Error SetOutputNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
return false; return false;
} }
std::clog << "Call SetInputNeurons: Neurons Are Created!" << "\n"; std::clog << "SetOutputNeurons: Memory Allocated!" << "\n";
return input -> SetNoron(neurons, size); std::clog << "SetOutputNeurons -> CreateNoron: Called!" << "\n";
result = input -> CreateNoron(size);
std::clog << "SetOutputNeurons -> CreateNoron: " << result << "\n";
// return input -> SetNoron(neurons, size);
return result;
} }
bool NeuralNetwork::ConnectLayers() bool NeuralNetwork::ConnectLayers()
{ {
if(!input -> SetForward(hiddenLayers)) if(!input -> SetForward(hiddenLayers))
{ {
std::clog << "Call ConnectLayers: Input Couldn't Set to Forward!" << "\n"; std::clog << "\n" << "ConnectLayers: Input Couldn't Set to Forward!" << "\n";
return false; return false;
} }
std::clog << "Call ConnectLayers: Input is Set to Forward Successfully!" << "\n"; std::clog << "\n" << "ConnectLayers: Input is Set to Forward Successfully!" << "\n";
for (int i = 0; i < hiddenSize - 1; i++) for (int i = 0; i < hiddenSize - 1; i++)
if(!(hiddenLayers + i) -> SetForward(hiddenLayers + i + 1)) if(!(hiddenLayers + i) -> SetForward(hiddenLayers + i + 1))
{ {
std::clog << "Call ConnectLayers: Hidden Layer " << i << " Couldn't Set to Forward!" << "\n"; std::clog << "ConnectLayers: Hidden Layer " << i << " Couldn't Set to Forward!" << "\n";
return false; return false;
} }
std::clog << "Call ConnectLayers: Hidden Layers are Set to Forward Successfully!" << "\n"; std::clog << "ConnectLayers: Hidden Layers are Set to Forward Successfully!" << "\n";
if(!(hiddenLayers + hiddenSize - 1) -> SetForward(output)) if(!(hiddenLayers + hiddenSize - 1) -> SetForward(output))
{ {
std::clog << "Call ConnectLayers: Output Couldn't Set to Forward!" << "\n"; std::clog << "ConnectLayers: Output Couldn't Set to Forward!" << "\n";
return false; return false;
} }
std::clog << "Call ConnectLayers: Output is Set to Forward Successfully!" << "\n"; std::clog << "ConnectLayers: Output is Set to Forward Successfully!" << "\n";
return output -> SetForward(NULL); return output -> SetForward(NULL);
} }
@ -566,54 +628,56 @@ float RandomFloat(int min, int max)
void NeuralNetwork::FireNetwork() void NeuralNetwork::FireNetwork()
{ {
// input -> FireLayer(); // input -> FireLayer();
// std::clog << "Call FireNetwork: Input Fired!" << "\n"; // std::clog << "\n" << "FireNetwork: Input Fired!" << "\n";
for (int i = 0; i < hiddenSize; i++) for (int i = 0; i < hiddenSize; i++)
{ {
(hiddenLayers + i) -> FireLayer(); (hiddenLayers + i) -> FireLayer();
std::clog << "Call FireNetwork: Hidden Layer " << i << " Fired!" << "\n"; std::clog << "FireNetwork: Hidden Layer " << i << " Fired!" << "\n";
} }
output -> FireLayer(); output -> FireLayer();
std::clog << "Call FireNetwork: Output Fired!" << "\n"; std::clog << "FireNetwork: Output Fired!" << "\n";
} }
void NeuralNetwork::SetInput(int index, float value) void NeuralNetwork::SetInput(int index, float value)
{ {
if(!input) if(!input)
{ {
std::clog << "Call SetInput: There's no Input Layer Set!" << "\n"; std::clog << "\n" << "SetInput: There's no Input Layer Set!" << "\n";
return; return;
} }
std::clog << "Call SetInput -> Input SetValue: SetValue(" << index << ", " << value << ")!" << "\n"; std::clog << "\n" << "SetInput -> Input SetValue: SetValue(" << index << ", " << value << ")!" << "\n";
input -> SetValue(index, value); input -> SetValue(index, value);
} }
void NeuralNetwork::RandomizeNetworkValues() void NeuralNetwork::RandomizeNetworkValues()
{ {
std::clog << "Call RandomizeNetworkValues: Input Sinapses Are Getting Randomized!" << "\n"; std::clog << "\n" << "RandomizeNetworkValues: Input Sinapses Are Getting Randomized!" << "\n";
input -> RandomizeSinapsValues(); input -> RandomizeSinapsValues();
for (int i = 0; i < hiddenSize; i++) for (int i = 0; i < hiddenSize; i++)
{ {
std::clog << "Call RandomizeNetworkValues: Hidden Layer " << i << " Sinapses Are Getting Randomized!" << "\n"; std::clog << "RandomizeNetworkValues: Hidden Layer " << i << " Sinapses Are Getting Randomized!" << "\n";
(hiddenLayers + i) -> RandomizeSinapsValues(); (hiddenLayers + i) -> RandomizeSinapsValues();
} }
std::clog << "Call RandomizeNetworkValues: Output Sinapses Are Getting Randomized!" << "\n"; std::clog << "RandomizeNetworkValues: Output Sinapses Are Getting Randomized!" << "\n";
output -> RandomizeSinapsValues(); output -> RandomizeSinapsValues();
} }
float NeuralNetwork::GetOutputValue(int index) float NeuralNetwork::GetOutputValue(int index)
{ {
float result = output -> GetValue(index); float result = output -> GetValue(index);
std::clog << "Call GetOutputValue: " << result << "\n"; std::clog << "\n" << "GetOutputValue: " << result << "\n";
return result; return result;
} }
#pragma endregion #pragma endregion
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
float result;
FILE *file;
NeuralNetwork network(3); NeuralNetwork network(3);
network.SetInputNeurons(1); network.SetInputNeurons(1);
@ -627,10 +691,21 @@ int main(int argc, char const *argv[])
network.RandomizeNetworkValues(); network.RandomizeNetworkValues();
std::cout << "m2\n"; std::cout << "m2\n";
// network.SetInput(0, 1); network.SetInput(0, 1);
std::cout << "m3\n"; std::cout << "m3\n";
// network.FireNetwork(); network.FireNetwork();
// std::cout << network.GetOutputValue(0) << "\n"; result = network.GetOutputValue(0);
std::cout << "Output is " << result << "\n";
file = fopen("result.txt", "w");
fprintf(file, "%f", result);
fclose(file);
// std::cout << "Sinaps = " << sizeof(Sinaps) * 30 << "\n";
// std::cout << "Noron = " << sizeof(Noron) * 9 << "\n";
// std::cout << "Katman = " << sizeof(Katman) * 3 << "\n";
// std::cout << "Girdi = " << sizeof(Girdi) * 1 << "\n";
// std::cout << "Cikti = " << sizeof(Cikti) * 1 << "\n";
// std::cout << "NeuralNetwork = " << sizeof(NeuralNetwork) * 1 << "\n";
return 0; return 0;
} }