26 #include <boost/thread/thread.hpp>
27 #include <boost/bind.hpp>
29 #include <importers/MNISTMatrixImporter.hpp>
31 #include <logger/Log.hpp>
32 #include <logger/ConsoleOutput.hpp>
33 using namespace mic::logger;
35 #include <application/ApplicationState.hpp>
37 #include <configuration/ParameterServer.hpp>
39 #include <opengl/visualization/WindowManager.hpp>
40 #include <opengl/visualization/WindowGrayscaleBatch.hpp>
41 using namespace mic::opengl::visualization;
45 using namespace mic::mlnn;
48 #include <encoders/MatrixXfMatrixXfEncoder.hpp>
49 #include <encoders/UIntMatrixXfEncoder.hpp>
59 mic::importers::MNISTMatrixImporter<float>*
importer;
86 LOG(LINFO) <<
"Generated new neural network";
92 while (!APP_STATE->Quit()) {
95 if (!APP_STATE->isPaused()) {
98 if (APP_STATE->isSingleStepModeOn())
99 APP_STATE->pressPause();
102 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
105 mic::types::MNISTBatch<float> bt =
importer->getRandomBatch();
108 w_input->setBatchUnsynchronized(bt.data());
111 mic::types::MatrixXfPtr encoded_batch =
mnist_encoder->encodeBatch(bt.data());
112 mic::types::MatrixXfPtr encoded_labels =
mnist_encoder->encodeBatch(bt.data());
115 float loss =
neural_net.train (encoded_batch, 0.05);
118 mic::types::MatrixXfPtr encoded_reconstruction =
neural_net.getPredictions();
120 std::vector<mic::types::MatrixXfPtr> decoded_reconstruction =
mnist_encoder->decodeBatch(encoded_reconstruction);
123 if (iteration%10 == 0) {
131 LOG(LINFO) <<
"Iteration: " << iteration <<
"loss= " << loss;
151 int main(
int argc,
char* argv[]) {
153 LOGGER->addOutput(
new ConsoleOutput());
154 LOG(LINFO) <<
"Logger initialized. Starting application";
157 PARAM_SERVER->parseApplicationParameters(argc, argv);
163 importer =
new mic::importers::MNISTMatrixImporter<float>();
171 PARAM_SERVER->loadPropertiesFromConfiguration();
174 PARAM_SERVER->initializePropertyDependentVariables();
181 VGL_MANAGER->initializeGLUT(argc, argv);
184 w_input =
new WindowGrayscaleBatch<float>(
"Input batch", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70, 0, 250, 250);
185 w_reconstruction =
new WindowGrayscaleBatch<float>(
"Reconstructed batch", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 320, 0, 250, 250);
186 w_weights1 =
new WindowGrayscaleBatch<float>(
"Permanences", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 570, 0, 250, 250);
192 VGL_MANAGER->startVisualizationLoop();
194 LOG(LINFO) <<
"Waiting for threads to join...";
197 LOG(LINFO) <<
"Threads joined - ending application";
WindowGrayscaleBatch< float > * w_weights2
mic::encoders::MatrixXfMatrixXfEncoder * mnist_encoder
MNIST matrix encoder.
WindowGrayscaleBatch< float > * w_reconstruction
Updates according to classical Hebbian rule (wij += ni * x * y) with additional normalization.
HebbianNeuralNetwork< float > neural_net
Multi-layer neural network.
int main(int argc, char *argv[])
Main program function. Runs two threads: main (for GLUT) and another one (for data processing)...
const size_t patch_size
Label 2 matrix encoder (1 hot).
mic::importers::MNISTMatrixImporter< float > * importer
MNIST importer.
WindowGrayscaleBatch< float > * w_input
Window for displaying the MNIST batch.
Class implementing a linear, fully connected layer.
const size_t output_units
WindowGrayscaleBatch< float > * w_weights1
Window for displaying the weights.
void batch_function(void)
Function for batch sampling.
Class representing a multi-layer neural network based on hebbian learning.