Clog
This commit is contained in:
parent
9f64919676
commit
70675843c3
|
@ -0,0 +1,2 @@
|
||||||
|
*.exe
|
||||||
|
*.txt
|
|
@ -0,0 +1,38 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"iostream": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"initializer_list": "cpp",
|
||||||
|
"ios": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"xfacet": "cpp",
|
||||||
|
"xiosbase": "cpp",
|
||||||
|
"xlocale": "cpp",
|
||||||
|
"xlocinfo": "cpp",
|
||||||
|
"xlocnum": "cpp",
|
||||||
|
"xmemory": "cpp",
|
||||||
|
"xmemory0": "cpp",
|
||||||
|
"xstddef": "cpp",
|
||||||
|
"xstring": "cpp",
|
||||||
|
"xtr1common": "cpp",
|
||||||
|
"xutility": "cpp"
|
||||||
|
}
|
||||||
|
}
|
252
main.cpp
252
main.cpp
|
@ -5,10 +5,14 @@
|
||||||
|
|
||||||
float RandomFloat(int min, int max)
|
float RandomFloat(int min, int max)
|
||||||
{
|
{
|
||||||
|
float result;
|
||||||
|
int value;
|
||||||
static unsigned long int counter = 0;
|
static unsigned long int counter = 0;
|
||||||
srand(time(0) + counter++ * 50);
|
srand(time(0) + counter++ * 50);
|
||||||
int value = (rand() % ((max - min) * 100));
|
value = (rand() % ((max - min) * 100));
|
||||||
return (float)value / 100.0 + (float)min + 1.0;
|
result = (float)value / 100.0 + (float)min;
|
||||||
|
std::clog << "Function RandomFloat: Between " << min << " and " << max << " returned value is " << result << "\n";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma region Sinaps
|
#pragma region Sinaps
|
||||||
|
@ -20,6 +24,7 @@ float RandomFloat(int min, int max)
|
||||||
float bias; // Öteleme
|
float bias; // Öteleme
|
||||||
public:
|
public:
|
||||||
Sinaps();
|
Sinaps();
|
||||||
|
~Sinaps();
|
||||||
Sinaps(float, float, float); // Kaydedilen değerleri yeniden yazabilmek için
|
Sinaps(float, float, float); // Kaydedilen değerleri yeniden yazabilmek için
|
||||||
void SetSinaps(float, float, float); // Sonradan tamamen değiştirebilmek için
|
void SetSinaps(float, float, float); // Sonradan tamamen değiştirebilmek için
|
||||||
void SetWeight(float);
|
void SetWeight(float);
|
||||||
|
@ -29,23 +34,44 @@ float RandomFloat(int min, int max)
|
||||||
};
|
};
|
||||||
|
|
||||||
Sinaps::Sinaps() { weight = value = bias = 0.0; }
|
Sinaps::Sinaps() { weight = value = bias = 0.0; }
|
||||||
|
Sinaps::~Sinaps()
|
||||||
|
{
|
||||||
|
std::clog << "Delete Sinaps: Weight = " << weight
|
||||||
|
<< " Value = " << value
|
||||||
|
<< " Bias = " << bias << "\n";
|
||||||
|
}
|
||||||
Sinaps::Sinaps(float weight, float value, float bias)
|
Sinaps::Sinaps(float weight, float value, float bias)
|
||||||
{
|
{
|
||||||
this -> weight = weight;
|
this -> weight = weight;
|
||||||
this -> value = value;
|
this -> value = value;
|
||||||
this -> bias = bias;
|
this -> bias = bias;
|
||||||
|
std::clog << "Create Sinaps: Weight = " << weight
|
||||||
|
<< " Value = " << value
|
||||||
|
<< " Bias = " << bias << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sinaps::SetSinaps(float weight, float value, float bias) {
|
void Sinaps::SetSinaps(float weight, float value, float bias)
|
||||||
std::cout << "weight = " << weight << "\n";
|
{
|
||||||
std::cout << "value = " << value << "\n";
|
this -> weight = weight;
|
||||||
std::cout << "bias = " << bias << "\n";
|
this -> value = value;
|
||||||
Sinaps(weight, value, bias); }
|
this -> bias = bias;
|
||||||
void Sinaps::SetWeight(float weight) { this -> weight = weight; }
|
std::clog << "Set Sinaps: Weight = " << weight
|
||||||
void Sinaps::SetValue(float value) { std::cout << value << "\n"; this -> value = value; }
|
<< " Value = " << value
|
||||||
void Sinaps::SetBias(float bias) { this -> bias = bias; }
|
<< " Bias = " << bias << "\n";
|
||||||
|
}
|
||||||
|
void Sinaps::SetWeight(float weight) { std::clog << "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::SetBias(float bias) { std::clog << "Set Sinaps Bias: " << bias << "\n"; this -> bias = bias; }
|
||||||
|
|
||||||
float Sinaps::Fire() { return weight * value + bias; }
|
float Sinaps::Fire()
|
||||||
|
{
|
||||||
|
float result = weight * value + bias;
|
||||||
|
std::clog << "Return Sinaps Fire: " << weight << " * " <<
|
||||||
|
value << " + " <<
|
||||||
|
bias << " = " <<
|
||||||
|
result << "\n";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
#pragma region Noron
|
#pragma region Noron
|
||||||
class Noron
|
class Noron
|
||||||
|
@ -67,6 +93,7 @@ float RandomFloat(int min, int max)
|
||||||
{
|
{
|
||||||
forwards = incoming = NULL;
|
forwards = incoming = NULL;
|
||||||
forwardsCount = incomingCount = 0;
|
forwardsCount = incomingCount = 0;
|
||||||
|
std::clog << "Create Noron: NULL" << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
Noron::~Noron()
|
Noron::~Noron()
|
||||||
|
@ -77,40 +104,51 @@ float RandomFloat(int min, int max)
|
||||||
|
|
||||||
bool Noron::SetForwards(Sinaps *newForwards, int size)
|
bool Noron::SetForwards(Sinaps *newForwards, int size)
|
||||||
{
|
{
|
||||||
forwards = (Sinaps *) new char[sizeof(Sinaps) * size];
|
forwards = new Sinaps[size];
|
||||||
|
|
||||||
if(!forwards) return false;
|
if(!forwards)
|
||||||
|
{
|
||||||
|
std::clog << "Set Forwards: Memory Couldn't Allocated!" << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
*(forwards+i) = *(newForwards+i);
|
*(forwards+i) = *(newForwards+i);
|
||||||
|
|
||||||
forwardsCount = size;
|
forwardsCount = size;
|
||||||
|
std::clog << "Set Forwards: Successfull!" << "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Noron::SetIncoming(Sinaps *newIncoming, int size)
|
bool Noron::SetIncoming(Sinaps *newIncoming, int size)
|
||||||
{
|
{
|
||||||
incoming = (Sinaps *) new char[sizeof(Sinaps) * size];
|
incoming = new Sinaps[size];
|
||||||
|
|
||||||
if(!incoming) return false;
|
if(!incoming)
|
||||||
|
{
|
||||||
|
std::clog << "Set Incoming: Memory Couldn't Allocated!" << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
*(incoming+i) = *(newIncoming+i);
|
*(incoming+i) = *(newIncoming+i);
|
||||||
|
|
||||||
incomingCount = size;
|
incomingCount = size;
|
||||||
|
std::clog << "Set Incoming: Successfull!" << "\n";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Noron::GetStatus()
|
float Noron::GetStatus()
|
||||||
{
|
{
|
||||||
float toplam = 0.0;
|
float toplam = 0.0;
|
||||||
std::cout << toplam << "\n";
|
|
||||||
for (int i = 0; i < incomingCount; i++)
|
for (int i = 0; i < incomingCount; i++)
|
||||||
toplam += (incoming + i) -> Fire();
|
toplam += (incoming + i) -> Fire();
|
||||||
|
|
||||||
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";
|
||||||
return toplam;
|
return toplam;
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
@ -136,14 +174,23 @@ float RandomFloat(int min, int max)
|
||||||
int GetSize();
|
int GetSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
Katman::Katman() { neurons = NULL; this -> size = 0; }
|
Katman::Katman()
|
||||||
|
{
|
||||||
|
neurons = NULL; this -> size = 0;
|
||||||
|
std::clog << "Create Layer: NULL" << "\n";
|
||||||
|
}
|
||||||
Katman::Katman(int size)
|
Katman::Katman(int size)
|
||||||
{
|
{
|
||||||
Katman();
|
Katman();
|
||||||
|
|
||||||
if(!CreateNoron(size))
|
if(!CreateNoron(size))
|
||||||
|
{
|
||||||
|
std::clog << "Error Create Layer: Neurons Couldn't Created!" << "\n";
|
||||||
std::cout << "Katman Oluşturulamadı!";
|
std::cout << "Katman Oluşturulamadı!";
|
||||||
else
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::clog << "Create Layer: " << size << " Neurons Has Been Created!" << "\n";
|
||||||
this -> size = size;
|
this -> size = size;
|
||||||
}
|
}
|
||||||
Katman::~Katman() { delete neurons; }
|
Katman::~Katman() { delete neurons; }
|
||||||
|
@ -151,11 +198,12 @@ float RandomFloat(int min, int max)
|
||||||
|
|
||||||
Sinaps *Katman::CreateSinapsSet(int size)
|
Sinaps *Katman::CreateSinapsSet(int size)
|
||||||
{
|
{
|
||||||
Sinaps* sinapses = (Sinaps *) new char[sizeof(Sinaps) * size];
|
Sinaps* sinapses = new Sinaps[size];
|
||||||
|
|
||||||
if(sinapses)
|
if(sinapses)
|
||||||
for (int i = 0; i < size; i++)
|
std::clog << "Create Sinaps Set: " << size << " Sinapses Has Been Created!" << "\n";
|
||||||
*(sinapses + i) = Sinaps();
|
else
|
||||||
|
std::clog << "Error Create Sinaps Set!" << "\n";
|
||||||
|
|
||||||
return sinapses;
|
return sinapses;
|
||||||
}
|
}
|
||||||
|
@ -164,21 +212,27 @@ float RandomFloat(int min, int max)
|
||||||
if(!forward)
|
if(!forward)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
float weight;
|
||||||
|
float value;
|
||||||
|
float bias;
|
||||||
|
|
||||||
int sinapsCount = size * (forward -> GetSize());
|
int sinapsCount = size * (forward -> GetSize());
|
||||||
for (int i = 0; i < sinapsCount; i++)
|
for (int i = 0; i < sinapsCount; i++)
|
||||||
{
|
{
|
||||||
(layerSinapses + i) -> SetSinaps(
|
weight = RandomFloat(-1, 1);
|
||||||
RandomFloat(-5, 5),
|
value = RandomFloat(-1, 1);
|
||||||
RandomFloat(-5, 5),
|
bias = RandomFloat(-1, 1);
|
||||||
RandomFloat(-5, 5)
|
|
||||||
);
|
(layerSinapses + i) -> SetSinaps(weight, value, bias);
|
||||||
|
std::clog << "Call RandomizeSinapsValues: SetSinaps Called 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";
|
||||||
for (int i = 0; i < size; i++)
|
for (int i = 0; i < size; i++)
|
||||||
std::cout << i << ". Fire = " << (neurons + i) -> GetStatus() << "\n";
|
std::clog << i << ". Neuron Status: " << (neurons + i) -> GetStatus() << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Katman::SetForward(Katman *forward)
|
bool Katman::SetForward(Katman *forward)
|
||||||
|
@ -192,14 +246,21 @@ float RandomFloat(int min, int max)
|
||||||
this -> forward = forward;
|
this -> forward = forward;
|
||||||
|
|
||||||
if(!forward)
|
if(!forward)
|
||||||
|
{
|
||||||
|
std::clog << "Call 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";
|
||||||
sinapses = (Sinaps *) new char[sizeof(Sinaps) * size * forwardSize];
|
sinapses = new Sinaps[size * forwardSize];
|
||||||
|
|
||||||
if(!sinapses)
|
if(!sinapses)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetForward: Couldn't Allocate Memory for Sinapses!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetForward: Sinapses Set 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++)
|
||||||
|
@ -207,16 +268,24 @@ float RandomFloat(int min, int max)
|
||||||
newSinapses = CreateSinapsSet(forwardSize);
|
newSinapses = CreateSinapsSet(forwardSize);
|
||||||
|
|
||||||
if(!newSinapses)
|
if(!newSinapses)
|
||||||
|
{
|
||||||
|
std::clog << "Call SetForward -> CreateSinapsSet: Couldn't Allocate Memory for Sinapses!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetForward -> CreateSinapsSet: Sinapses Set Created!" << "\n";
|
||||||
|
|
||||||
(neurons + thisCounter) -> SetForwards(newSinapses, forwardSize);
|
std::clog << "Call SetForward -> SetForwards: " <<
|
||||||
|
(neurons + thisCounter) -> SetForwards(newSinapses, forwardSize)
|
||||||
|
<< "\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 + (sinapsesIndex++)) = *(newSinapses + forwardCounter);
|
||||||
|
std::clog << "Call 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";
|
||||||
// Send the sinapses to the forward layer
|
// Send the sinapses to the forward layer
|
||||||
return forward -> SetIncoming(sinapses, size);
|
return forward -> SetIncoming(sinapses, size);
|
||||||
}
|
}
|
||||||
|
@ -225,45 +294,66 @@ float RandomFloat(int min, int max)
|
||||||
{
|
{
|
||||||
Sinaps *sinapses = NULL;
|
Sinaps *sinapses = NULL;
|
||||||
|
|
||||||
sinapses = (Sinaps *) new char[sizeof(Sinaps) * backwardsNeuronCount];
|
std::clog << "Call SetIncoming: Creating Sinaps Set with Number of " << backwardsNeuronCount << "\n";
|
||||||
|
sinapses = new Sinaps[backwardsNeuronCount];
|
||||||
|
|
||||||
if(!sinapses)
|
if(!sinapses)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetIncoming: Couldn't Allocate Memory for Sinapses!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetIncoming: Sinapses Set 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";
|
||||||
// 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 + (size * thisCounter + incomingCounter)) = *(sinapsSet + incomingCounter);
|
||||||
|
|
||||||
(neurons + thisCounter) -> SetIncoming(sinapses, backwardsNeuronCount);
|
std::clog << "Call SetIncoming -> Neuron SetIncoming: " <<
|
||||||
|
(neurons + thisCounter) -> SetIncoming(sinapses, backwardsNeuronCount)
|
||||||
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Katman::SetNoron(Noron *newneurons, int size)
|
bool Katman::SetNoron(Noron *newNeurons, int size)
|
||||||
{
|
{
|
||||||
neurons = (Noron *) new char[sizeof(Noron) * size];
|
std::clog << "Call SetNoron: Creating Neurons with Number of " << size << "\n";
|
||||||
|
neurons = new Noron[size];
|
||||||
|
|
||||||
if(!neurons) return false;
|
if(!neurons)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetNoron: Creating Neurons Failed!" << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetNoron: Neurons Created Successfully!" << "\n";
|
||||||
|
|
||||||
|
std::clog << "Call 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";
|
||||||
this -> size = size;
|
this -> size = size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Katman::CreateNoron(int size)
|
bool Katman::CreateNoron(int size)
|
||||||
{
|
{
|
||||||
neurons = (Noron *) new char[sizeof(Noron) * size];
|
std::clog << "Call CreateNoron: Creating Neurons with Number of " << size << "\n";
|
||||||
|
|
||||||
if(!neurons) return false;
|
neurons = new Noron[size];
|
||||||
|
|
||||||
for (int i = 0; i < size; i++)
|
if(!neurons)
|
||||||
*(neurons+i) = Noron();
|
{
|
||||||
|
std::clog << "Error Call CreateNoron: Creating Neurons Failed!" << "\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call CreateNoron: Neurons Created Successfully!" << "\n";
|
||||||
|
|
||||||
|
std::clog << "Call CreateNoron: Neurons are Set Successfully!" << "\n";
|
||||||
this -> size = size;
|
this -> size = size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -287,12 +377,16 @@ float RandomFloat(int min, int max)
|
||||||
{
|
{
|
||||||
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";
|
||||||
|
|
||||||
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";
|
||||||
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 << "Call SetValue: Successfull" << "\n";
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
#pragma region Cikti
|
#pragma region Cikti
|
||||||
|
@ -309,7 +403,9 @@ float RandomFloat(int min, int max)
|
||||||
|
|
||||||
float Cikti::GetValue(int index)
|
float Cikti::GetValue(int index)
|
||||||
{
|
{
|
||||||
return (neurons + index) -> GetStatus();
|
float result = (neurons + index) -> GetStatus();
|
||||||
|
std::clog << "Call GetValue: " << result << "\n";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
@ -337,6 +433,7 @@ float RandomFloat(int min, int max)
|
||||||
|
|
||||||
NeuralNetwork::NeuralNetwork()
|
NeuralNetwork::NeuralNetwork()
|
||||||
{
|
{
|
||||||
|
std::clog << "Create NeuralNetwork: NULL" << "\n";
|
||||||
hiddenSize = 0;
|
hiddenSize = 0;
|
||||||
input = NULL;
|
input = NULL;
|
||||||
hiddenLayers = NULL;
|
hiddenLayers = NULL;
|
||||||
|
@ -348,17 +445,28 @@ float RandomFloat(int min, int max)
|
||||||
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";
|
||||||
|
|
||||||
if(!input)
|
if(!input)
|
||||||
|
{
|
||||||
|
std::clog << "Error Create NeuralNetwork: Memory Couldn't Allocated for Input Layer!" << "\n";
|
||||||
std::cout << "Girdi Katmani Olusturulamadi!" << "\n";
|
std::cout << "Girdi Katmani Olusturulamadi!" << "\n";
|
||||||
|
}
|
||||||
if(!hiddenLayers)
|
if(!hiddenLayers)
|
||||||
|
{
|
||||||
|
std::clog << "Error Create NeuralNetwork: Memory Couldn't Allocated for Hidden Layers!" << "\n";
|
||||||
std::cout << "Ara Katmanlar Olusturulamadi!" << "\n";
|
std::cout << "Ara Katmanlar Olusturulamadi!" << "\n";
|
||||||
|
}
|
||||||
if(!output)
|
if(!output)
|
||||||
|
{
|
||||||
|
std::clog << "Error Create NeuralNetwork: Memory Couldn't Allocated for Output Layer!" << "\n";
|
||||||
std::cout << "Cikti Katmani Olusturulamadi!" << "\n";
|
std::cout << "Cikti Katmani Olusturulamadi!" << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
if(!input || !hiddenLayers || !output)
|
if(!input || !hiddenLayers || !output)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
std::clog << "Create NeuralNetwork: Succesfull!" << "\n";
|
||||||
this -> hiddenSize = hiddenSize;
|
this -> hiddenSize = hiddenSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,30 +479,48 @@ 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";
|
||||||
|
std::clog << "Call SetHiddenLayerNeurons: Creating " << size << " Neurons!" << "\n";
|
||||||
Noron *neurons = new Noron[size];
|
Noron *neurons = new Noron[size];
|
||||||
|
|
||||||
if(!neurons)
|
if(!neurons)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetHiddenLayerNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetHiddenLayerNeurons: Neurons Are Created!" << "\n";
|
||||||
|
|
||||||
return (hiddenLayers + index) -> SetNoron(neurons, size);
|
return (hiddenLayers + index) -> SetNoron(neurons, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NeuralNetwork::SetInputNeurons(int size)
|
bool NeuralNetwork::SetInputNeurons(int size)
|
||||||
{
|
{
|
||||||
|
std::clog << "Call SetInputNeurons: Size of " << size << "\n";
|
||||||
|
std::clog << "Call SetInputNeurons: Creating " << size << " Neurons!" << "\n";
|
||||||
Noron *neurons = new Noron[size];
|
Noron *neurons = new Noron[size];
|
||||||
|
|
||||||
if(!neurons)
|
if(!neurons)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetInputNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetInputNeurons: Neurons Are Created!" << "\n";
|
||||||
|
|
||||||
return output -> SetNoron(neurons, size);
|
return output -> SetNoron(neurons, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NeuralNetwork::SetOutputNeurons(int size)
|
bool NeuralNetwork::SetOutputNeurons(int size)
|
||||||
{
|
{
|
||||||
|
std::clog << "Call SetInputNeurons: Size of " << size << "\n";
|
||||||
|
std::clog << "Call SetInputNeurons: Creating " << size << " Neurons!" << "\n";
|
||||||
Noron *neurons = new Noron[size];
|
Noron *neurons = new Noron[size];
|
||||||
|
|
||||||
if(!neurons)
|
if(!neurons)
|
||||||
|
{
|
||||||
|
std::clog << "Error Call SetInputNeurons: Couldn't Allocate Memory for Neurons!" << "\n";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call SetInputNeurons: Neurons Are Created!" << "\n";
|
||||||
|
|
||||||
return input -> SetNoron(neurons, size);
|
return input -> SetNoron(neurons, size);
|
||||||
}
|
}
|
||||||
|
@ -402,49 +528,77 @@ float RandomFloat(int min, int max)
|
||||||
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";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call 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";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call 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";
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
std::clog << "Call ConnectLayers: Output is Set to Forward Successfully!" << "\n";
|
||||||
|
|
||||||
return output -> SetForward(NULL);
|
return output -> SetForward(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NeuralNetwork::FireNetwork()
|
void NeuralNetwork::FireNetwork()
|
||||||
{
|
{
|
||||||
input -> FireLayer();
|
// input -> FireLayer();
|
||||||
|
// std::clog << "Call 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";
|
||||||
|
}
|
||||||
|
|
||||||
output -> FireLayer();
|
output -> FireLayer();
|
||||||
|
std::clog << "Call 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";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::clog << "Call 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";
|
||||||
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";
|
||||||
(hiddenLayers + i) -> RandomizeSinapsValues();
|
(hiddenLayers + i) -> RandomizeSinapsValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::clog << "Call RandomizeNetworkValues: Output Sinapses Are Getting Randomized!" << "\n";
|
||||||
output -> RandomizeSinapsValues();
|
output -> RandomizeSinapsValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
float NeuralNetwork::GetOutputValue(int index)
|
float NeuralNetwork::GetOutputValue(int index)
|
||||||
{
|
{
|
||||||
return output -> GetValue(index);
|
float result = output -> GetValue(index);
|
||||||
|
std::clog << "Call GetOutputValue: " << result << "\n";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
int main(int argc, char const *argv[])
|
int main(int argc, char const *argv[])
|
||||||
|
@ -467,17 +621,5 @@ int main(int argc, char const *argv[])
|
||||||
std::cout << "m2\n";
|
std::cout << "m2\n";
|
||||||
std::cout << network.GetOutputValue(0) << "\n";
|
std::cout << network.GetOutputValue(0) << "\n";
|
||||||
std::cout << "m3\n";
|
std::cout << "m3\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Katman k1(5);
|
|
||||||
// Katman k2(3);
|
|
||||||
|
|
||||||
// std::cout << "k1 SetForward = " << k1.SetForward(&k2) << "\n";
|
|
||||||
// std::cout << "k2 SetForward = " << k2.SetForward(NULL) << "\n";
|
|
||||||
// k1.FireLayer();
|
|
||||||
// k2.FireLayer();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue