Skip to content

Commit

Permalink
formatting of spaces around ()
Browse files Browse the repository at this point in the history
  • Loading branch information
hughperkins committed Mar 27, 2016
1 parent b32766f commit b060a6b
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 196 deletions.
2 changes: 1 addition & 1 deletion clMathLibraries/clBLAS
Submodule clBLAS updated 355 files
250 changes: 125 additions & 125 deletions prototyping/clconvolve-fixedweights.cpp

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions prototyping/qlearning/ScenarioImage.cpp
Expand Up @@ -15,7 +15,7 @@ using namespace std;
#undef VIRTUAL
#define VIRTUAL

ScenarioImage::ScenarioImage( int size, bool appleMoves ) :
ScenarioImage::ScenarioImage(int size, bool appleMoves) :
net(0), // this is simply used by the showQRepresentation method
size(size),
appleMoves(appleMoves) {
Expand All @@ -31,37 +31,37 @@ ScenarioImage::ScenarioImage( int size, bool appleMoves ) :
reset();
print();
}
void ScenarioImage::setNet( NeuralNet *net ) {
void ScenarioImage::setNet(NeuralNet *net) {
this->net = net;
}
void ScenarioImage::printQRepresentation() {
ScenarioImage *scenario = this;
cout << "q directions:" << endl;
int size = scenario->getPerceptionSize();
float *input = new float[ size * size * 2 ];
arrayZero( input, size * size * 2 );
arrayZero(input, size * size * 2);
input[ scenario->appleY * size + scenario->appleX ] = 1;
for( int y = 0; y < size; y++ ) {
for(int y = 0; y < size; y++) {
string thisLine = "";
for( int x = 0; x < size; x++ ) {
for(int x = 0; x < size; x++) {
float highestQ = 0;
int bestAction = 0;
input[ size * size + y * size + x ] = 1;
net->forward( input );
net->forward(input);
input[ size * size + y * size + x ] = 0;
float const*output = net->getOutput();
for( int action = 0; action < 4; action++ ) {
for(int action = 0; action < 4; action++) {
float thisQ = output[action];
if( action == 0 || thisQ > highestQ ) {
if(action == 0 || thisQ > highestQ) {
highestQ = thisQ;
bestAction = action;
}
}
if( bestAction == 0 ) {
if(bestAction == 0) {
thisLine += ">";
} else if( bestAction == 1 ) {
} else if(bestAction == 1) {
thisLine += "<";
} else if( bestAction == 2 ) {
} else if(bestAction == 2) {
thisLine += "V";
} else {
thisLine += "^";
Expand All @@ -73,12 +73,12 @@ void ScenarioImage::printQRepresentation() {
}

VIRTUAL void ScenarioImage::print() {
for( int y = 0; y < size; y++ ) {
for(int y = 0; y < size; y++) {
string line = "";
for( int x = 0; x < size; x++ ) {
if( x == posX && y == posY ) {
for(int x = 0; x < size; x++) {
if(x == posX && y == posY) {
line += "X";
} else if( x == appleX && y == appleY ) {
} else if(x == appleX && y == appleY) {
line += "O";
} else {
line += ".";
Expand All @@ -92,11 +92,11 @@ VIRTUAL ScenarioImage::~ScenarioImage() {
VIRTUAL int ScenarioImage::getNumActions() {
return 4;
}
VIRTUAL float ScenarioImage::act( int index ) { // returns reward
VIRTUAL float ScenarioImage::act(int index) { // returns reward
numMoves++;
int dx = 0;
int dy = 0;
switch( index ) {
switch(index) {
case 0:
dx = 1;
break;
Expand All @@ -112,10 +112,10 @@ VIRTUAL float ScenarioImage::act( int index ) { // returns reward
}
int newX = posX + dx;
int newY = posY + dy;
if( newX < 0 || newX >= size || newY < 0 || newY >= size ) {
if(newX < 0 || newX >= size || newY < 0 || newY >= size) {
return -0.5f;
}
if( newX == appleX && newY == appleY ) {
if(newX == appleX && newY == appleY) {
finished = true;
posX = newX;
posY = newY;
Expand All @@ -135,8 +135,8 @@ VIRTUAL int ScenarioImage::getPerceptionSize() {
VIRTUAL int ScenarioImage::getPerceptionPlanes() {
return 2;
}
VIRTUAL void ScenarioImage::getPerception( float *perception ) {
for( int i = 0; i < size * size * 2; i++ ) {
VIRTUAL void ScenarioImage::getPerception(float *perception) {
for(int i = 0; i < size * size * 2; i++) {
perception[i] = 0;
}
perception[appleY * size + appleX] = 1;
Expand All @@ -146,20 +146,20 @@ VIRTUAL int ScenarioImage::getWorldSize() {
return size;
}
VIRTUAL void ScenarioImage::reset() {
if( net != 0 ) {
if(net != 0) {
this->print();
this->printQRepresentation();
cout << "game: " << game << " moves: " << numMoves << endl;
}
if( appleMoves ) {
if(appleMoves) {
appleX = myrand() % size;
appleY = myrand() % size;
} else {
appleX = appleY = size / 2;
}
finished = false;
bool sampledOnce = false;
while( !sampledOnce || ( posX == appleX && posY == appleY ) ) {
while(!sampledOnce || (posX == appleX && posY == appleY)) {
posX = myrand() % size;
posY = myrand() % size;
sampledOnce = true;
Expand Down
30 changes: 15 additions & 15 deletions test/testGenericLoader.cpp
Expand Up @@ -14,42 +14,42 @@

using namespace std;

void go( string trainFilepath, int startN, int numExamples ) {
void go(string trainFilepath, int startN, int numExamples) {
int N;
int numPlanes;
int imageSize;
// int totalSize;
GenericLoader::getDimensions(trainFilepath.c_str(), &N, &numPlanes, &imageSize );
GenericLoader::getDimensions(trainFilepath.c_str(), &N, &numPlanes, &imageSize);
cout << "N " << N << " numplanes " << numPlanes << " imageSize " << imageSize << endl;
float *images = new float[ numExamples * numPlanes * imageSize * imageSize ];
int *labels = new int[ numExamples ];
GenericLoader::load(trainFilepath.c_str(), images, labels, startN, numExamples );
GenericLoader::load(trainFilepath.c_str(), images, labels, startN, numExamples);
// float *images = new float[ N * numPlanes * imageSize * imageSize ];
// for( int i = 0; i < N * numPlanes * imageSize * imageSize; i++ ) {
// for(int i = 0; i < N * numPlanes * imageSize * imageSize; i++) {
// images[i] = imagesUchar[i];
// }
float thismin;
float thismax;
NormalizationHelper::getMinMax( images, numExamples * numPlanes * imageSize * imageSize, &thismin, &thismax );
NormalizationHelper::getMinMax(images, numExamples * numPlanes * imageSize * imageSize, &thismin, &thismax);
cout << "min: " << thismin << " max: " << thismax << endl;
ImagePng::writeImagesToPng( "testGenericLoader.png", images, numExamples * numPlanes, imageSize );
for( int i = 0; i < numExamples; i++ ) {
ImagePng::writeImagesToPng("testGenericLoader.png", images, numExamples * numPlanes, imageSize);
for(int i = 0; i < numExamples; i++) {
cout << "labels[" << i << "]=" << labels[i] << endl;
}
// float *translated = new float[N * numPlanes * imageSize * imageSize];
// Translator::translate( n, numPlanes, imageSize, translateRows, translateCols, images, translated );
// ImagePng::writeImagesToPng( "testTranslator-2.png", translated + n * numPlanes * imageSize * imageSize, numPlanes, imageSize );
// Translator::translate(n, numPlanes, imageSize, translateRows, translateCols, images, translated);
// ImagePng::writeImagesToPng("testTranslator-2.png", translated + n * numPlanes * imageSize * imageSize, numPlanes, imageSize);
}

int main( int argc, char *argv[] ) {
if( argc != 4 ) {
int main(int argc, char *argv[]) {
if(argc != 4) {
cout << "Usage: [trainfilepath] [startn] [numexamples]" << endl;
return -1;
}
string trainFilepath = string( argv[1] );
int startN = atoi( argv[2] );
int numExamples = atoi( argv[3] );
go( trainFilepath, startN, numExamples );
string trainFilepath = string(argv[1]);
int startN = atoi(argv[2]);
int numExamples = atoi(argv[3]);
go(trainFilepath, startN, numExamples);
return 0;
}

Expand Down
30 changes: 15 additions & 15 deletions test/testPatchExtractor.cpp
Expand Up @@ -7,35 +7,35 @@

using namespace std;

void go( string dataDir, string setName, int n, int patchSize, int patchRow, int patchCol ) {
void go(string dataDir, string setName, int n, int patchSize, int patchRow, int patchCol) {
int N;
int numPlanes;
int imageSize;
unsigned char *imagesUchar = NorbLoader::loadImages( dataDir + "/" + setName + "-dat.mat", &N, &numPlanes, &imageSize, n + 1 );
unsigned char *imagesUchar = NorbLoader::loadImages(dataDir + "/" + setName + "-dat.mat", &N, &numPlanes, &imageSize, n + 1);
cout << "n " << n << " N " << N << endl;
N = n + 1;
float *images = new float[ N * numPlanes * imageSize * imageSize ];
for( int i = 0; i < N * numPlanes * imageSize * imageSize; i++ ) {
for(int i = 0; i < N * numPlanes * imageSize * imageSize; i++) {
images[i] = imagesUchar[i];
}
ImagePng::writeImagesToPng( "testPatchExtractor-1.png", images + n * numPlanes * imageSize * imageSize, numPlanes, imageSize );
ImagePng::writeImagesToPng("testPatchExtractor-1.png", images + n * numPlanes * imageSize * imageSize, numPlanes, imageSize);
float *patches = new float[N * numPlanes * patchSize * patchSize];
PatchExtractor::extractPatch( n, numPlanes, imageSize, patchSize, patchRow, patchCol, images, patches );
ImagePng::writeImagesToPng( "testPatchExtractor-2.png", patches + n * numPlanes * patchSize * patchSize, numPlanes, patchSize );
PatchExtractor::extractPatch(n, numPlanes, imageSize, patchSize, patchRow, patchCol, images, patches);
ImagePng::writeImagesToPng("testPatchExtractor-2.png", patches + n * numPlanes * patchSize * patchSize, numPlanes, patchSize);
}

int main( int argc, char *argv[] ) {
if( argc != 7 ) {
int main(int argc, char *argv[]) {
if(argc != 7) {
cout << "Usage: [datadir] [setname] [n] [patchsize] [patchrow] [patchcol]" << endl;
return -1;
}
string dataDir = string( argv[1] );
string setName = string( argv[2] );
int n = atoi( argv[3] );
int patchSize = atoi( argv[4] );
int patchRow = atoi( argv[5] );
int patchCol = atoi( argv[6] );
go( dataDir, setName, n, patchSize, patchRow, patchCol );
string dataDir = string(argv[1]);
string setName = string(argv[2]);
int n = atoi(argv[3]);
int patchSize = atoi(argv[4]);
int patchRow = atoi(argv[5]);
int patchCol = atoi(argv[6]);
go(dataDir, setName, n, patchSize, patchRow, patchCol);
return 0;
}

Expand Down
30 changes: 15 additions & 15 deletions test/testTranslator.cpp
Expand Up @@ -7,38 +7,38 @@

using namespace std;

void go( string dataDir, string setName, int n, int translateRows, int translateCols ) {
void go(string dataDir, string setName, int n, int translateRows, int translateCols) {
int N;
int numPlanes;
int imageSize;
string filePath = dataDir + "/" + setName + "-dat.mat";
NorbLoader::getDimensions( filePath, &N, &numPlanes, &imageSize );
NorbLoader::getDimensions(filePath, &N, &numPlanes, &imageSize);
N = n + 1;
unsigned char *imagesUchar = new unsigned char[ N * numPlanes * imageSize * imageSize ];
int *labels = new int[ N ];
NorbLoader::load( filePath, imagesUchar, labels, 0, N );
NorbLoader::load(filePath, imagesUchar, labels, 0, N);
cout << "n " << n << " N " << N << endl;
float *images = new float[ N * numPlanes * imageSize * imageSize ];
for( int i = 0; i < N * numPlanes * imageSize * imageSize; i++ ) {
for(int i = 0; i < N * numPlanes * imageSize * imageSize; i++) {
images[i] = imagesUchar[i];
}
ImagePng::writeImagesToPng( "testTranslator-1.png", images + n * numPlanes * imageSize * imageSize, numPlanes, imageSize );
ImagePng::writeImagesToPng("testTranslator-1.png", images + n * numPlanes * imageSize * imageSize, numPlanes, imageSize);
float *translated = new float[N * numPlanes * imageSize * imageSize];
Translator::translate( n, numPlanes, imageSize, translateRows, translateCols, images, translated );
ImagePng::writeImagesToPng( "testTranslator-2.png", translated + n * numPlanes * imageSize * imageSize, numPlanes, imageSize );
Translator::translate(n, numPlanes, imageSize, translateRows, translateCols, images, translated);
ImagePng::writeImagesToPng("testTranslator-2.png", translated + n * numPlanes * imageSize * imageSize, numPlanes, imageSize);
}

int main( int argc, char *argv[] ) {
if( argc != 6 ) {
int main(int argc, char *argv[]) {
if(argc != 6) {
cout << "Usage: [datadir] [setname] [n] [translaterows] [translatecols]" << endl;
return -1;
}
string dataDir = string( argv[1] );
string setName = string( argv[2] );
int n = atoi( argv[3] );
int translateRows = atoi( argv[4] );
int translateCols = atoi( argv[5] );
go( dataDir, setName, n, translateRows, translateCols );
string dataDir = string(argv[1]);
string setName = string(argv[2]);
int n = atoi(argv[3]);
int translateRows = atoi(argv[4]);
int translateCols = atoi(argv[5]);
go(dataDir, setName, n, translateRows, translateCols);
return 0;
}

Expand Down

0 comments on commit b060a6b

Please sign in to comment.