28 #ifndef UNSUPERVISED_RBM_PROBLEMS_MNIST_H 29 #define UNSUPERVISED_RBM_PROBLEMS_MNIST_H 50 std::string m_filename;
52 std::size_t m_batchSize;
54 int readInt (
unsigned char *memblock)
const{
55 return ((
int)memblock[0] << 24) + ((int)memblock[1] << 16) + ((int)memblock[2] << 8) + memblock[3];
59 std::ifstream infile(m_filename.c_str(), std::ios::binary);
63 infile.seekg(0,std::ios::end);
64 std::ifstream::pos_type inputSize = infile.tellg();
67 unsigned char *memblock =
new unsigned char [inputSize];
68 infile.seekg (0, std::ios::beg);
69 infile.read ((
char *) memblock, inputSize);
72 std::size_t numImages = readInt(memblock + 4);
73 std::size_t numRows = readInt(memblock + 8);
74 std::size_t numColumns = readInt(memblock + 12);
75 std::size_t sizeOfVis = numRows * numColumns;
77 std::vector<RealVector>
data(numImages,RealVector(sizeOfVis));
78 for (std::size_t i = 0; i != numImages; ++i){
79 RealVector imgVec(sizeOfVis);
81 for (
size_t j = 0; j != sizeOfVis; ++j){
82 char pixel = memblock[ 16 + i * sizeOfVis + j ] > m_threshold;
87 for (
size_t j = 0; j != sizeOfVis; ++j){
88 data[i](j) = memblock[ 16 + i * sizeOfVis + j ];
102 : m_filename(filename), m_threshold(threshold), m_batchSize(
batchSize){