Practical use of behavioral design patterns.
Artificial intelligence and neural networks.
layer_iterator.h LayerIterator class, used for the functionality of traversing the neural network layers without exposing its structure.
Because i used the C++ language, which already has syntax for iterators, i just wrote the LayerIterator as a custom iterator for the Network class, which means that i can use C++ iterator specific syntax:
Usage of the LayerIterator within the Network class
Because of the non-linear nature of the neural network implementation of layers, no layer has a direct connection to the next layer, which means that if we need to traverse layers, we need to query one of the nodes inside the layer, to get the next layer. This iterator does this for us, and using the begin and end function, we can traverse all the layers in all neural networks with ease.
Using the Iterator design pattern we have a way to access all the layers of the neural network with ease, in the case i used, i only printed the weights of the neurons, but because i have a pointer to those neurons, i can virtually do anything with them, where previously i couldn't.
dnetwork.h DNetwork class(decorator network), used for the added functionality of printing the neural network's layers without modifying the base class.
Usage: (Network does not have a print_all_layers() function)
fsoftmax.h softmax_layer function (facade for softmax), used for simplifying the softmax interface.
Usage: Adds the ability to call the softmax singleton to easily apply the softmax transformation for an array of numbers.
link.h Link class, used as a composite for neurons, by calling all children' on_send(), or on_receive() functions.
Usage: Call the same function with the same arguments for multiple neurons in a layer using a link.
- NeuronBuilder - Builder pattern.
- IObject::copy() virtual method - Prototype pattern.
- IObject::copy() virtual method - Prototype pattern.
- Softmax::getInstance() static method - Singleton pattern.
- Easy network creation, thanks to builder pattern:
- Easy softmax usage, thanks to singleton pattern:
- Easy copying of neurons and links, thanks to the prototype pattern.