updated cpp src-code and uploading cpp .exe and renamed cs .exe
This commit is contained in:
parent
0233a4c997
commit
9a888d99df
Binary file not shown.
|
@ -11,7 +11,6 @@ Created by Stefan Friese on 26.04.2018
|
|||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
//#include <float.h> // DBL_MAX
|
||||
#include "nlms_types.h" // added types
|
||||
|
||||
#define RGB_COLOR 255
|
||||
|
@ -145,7 +144,8 @@ int main( int argc, char **argv ) {
|
|||
if ((seed != NULL)) {
|
||||
srand(*seed); // Seed for random number generating
|
||||
printf("srand is reproducable\n");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
srand((unsigned int)time(NULL));
|
||||
printf("srand depends on time\n"); // Default seed is time(NULL)
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ Variant (1/3), substract local mean.
|
|||
*/
|
||||
void localMean(mldata_t *mlData, point_t points[]) {
|
||||
double *localWeights = (double *)malloc(sizeof(double) * mlData->windowSize + 1);
|
||||
memcpy ( localWeights, mlData->weights, mlData->windowSize ); // Copy weights so they can be changed locally
|
||||
localWeights = mlData->weights; // Copy weights so they can be changed locally
|
||||
|
||||
char fileName[50];
|
||||
double *xError = (double *)malloc(sizeof(double) * mlData->samplesCount + 1); // Includes e(n)
|
||||
|
@ -213,7 +213,7 @@ void localMean ( mldata_t *mlData, point_t points[] ) {
|
|||
double xPredicted = 0.0;
|
||||
double xActual = 0.0;
|
||||
|
||||
for ( xCount = 1; xCount < mlData->samplesCount; xCount++ ) { // First value will not get predicted
|
||||
for (xCount = 1; xCount < mlData->samplesCount-1; xCount++) { // First value will not get predicted
|
||||
unsigned _arrayLength = (xCount > mlData->windowSize) ? mlData->windowSize + 1 : xCount; // Ensures corect length at start
|
||||
xMean = (xCount > 0) ? windowXMean(_arrayLength, xCount) : 0;
|
||||
xPredicted = 0.0;
|
||||
|
@ -260,7 +260,7 @@ void localMean ( mldata_t *mlData, point_t points[] ) {
|
|||
deviation /= xErrorLength; // Deviation
|
||||
printf("mean:%lf, devitation:%lf\t\tlocal Mean\n", mean, deviation);
|
||||
fprintf(fp4, "\nQuadratische Varianz(x_error): %f\nMittelwert:(x_error): %f\n\n", deviation, mean); // Write to logfile
|
||||
free(localWeights);
|
||||
//free(localWeights);
|
||||
free(xErrorPtr);
|
||||
free(xError);
|
||||
|
||||
|
@ -281,9 +281,10 @@ substract direct predecessor
|
|||
*/
|
||||
void directPredecessor(mldata_t *mlData, point_t points[]) {
|
||||
double *localWeights = (double *)malloc(sizeof(double) * mlData->windowSize + 1);
|
||||
memcpy ( localWeights, mlData->weights, mlData->windowSize );
|
||||
localWeights = mlData->weights;
|
||||
char fileName[512];
|
||||
double *xError = (double *)malloc(sizeof(double) * mlData->samplesCount + 1);
|
||||
memset(xError, 0.0, mlData->samplesCount);
|
||||
unsigned xCount = 0, i;
|
||||
double xActual = 0.0;
|
||||
double xPredicted = 0.0;
|
||||
|
@ -295,7 +296,7 @@ void directPredecessor( mldata_t *mlData, point_t points[]) {
|
|||
mkFileName(fileName, sizeof(fileName), USED_WEIGHTS_DIR_PRED);
|
||||
FILE *fp9 = fopen(fileName, "w");
|
||||
|
||||
for (xCount = 1; xCount < mlData->samplesCount; xCount++) { // first value will not get predicted
|
||||
for (xCount = 1; xCount < mlData->samplesCount-1; xCount++) { // first value will not get predicted
|
||||
unsigned _arrayLength = (xCount > mlData->windowSize) ? mlData->windowSize + 1 : xCount;
|
||||
xPredicted = 0.0;
|
||||
xActual = xSamples[xCount];
|
||||
|
@ -346,7 +347,7 @@ void directPredecessor( mldata_t *mlData, point_t points[]) {
|
|||
printf("mean:%lf, devitation:%lf\t\tdirect Predecessor\n", mean, deviation);
|
||||
fprintf(fp3, "\nQuadratische Varianz(x_error): %f\nMittelwert:(x_error): %f\n\n", deviation, mean);
|
||||
fclose(fp3);
|
||||
free(localWeights);
|
||||
//free(localWeights);
|
||||
free(xErrorPtr);
|
||||
free(xError);
|
||||
}
|
||||
|
@ -363,9 +364,10 @@ differential predecessor.
|
|||
*/
|
||||
void differentialPredecessor(mldata_t *mlData, point_t points[]) {
|
||||
double *localWeights = (double *)malloc(sizeof(double) * mlData->windowSize + 1);
|
||||
memcpy( localWeights, mlData->weights, mlData->windowSize );
|
||||
localWeights = mlData->weights;
|
||||
char fileName[512];
|
||||
double *xError = (double *)malloc(sizeof(double) * mlData->samplesCount + 1);
|
||||
memset(xError, 0.0, mlData->samplesCount);
|
||||
unsigned xCount = 0, i;
|
||||
double xPredicted = 0.0;
|
||||
double xActual = 0.0;
|
||||
|
@ -377,7 +379,7 @@ void differentialPredecessor ( mldata_t *mlData, point_t points[] ) {
|
|||
mkFileName(fileName, sizeof(fileName), USED_WEIGHTS_DIFF_PRED);
|
||||
FILE *fp9 = fopen(fileName, "w");
|
||||
|
||||
for (xCount = 1; xCount < mlData->samplesCount; xCount++) { // First value will not get predicted
|
||||
for (xCount = 1; xCount < mlData->samplesCount-1; xCount++) { // First value will not get predicted
|
||||
|
||||
unsigned _arrayLength = (xCount > mlData->windowSize) ? mlData->windowSize + 1 : xCount;
|
||||
xPredicted = 0.0;
|
||||
|
@ -428,7 +430,7 @@ void differentialPredecessor ( mldata_t *mlData, point_t points[] ) {
|
|||
printf("mean:%lf, devitation:%lf\t\tdifferential Predecessor\n", mean, deviation);
|
||||
fprintf(fp6, "\nQuadratische Varianz(x_error): %f\nMittelwert:(x_error): %f\n\n", deviation, mean);
|
||||
fclose(fp6);
|
||||
free(localWeights);
|
||||
//free(localWeights);
|
||||
free(xErrorPtr);
|
||||
free(xError);
|
||||
|
||||
|
@ -539,22 +541,22 @@ void bufferLogger(char *buffer, point_t points[]) {
|
|||
unsigned i;
|
||||
char _buffer[512] = ""; // TODO: resize buffer and _buffer so greater sampleval can be choosen
|
||||
// char *_buffer = (char *) malloc ( sizeof(char) * 512 + 1);
|
||||
for (i = 0; i < mlData->samplesCount - 1; i++) { // xActual
|
||||
for (i = 1; i < mlData->samplesCount - 1; i++) { // xActual
|
||||
sprintf(_buffer, "L %f %f\n", points[i].xVal[0], points[i].yVal[0]);
|
||||
strcat(buffer, _buffer);
|
||||
}
|
||||
strcat(buffer, "\" fill=\"none\" id=\"svg_1\" stroke=\"black\" stroke-width=\"0.4px\"/>\n<path d=\"M0 0\n");
|
||||
for (i = 0; i < mlData->samplesCount - 1; i++) { // xPredicted from localMean
|
||||
for (i = 1; i < mlData->samplesCount - 1; i++) { // xPredicted from localMean
|
||||
sprintf(_buffer, "L %f %f\n", points[i].xVal[1], points[i].yVal[1]);
|
||||
strcat(buffer, _buffer);
|
||||
}
|
||||
strcat(buffer, "\" fill=\"none\" id=\"svg_2\" stroke=\"green\" stroke-width=\"0.4px\"/>\n<path d=\"M0 0\n");
|
||||
for (i = 0; i <= mlData->samplesCount - 1; i++) { //xPredicted from directPredecessor
|
||||
for (i = 1; i <= mlData->samplesCount - 1; i++) { //xPredicted from directPredecessor
|
||||
sprintf(_buffer, "L %f %f\n", points[i].xVal[2], points[i].yVal[2]);
|
||||
strcat(buffer, _buffer);
|
||||
}
|
||||
strcat(buffer, "\" fill=\"none\" id=\"svg_3\" stroke=\"blue\" stroke-width=\"0.4px\"/>\n<path d=\"M0 0\n");
|
||||
for (i = 0; i < mlData->samplesCount - 1; i++) { //xPredicted from diff Pred
|
||||
for (i = 1; i < mlData->samplesCount - 1; i++) { //xPredicted from diff Pred
|
||||
sprintf(_buffer, "L %f %f\n", points[i].xVal[3], points[i].yVal[3]);
|
||||
strcat(buffer, _buffer);
|
||||
}
|
||||
|
@ -793,16 +795,19 @@ int ppmColorChannel(FILE* fp, imagePixel_t *image, char *colorChannel, mldata_t
|
|||
for (i = 0; i < mlData->samplesCount - 1; i++) {
|
||||
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++) {
|
||||
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++) {
|
||||
fprintf(fp, "%d\n", image->data[i].blue);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printf("Colorchannels are red, green and blue. Pick one of them!");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue