summaryrefslogtreecommitdiff
path: root/src/c/statisticsFunctions/wcenter/dwcenterrowa.c
blob: 72e379317993da7d07bd9a7a9cf857d00c57dce7 (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
62
63
64
65
66
67
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];

}