added stuff

This commit is contained in:
Friese 2018-05-14 13:54:56 +02:00
parent 121955bc5a
commit 6d23b63f0e
1 changed files with 30 additions and 25 deletions

View File

@ -13,6 +13,7 @@
#include <string.h>
#include <float.h> // DBL_MAX
#define NUMBER_OF_SAMPLES 500
#define WINDOWSIZE 5
#define tracking 40 //Count of weights
@ -33,6 +34,9 @@ typedef SSIZE_T ssize_t;
//double x[] = { 0.0 };
double xSamples[NUMBER_OF_SAMPLES] = { 0.0 };
/* *svg graph building* */
typedef struct {
double xVal[7];
@ -84,7 +88,7 @@ int main( void ) {
int i,k, xLength;
imagePixel_t *image;
image = rdPPM("beaches.ppm");
image = rdPPM("cow.ppm");
mkFileName(fileName, sizeof(fileName), TEST_VALUES);
FILE* fp5 = fopen(fileName, "w");
xLength = ppmColorChannel(fp5, image);
@ -120,11 +124,11 @@ int main( void ) {
printf("ALT::%f\n", local_weights[k][i]);
}
}*/
localMean(weights);
//localMean(weights);
// memcpy(local_weights, weights, sizeof(double) * WINDOWSIZE * NUMBER_OF_SAMPLES);
// directPredecessor(weights);
// memcpy(local_weights, weights, sizeof(double) * WINDOWSIZE * NUMBER_OF_SAMPLES);
// differentialPredecessor(weights);
differentialPredecessor(weights);
mkSvgGraph(points);
// save test_array after math magic happened
// memset( fileName, '\0', sizeof(fileName) );
@ -213,11 +217,12 @@ void localMean(double weights[WINDOWSIZE][NUMBER_OF_SAMPLES]) {
}
// int xErrorLength = sizeof(xError) / sizeof(xError[0]);
// printf("vor:%d", xErrorLength);
popNAN(xError); // delete NAN values from xError[]
// printf("%lf", xError[499]);
double xErrorLength = xError[0]; // Watch popNAN()!
double *xErrorPtr = popNAN(xError); // delete NAN values from xError[]
//printf("%lf", xErrorPtr[499]);
double xErrorLength = *xErrorPtr; // Watch popNAN()!
printf("Xerrorl:%lf", xErrorLength);
double mean = sum_array(xError, xErrorLength) / xErrorLength;
/* double mean = sum_array(*xErrorPtr, xErrorLength) / xErrorLength;
double deviation = 0.0;
// Mean square
@ -230,7 +235,7 @@ void localMean(double weights[WINDOWSIZE][NUMBER_OF_SAMPLES]) {
mkFileName(fileName, sizeof(fileName), RESULTS);
FILE *fp2 = fopen(fileName, "w");
fprintf(fp2, "quadr. Varianz(x_error): {%f}\nMittelwert:(x_error): {%f}\n\n", deviation, mean);
fclose(fp2);
fclose(fp2);*/
free(local_weights);
fclose(fp4);
@ -370,7 +375,7 @@ void differentialPredecessor(double weights[WINDOWSIZE][NUMBER_OF_SAMPLES]) {
local_weights[i][xCount+1] = local_weights[i][xCount] + learnrate * xError[xCount] * ((xSamples[xCount - i] - xSamples[xCount - i - 1]) / xSquared);
}
}
/*
int xErrorLength = sizeof(xError) / sizeof(xError[0]);
printf("vor:%d", xErrorLength);
popNAN(xError);
@ -386,7 +391,7 @@ void differentialPredecessor(double weights[WINDOWSIZE][NUMBER_OF_SAMPLES]) {
//mkSvgGraph(points);
fprintf(fp6, "{%d}.\tLeast Mean Squared{%f}\tMean{%f}\n\n", xCount, deviation, mean);
*/
fclose(fp6);
@ -469,7 +474,7 @@ void bufferLogger(char *buffer, point_t points[]) {
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 < NUMBER_OF_SAMPLES - 1; i++) { // xPrediceted from localMean
for (i = 0; i < NUMBER_OF_SAMPLES - 1; i++) { // xPredicted from localMean
sprintf(_buffer, "L %f %f\n", points[i].xVal[1], points[i].yVal[1]);
strcat(buffer, _buffer);
}
@ -483,7 +488,7 @@ void bufferLogger(char *buffer, point_t points[]) {
sprintf(_buffer, "L %f %f\n", points[i].xVal[3], points[i].xVal[3]);
strcat(buffer, _buffer);
}
strcat(buffer, "\" fill=\"none\" id=\"svg_4\" stroke=\"blue\" stroke-width=\"0.4px\"/>\n");
strcat(buffer, "\" fill=\"none\" id=\"svg_4\" stroke=\"red\" stroke-width=\"0.4px\"/>\n");
}
@ -541,7 +546,7 @@ double *popNAN(double *xError) {
counter += 1;
more_tmp = (double *) realloc ( tmp, counter * sizeof(double) );
tmp = more_tmp;
tmp = &tmpLength; // Length of array has to be stored in tmp[0],
*tmp = tmpLength; // Length of array has to be stored in tmp[0],
// Cause length is needed later on in the math functions.
// xError counting has to begin with 1 in the other functions !
printf("tmpLength in tmp:%lf, %lf\n", tmp[counter-2], *tmp);