diff options
Diffstat (limited to '2.3-1/src/c/statisticsFunctions/wcenter')
9 files changed, 505 insertions, 0 deletions
diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/dwcentera.c b/2.3-1/src/c/statisticsFunctions/wcenter/dwcentera.c new file mode 100644 index 00000000..5c05cc86 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/dwcentera.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "multiplication.h" +#include "wcenter.h" + +void dwcentera (double* inp, int row, int col, double* out) +{ + double sum = 0, xbar = 0, sigma = 0; + for(int i = 0; i < row*col; i++) // Findinag the maen of all the elements of the matrix + sum += inp[i]; + xbar = sum/(row*col); + + double one[row*col]; // Creating a matrix of ones + donesa(one,row,col); + + double prod[row*col]; + for(int i = 0; i < row*col; i++) // Applying the formula (x(i,j)-xbar)/sigma + prod[i] = one[i]*xbar; + + for(int i = 0; i < row*col; i++) + out[i] = inp[i] - prod[i]; + + sum = 0; + for(int i = 0; i < row*col; i++) + sum = sum + out[i]*out[i]; + + sigma = sqrt(sum/(row*col-1)); + + for(int i = 0; i < row*col; i++) + out[i] = out[i]/sigma; +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/dwcentercola.c b/2.3-1/src/c/statisticsFunctions/wcenter/dwcentercola.c new file mode 100644 index 00000000..ab82acfe --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/dwcentercola.c @@ -0,0 +1,64 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "matrixMultiplication.h" +#include "wcenter.h" + +void dwcentercola (double* inp, int row, int col, double* out) +{ + + double sum[row], xbar[row]; + for(int i = 0; i < row; i++) + sum[i] = 0; + + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] += inp[i + j*row]; + } + } + + //for(int i = 0; i < row; i++) + //printf("%lf \n",sum[i]); + + for(int i = 0; i < row; i++) + xbar[i] = sum[i]/col; + + double one[col]; // Creating a matrix of ones + donesa(one,1,col); + + + double prod[row*col]; + dmulma(xbar, row, 1, one, 1, col, prod); + + for(int i = 0; i< row*col; i++) + out[i] = inp[i] - prod[i]; + + for(int i = 0; i < row; i++) + sum[i] = 0; + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] += out[i + j*row] * out[i + j*row]; + } + } + + double sigma[row]; + for(int i = 0; i < row; i++) + sigma[i] = sqrt(sum[i]/(col-1)); + + for(int i = 0; i < row*col; i++) + prod[i] = 0; + + dmulma(sigma, row, 1, one, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = out[i] / prod[i]; + +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/dwcenterrowa.c b/2.3-1/src/c/statisticsFunctions/wcenter/dwcenterrowa.c new file mode 100644 index 00000000..72e37931 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/dwcenterrowa.c @@ -0,0 +1,68 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "matrixMultiplication.h" +#include "wcenter.h" + +void dwcenterrowa (double* inp, int row, int col, double* out) +{ + + double sum[col], xbar[col]; + for(int i = 0; i < col; i++) + sum[i] = 0; + + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] += inp[j + i*row]; + } + } + + + + for(int i = 0; i < col; i++) + xbar[i] = sum[i]/row; + + double one[row]; // Creating a matrix of ones + donesa(one,row,1); + + double prod[row*col]; + dmulma(one, row, 1, xbar, 1, col, prod); + + + + for(int i = 0; i< row*col; i++) + out[i] = inp[i] - prod[i]; + + + for(int i = 0; i < col; i++) + sum[i] = 0; + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] += out[j + i*row] * out[j + i*row]; + } + } + + + + double sigma[col]; + for(int i = 0; i < col; i++) + sigma[i] = sqrt(sum[i]/(row-1)); + + + for(int i = 0; i < row*col; i++) + prod[i] = 0; + + dmulma(one, row, 1, sigma, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = out[i] / prod[i]; + +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/swcentera.c b/2.3-1/src/c/statisticsFunctions/wcenter/swcentera.c new file mode 100644 index 00000000..91206fcf --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/swcentera.c @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "multiplication.h" +#include "wcenter.h" + +void swcentera (float* inp, int row, int col, float* out) +{ + float sum = 0, xbar = 0, sigma = 0; + for(int i = 0; i < row*col; i++) // Findinag the maen of all the elements of the matrix + sum += inp[i]; + xbar = sum/(row*col); + + float one[row*col]; // Creating a matrix of ones + sonesa(one,row,col); + + float prod[row*col]; + for(int i = 0; i < row*col; i++) // Applying the formula (x(i,j)-xbar)/sigma + prod[i] = one[i]*xbar; + + for(int i = 0; i < row*col; i++) + out[i] = inp[i] - prod[i]; + + sum = 0; + for(int i = 0; i < row*col; i++) + sum = sum + out[i]*out[i]; + + sigma = sqrt(sum/(row*col-1)); + + for(int i = 0; i < row*col; i++) + out[i] = out[i]/sigma; +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/swcentercola.c b/2.3-1/src/c/statisticsFunctions/wcenter/swcentercola.c new file mode 100644 index 00000000..6fafe9f9 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/swcentercola.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "matrixMultiplication.h" +#include "wcenter.h" + +void swcentercola (float* inp, int row, int col, float* out) +{ + + float sum[row], xbar[row]; + for(int i = 0; i < row; i++) + sum[i] = 0; + + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] += inp[i + j*row]; + } + } + + for(int i = 0; i < row; i++) + xbar[i] = sum[i]/col; + + float one[col]; // Creating a matrix of ones + sonesa(one,1,col); + + + float prod[row*col]; + smulma(xbar, row, 1, one, 1, col, prod); + + for(int i = 0; i< row*col; i++) + out[i] = inp[i] - prod[i]; + + for(int i = 0; i < row; i++) + sum[i] = 0; + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] += out[i + j*row] * out[i + j*row]; + } + } + + float sigma[row]; + for(int i = 0; i < row; i++) + sigma[i] = sqrt(sum[i]/(col-1)); + + for(int i = 0; i < row*col; i++) + prod[i] = 0; + + smulma(sigma, row, 1, one, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = out[i] / prod[i]; + +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/swcenterrowa.c b/2.3-1/src/c/statisticsFunctions/wcenter/swcenterrowa.c new file mode 100644 index 00000000..ce1df2e9 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/swcenterrowa.c @@ -0,0 +1,68 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "subtraction.h" +#include "matrixMultiplication.h" +#include "wcenter.h" + +void swcenterrowa (float* inp, int row, int col, float* out) +{ + + float sum[col], xbar[col]; + for(int i = 0; i < col; i++) + sum[i] = 0; + + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] += inp[j + i*row]; + } + } + + + + for(int i = 0; i < col; i++) + xbar[i] = sum[i]/row; + + float one[row]; // Creating a matrix of ones + sonesa(one,row,1); + + float prod[row*col]; + smulma(one, row, 1, xbar, 1, col, prod); + + + + for(int i = 0; i< row*col; i++) + out[i] = inp[i] - prod[i]; + + + for(int i = 0; i < col; i++) + sum[i] = 0; + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] += out[j + i*row] * out[j + i*row]; + } + } + + + + float sigma[col]; + for(int i = 0; i < col; i++) + sigma[i] = sqrt(sum[i]/(row-1)); + + + for(int i = 0; i < row*col; i++) + prod[i] = 0; + + smulma(one, row, 1, sigma, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = out[i] / prod[i]; + +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/zwcentera.c b/2.3-1/src/c/statisticsFunctions/wcenter/zwcentera.c new file mode 100644 index 00000000..8571dd62 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/zwcentera.c @@ -0,0 +1,38 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "addition.h" +#include "subtraction.h" +#include "multiplication.h" +#include "division.h" +#include "wcenter.h" +#include "doubleComplex.h" +#include "sqrt.h" + +void zwcentera (doubleComplex* inp, int row, int col, doubleComplex* out) +{ + doubleComplex sum = 0, xbar = 0, sigma = 0; + for(int i = 0; i < row*col; i++) // Findinag the maen of all the elements of the matrix + sum = zadds(sum,inp[i]); + xbar = zrdivs(sum,(row*col)); + + doubleComplex one[row*col]; // Creating a matrix of ones + zonesa(one,row,col); + + doubleComplex prod[row*col]; + for(int i = 0; i < row*col; i++) // Applying the formula (x(i,j)-xbar)/sigma + prod[i] = zmuls(one[i],xbar); + + for(int i = 0; i < row*col; i++) + out[i] = zdiffs(inp[i], prod[i]); + + sum = DoubleComplex(0,0); + for(int i = 0; i < row*col; i++) + sum = zadds(sum, zmuls(out[i],out[i])); + + sigma = zsqrts(zrdivs(sum,(row*col-1))); + + for(int i = 0; i < row*col; i++) + out[i] = zrdivs(out[i],sigma); +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/zwcentercola.c b/2.3-1/src/c/statisticsFunctions/wcenter/zwcentercola.c new file mode 100644 index 00000000..5e4e2bdd --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/zwcentercola.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "addition.h" +#include "subtraction.h" +#include "multiplication.h" +#include "division.h" +#include "wcenter.h" +#include "doubleComplex.h" +#include "sqrt.h" + +void zwcentercola (doubleComplex* inp, int row, int col, doubleComplex* out) +{ + + doubleComplex sum[row], xbar[row]; + for(int i = 0; i < row; i++) + sum[i] = DoubleComplex(0,0); + + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] = zadds(sum[i], inp[i + j*row]); + } + } + + + for(int i = 0; i < row; i++) + xbar[i] = zrdivs(sum[i], col); + + doubleComplex one[col]; // Creating a matrix of ones + zonesa(one,1,col); + + + doubleComplex prod[row*col]; + zmulma(xbar, row, 1, one, 1, col, prod); + + for(int i = 0; i< row*col; i++) + out[i] = zdiffs(inp[i], prod[i]); + + for(int i = 0; i < row; i++) + sum[i] = DoubleComplex(0,0); + + for(int i = 0; i < row; i++) + { + for(int j = 0; j < col; j++) + { + sum[i] = zadds(sum[i], zmuls(out[i + j*row], out[i + j*row])); + } + } + + doubleComplex sigma[row]; + for(int i = 0; i < row; i++) + sigma[i] = zsqrts(zrdivs(sum[i],(col-1))); + + for(int i = 0; i < row*col; i++) + prod[i] = DoubleComplex(0,0); + + zmulma(sigma, row, 1, one, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = zrdivs(out[i], prod[i]); + +} diff --git a/2.3-1/src/c/statisticsFunctions/wcenter/zwcenterrowa.c b/2.3-1/src/c/statisticsFunctions/wcenter/zwcenterrowa.c new file mode 100644 index 00000000..f68835d8 --- /dev/null +++ b/2.3-1/src/c/statisticsFunctions/wcenter/zwcenterrowa.c @@ -0,0 +1,72 @@ +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <ones.h> +#include "addition.h" +#include "subtraction.h" +#include "multiplication.h" +#include "division.h" +#include "wcenter.h" +#include "doubleComplex.h" +#include "sqrt.h" + +void zwcenterrowa (doubleComplex* inp, int row, int col, doubleComplex* out) +{ + + doubleComplex sum[col], xbar[col]; + for(int i = 0; i < col; i++) + sum[i] = DoubleComplex(0,0); + + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] = zadds(sum[i], inp[j + i*row]); + } + } + + + + for(int i = 0; i < col; i++) + xbar[i] = zrdivs(sum[i], row); + + doubleComplex one[row]; // Creating a matrix of ones + zonesa(one,row,1); + + doubleComplex prod[row*col]; + zmulma(one, row, 1, xbar, 1, col, prod); + + + + for(int i = 0; i< row*col; i++) + out[i] = zdiffs(inp[i], prod[i]); + + + for(int i = 0; i < col; i++) + sum[i] = DoubleComplex(0,0); + + for(int i = 0; i < col; i++) + { + for(int j = 0; j < row; j++) + { + sum[i] = zadds(sum[i], zmuls(out[j + i*row], out[j + i*row])); + } + } + + + + doubleComplex sigma[col]; + for(int i = 0; i < col; i++) + sigma[i] = zsqrts(zrdivs(sum[i],(row-1))); + + + for(int i = 0; i < row*col; i++) + prod[i] = DoubleComplex(0,0); + + zmulma(one, row, 1, sigma, 1, col, prod); + + for(int i = 0; i < row*col; i++) + out[i] = zrdivs(out[i], prod[i]); + +} |