Bezva, zdá se, že metody, které zatím mám fungují. Poprvé jsem musel kouknout na list do manuálu. Zvětšování počtů neuronů stále nefunguje. Jestly je moje vyjadřování horší než minule, tak se omlouvám, jsem dost nachcípanej. Používání poloanglických výrazů je můj blbej zvyk.
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
//namespace Neuron_Class {
template <class Data, class Synapse>
class ListOfNeuron
{
public:
ListOfNeuron ();
ListOfNeuron (ListOfNeuron&);
~ListOfNeuron ();
ListOfNeuron (Synapse*, Data*, ListOfNeuron*, ListOfNeuron*);
ListOfNeuron (Synapse*, ListOfNeuron*, ListOfNeuron*);
ListOfNeuron<Data,Synapse> *Construct ();
ListOfNeuron<Data,Synapse> *GetNext ();
ListOfNeuron<Data,Synapse> *GetPrev ();
void Destruct ();
void DestructFirst ();
void DestructLast ();
void SetSynapse (Synapse*);
Synapse *GetSynapse () const {return synapse;}
private:
Synapse *synapse;
Data *data;
ListOfNeuron<Data,Synapse> *next;
ListOfNeuron<Data,Synapse> *prev;
};
class InputOfNeuron
{
public:
InputOfNeuron ();
~InputOfNeuron ();
private:
int *input;
float *w;
};
class OutputOfNeuron
{
public:
OutputOfNeuron ();
~OutputOfNeuron ();
private:
};
class Neuron
{
public:
Neuron ();
~Neuron ();
bool SetNextInput ();
bool SetNextOutput ();
bool SetNumInput (int);
bool SetNumOutput (int);
bool SetStartInput ();
bool SetStartOutput ();
ListOfNeuron<InputOfNeuron, Neuron> *GetThisInput ();
ListOfNeuron<OutputOfNeuron, Neuron> *GetThisOutput ();
void ConstructInput ();
void ConstructOutput ();
void ConstructSynapse (Neuron*);
void DestructInput (int i);
void DestructOutput (int i);
void DestructSynapse (Neuron*);
void SetLastInput ();
void SetLastOutput ();
void SetSynapseInput (Neuron*);
void SetSynapseOutput (Neuron*);
private:
float *P;
ListOfNeuron<InputOfNeuron, Neuron> *lastInput;
ListOfNeuron<OutputOfNeuron, Neuron> *lastOutput;
ListOfNeuron<InputOfNeuron, Neuron> *input;
ListOfNeuron<InputOfNeuron, Neuron> *startInput;
ListOfNeuron<OutputOfNeuron, Neuron> *startOutput;
ListOfNeuron<OutputOfNeuron, Neuron> *output;
};
Neuron::Neuron ()
{
P = new float;
*P = 0;
lastInput = 0;
lastOutput = 0;
input = 0;
startInput = 0;
startOutput = 0;
output = 0;
};
Neuron::~Neuron ()
{
delete P;
};
bool Neuron::SetNextInput ()
{
if (input != lastInput)
{
input = input->GetNext ();
return true;
}
else
{
return false;
}
};
bool Neuron::SetNextOutput ()
{
if (output != lastOutput)
{
output = output->GetNext ();
return true;
}
else
{
return false;
}
};
bool Neuron::SetNumInput (int i)
{
SetStartInput ();
for (int k = 0; k < i; ++k)
{
if (input != lastInput)
{
input->GetNext ();
}
else
{
return false;
}
}
return true;
};
bool Neuron::SetNumOutput (int i)
{
SetStartOutput ();
for (int k = 0; k < i; ++k)
{
if (output != lastOutput)
{
output->GetNext ();
}
else
{
return false;
}
}
return true;
};
bool Neuron::SetStartInput ()
{
if (startInput)
{
input = startInput;
return true;
}
else
{
return false;
}
};
bool Neuron::SetStartOutput ()
{
if (startOutput)
{
output = startOutput;
return true;
}
else
{
return false;
}
};
ListOfNeuron<InputOfNeuron, Neuron> *Neuron::GetThisInput ()
{
if (input)
{
return input;
}
else
{
return 0;
}
};
ListOfNeuron<OutputOfNeuron, Neuron> *Neuron::GetThisOutput ()
{
if (output)
{
return output;
}
else
{
return 0;
}
};
void Neuron::ConstructInput ()
{
if (lastInput)
{
input = lastInput;
lastInput = input->Construct ();
}
else
{
startInput = new ListOfNeuron<InputOfNeuron, Neuron>;
lastInput = startInput;
}
};
void Neuron::DestructInput (int i)
{
SetNumInput (i);
if (input == startInput)
{
input->DestructFirst ();
}
if (input == lastInput)
{
input->DestructLast ();
}
if (input != startInput && input != lastInput)
{
input->Destruct ();
}
};
void Neuron::ConstructOutput ()
{
if (lastOutput)
{
output = lastOutput;
lastOutput = output->Construct ();
std::cout << "output " << output << " lastOutput " << lastOutput << std::endl;
}
else
{
startOutput = new ListOfNeuron<OutputOfNeuron, Neuron>;
lastOutput = startOutput;
}
};
void Neuron::ConstructSynapse (Neuron *i)
{
this->SetSynapseOutput (i);
i->SetSynapseInput (this);
};
void Neuron::DestructOutput (int i)
{
SetNumOutput (i);
if (output == startOutput)
{
output->DestructFirst ();
}
if (output == lastOutput)
{
output->DestructLast ();
}
if (output != startOutput && output != lastOutput)
{
output->Destruct ();
}
};
void Neuron::DestructSynapse (Neuron *i)
{
this->SetSynapseOutput (i);
i->SetSynapseInput (this);
this->output->Destruct ();
i->input->Destruct ();
};
void Neuron::SetLastInput ()
{
input = lastInput;
};
void Neuron::SetLastOutput ()
{
output = lastOutput;
};
void Neuron::SetSynapseInput (Neuron *i)
{
this->ConstructInput();
lastInput->ListOfNeuron<InputOfNeuron, Neuron>::SetSynapse (i);
};
void Neuron::SetSynapseOutput (Neuron *i)
{
this->ConstructOutput();
lastOutput->ListOfNeuron<OutputOfNeuron, Neuron>::SetSynapse (i);
};
template <class Data, class Synapse>
ListOfNeuron<Data, Synapse>::ListOfNeuron ()
{
synapse = 0;
data = new Data;
next = 0;
prev = 0;
};
template <class Data, class Synapse>
ListOfNeuron<Data, Synapse>::ListOfNeuron (ListOfNeuron&)
{
synapse = 0;
data = new Data;
next = 0;
prev = 0;
};
template <class Data, class Synapse>
ListOfNeuron<Data, Synapse>::~ListOfNeuron ()
{
delete data;
};
template <class Data, class Synapse>
ListOfNeuron<Data, Synapse>::ListOfNeuron (Synapse* sy, Data* it, ListOfNeuron* pNext, ListOfNeuron* pPrev)
{
synapse = sy;
data = it;
next = pNext;
prev = pPrev;
};
template <class Data, class Synapse>
ListOfNeuron<Data, Synapse>::ListOfNeuron (Synapse* sy = NULL, ListOfNeuron* pNext = NULL, ListOfNeuron* pPrev = NULL)
{
synapse = sy;
next = pNext;
prev = pPrev;
};
template <class Data, class Synapse>
ListOfNeuron<Data,Synapse> *ListOfNeuron<Data,Synapse>::Construct ()
{
this->next = new ListOfNeuron<Data,Synapse>;
next->prev = this;
return next;
};
template <class Data, class Synapse>
ListOfNeuron<Data,Synapse> *ListOfNeuron<Data,Synapse>::GetNext ()
{
if (next)
{
return next;
}
else
{
return 0;
}
};
template <class Data, class Synapse>
ListOfNeuron<Data,Synapse> *ListOfNeuron<Data,Synapse>::GetPrev ()
{
if (prev)
return prev;
else
return 0;
};
template <class Data, class Synapse>
void ListOfNeuron<Data,Synapse>::Destruct ()
{
prev->next = next;
next->prev = prev;
delete this;
};
template <class Data, class Synapse>
void ListOfNeuron<Data,Synapse>::DestructFirst ()
{
next->prev = prev;
delete this;
};
template <class Data, class Synapse>
void ListOfNeuron<Data,Synapse>::DestructLast ()
{
prev->next = next;
delete this;
};
template <class Data, class Synapse>
void ListOfNeuron<Data,Synapse>::SetSynapse (Synapse *itsSynapse)
{
synapse = itsSynapse;
};
InputOfNeuron::InputOfNeuron ()
{
input = new int;
w = new float;
*input = 0;
*w = rand() % 100 + 0;
*w = *w/100;
};
InputOfNeuron::~InputOfNeuron ()
{
delete input;
delete w;
};
OutputOfNeuron::OutputOfNeuron () {};
OutputOfNeuron::~OutputOfNeuron () {};
//};
// Neural_Network.cpp : main project file.
#include "stdafx.h"
#include "Neuron_Class.h"
#include <iostream>
#include <vector>
using namespace System;
int main(array<System::String ^> ^args)
{
bool a = true;
int b = 15;
int c;
Neuron d;
bool e;
int f;
int g;
Neuron *h;
ListOfNeuron<InputOfNeuron, Neuron> *in;
ListOfNeuron<OutputOfNeuron, Neuron> *on;
std::vector<Neuron> neuron(b);
while (a)
{
std::cout << "Write numer" << std::endl<< "if 0 so programm is ending." << std::endl<< "If 1 so insert one Neutron. " << std::endl << "if 2 so look all neutrons." << std::endl<< "If 3 so insert input." << std::endl<< "If 4 so Construct new synapse" /*<< std::endl<< "Write numer"*/ << std::endl;
std::cin >> c;
switch (c)
{
case 0:
a = false;
break;
case 1:
++b;
neuron.emplace_back (d);
std::cout << b << std::endl;
break;
case 2:
for (int i = 0; i < b; ++i)
{
std::cout << "Neuron n. "<< i << " "<< &neuron[i] << std::endl;
e = true;
std::cout << " input: " << std::endl;
if (neuron[i].SetStartInput ())
{
int j = 0;
while (e)
{
in = neuron[i].GetThisInput ();
std::cout << " " << j << " " << in << " " ;
if (in->GetSynapse ())
{
std::cout << in->GetSynapse () <<std::endl;
}
else
{
std::cout << std::endl;
}
e = neuron[i].SetNextInput ();
++j;
}
}
e = true;
std::cout << " output: " << std::endl;
if (neuron[i].SetStartOutput ())
{
int j = 0;
while (e)
{
on = neuron[i].GetThisOutput ();
std::cout << " " << j << " " << on << " ";
if (on->GetSynapse ())
{
std::cout << on->GetSynapse () << std::endl;
}
else
{
std::cout << std::endl;
}
e = neuron[i].SetNextOutput ();
++j;
}
}
}
break;
case 3:
std::cout << "Chose Neuron n. ";
std::cin >> f;
std:: cout << std::endl;
std::cout << "How many insert input? ";
std::cin >> g;
std:: cout << std::endl;
for (int i = 0; i < g; ++i)
{
neuron[f].SetStartInput ();
neuron[f].ConstructInput ();
}
break;
case 4:
int e;
int f;
std::cout << "Chose Neuron n. of output";
std::cin >> e;
std:: cout << std::endl;
std::cout << "Chose Neuron n. of input";
std::cin >> f;
std:: cout << std::endl;
h = &neuron[f];
neuron[e].SetStartInput ();
neuron[e].ConstructSynapse (h);
break;
default:
std::cout << "Error" << std::endl;
break;
}
}
return 0;
}