Commit acd7e541 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated testresults

parent 0a048ab4
......@@ -18,7 +18,7 @@
<monticore.version>4.5.3-SNAPSHOT</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<SIUnit.version>0.0.7</SIUnit.version>
<SIUnit.version>0.0.10-SNAPSHOT</SIUnit.version>
<Common-MontiCar.version>0.0.7</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.8</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.8</Embedded-MontiArc-Behaviour.version>
......
......@@ -113,7 +113,9 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l0");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/detectionObjectDetector"+number+"/l0/";
testFilesAreEqual(files, restPath);
}
private void testObjectDetectorInstancingL1(int number) throws IOException {
......@@ -125,7 +127,9 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
generatorCPP.setUseAlgebraicOptimizations(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l1");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/detectionObjectDetector"+number+"/l1/";
testFilesAreEqual(files, restPath);
}
private void testObjectDetectorInstancingL2(int number) throws IOException {
......@@ -137,7 +141,9 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
generatorCPP.setUseThreadingOptimization(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l2");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/detectionObjectDetector"+number+"/l2/";
testFilesAreEqual(files, restPath);
}
......@@ -150,6 +156,8 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
generatorCPP.setUseThreadingOptimization(true);
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector"+number+"/l3");
generatorCPP.generateFiles(symtab, componentSymbol, symtab);
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "armadillo/detectionObjectDetector"+number+"/l3/";
testFilesAreEqual(files, restPath);
}
}
#ifndef HELPERA_H
#define HELPERA_H
#define _GLIBCXX_USE_CXX11_ABI 0
#include <iostream>
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
using namespace arma;
class HelperA{
public:
static mat getEigenVectors(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenVectors;
}
static vec getEigenValues(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenValues;
}
static mat getKMeansClusters(mat A, int k){
mat clusters;
kmeans(clusters,A.t(),k,random_subset,20,true);
printf("cluster centroid calculation done\n");
std::ofstream myfile;
myfile.open("data after cluster.txt");
myfile << A;
myfile.close();
std::ofstream myfile2;
myfile2.open("cluster centroids.txt");
myfile2 << clusters;
myfile2.close();
mat indexedData=getKMeansClustersIndexData(A.t(), clusters);
std::ofstream myfile3;
myfile3.open("data after index.txt");
myfile3 << indexedData;
myfile3.close();
return indexedData;
}
static mat getKMeansClustersIndexData(mat A, mat centroids){
mat result=mat(A.n_cols, 1);
for(int i=0;i<A.n_cols;++i){
result(i, 0) = getIndexForClusterCentroids(A, i, centroids);
}
return result;
}
static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){
int index=1;
double lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);
for(int i=1;i<centroids.n_cols;++i){
double curDistance=getEuclideanDistance(A, colIndex, centroids, i);
if(curDistance<lowestDistance){
lowestDistance=curDistance;
index=i+1;
}
}
return index;
}
static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){
double distance=0;
for(int i=0;i<A.n_rows;++i){
double elementA=A(i,colIndexA);
double elementB=B(i,colIndexB);
double diff=elementA-elementB;
distance+=diff*diff;
}
return sqrt(distance);
}
static mat getSqrtMat(mat A){
cx_mat result=sqrtmat(A);
return real(result);
}
static mat invertDiagMatrix(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = 1/curVal;
}
return A;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1
#define DETECTION_OBJECTDETECTOR1
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "detection_objectDetector1_spectralClusterer.h"
using namespace arma;
class detection_objectDetector1{
public:
mat imgFront;
mat clusters;
detection_objectDetector1_spectralClusterer spectralClusterer;
void init()
{
imgFront=mat(2500,3);
clusters=mat(2500,1);
spectralClusterer.init();
}
void execute()
{
spectralClusterer.imgMatrix = imgFront;
spectralClusterer.execute();
clusters = spectralClusterer.clusters;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "detection_objectDetector1_spectralClusterer_similarity.h"
#include "detection_objectDetector1_spectralClusterer_normalizedLaplacian.h"
#include "detection_objectDetector1_spectralClusterer_eigenSolver.h"
#include "detection_objectDetector1_spectralClusterer_kMeansClustering.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer{
const int n = 2500;
const int k = 4;
const int maximumClusters = 4;
public:
mat imgMatrix;
mat clusters;
detection_objectDetector1_spectralClusterer_similarity similarity;
detection_objectDetector1_spectralClusterer_normalizedLaplacian normalizedLaplacian;
detection_objectDetector1_spectralClusterer_eigenSolver eigenSolver;
detection_objectDetector1_spectralClusterer_kMeansClustering kMeansClustering;
void init()
{
imgMatrix=mat(n*n,3);
clusters=mat(n,maximumClusters);
similarity.init();
normalizedLaplacian.init();
eigenSolver.init();
kMeansClustering.init();
}
void execute()
{
similarity.data = imgMatrix;
similarity.execute();
normalizedLaplacian.degree = similarity.degree;
normalizedLaplacian.W = similarity.similarity;
normalizedLaplacian.execute();
eigenSolver.matrix = normalizedLaplacian.nLaplacian;
eigenSolver.execute();
kMeansClustering.vectors = eigenSolver.eigenvectors;
kMeansClustering.execute();
clusters = kMeansClustering.clusters;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_EIGENSOLVER
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_EIGENSOLVER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "HelperA.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer_eigenSolver{
const int n = 2500;
const int targetEigenvectors = 4;
public:
mat matrix;
mat eigenvectors;
void init()
{
matrix=mat(n,n);
eigenvectors=mat(n,targetEigenvectors);
}
void execute()
{
mat eigenVectors = (HelperA::getEigenVectors((matrix)));
double counter = 1;
double start = (eigenVectors.n_cols)-(targetEigenvectors-1);
for( auto i=start;i<=(eigenVectors.n_rows);++i){
eigenvectors.col(counter-1) = eigenVectors.col(i-1);
counter = counter+1;
}
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_KMEANSCLUSTERING
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_KMEANSCLUSTERING
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "HelperA.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer_kMeansClustering{
const int n = 2500;
const int amountVectors = 4;
const int maximumClusters = 4;
public:
mat vectors;
mat clusters;
void init()
{
vectors=mat(n,amountVectors);
clusters=mat(n,1);
}
void execute()
{
mat UMatrix=mat(n,amountVectors);
for( auto i=1;i<=(vectors.n_rows);++i){
rowvec target = pow(vectors.row(i-1),2);
double amount = (sqrt((accu(target))));
UMatrix.row(i-1) = vectors.row(i-1)/amount;
}
clusters = (HelperA::getKMeansClusters(UMatrix, maximumClusters));
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_NORMALIZEDLAPLACIAN
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_NORMALIZEDLAPLACIAN
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "HelperA.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer_normalizedLaplacian{
const int n = 2500;
public:
mat degree;
mat W;
mat nLaplacian;
void init()
{
degree=mat(n,n);
W=mat(n,n);
nLaplacian=mat(n,n);
}
void execute()
{
nLaplacian = (HelperA::getSqrtMat((inv(degree))))*W*(HelperA::getSqrtMat((inv(degree))));
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_SIMILARITY
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_SIMILARITY
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "HelperA.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer_similarity{
const int n = 2500;
public:
mat data;
mat similarity;
mat degree;
void init()
{
data=mat(n,3);
similarity=mat(n,n);
degree=mat(n,n);
}
void execute()
{
for( auto i=1;i<=(data.n_rows);++i){
for( auto j=1;j<=(data.n_rows);++j){
double dist = (sqrt((data(i-1, 1-1)-data(j-1, 1-1))*(data(i-1, 1-1)-data(j-1, 1-1))+(data(i-1, 2-1)-data(j-1, 2-1))*(data(i-1, 2-1)-data(j-1, 2-1))+(data(i-1, 3-1)-data(j-1, 3-1))*(data(i-1, 3-1)-data(j-1, 3-1))));
similarity(i-1, j-1) = (exp((0-dist)/(2)));
}
}
for( auto k=1;k<=(similarity.n_rows);++k){
degree(k-1, k-1) = (accu(similarity.row(k-1)));
}
}
};
#endif
#ifndef HELPERA_H
#define HELPERA_H
#define _GLIBCXX_USE_CXX11_ABI 0
#include <iostream>
#include "armadillo.h"
#include <stdarg.h>
#include <initializer_list>
using namespace arma;
class HelperA{
public:
static mat getEigenVectors(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenVectors;
}
static vec getEigenValues(mat A){
vec eigenValues;
mat eigenVectors;
eig_sym(eigenValues,eigenVectors,A);
return eigenValues;
}
static mat getKMeansClusters(mat A, int k){
mat clusters;
kmeans(clusters,A.t(),k,random_subset,20,true);
printf("cluster centroid calculation done\n");
std::ofstream myfile;
myfile.open("data after cluster.txt");
myfile << A;
myfile.close();
std::ofstream myfile2;
myfile2.open("cluster centroids.txt");
myfile2 << clusters;
myfile2.close();
mat indexedData=getKMeansClustersIndexData(A.t(), clusters);
std::ofstream myfile3;
myfile3.open("data after index.txt");
myfile3 << indexedData;
myfile3.close();
return indexedData;
}
static mat getKMeansClustersIndexData(mat A, mat centroids){
mat result=mat(A.n_cols, 1);
for(int i=0;i<A.n_cols;++i){
result(i, 0) = getIndexForClusterCentroids(A, i, centroids);
}
return result;
}
static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){
int index=1;
double lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);
for(int i=1;i<centroids.n_cols;++i){
double curDistance=getEuclideanDistance(A, colIndex, centroids, i);
if(curDistance<lowestDistance){
lowestDistance=curDistance;
index=i+1;
}
}
return index;
}
static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){
double distance=0;
for(int i=0;i<A.n_rows;++i){
double elementA=A(i,colIndexA);
double elementB=B(i,colIndexB);
double diff=elementA-elementB;
distance+=diff*diff;
}
return sqrt(distance);
}
static mat getSqrtMat(mat A){
cx_mat result=sqrtmat(A);
return real(result);
}
static mat invertDiagMatrix(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = 1/curVal;
}
return A;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1
#define DETECTION_OBJECTDETECTOR1
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "detection_objectDetector1_spectralClusterer.h"
using namespace arma;
class detection_objectDetector1{
public:
mat imgFront;
mat clusters;
detection_objectDetector1_spectralClusterer spectralClusterer;
void init()
{
imgFront=mat(2500,3);
clusters=mat(2500,1);
spectralClusterer.init();
}
void execute()
{
spectralClusterer.imgMatrix = imgFront;
spectralClusterer.execute();
clusters = spectralClusterer.clusters;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "detection_objectDetector1_spectralClusterer_similarity.h"
#include "detection_objectDetector1_spectralClusterer_normalizedLaplacian.h"
#include "detection_objectDetector1_spectralClusterer_eigenSolver.h"
#include "detection_objectDetector1_spectralClusterer_kMeansClustering.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer{
const int n = 2500;
const int k = 4;
const int maximumClusters = 4;
public:
mat imgMatrix;
mat clusters;
detection_objectDetector1_spectralClusterer_similarity similarity;
detection_objectDetector1_spectralClusterer_normalizedLaplacian normalizedLaplacian;
detection_objectDetector1_spectralClusterer_eigenSolver eigenSolver;
detection_objectDetector1_spectralClusterer_kMeansClustering kMeansClustering;
void init()
{
imgMatrix=mat(n*n,3);
clusters=mat(n,maximumClusters);
similarity.init();
normalizedLaplacian.init();
eigenSolver.init();
kMeansClustering.init();
}
void execute()
{
similarity.data = imgMatrix;
similarity.execute();
normalizedLaplacian.degree = similarity.degree;
normalizedLaplacian.W = similarity.similarity;
normalizedLaplacian.execute();
eigenSolver.matrix = normalizedLaplacian.nLaplacian;
eigenSolver.execute();
kMeansClustering.vectors = eigenSolver.eigenvectors;
kMeansClustering.execute();
clusters = kMeansClustering.clusters;
}
};
#endif
#ifndef DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_EIGENSOLVER
#define DETECTION_OBJECTDETECTOR1_SPECTRALCLUSTERER_EIGENSOLVER
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "armadillo.h"
#include "HelperA.h"
using namespace arma;
class detection_objectDetector1_spectralClusterer_eigenSolver{
const int n = 2500;
const int targetEigenvectors = 4;
public:
mat matrix;
mat eigenvectors;
void init()
{
matrix=mat(n,n);
eigenvectors=mat(n,targetEigenvectors);
}
void execute()
{
mat eigenVectors = (HelperA::getEigenVectors((matrix)));
double counter = 1;
double start = (eigenVectors.n_cols)-(targetEigenvectors-1);
for( auto i=start;i<=(eigenVectors.n_rows);++i){
eigenvectors.col(counter-1) = eigenVectors.col(i-1);