15double ChiSquare(T *dMat,
long int dim1,
long int dim2) {
33 rowSums =
new T[dim1];
34 for (i = 0; i < dim1; i++) {
37 for (j = 0; j < dim2; j++) {
38 rowSums[i] += dMat[idx1 + j];
40 tSum += (int)rowSums[i];
44 colSums =
new T[dim2];
45 for (i = 0; i < dim2; i++) {
47 for (j = 0; j < dim1; j++) {
48 colSums[i] += dMat[j * dim2 + i];
53 for (i = 0; i < dim1; i++) {
55 for (j = 0; j < dim2; j++) {
56 rchi += (pow((
double)dMat[i * dim2 + j], 2) / colSums[j]);
58 chi += (((double)tSum / rowSums[i]) * rchi);
71 double accum = 0.0, d;
73 for (i = 0; i < dim; i++) {
74 nInstances += tPtr[i];
77 if (nInstances != 0) {
78 for (i = 0; i < dim; i++) {
79 d = (double)tPtr[i] / nInstances;
85 return accum / log(2.0);
90 T *variableRes, *overallRes;
95 variableRes =
new T[dim1];
96 for (
long int i = 0; i < dim1; i++) {
97 long int idx1 = i * dim2;
98 variableRes[i] = (T)0.0;
99 for (
long int j = 0; j < dim2; j++) {
100 variableRes[i] += dMat[idx1 + j];
105 overallRes =
new T[dim2];
107 for (
long int i = 0; i < dim2; i++) {
108 overallRes[i] = (T)0.0;
109 for (
long int j = 0; j < dim1; j++) {
110 overallRes[i] += dMat[j * dim2 + i];
116 for (
long int i = 0; i < dim1; i++) {
118 tPtr = dMat + i * dim2;
122 for (
long int i = 0; i < dim2; i++) {
123 tSum +=
static_cast<int>(overallRes[i]);
135 delete[] variableRes;
Class used to rank bits based on a specified measure of information.
double InfoEntropyGain(T *dMat, long int dim1, long int dim2)
double ChiSquare(T *dMat, long int dim1, long int dim2)
double InfoEntropy(T *tPtr, long int dim)