summaryrefslogtreecommitdiff
path: root/src/c/statisticsFunctions/wcenter/swcentercola.c
blob: 6fafe9f914dbd7bce17006193aa56e772d80c219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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];
    
}