00001
00002 #include <assert.h>
00003 #include <stdio.h>
00004 #include <math.h>
00005
00006 #include "costshannon.h"
00007
00008
00021 double costshannon::costCalc( packnode<double> *node )
00022 {
00023 assert( node != 0 );
00024
00025 size_t len = node->length();
00026 const double *a = node->getData();
00027
00028 double sum = 0.0;
00029 for (int i = 0; i < len; i++) {
00030 double val = 0.0;
00031 if (a[i] != 0.0) {
00032 double square = a[i] * a[i];
00033 val = square * log( square );
00034 }
00035 sum = sum + val;
00036 }
00037
00038 return -sum;
00039 }