Skip to content
Snippets Groups Projects
Commit 6b4799d6 authored by Emmanouil Stergiadis's avatar Emmanouil Stergiadis Committed by Lorenzo Moneta
Browse files

Added tests for all architectures for the RotateWeights methods

parent 45704630
No related branches found
No related tags found
No related merge requests found
...@@ -32,61 +32,26 @@ ...@@ -32,61 +32,26 @@
#include <cmath> #include <cmath>
#include "TMVA/DNN/Architectures/Reference.h" #include "TMVA/DNN/Architectures/Reference.h"
#include "TestConvNet.h" #include "TestRotateWeights.h"
using namespace TMVA::DNN; using namespace TMVA::DNN;
using namespace TMVA::DNN::CNN; using namespace TMVA::DNN::CNN;
using Matrix_t = typename TReference<double>::Matrix_t;
/************************************************************************* int main()
* Test 1:
* filter depth = 3, filter height = 2, filter width = 2, num. filters = 4
*************************************************************************/
void test1()
{ {
double weightsTest1[][12] = {{252, 116, 155, 246, 170, 149, 227, 113, 166, 227, 119, 57}, using Scalar_t = Double_t;
{92, 103, 151, 37, 110, 46, 70, 8, 88, 182, 43, 236},
{153, 246, 216, 102, 179, 248, 187, 227, 66, 102, 180, 169},
{5, 215, 115, 103, 35, 138, 193, 28, 213, 93, 117, 208}};
double answerTest1[][16] = {{246, 155, 116, 252, 37, 151, 103, 92, 102, 216, 246, 153, 103, 115, 215, 5},
{113, 227, 149, 170, 8, 70, 46, 110, 227, 187, 248, 179, 28, 193, 138, 35},
{57, 119, 227, 166, 236, 43, 182, 88, 169, 180, 102, 66, 208, 117, 93, 213}};
size_t filterDepthTest1 = 3;
size_t filterHeightTest1 = 2;
size_t filterWidthTest1 = 2;
size_t numFiltersTest1 = 4;
Matrix_t A(numFiltersTest1, filterDepthTest1 * filterHeightTest1 * filterWidthTest1); std::cout << "Testing Rotate Weights function on a Reference architecture:" << std::endl;
for (size_t i = 0; i < (size_t)A.GetNrows(); i++) { bool status = true;
for (size_t j = 0; j < (size_t)A.GetNcols(); j++) {
A(i, j) = weightsTest1[i][j];
}
}
Matrix_t B(filterDepthTest1, numFiltersTest1 * filterHeightTest1 * filterWidthTest1);
for (size_t i = 0; i < (size_t)B.GetNrows(); i++) { std::cout << "Test 1: " << std::endl;
for (size_t j = 0; j < (size_t)B.GetNcols(); j++) { status &= test1<TReference<Scalar_t>>();
B(i, j) = answerTest1[i][j]; if (!status) {
} std::cerr << "ERROR - Forward-Propagation 1 failed " << std::endl;
return -1;
} }
bool status = testRotateWeights<TReference<double>>(A, B, filterDepthTest1, filterHeightTest1, filterWidthTest1, std::cout << "All tests passed!" << std::endl;
numFiltersTest1);
if (status) }
std::cout << "Test passed!" << std::endl; \ No newline at end of file
else
std::cout << "Test not passed!" << std::endl;
}
int main()
{
std::cout << "Testing Rotate Weights function:" << std::endl;
std::cout << "Test 1: " << std::endl;
test1();
}
// @(#)root/tmva/tmva/cnn:$Id$
// Author: Manos Stergiadis
/**********************************************************************************
* Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
* Package: TMVA *
* Class : *
* Web : http://tmva.sourceforge.net *
* *
* Description: *
* Testing RotateWeights method on a CPU architecture *
* *
* Authors (alphabetical): *
* Manos Stergiadis <em.stergiadis@gmail.com> - CERN, Switzerland *
* *
* Copyright (c) 2005-2015: *
* CERN, Switzerland *
* U. of Victoria, Canada *
* MPI-K Heidelberg, Germany *
* U. of Bonn, Germany *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted according to the terms listed in LICENSE *
* (http://tmva.sourceforge.net/LICENSE) *
**********************************************************************************/
////////////////////////////////////////////////////////////////////
// Testing the Rotate Weights function //
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
#include "TestConvNet.h"
using namespace TMVA::DNN;
using namespace TMVA::DNN::CNN;
/*************************************************************************
* Test 1:
* filter depth = 3, filter height = 2, filter width = 2, num. filters = 4
*************************************************************************/
template<typename Architecture>
bool test1()
{
using Matrix_t = typename Architecture::Matrix_t;
double weights[][12] = {{252, 116, 155, 246, 170, 149, 227, 113, 166, 227, 119, 57},
{92, 103, 151, 37, 110, 46, 70, 8, 88, 182, 43, 236},
{153, 246, 216, 102, 179, 248, 187, 227, 66, 102, 180, 169},
{5, 215, 115, 103, 35, 138, 193, 28, 213, 93, 117, 208}};
double answer[][16] = {{246, 155, 116, 252, 37, 151, 103, 92, 102, 216, 246, 153, 103, 115, 215, 5},
{113, 227, 149, 170, 8, 70, 46, 110, 227, 187, 248, 179, 28, 193, 138, 35},
{57, 119, 227, 166, 236, 43, 182, 88, 169, 180, 102, 66, 208, 117, 93, 213}};
size_t filterDepth = 3;
size_t filterHeight = 2;
size_t filterWidth = 2;
size_t numFilters = 4;
Matrix_t A(numFilters, filterDepth * filterHeight * filterWidth);
for (size_t i = 0; i < (size_t)A.GetNrows(); i++) {
for (size_t j = 0; j < (size_t)A.GetNcols(); j++) {
A(i, j) = weights[i][j];
}
}
Matrix_t B(filterDepth, numFilters * filterHeight * filterWidth);
for (size_t i = 0; i < (size_t)B.GetNrows(); i++) {
for (size_t j = 0; j < (size_t)B.GetNcols(); j++) {
B(i, j) = answer[i][j];
}
}
return testRotateWeights<Architecture>(A, B, filterDepth, filterHeight, filterWidth, numFilters);
}
/*************************************************************************
* Test 2:
* filter depth = 2, filter height = 2, filter width = 3, num. filters = 4
*************************************************************************/
template<typename Architecture>
bool test2()
{
using Matrix_t = typename Architecture::Matrix_t;
double input[][12] = {{252, 116, 155, 246, 170, 149, 227, 113, 166, 227, 119, 57},
{92, 103, 151, 37, 110, 46, 70, 8, 88, 182, 43, 236},
{153, 246, 216, 102, 179, 248, 187, 227, 66, 102, 180, 169},
{5, 215, 115, 103, 35, 138, 193, 28, 213, 93, 117, 208}};
double output[][24] = {{149,170,246,155,116,252,46,110,37,151,103,92,248,179,102,216,246,153,138,35,103,115,215,5},
{57,119,227,166,113,227,236,43,182,88,8,70,169,180,102,66,227,187,208,117,93,213,28,193}};
size_t filterDepth = 2;
size_t filterHeight = 2;
size_t filterWidth = 3;
size_t numFilters = 4;
Matrix_t A(numFilters, filterDepth * filterHeight * filterWidth);
for (size_t i = 0; i < (size_t)A.GetNrows(); i++) {
for (size_t j = 0; j < (size_t)A.GetNcols(); j++) {
A(i, j) = input[i][j];
}
}
Matrix_t B(filterDepth, numFilters * filterHeight * filterWidth);
for (size_t i = 0; i < (size_t)B.GetNrows(); i++) {
for (size_t j = 0; j < (size_t)B.GetNcols(); j++) {
B(i, j) = output[i][j];
}
}
return testRotateWeights<Architecture>(A, B, filterDepth, filterHeight, filterWidth, numFilters);
}
\ No newline at end of file
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* * * *
* Authors (alphabetical): * * Authors (alphabetical): *
* Vladimir Ilievski <ilievski.vladimir@live.com> - CERN, Switzerland * * Vladimir Ilievski <ilievski.vladimir@live.com> - CERN, Switzerland *
* Manos Stergiadis <em.stergiadis@gmail.com> - CERN, Switzerland *
* * * *
* Copyright (c) 2005-2015: * * Copyright (c) 2005-2015: *
* CERN, Switzerland * * CERN, Switzerland *
...@@ -25,68 +26,40 @@ ...@@ -25,68 +26,40 @@
**********************************************************************************/ **********************************************************************************/
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Testing the Rotate Weights function // // Testing the Rotate Weights function on the CPU //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include "TMVA/DNN/Architectures/Cpu.h" #include "TMVA/DNN/Architectures/Cpu.h"
#include "TestConvNet.h" #include "TestRotateWeights.h"
using namespace TMVA::DNN; using namespace TMVA::DNN;
using namespace TMVA::DNN::CNN; using namespace TMVA::DNN::CNN;
using Matrix_t = typename TCpu<double>::Matrix_t;
/************************************************************************* int main()
* Test 1:
* filter depth = 3, filter height = 2, filter width = 2, num. filters = 4
*************************************************************************/
void test1()
{ {
double weightsTest1[][12] = {{252, 116, 155, 246, 170, 149, 227, 113, 166, 227, 119, 57}, using Scalar_t = Double_t;
{92, 103, 151, 37, 110, 46, 70, 8, 88, 182, 43, 236},
{153, 246, 216, 102, 179, 248, 187, 227, 66, 102, 180, 169},
{5, 215, 115, 103, 35, 138, 193, 28, 213, 93, 117, 208}};
double answerTest1[][16] = {{246, 155, 116, 252, 37, 151, 103, 92, 102, 216, 246, 153, 103, 115, 215, 5},
{113, 227, 149, 170, 8, 70, 46, 110, 227, 187, 248, 179, 28, 193, 138, 35},
{57, 119, 227, 166, 236, 43, 182, 88, 169, 180, 102, 66, 208, 117, 93, 213}};
size_t filterDepthTest1 = 3; std::cout << "Testing Rotate Weights function on a CPU architecture:" << std::endl;
size_t filterHeightTest1 = 2;
size_t filterWidthTest1 = 2;
size_t numFiltersTest1 = 4;
Matrix_t A(numFiltersTest1, filterDepthTest1 * filterHeightTest1 * filterWidthTest1); bool status = true;
for (size_t i = 0; i < (size_t)A.GetNrows(); i++) { std::cout << "Test 1: " << std::endl;
for (size_t j = 0; j < (size_t)A.GetNcols(); j++) { status &= test1<TCpu<Scalar_t>>();
A(i, j) = weightsTest1[i][j]; if (!status) {
} std::cerr << "ERROR - Forward-Propagation 1 failed " << std::endl;
return -1;
} }
Matrix_t B(filterDepthTest1, numFiltersTest1 * filterHeightTest1 * filterWidthTest1); std::cout << "Test 2: " << std::endl;
status &= test2<TCpu<Scalar_t>>();
for (size_t i = 0; i < (size_t)B.GetNrows(); i++) { if (!status) {
for (size_t j = 0; j < (size_t)B.GetNcols(); j++) { std::cerr << "ERROR - Forward-Propagation 1 failed " << std::endl;
B(i, j) = answerTest1[i][j]; return -1;
}
} }
bool status = std::cout << "All tests passed!" << std::endl;
testRotateWeights<TCpu<double>>(A, B, filterDepthTest1, filterHeightTest1, filterWidthTest1, numFiltersTest1);
if (status)
std::cout << "Test passed!" << std::endl;
else
std::cout << "Test not passed!" << std::endl;
}
int main()
{
std::cout << "Testing Rotate Weights function on a CPU architecture:" << std::endl;
std::cout << "Test 1: " << std::endl;
test1();
} }
// @(#)root/tmva/tmva/cnn:$Id$
// Author: Manos Stergiadis
/**********************************************************************************
* Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
* Package: TMVA *
* Class : *
* Web : http://tmva.sourceforge.net *
* *
* Description: *
* Testing RotateWeights method on a CPU architecture *
* *
* Authors (alphabetical): *
* Manos Stergiadis <em.stergiadis@gmail.com> - CERN, Switzerland *
* *
* Copyright (c) 2005-2015: *
* CERN, Switzerland *
* U. of Victoria, Canada *
* MPI-K Heidelberg, Germany *
* U. of Bonn, Germany *
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted according to the terms listed in LICENSE *
* (http://tmva.sourceforge.net/LICENSE) *
**********************************************************************************/
#include <iostream>
#include <cmath>
#include "TMVA/DNN/Architectures/Cuda.h"
#include "TestRotateWeights.h"
using namespace TMVA::DNN;
using namespace TMVA::DNN::CNN;
int main()
{
using Scalar_t = Double_t;
std::cout << "Testing Rotate Weights function on a GPU architecture:" << std::endl;
bool status = true;
std::cout << "Test 1: " << std::endl;
status &= test1<TCuda<Scalar_t>>();
if (!status) {
std::cerr << "ERROR - Rotate Weights failed " << std::endl;
return -1;
}
std::cout << "Test 2: " << std::endl;
status &= test2<TCuda<Scalar_t>>();
if (!status) {
std::cerr << "ERROR - Rotate Weights failed " << std::endl;
return -1;
}
std::cout << "All tests passed!" << std::endl;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment