diff --git a/.travis/config.hpp b/.travis/config.hpp deleted file mode 100644 index 62c4a170..00000000 --- a/.travis/config.hpp +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (C) 2008-2012 NICTA (www.nicta.com.au) -// Copyright (C) 2008-2012 Conrad Sanderson -// -// This file is part of the Armadillo C++ library. -// It is provided without any warranty of fitness -// for any purpose. You can redistribute this file -// and/or modify it under the terms of the GNU -// Lesser General Public License (LGPL) as published -// by the Free Software Foundation, either version 3 -// of the License or (at your option) any later version. -// (see http://www.opensource.org/licenses for more info) - - - -#if !defined(ARMA_USE_LAPACK) -#define ARMA_USE_LAPACK -//// Uncomment the above line if you have LAPACK or a high-speed replacement for LAPACK, -//// such as Intel's MKL, AMD's ACML, or the Accelerate framework. -//// LAPACK is required for matrix decompositions (eg. SVD) and matrix inverse. -#endif - -#if !defined(ARMA_USE_BLAS) -#define ARMA_USE_BLAS -//// Uncomment the above line if you have BLAS or a high-speed replacement for BLAS, -//// such as GotoBLAS, Intel's MKL, AMD's ACML, or the Accelerate framework. -//// BLAS is used for matrix multiplication. -//// Without BLAS, matrix multiplication will still work, but might be slower. -#endif - -#define ARMA_USE_WRAPPER -//// Comment out the above line if you prefer to directly link with LAPACK and/or BLAS (eg. -llapack -lblas) -//// instead of linking indirectly with LAPACK and/or BLAS via Armadillo's run-time wrapper library. - -// #define ARMA_BLAS_CAPITALS -//// Uncomment the above line if your BLAS and LAPACK libraries have capitalised function names (eg. ACML on 64-bit Windows) - -#define ARMA_BLAS_UNDERSCORE -//// Uncomment the above line if your BLAS and LAPACK libraries have function names with a trailing underscore. -//// Conversely, comment it out if the function names don't have a trailing underscore. - -// #define ARMA_BLAS_LONG -//// Uncomment the above line if your BLAS and LAPACK libraries use "long" instead of "int" - -// #define ARMA_BLAS_LONG_LONG -//// Uncomment the above line if your BLAS and LAPACK libraries use "long long" instead of "int" - -// #define ARMA_USE_TBB_ALLOC -//// Uncomment the above line if you want to use Intel TBB scalable_malloc() and scalable_free() instead of standard new[] and delete[] - -// #define ARMA_USE_MKL_ALLOC -//// Uncomment the above line if you want to use Intel MKL mkl_malloc() and mkl_free() instead of standard new[] and delete[] - -/* #undef ARMA_USE_ATLAS */ -#define ARMA_ATLAS_INCLUDE_DIR / -//// If you're using ATLAS and the compiler can't find cblas.h and/or clapack.h -//// uncomment the above define and specify the appropriate include directory. -//// Make sure the directory has a trailing / - -#define ARMA_64BIT_WORD -//// Uncomment the above line if you require matrices/vectors capable of holding more than 4 billion elements. -//// Your machine and compiler must have support for 64 bit integers (eg. via "long" or "long long") - -#if !defined(ARMA_USE_CXX11) -#define ARMA_USE_CXX11 -//// Uncomment the above line if you have a C++ compiler that supports the C++11 standard -//// This will enable additional features, such as use of initialiser lists -#endif - -#if !defined(ARMA_USE_HDF5) -/* #undef ARMA_USE_HDF5 */ -//// Uncomment the above line if you want the ability to save and load matrices stored in the HDF5 format; -//// the hdf5.h header file must be available on your system and you will need to link with the hdf5 library (eg. -lhdf5) -#endif - -#if !defined(ARMA_MAT_PREALLOC) - #define ARMA_MAT_PREALLOC 16 -#endif -//// This is the number of preallocated elements used by matrices and vectors; -//// it must be an integer that is at least 1. -//// If you mainly use lots of very small vectors (eg. <= 4 elements), -//// change the number to the size of your vectors. - -#if !defined(ARMA_SPMAT_CHUNKSIZE) - #define ARMA_SPMAT_CHUNKSIZE 256 -#endif -//// This is the minimum increase in the amount of memory (in terms of elements) allocated by a sparse matrix; -//// it must be an integer that is at least 1. -//// The minimum recommended size is 16. - -// #define ARMA_NO_DEBUG -//// Uncomment the above line if you want to disable all run-time checks. -//// This will result in faster code, but you first need to make sure that your code runs correctly! -//// We strongly recommend to have the run-time checks enabled during development, -//// as this greatly aids in finding mistakes in your code, and hence speeds up development. -//// We recommend that run-time checks be disabled _only_ for the shipped version of your program. - -// #define ARMA_EXTRA_DEBUG -//// Uncomment the above line if you want to see the function traces of how Armadillo evaluates expressions. -//// This is mainly useful for debugging of the library. - - -// #define ARMA_USE_BOOST -// #define ARMA_USE_BOOST_DATE - - -#if !defined(ARMA_DEFAULT_OSTREAM) - #define ARMA_DEFAULT_OSTREAM std::cout -#endif - -#define ARMA_PRINT_LOGIC_ERRORS -#define ARMA_PRINT_RUNTIME_ERRORS -//#define ARMA_PRINT_HDF5_ERRORS - -#define ARMA_HAVE_STD_ISFINITE -#define ARMA_HAVE_STD_ISINF -#define ARMA_HAVE_STD_ISNAN -#define ARMA_HAVE_STD_SNPRINTF - -#define ARMA_HAVE_LOG1P -#define ARMA_HAVE_GETTIMEOFDAY - - - -#if defined(ARMA_DONT_USE_LAPACK) - #undef ARMA_USE_LAPACK -#endif - -#if defined(ARMA_DONT_USE_BLAS) - #undef ARMA_USE_BLAS -#endif - -#if defined(ARMA_DONT_USE_ATLAS) - #undef ARMA_USE_ATLAS - #undef ARMA_ATLAS_INCLUDE_DIR -#endif - -#if defined(ARMA_DONT_PRINT_LOGIC_ERRORS) - #undef ARMA_PRINT_LOGIC_ERRORS -#endif - -#if defined(ARMA_DONT_PRINT_RUNTIME_ERRORS) - #undef ARMA_PRINT_RUNTIME_ERRORS -#endif diff --git a/Kaggle/DigitRecognizer/src/DigitRecognizer.cpp b/Kaggle/DigitRecognizer/src/DigitRecognizer.cpp index 1b84d81c..f9078ffb 100644 --- a/Kaggle/DigitRecognizer/src/DigitRecognizer.cpp +++ b/Kaggle/DigitRecognizer/src/DigitRecognizer.cpp @@ -79,7 +79,7 @@ int main() train.n_cols - 1) / 255.0; const mat validX = valid.submat(1, 0, valid.n_rows - 1, valid.n_cols - 1) / 255.0; - + const int ITERATIONS_PER_CYCLE = trainX.n_cols; // According to NegativeLogLikelihood output layer of NN, labels should // specify class of a data point and be in the interval from 1 to diff --git a/Kaggle/DigitRecognizerBatchNorm/src/DigitRecognizerBatchNorm.cpp b/Kaggle/DigitRecognizerBatchNorm/src/DigitRecognizerBatchNorm.cpp index b8474e8b..c0409508 100644 --- a/Kaggle/DigitRecognizerBatchNorm/src/DigitRecognizerBatchNorm.cpp +++ b/Kaggle/DigitRecognizerBatchNorm/src/DigitRecognizerBatchNorm.cpp @@ -3,7 +3,8 @@ * solving Digit Recognizer problem from Kaggle website. * * The full description of a problem as well as datasets for training - * and testing are available here https://www.kaggle.com/c/digit-recognizer using BatchNorm + * and testing are available here https://www.kaggle.com/c/digit-recognizer + * using BatchNorm * * mlpack is free software; you may redistribute it and/or modify it under the * terms of the 3-clause BSD license. You should have received a copy of the @@ -97,15 +98,15 @@ int main() { // data and PRelU layer. Parameters specify the number of input features // and number of neurons in the next layer. model.Add >(trainX.n_rows, H1); - // The first PReLU activation layer. parameter can be set as constructor argument. + // The first PReLU activation layer. parameter can be set as constructor arg. model.Add >(); - // BatchNorm layer applied after PReLU activation as it gives better results practically. + // BatchNorm layer applied after PReLU activation as it gives better results. model.Add >(H1); // Intermediate layer between PReLU activation layers. model.Add >(H1, H2); // The second PReLU layer. model.Add >(); - //Second BatchNorm layer + // Second BatchNorm layer model.Add >(H2); // Intermediate layer. model.Add >(H2, 10); @@ -136,7 +137,6 @@ int main() { // Cycles for monitoring the process of a solution. for (int i = 0; i <= CYCLES; i++) { - // Train neural network. If this is the first iteration, weights are // random, using current values as starting point otherwise. model.Train(trainX, trainY, optimizer); diff --git a/Kaggle/DigitRecognizerCNN/src/DigitRecognizerCNN.cpp b/Kaggle/DigitRecognizerCNN/src/DigitRecognizerCNN.cpp index d1a3c4d2..4c55d14f 100644 --- a/Kaggle/DigitRecognizerCNN/src/DigitRecognizerCNN.cpp +++ b/Kaggle/DigitRecognizerCNN/src/DigitRecognizerCNN.cpp @@ -116,8 +116,7 @@ int main() 0, // Padding width. 0, // Padding height. 28, // Input width. - 28 // Input height. - ); + 28); // Input Height // Add first ReLU. model.Add >(); @@ -128,8 +127,7 @@ int main() 2, // Height of field. 2, // Stride along width. 2, // Stride along height. - true - ); + true); // Add the second convolution layer. model.Add >( @@ -142,8 +140,7 @@ int main() 0, // Padding width. 0, // Padding height. 12, // Input width. - 12 // Input height. - ); + 12); // Input Height // Add the second ReLU. model.Add >(); @@ -223,6 +220,6 @@ int main() // Saving results into Kaggle compatibe CSV file. save("Kaggle/results.csv", "ImageId,Label", testPred); - cout << "Results were saved to Kaggle/results.csv. This file can be uploaded to " - << "https://www.kaggle.com/c/digit-recognizer/submissions." << endl; + cout << "Results were saved to Kaggle/results.csv. This file can be uploaded " + << "to https://www.kaggle.com/c/digit-recognizer/submissions." << endl; } diff --git a/Kaggle/kaggle_utils.hpp b/Kaggle/kaggle_utils.hpp index 8a90ce2a..9caa5c3b 100644 --- a/Kaggle/kaggle_utils.hpp +++ b/Kaggle/kaggle_utils.hpp @@ -71,20 +71,20 @@ double accuracy(arma::Row predLabels, const arma::mat& realY) void save(const std::string filename, std::string header, const arma::Row& predLabels) { - std::ofstream out(filename); - out << header << std::endl; - for (size_t j = 0; j < predLabels.n_cols; ++j) - { - // j + 1 because Kaggle indexes start from 1 - // pred - 1 because 1st class is 0, 2nd class is 1 and etc. - out << j + 1 << "," << std::round(predLabels(j)) - 1; + std::ofstream out(filename); + out << header << std::endl; + for (size_t j = 0; j < predLabels.n_cols; ++j) + { + // j + 1 because Kaggle indexes start from 1 + // pred - 1 because 1st class is 0, 2nd class is 1 and etc. + out << j + 1 << "," << std::round(predLabels(j)) - 1; // to avoid an empty line in the end of the file - if (j < predLabels.n_cols - 1) - { - out << std::endl; - } - } - out.close(); + if (j < predLabels.n_cols - 1) + { + out << std::endl; + } + } + out.close(); } #endif diff --git a/LSTM/TimeSeries-Multivariate/src/LSTMTimeSeriesMultivariate.cpp b/LSTM/TimeSeries-Multivariate/src/LSTMTimeSeriesMultivariate.cpp index 52aed0e2..521bce12 100644 --- a/LSTM/TimeSeries-Multivariate/src/LSTMTimeSeriesMultivariate.cpp +++ b/LSTM/TimeSeries-Multivariate/src/LSTMTimeSeriesMultivariate.cpp @@ -14,7 +14,7 @@ */ /* -NOTE: the data need to be sorted by date in ascending order! The RNN learns from +NOTE: the data need to be sorted by date in ascending order! The RNN learns from oldest to newest! date close volume open high low @@ -101,7 +101,8 @@ void SaveResults(const string filename, // The prediction results are the (high, low) for the next day and come from // the last slice from the prediction. flatDataAndPreds.rows(flatDataAndPreds.n_rows - 2, - flatDataAndPreds.n_rows - 1) = predictions.slice(predictions.n_slices - 1); + flatDataAndPreds.n_rows - 1) = predictions.slice( + predictions.n_slices - 1); scale.InverseTransform(flatDataAndPreds, flatDataAndPreds); @@ -193,10 +194,10 @@ int main() size_t inputSize = 5, outputSize = 2; // Split the dataset into training and validation sets. - arma::mat trainData = dataset.submat(arma::span(),arma::span(0, (1 - RATIO) * + arma::mat trainData = dataset.submat(arma::span(), arma::span(0, (1 - RATIO) * dataset.n_cols)); - arma::mat testData = dataset.submat(arma::span(), arma::span((1 - RATIO) * dataset.n_cols, - dataset.n_cols - 1)); + arma::mat testData = dataset.submat(arma::span(), + arma::span((1 - RATIO) * dataset.n_cols, dataset.n_cols - 1)); // Number of epochs for training. const int EPOCHS = 150; @@ -255,13 +256,13 @@ int main() BATCH_SIZE, // Batch size. Number of data points that are used in each // iteration. trainData.n_cols * EPOCHS, // Max number of iterations. - 1e-8,// Tolerance. + 1e-8, // Tolerance. true, // Shuffle. AdamUpdate(1e-8, 0.9, 0.999)); // Adam update policy. // Instead of terminating based on the tolerance of the objective function, - // we'll depend on the maximum number of iterations, and terminate early using - // the EarlyStopAtMinLoss callback. + // we'll depend on the maximum number of iterations, and terminate early + // using the EarlyStopAtMinLoss callback. optimizer.Tolerance() = -1; cout << "Training ..." << endl; @@ -305,6 +306,6 @@ int main() SaveResults(predFile, predOutP, scale, testX); // Use this on Windows in order to keep the console window open. - //cout << "Ready!" << endl; - //getchar(); + // cout << "Ready!" << endl; + // getchar(); } diff --git a/LSTM/TimeSeries-Univariate/src/LSTMTimeSeriesUnivariate.cpp b/LSTM/TimeSeries-Univariate/src/LSTMTimeSeriesUnivariate.cpp index 0dd06c63..0586da31 100644 --- a/LSTM/TimeSeries-Univariate/src/LSTMTimeSeriesUnivariate.cpp +++ b/LSTM/TimeSeries-Univariate/src/LSTMTimeSeriesUnivariate.cpp @@ -1,5 +1,5 @@ /** - * An example of using Recurrent Neural Network (RNN) + * An example of using Recurrent Neural Network (RNN) * to make forcasts on a time series of number of kilowatt-hours used in a * residential home over a 3.5 month period, 25 November 2011 to 17 March 2012, * which we aim to solve using a simple LSTM neural network. Electricity usage @@ -16,7 +16,7 @@ */ /* -NOTE: the data need to be sorted by date in ascending order! The RNN learns from +NOTE: the data need to be sorted by date in ascending order! The RNN learns from oldest to newest! DateTime,Consumption kWh,Off-peak,Mid-peak,On-peak @@ -72,7 +72,7 @@ void CreateTimeSeriesData(InputDataType dataset, LabelType& y, const size_t rho) { - for(size_t i = 0; i < dataset.n_cols - rho; i++) + for (size_t i = 0; i < dataset.n_cols - rho; i++) { X.subcube(arma::span(), arma::span(i), arma::span()) = dataset.submat(arma::span(), arma::span(i, i + rho - 1)); @@ -98,7 +98,8 @@ void SaveResults(const string& filename, // The prediction result is the energy consumption for the next hour and comes // from the last slice of the prediction. flatDataAndPreds.rows(flatDataAndPreds.n_rows - 1, - flatDataAndPreds.n_rows - 1) = predictions.slice(predictions.n_slices - 1); + flatDataAndPreds.n_rows - 1) = predictions.slice( + predictions.n_slices - 1); scale.InverseTransform(flatDataAndPreds, flatDataAndPreds); // We need to remove the last column because it was not used for training @@ -188,10 +189,10 @@ int main() dataset = dataset.submat(1, 1, 1, dataset.n_cols - 1); // Split the dataset into training and validation sets. - arma::mat trainData = dataset.submat(arma::span(),arma::span(0, (1 - RATIO) * + arma::mat trainData = dataset.submat(arma::span(), arma::span(0, (1 - RATIO) * dataset.n_cols)); - arma::mat testData = dataset.submat(arma::span(), arma::span((1 - RATIO) * dataset.n_cols, - dataset.n_cols - 1)); + arma::mat testData = dataset.submat(arma::span(), + arma::span((1 - RATIO) * dataset.n_cols, dataset.n_cols - 1)); // Number of iterations per cycle. const int EPOCHS = 150; @@ -243,15 +244,15 @@ int main() // Set parameters for the Stochastic Gradient Descent (SGD) optimizer. SGD optimizer( STEP_SIZE, // Step size of the optimizer. - BATCH_SIZE, // Batch size. Number of data points that are used in each iteration. + BATCH_SIZE, // Batch size. Number of data points used per iteration. trainData.n_cols * EPOCHS, // Max number of iterations. 1e-8, // Tolerance. true, // Shuffle. AdamUpdate(1e-8, 0.9, 0.999)); // Adam update policy. // Instead of terminating based on the tolerance of the objective function, - // we'll depend on the maximum number of iterations, and terminate early using - // the EarlyStopAtMinLoss callback. + // we'll depend on the maximum number of iterations, and terminate early + // using the EarlyStopAtMinLoss callback. optimizer.Tolerance() = -1; cout << "Training ..." << endl; @@ -296,6 +297,6 @@ int main() SaveResults(predFile, predOutP, scale, testX); // Use this on Windows in order to keep the console window open. - //cout << "Ready!" << endl; - //getchar(); + // cout << "Ready!" << endl; + // getchar(); } diff --git a/vae/vae_cnn_mnist/src/vae_cnn.cpp b/vae/vae_cnn_mnist/src/vae_cnn.cpp index 5a09fd83..a51d87d5 100644 --- a/vae/vae_cnn_mnist/src/vae_cnn.cpp +++ b/vae/vae_cnn_mnist/src/vae_cnn.cpp @@ -126,16 +126,16 @@ int main() // Add the first convolution layer. encoder->Add >( - 1, // Number of input activation maps - 16, // Number of output activation maps. - 5, // Filter width. - 5, // Filter height. - 2, // Stride along width. - 2, // Stride along height. - 2, // Padding width. - 2, // Padding height. - 28, // Input width. - 28);// Input height. + 1, // Number of input activation maps + 16, // Number of output activation maps. + 5, // Filter width. + 5, // Filter height. + 2, // Stride along width. + 2, // Stride along height. + 2, // Padding width. + 2, // Padding height. + 28, // Input width. + 28); // Input height. // Add first ReLU. encoder->Add >(); @@ -163,16 +163,16 @@ int main() // Add the first transposed convolution(deconvolution) layer. decoder->Add >( - 24, // Number of input activation maps. - 16, // Number of output activation maps. - 5, // Filter width. - 5, // Filter height. - 1, // Stride along width. - 1, // Stride along height. - 0, // Padding width. - 0, // Padding height. - 10, // Input width. - 10);// Input height. + 24, // Number of input activation maps. + 16, // Number of output activation maps. + 5, // Filter width. + 5, // Filter height. + 1, // Stride along width. + 1, // Stride along height. + 0, // Padding width. + 0, // Padding height. + 10, // Input width. + 10); // Input height. decoder->Add >(); decoder->Add >(16, 1, 15, 15, 1, 1, 1, 1, 14, 14); diff --git a/vae/vae_generate.cpp b/vae/vae_generate.cpp index 0da0d3da..9728ab14 100644 --- a/vae/vae_generate.cpp +++ b/vae/vae_generate.cpp @@ -109,7 +109,8 @@ int main() gaussianVaried.col(j)(i) = -1.5 + j * (3.0 / nofSamples); } - // Forward pass only through the decoder(and Sigmod layer in case of binary). + // Forward pass only through the decoder + // (and Sigmod layer in case of binary). vaeModel.Forward(gaussianVaried, outputDists, 3 /* Index of the decoder */, @@ -117,8 +118,11 @@ int main() GetSample(outputDists, samples, isBinary); // Save the prior samples as csv. - data::Save("samples_csv_files/samples_prior_latent" + std::to_string(i) + ".csv", - samples, false, false); + data::Save( + "samples_csv_files/samples_prior_latent" + std::to_string(i) + ".csv", + samples, + false, + false); } /* @@ -139,7 +143,8 @@ int main() gaussianVaried.col(j)(latent2) = -1.5 + j * (3.0 / nofSamples); } - // Forward pass only through the decoder(and Sigmod layer in case of binary). + // Forward pass only through the decoder + // (and Sigmod layer in case of binary). vaeModel.Forward(gaussianVaried, outputDists, 3 /* Index of the decoder */, @@ -164,6 +169,10 @@ int main() GetSample(outputDists, samples, isBinary); // Save the posterior samples as csv. - data::Save("samples_csv_files/samples_posterior.csv", samples, false, false); + data::Save( + "samples_csv_files/samples_posterior.csv", + samples, + false, + false); } }