Commit e0a54f03 authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Fix naming

parent 7744bd09
Pipeline #394728 passed with stage
in 15 minutes and 3 seconds
/*
* (c) https://github.com/MontiCore/monticore
*/
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp.armadillo;
......@@ -215,7 +219,7 @@ public class BasicGenerationArmadilloTest extends AbstractSymtabTest {
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/armadillo/detectionObjectDetector" + number + "/l0");
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol);
String restPath = "armadillo/detectionObjectDetector" + number + "/l0/";
// testFilesAreEqual(files, restPath);
testFilesAreEqual(files, restPath);
}
private void testObjectDetectorInstancingL1(int number) throws IOException {
......
......@@ -5,7 +5,49 @@
#include "armadillo"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......@@ -77,12 +119,8 @@ static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){
}
static mat getSqrtMat(mat A){
for(int i=0;i<A.n_rows;++i){
double curVal = A(i,i);
A(i,i) = sqrt(curVal);
}
return A;
cx_mat result=sqrtmat(A);
return real(result);
}
static mat getSqrtMatDiag(mat A){
......
......@@ -9,18 +9,34 @@
using namespace arma;
class detection_objectDetector{
public:
mat imgFront;
mat imgBack;
mat imgLeft;
mat imgRight;
mat red1;
mat green1;
mat blue1;
mat red2;
mat green2;
mat blue2;
mat red3;
mat green3;
mat blue3;
mat red4;
mat green4;
mat blue4;
mat clusters[4];
detection_objectDetector_spectralClusterer_1_ spectralClusterer[4];
void init()
{
imgFront=mat(2500,3);
imgBack=mat(2500,3);
imgLeft=mat(2500,3);
imgRight=mat(2500,3);
red1=mat(50,50);
green1=mat(50,50);
blue1=mat(50,50);
red2=mat(50,50);
green2=mat(50,50);
blue2=mat(50,50);
red3=mat(50,50);
green3=mat(50,50);
blue3=mat(50,50);
red4=mat(50,50);
green4=mat(50,50);
blue4=mat(50,50);
clusters[0]=mat(2500,1);
clusters[1]=mat(2500,1);
clusters[2]=mat(2500,1);
......@@ -32,18 +48,54 @@ spectralClusterer[3].init();
}
void execute()
{
spectralClusterer[0].imgMatrix = imgFront;
spectralClusterer[0].execute();
spectralClusterer[1].imgMatrix = imgRight;
spectralClusterer[1].execute();
spectralClusterer[2].imgMatrix = imgLeft;
spectralClusterer[2].execute();
spectralClusterer[3].imgMatrix = imgBack;
spectralClusterer[3].execute();
clusters[0] = spectralClusterer[0].clusters;
clusters[1] = spectralClusterer[1].clusters;
clusters[2] = spectralClusterer[2].clusters;
clusters[3] = spectralClusterer[3].clusters;
spectralClusterer[0].similarity.red = red1;
spectralClusterer[0].similarity.green = green1;
spectralClusterer[0].similarity.blue = blue1;
spectralClusterer[1].similarity.red = red2;
spectralClusterer[1].similarity.green = green2;
spectralClusterer[1].similarity.blue = blue2;
spectralClusterer[2].similarity.red = red3;
spectralClusterer[2].similarity.green = green3;
spectralClusterer[2].similarity.blue = blue3;
spectralClusterer[3].similarity.red = red4;
spectralClusterer[3].similarity.green = green4;
spectralClusterer[3].similarity.blue = blue4;
spectralClusterer[0].similarity.execute();
spectralClusterer[0].normalizedLaplacian.similarity = spectralClusterer[0].similarity.similarity;
spectralClusterer[0].normalizedLaplacian.degree = spectralClusterer[0].similarity.degree;
spectralClusterer[1].similarity.execute();
spectralClusterer[1].normalizedLaplacian.similarity = spectralClusterer[1].similarity.similarity;
spectralClusterer[1].normalizedLaplacian.degree = spectralClusterer[1].similarity.degree;
spectralClusterer[2].similarity.execute();
spectralClusterer[2].normalizedLaplacian.similarity = spectralClusterer[2].similarity.similarity;
spectralClusterer[2].normalizedLaplacian.degree = spectralClusterer[2].similarity.degree;
spectralClusterer[3].similarity.execute();
spectralClusterer[3].normalizedLaplacian.similarity = spectralClusterer[3].similarity.similarity;
spectralClusterer[3].normalizedLaplacian.degree = spectralClusterer[3].similarity.degree;
spectralClusterer[0].normalizedLaplacian.execute();
spectralClusterer[0].eigenSolver.matrix = spectralClusterer[0].normalizedLaplacian.nLaplacian;
spectralClusterer[1].normalizedLaplacian.execute();
spectralClusterer[1].eigenSolver.matrix = spectralClusterer[1].normalizedLaplacian.nLaplacian;
spectralClusterer[2].normalizedLaplacian.execute();
spectralClusterer[2].eigenSolver.matrix = spectralClusterer[2].normalizedLaplacian.nLaplacian;
spectralClusterer[3].normalizedLaplacian.execute();
spectralClusterer[3].eigenSolver.matrix = spectralClusterer[3].normalizedLaplacian.nLaplacian;
spectralClusterer[0].eigenSolver.execute();
spectralClusterer[0].kMeansClustering.vectors = spectralClusterer[0].eigenSolver.eigenvectors;
spectralClusterer[1].eigenSolver.execute();
spectralClusterer[1].kMeansClustering.vectors = spectralClusterer[1].eigenSolver.eigenvectors;
spectralClusterer[2].eigenSolver.execute();
spectralClusterer[2].kMeansClustering.vectors = spectralClusterer[2].eigenSolver.eigenvectors;
spectralClusterer[3].eigenSolver.execute();
spectralClusterer[3].kMeansClustering.vectors = spectralClusterer[3].eigenSolver.eigenvectors;
spectralClusterer[0].kMeansClustering.execute();
clusters[0] = spectralClusterer[0].kMeansClustering.clusters;
spectralClusterer[1].kMeansClustering.execute();
clusters[1] = spectralClusterer[1].kMeansClustering.clusters;
spectralClusterer[2].kMeansClustering.execute();
clusters[2] = spectralClusterer[2].kMeansClustering.clusters;
spectralClusterer[3].kMeansClustering.execute();
clusters[3] = spectralClusterer[3].kMeansClustering.clusters;
}
};
......
......@@ -11,11 +11,14 @@
#include "detection_objectDetector_spectralClusterer_1__kMeansClustering.h"
using namespace arma;
class detection_objectDetector_spectralClusterer_1_{
const int n = 2500;
const int n = 50;
const int elements = 2500;
const int k = 4;
const int maximumClusters = 4;
const int maximumClusters = 1;
public:
mat imgMatrix;
mat red;
mat green;
mat blue;
mat clusters;
detection_objectDetector_spectralClusterer_1__similarity similarity;
detection_objectDetector_spectralClusterer_1__normalizedLaplacian normalizedLaplacian;
......@@ -23,8 +26,10 @@ detection_objectDetector_spectralClusterer_1__eigenSolver eigenSolver;
detection_objectDetector_spectralClusterer_1__kMeansClustering kMeansClustering;
void init()
{
imgMatrix=mat(n*n,3);
clusters=mat(n,maximumClusters);
red=mat(n,n);
green=mat(n,n);
blue=mat(n,n);
clusters=mat(elements,maximumClusters);
similarity.init();
normalizedLaplacian.init();
eigenSolver.init();
......@@ -32,16 +37,6 @@ 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;
}
};
......
......@@ -10,7 +10,7 @@ using namespace arma;
class detection_objectDetector_spectralClusterer_1__kMeansClustering{
const int n = 2500;
const int amountVectors = 4;
const int maximumClusters = 4;
const int maximumClusters = 1;
public:
mat vectors;
mat clusters;
......
......@@ -11,17 +11,17 @@ class detection_objectDetector_spectralClusterer_1__normalizedLaplacian{
const int n = 2500;
public:
mat degree;
mat W;
mat similarity;
mat nLaplacian;
void init()
{
degree=mat(n,n);
W=mat(n,n);
similarity=mat(n,n);
nLaplacian=mat(n,n);
}
void execute()
{
nLaplacian = (HelperA::getSqrtMat((inv(degree))))*W*(HelperA::getSqrtMat((inv(degree))));
nLaplacian = (HelperA::getSqrtMat((inv(degree))))*similarity*(HelperA::getSqrtMat((inv(degree))));
}
};
......
......@@ -8,23 +8,35 @@
#include "HelperA.h"
using namespace arma;
class detection_objectDetector_spectralClusterer_1__similarity{
const int n = 2500;
const int n = 50;
public:
mat data;
mat red;
mat green;
mat blue;
mat similarity;
mat degree;
void init()
{
data=mat(n,3);
similarity=mat(n,n);
degree=mat(n,n);
red=mat(n,n);
green=mat(n,n);
blue=mat(n,n);
similarity=mat(n*n,n*n);
degree=mat(n*n,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)));
int counter2 = 1;
for( auto j=1;j<=(red.n_rows);++j){
for( auto i=1;i<=(red.n_rows);++i){
int counter1 = 1;
for( auto j2=1;j2<=(red.n_rows);++j2){
for( auto i2=1;i2<=(red.n_rows);++i2){
double dist = (sqrt((red(i-1, j-1)-red(i2-1, j2-1))*(red(i-1, j-1)-red(i2-1, j2-1))+(green(i-1, j-1)-green(i2-1, j2-1))*(green(i-1, j-1)-green(i2-1, j2-1))+(blue(i-1, j-1)-blue(i2-1, j2-1))*(blue(i-1, j-1)-blue(i2-1, j2-1))));
similarity(counter2-1, counter1-1) = (exp(-dist/(2)));
counter1 = counter1+1;
}
}
counter2 = counter2+1;
}
}
for( auto k=1;k<=(similarity.n_rows);++k){
......
......@@ -5,7 +5,49 @@
#include "armadillo"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......
......@@ -24,11 +24,18 @@ spectralClusterer.init();
}
void execute()
{
spectralClusterer.red = red1;
spectralClusterer.green = green1;
spectralClusterer.blue = blue1;
spectralClusterer.execute();
clusters = spectralClusterer.clusters;
spectralClusterer.similarity.red = red1;
spectralClusterer.similarity.green = green1;
spectralClusterer.similarity.blue = blue1;
spectralClusterer.similarity.execute();
spectralClusterer.normalizedLaplacian.similarity = spectralClusterer.similarity.similarity;
spectralClusterer.normalizedLaplacian.degree = spectralClusterer.similarity.degree;
spectralClusterer.normalizedLaplacian.execute();
spectralClusterer.eigenSolver.matrix = spectralClusterer.normalizedLaplacian.nLaplacian;
spectralClusterer.eigenSolver.execute();
spectralClusterer.kMeansClustering.vectors = spectralClusterer.eigenSolver.eigenvectors;
spectralClusterer.kMeansClustering.execute();
clusters = spectralClusterer.kMeansClustering.clusters;
}
};
......
......@@ -37,18 +37,6 @@ kMeansClustering.init();
}
void execute()
{
similarity.red = red;
similarity.green = green;
similarity.blue = blue;
similarity.execute();
normalizedLaplacian.degree = similarity.degree;
normalizedLaplacian.similarity = similarity.similarity;
normalizedLaplacian.execute();
eigenSolver.matrix = normalizedLaplacian.nLaplacian;
eigenSolver.execute();
kMeansClustering.vectors = eigenSolver.eigenvectors;
kMeansClustering.execute();
clusters = kMeansClustering.clusters;
}
};
......
......@@ -5,7 +5,49 @@
#include "armadillo"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......
......@@ -5,7 +5,49 @@
#include "armadillo"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std::ofstream& myfile, bool A){
myfile << A;
}
bool Is_close(mat& X, mat& Y, double tol)
{
// abs returns a mat type then max checks columns and returns a row_vec
// max used again will return the biggest element in the row_vec
bool close(false);
if(arma::max(arma::max(arma::abs(X-Y))) < tol)
{
close = true;
}
return close;
}
#endif
class HelperA{
public:
static mat getEigenVectors(mat A){
......
......@@ -5,7 +5,49 @@
#include "armadillo"
#include <stdarg.h>
#include <initializer_list>
#include <fstream>
using namespace arma;
#ifndef _FILESTRING_CONVERSION___A
#define _FILESTRING_CONVERSION___A
void toFileString(std::ofstream& myfile, mat A){
myfile << "[";
for (int i = 0; i < A.n_rows; i++){
for (int j = 0; j < A.n_cols; j++){
myfile << A(i,j);
if(j + 1 < A.n_cols){
myfile << ", ";
}
}
if(i + 1 < A.n_rows){
myfile << ";";
}
}
myfile << "]";
}
void toFileString(std::ofstream& myfile, double A){
myfile << A;
}
void toFileString(std::ofstream& myfile, float A){
myfile << A;
}
void toFileString(std::ofstream& myfile, int A){
myfile << A;
}
void toFileString(std