updated .exe and src file

This commit is contained in:
Kevin Becker 2018-05-31 10:02:59 +02:00
parent f48178dba2
commit aa84dad655
2 changed files with 243 additions and 233 deletions

Binary file not shown.

View File

@ -11,7 +11,7 @@ Created by Stefan Friese on 26.04.2018
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "nlms_types.h" // added types #include "nlms_types.h"
#define RGB_COLOR 255 #define RGB_COLOR 255
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -64,11 +64,11 @@ int main( int argc, char **argv ) {
unsigned k, include = 0; unsigned k, include = 0;
unsigned windowSize = 5; unsigned windowSize = 5;
unsigned samplesCount = 512; unsigned samplesCount = 512;
char *stdcolor = "green", xBuffer[512]; char *stdcolor = (char*)"green", xBuffer[512];
colorChannel = stdcolor; colorChannel = stdcolor;
unsigned int uint_buffer[1], windowBuffer[1]; unsigned int uint_buffer[1], windowBuffer[1];
double learnrate = 0.4; double learnrate = 0.4;
char *istrue = "true"; char *istrue = (char*)"true";
char *templatePath = NULL; char *templatePath = NULL;
while ((argc > 1) && (argv[1][0] == '-')) { // Parses parameters from stdin while ((argc > 1) && (argv[1][0] == '-')) { // Parses parameters from stdin
@ -113,10 +113,12 @@ int main( int argc, char **argv ) {
sscanf(&argv[1][3], "%s", xBuffer); sscanf(&argv[1][3], "%s", xBuffer);
if (strstr(xBuffer, istrue)) { if (strstr(xBuffer, istrue)) {
include = 1; include = 1;
} else if ( xBuffer && !strstr(xBuffer, istrue) ) { }
else if (xBuffer && !strstr(xBuffer, istrue)) {
templatePath = xBuffer; templatePath = xBuffer;
include = 1; include = 1;
} else { }
else {
printf("Wrong Argruments: %s\n", argv[1]); printf("Wrong Argruments: %s\n", argv[1]);
usage(argv); usage(argv);
} }
@ -149,7 +151,8 @@ int main( int argc, char **argv ) {
if ((seed != NULL)) { if ((seed != NULL)) {
srand(*seed); // Seed for random number generating srand(*seed); // Seed for random number generating
printf("srand is reproducable\n"); printf("srand is reproducable\n");
} else { }
else {
srand((unsigned int)time(NULL)); srand((unsigned int)time(NULL));
printf("srand depends on time\n"); // Default seed is time(NULL) printf("srand depends on time\n"); // Default seed is time(NULL)
} }
@ -197,8 +200,10 @@ void localMean ( mldata_t *mlData, point_t points[] ) {
localWeights = mlData->weights; localWeights = mlData->weights;
char fileName[50]; char fileName[50];
const unsigned xErrorLength = mlData->samplesCount; unsigned xErrorLength = mlData->samplesCount;
double xError[xErrorLength]; double *xError = (double *)malloc(sizeof(double) * xErrorLength+1);
memset(xError, 0.0, sizeof(double) * xErrorLength);
unsigned i, xCount = 0; // Runtime vars unsigned i, xCount = 0; // Runtime vars
mkFileName(fileName, sizeof(fileName), LOCAL_MEAN); // Create Logfile and its filename mkFileName(fileName, sizeof(fileName), LOCAL_MEAN); // Create Logfile and its filename
@ -277,7 +282,8 @@ void directPredecessor( mldata_t *mlData, point_t points[]) {
char fileName[512]; char fileName[512];
const unsigned xErrorLength = mlData->samplesCount; const unsigned xErrorLength = mlData->samplesCount;
double xError[xErrorLength]; double *xError = (double *)malloc(sizeof(double) * xErrorLength);
memset(xError, 0.0, sizeof(double) * xErrorLength);
unsigned xCount = 0, i; unsigned xCount = 0, i;
double xActual = 0.0; double xActual = 0.0;
double xPredicted = 0.0; double xPredicted = 0.0;
@ -350,7 +356,8 @@ void differentialPredecessor ( mldata_t *mlData, point_t points[] ) {
localWeights = mlData->weights; localWeights = mlData->weights;
const unsigned xErrorLength = mlData->samplesCount; const unsigned xErrorLength = mlData->samplesCount;
char fileName[512]; char fileName[512];
double xError[xErrorLength]; double *xError = (double *)malloc(sizeof(double) * xErrorLength);
memset(xError, 0.0, sizeof(double) * xErrorLength);
unsigned xCount = 0, i; unsigned xCount = 0, i;
double xPredicted = 0.0; double xPredicted = 0.0;
@ -402,7 +409,6 @@ void differentialPredecessor ( mldata_t *mlData, point_t points[] ) {
double mean = sum_array(xError, xErrorLength) / xErrorLength; double mean = sum_array(xError, xErrorLength) / xErrorLength;
double deviation = 0.0; double deviation = 0.0;
for (i = 1; i < xErrorLength; i++) { // Mean square for (i = 1; i < xErrorLength; i++) { // Mean square
deviation += pow(xError[i] - mean, 2); deviation += pow(xError[i] - mean, 2);
} }
@ -445,15 +451,15 @@ Contains and returns every suffix for all existing filenames
====================================================================================================== ======================================================================================================
*/ */
char * fileSuffix(int id) { char * fileSuffix(int id) {
char * suffix[] = { "_weights_pure.txt", char * suffix[] = { (char*)"_weights_pure.txt",
"_weights_used_dir_pred_.txt", (char*)"_weights_used_dir_pred_.txt",
"_direct_predecessor.txt", (char*)"_direct_predecessor.txt",
"_ergebnisse.txt", (char*)"_ergebnisse.txt",
"_localMean.txt", (char*)"_localMean.txt",
"_testvalues.txt", (char*)"_testvalues.txt",
"_differential_predecessor.txt", (char*)"_differential_predecessor.txt",
"_weights_used_local_mean.txt", (char*)"_weights_used_local_mean.txt",
"_weights_used_diff_pred.txt", (char*)"_weights_used_diff_pred.txt",
}; };
return suffix[id]; return suffix[id];
} }
@ -468,9 +474,9 @@ Contains and returns header from logfiles
====================================================================================================== ======================================================================================================
*/ */
char * fileHeader(int id) { char * fileHeader(int id) {
char * header[] = { "\n=========================== Local Mean ===========================\nNo.\txPredicted\txAcutal\t\txError\n", char * header[] = { (char*)"\n=========================== Local Mean ===========================\nNo.\txPredicted\txAcutal\t\txError\n",
"\n=========================== Direct Predecessor ===========================\nNo.\txPredicted\txAcutal\t\txError\n", (char*)"\n=========================== Direct Predecessor ===========================\nNo.\txPredicted\txAcutal\t\txError\n",
"\n=========================== Differential Predecessor ===========================\nNo.\txPredicted\txAcutal\t\txError\n" (char*)"\n=========================== Differential Predecessor ===========================\nNo.\txPredicted\txAcutal\t\txError\n"
}; };
return header[id]; return header[id];
} }
@ -599,7 +605,8 @@ void mkSvgGraph(point_t points[], char *templatePath) {
if (templatePath) { if (templatePath) {
printf("\ngraph template src at: %s\n", templatePath); printf("\ngraph template src at: %s\n", templatePath);
input = fopen(templatePath, "r"); input = fopen(templatePath, "r");
} else { }
else {
input = fopen("graphResults_template.html", "r"); input = fopen("graphResults_template.html", "r");
} }
@ -735,16 +742,19 @@ int ppmColorChannel(FILE* fp, imagePixel_t *image, char *colorChannel, mldata_t
for (i = 0; i < mlData->samplesCount - 1; i++) { for (i = 0; i < mlData->samplesCount - 1; i++) {
fprintf(fp, "%d\n", image->data[i].green); fprintf(fp, "%d\n", image->data[i].green);
} }
} else if ( strcmp(colorChannel, "red") == 0 ){ }
else if (strcmp(colorChannel, "red") == 0) {
for (i = 0; i < mlData->samplesCount - 1; i++) { for (i = 0; i < mlData->samplesCount - 1; i++) {
fprintf(fp, "%d\n", image->data[i].red); fprintf(fp, "%d\n", image->data[i].red);
} }
} else if ( strcmp(colorChannel, "blue") == 0 ) { }
else if (strcmp(colorChannel, "blue") == 0) {
for (i = 0; i < mlData->samplesCount - 1; i++) { for (i = 0; i < mlData->samplesCount - 1; i++) {
fprintf(fp, "%d\n", image->data[i].blue); fprintf(fp, "%d\n", image->data[i].blue);
} }
} else { }
else {
printf("Colorchannels are red, green and blue. Pick one of them!"); printf("Colorchannels are red, green and blue. Pick one of them!");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }