Updating functions
This commit is contained in:
parent
5534661b91
commit
26ae13b72e
3 changed files with 107 additions and 6 deletions
8
main.cpp
8
main.cpp
|
@ -14,11 +14,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
|
||||||
cout << "Bonjour et bienvenu" << endl;
|
cout << "Bonjour et bienvenu" << endl;
|
||||||
vector<int> v = {1,2,3,4};
|
|
||||||
cout << "size = " << v.size() << endl;
|
|
||||||
cout << "size of bool = " << sizeof(bool) << endl;
|
|
||||||
|
|
||||||
Neuron n0(3,SIGMOID);
|
/*Neuron n0(3,SIGMOID);
|
||||||
|
|
||||||
Neuron n1(3,RELU);n1.set_output(1.0);
|
Neuron n1(3,RELU);n1.set_output(1.0);
|
||||||
Neuron n2(3,RELU);n2.set_output(2.0);
|
Neuron n2(3,RELU);n2.set_output(2.0);
|
||||||
|
@ -28,6 +25,7 @@ int main(int argc, char *argv[])
|
||||||
forward_list<Neuron>::iterator it(fl.begin());
|
forward_list<Neuron>::iterator it(fl.begin());
|
||||||
|
|
||||||
n0.activate(it);
|
n0.activate(it);
|
||||||
cout << "is = " << n0.get_output() << endl;
|
cout << "is = " << n0.get_output() << endl;*/
|
||||||
|
Network(4, 5);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
102
myclasses.cpp
102
myclasses.cpp
|
@ -57,6 +57,108 @@ float Neuron::get_output()//to be deleted later
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Network::Network(int n_layers, int n_neurons)
|
||||||
|
{
|
||||||
|
for(int i(1) ; i<=n_layers ; i++)
|
||||||
|
{
|
||||||
|
forward_list<Neuron> current_layer;
|
||||||
|
for(int j(1) ; j<=n_neurons ; j++)
|
||||||
|
{
|
||||||
|
if(i==1)
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(0, LINEAR) );
|
||||||
|
}else if(i==n_layers)
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(n_neurons, SIGMOID) );
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(n_neurons, RELU) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layers.push_back(current_layer);
|
||||||
|
}
|
||||||
|
h_activ = RELU;
|
||||||
|
o_activ = SIGMOID;
|
||||||
|
}
|
||||||
|
|
||||||
|
Network::Network(const std::vector<int> &n_neurons, Activ h_activ, Activ o_activ)
|
||||||
|
{
|
||||||
|
for(int i(0) ; i<n_neurons.size() ; i++)
|
||||||
|
{
|
||||||
|
forward_list<Neuron> current_layer;
|
||||||
|
for(int j(1) ; j<=n_neurons[i] ; j++)
|
||||||
|
{
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(0, LINEAR) );
|
||||||
|
}else if(i==n_neurons.size()-1)
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(n_neurons[i-1], o_activ) );
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
current_layer.push_front( Neuron(n_neurons[i-1], h_activ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
layers.push_back(current_layer);
|
||||||
|
}
|
||||||
|
h_activ = h_activ;
|
||||||
|
o_activ = o_activ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Network::print()
|
||||||
|
{
|
||||||
|
cout << endl << "#>>==========================================<<#" << endl;
|
||||||
|
cout << "# NEURAL NETWORK #" << endl;
|
||||||
|
cout << "#>>==========================================<<#" << endl;
|
||||||
|
cout << ">> Number of layers : " << layers.size() << endl;
|
||||||
|
cout << "------------------------------------------------" << endl;
|
||||||
|
for(list<forward_list<Neuron>>::iterator it1(layers.begin()) ; it1!=layers.end() ; ++it1)
|
||||||
|
{
|
||||||
|
int current_layer_size = 0;
|
||||||
|
for(forward_list<Neuron>::iterator it2(it1) ; it2!=it1.end() ; ++it2)
|
||||||
|
{
|
||||||
|
current_layer_size++;
|
||||||
|
}
|
||||||
|
if(i==0)
|
||||||
|
{
|
||||||
|
cout << ">> Input layer" << endl;
|
||||||
|
cout << "size : " << layers << endl;
|
||||||
|
cout << "neurons' outputs : ";
|
||||||
|
temp = network->layers_first_neurons[i];
|
||||||
|
while(temp != NULL)
|
||||||
|
{
|
||||||
|
cout << ("%f ", temp->output);
|
||||||
|
temp = temp->same_layer_next_neuron;
|
||||||
|
}
|
||||||
|
cout << ("\n");
|
||||||
|
}else if(i==layers.size()-1)
|
||||||
|
{
|
||||||
|
cout << (">> Output layer\n");
|
||||||
|
cout << ("size : %d\n", network->neurons_per_layer[i]);
|
||||||
|
cout << ("neurons' outputs : ");
|
||||||
|
temp = network->layers_first_neurons[i];
|
||||||
|
while(temp != NULL)
|
||||||
|
{
|
||||||
|
cout << ("%f ", temp->output);
|
||||||
|
temp = temp->same_layer_next_neuron;
|
||||||
|
}
|
||||||
|
cout << ("\n");
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
cout << (">> Hidden layer %d\n", i);
|
||||||
|
cout << ("size : %d\n", network->neurons_per_layer[i]);
|
||||||
|
}
|
||||||
|
cout << ("------------------------------------------------\n");
|
||||||
|
}
|
||||||
|
cout << ("Number of parameters : ");
|
||||||
|
for(i=1 ; i<network->n_layers ; i++)
|
||||||
|
{
|
||||||
|
n_params += network->neurons_per_layer[i] * (network->neurons_per_layer[i-1] + 1);
|
||||||
|
}
|
||||||
|
cout << ("%d\n", n_params);
|
||||||
|
cout << "#>>==========================================<<#" << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
void Tools::activate_randomness()
|
void Tools::activate_randomness()
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
|
@ -30,8 +30,9 @@ private:
|
||||||
class Network
|
class Network
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Network(int n_neurons);
|
Network(int n_layers, int n_neurons);
|
||||||
Network(const std::vector<int> &n_neurons, Activ h_activ=RELU, Activ o_activ=SIGMOID);
|
Network(const std::vector<int> &n_neurons, Activ h_activ=RELU, Activ o_activ=SIGMOID);
|
||||||
|
void print() const;
|
||||||
bool forward(const std::vector<float> &input, const std::vector<float> &target);
|
bool forward(const std::vector<float> &input, const std::vector<float> &target);
|
||||||
bool backward();
|
bool backward();
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue