vendredi 9 mars 2018

Using Chain of Responsibility pattern in machine learning

I've read a lot of C++ and Java code of machine learning where each hidden layer is called inside a for loop. Why the pattern Chain of Responsability is never used ? What is its disavantages ?

-Classic approach:

std::vector<Layer> layers(10);
for(Layer& hidden : layers)
  hidden.activation();

-With Chain of Responsability:

std::vector<Layer*> layers();
// ... init layers vector ...
layers[0]->nextLayer(layers[1]);
layers[1]->nextLayer(layers[2]);
layers[2]->nextLayer(layers[3]);
// and so on...
layers[0]->activation();

In Layer:

Layer::activation()
{
  // do something
  nextLayer->activation();
}

Thank you.

Aucun commentaire:

Enregistrer un commentaire