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 #include <opengl/visualization/WindowCollectorChart.hpp>
43 using namespace mic::opengl::visualization;
47 using namespace mic::mlnn;
50 #include <encoders/ColMatrixEncoder.hpp>
51 #include <encoders/UIntMatrixEncoder.hpp>
54 using namespace mic::mlnn::experimental;
70 mic::importers::MNISTMatrixImporter<double>*
importer;
100 LOG(LINFO) <<
"Generated new neural network";
103 std::shared_ptr<mic::mlnn::experimental::ConvHebbian<double> > layer1 =
106 size_t iteration = 0;
108 const double learning_rate = 5e-3;
111 while (!APP_STATE->Quit()) {
114 if (!APP_STATE->isPaused()) {
117 if (APP_STATE->isSingleStepModeOn())
118 APP_STATE->pressPause();
121 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
124 mic::types::MNISTBatch<double> bt =
importer->getRandomBatch();
127 mic::types::MatrixPtr<double> encoded_batch =
mnist_encoder->encodeBatch(bt.data());
129 MNISTBatch<double> next_batch =
importer->getNextBatch();
130 encoded_batch =
mnist_encoder->encodeBatch(next_batch.data());
132 neural_net.train(encoded_batch, learning_rate);
134 if (iteration % 10 == 0) {
137 w_input->setBatchUnsynchronized(layer1->getInputActivations());
138 w_weights1->setBatchUnsynchronized(layer1->getWeightActivations());
139 w_similarity->setBatchUnsynchronized(layer1->getWeightSimilarity(
true));
140 w_output->setBatchUnsynchronized(layer1->getOutputActivations());
141 w_reconstruction->setBatchUnsynchronized(layer1->getOutputReconstruction());
142 collector_ptr->addDataToContainer(
"Reconstruction error", layer1->getOutputReconstructionError());
143 LOG(LINFO) <<
"Iteration: " << iteration;
166 int main(
int argc,
char* argv[]) {
168 LOGGER->addOutput(
new ConsoleOutput());
169 LOG(LINFO) <<
"Logger initialized. Starting application";
172 PARAM_SERVER->parseApplicationParameters(argc, argv);
178 importer =
new mic::importers::MNISTMatrixImporter<double>();
179 importer->setDataFilename(
"../data/mnist/train-images.idx3-ubyte");
180 importer->setLabelsFilename(
"../data/mnist/train-labels.idx1-ubyte");
188 PARAM_SERVER->loadPropertiesFromConfiguration();
191 PARAM_SERVER->initializePropertyDependentVariables();
198 VGL_MANAGER->initializeGLUT(argc, argv);
201 w_input =
new WindowGrayscaleBatch<double>(
"Input batch", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70, 0, 250, 250);
202 w_weights1 =
new WindowGrayscaleBatch<double>(
"Permanences", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70+250, 0, 250, 250);
203 w_similarity =
new WindowGrayscaleBatch<double>(
"Cosine similarity matrix", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70+(2*250), 0, 250, 250);
204 w_output =
new WindowGrayscaleBatch<double>(
"Output", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70+(3*250), 0, 250, 250);
205 w_reconstruction =
new WindowGrayscaleBatch<double>(
"Reconstruction", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 70+(4*250), 0, 250, 250);
208 w_chart =
new WindowCollectorChart<double>(
"Statistics", 60, 878, 512, 256);
209 collector_ptr= std::make_shared < mic::utils::DataCollector<std::string, double> >( );
210 w_chart->setDataCollectorPtr(collector_ptr);
213 collector_ptr->createContainer(
"Reconstruction error", mic::types::color_rgba(255, 255, 255, 180));
218 VGL_MANAGER->startVisualizationLoop();
220 LOG(LINFO) <<
"Waiting for threads to join...";
223 LOG(LINFO) <<
"Threads joined - ending application";
WindowGrayscaleBatch< double > * w_similarity
WindowGrayscaleBatch< double > * w_input
Window for displaying the MNIST batch.
const size_t filter_size[]
WindowGrayscaleBatch< double > * w_weights1
Window for displaying the weights.
mic::importers::MNISTMatrixImporter< double > * importer
MNIST importer.
const size_t input_channels
void batch_function(void)
Function for batch sampling.
Class implementing a convolutional hebbian layer.
: Alexis Asseman alexis.asseman@ibm.com, Tomasz Kornuta tkornut@us.ibm.com : May 30, 2017
WindowGrayscaleBatch< double > * w_reconstruction
mic::utils::DataCollectorPtr< std::string, double > collector_ptr
int main(int argc, char *argv[])
Main program function. Runs two threads: main (for GLUT) and another one (for data processing)...
Class representing a multi-layer neural network based on hebbian learning.
HebbianNeuralNetwork< double > neural_net
Multi-layer neural network.
WindowCollectorChart< double > * w_chart
Data collector.
WindowGrayscaleBatch< double > * w_output
const size_t patch_size
Label 2 matrix encoder (1 hot).
mic::encoders::ColMatrixEncoder< double > * mnist_encoder
MNIST matrix encoder.