Home Forums C Programming Calculating Entropy of a file and coding it using Hamming

• Author
Posts
• #2206

Hello there!

I am trying to solve a problem for a project i took and i am in the final

part of it…(view below for my until now code)

Well the aim is to calculate the entropy of a file and then to use

Hamming to code it. I managed to make both parts based on what I learned

from the class and read in the book. (Please if you are familiar with the

object tell me if it is correct )

So, my problem is that I am not able to merge those two parts below (you

dont need to read the theory for it).. like finding the entropy and then

continue for the coding of that file.

Any help, advice, anything is appreciate.
Thank you!

Entropy Calculation

``````#include "BufferedNode.h"
#include "Buffer.h"
#include "Vector.h"
#include
#include

#ifdef HAVE_VALUES_H
#include
#endif

#ifdef HAVE_FLOAT_H
#include
#endif

class Entropy;

DECLARE_NODE(Entropy)
/*Node
*
* @name Entropy
* @category DSP:Misc
* @description Calculates the entropy of a vector
*
* @input_name INPUT
* @input_type Vector
* @input_description Input vector
*
* @output_name OUTPUT
* @output_type Vector
* @output_description Entropy value (vector of 1)
*
END*/

class Entropy : public BufferedNode {

int inputID;
int outputID;

public:
Entropy(string nodeName, ParameterSet params)
: BufferedNode(nodeName, params)

{
}

void calculate(int output_id, int count, Buffer &out)
{
ObjectRef inputValue = getInput(inputID, count);

const Vector &in = object_cast > (inputValue);
int inputLength = in.size();

Vector &output = *Vector::alloc(1);
out[count] = &output;

float s2=0;
float entr=0;
for (int i=0;i
{
s2+=in*in;
}
s2 = 1/s2;

for (int i=0;i
{
if (in != 0)
entr -= s2*in*in * log(s2*in*in);
}
//cout << entr << endl;
output = entr;
}

};``````

Hamming coding :

`````` #include
#include
void hanming()
{
int i,n,k=2;
int h;
for(i=0;i<20;i++)h=0;
cout<<"bla bla"<>n;
while(pow(2,k)<<"bla bla"<>h;
}
h=(h+h+h+h+h+h+h)%2;
h=(h+h+h+h+h+h+h)%2;
h=(h+h+h+h+h+h+h)%2;
h=(h+h+h+h+h+h+h)%2;
for(i=1;i<=n+k;i++)cout<; jiaoyan(int="" a[],int="" n)="" {="" i,p1,p2,p4,p8,m;="" int="" h;="" for(i="0;i

[i+1]=a;" k="2;" p1="(h+h)%2;" p2="(h+h)%2;" m="2*p2+p1;" return="" m;="" }="" if(n="=3){">=5&&n<=7){
// k=3;
p1=(h+h+h+h)%2;
p2=(h+h+h+h)%2;
p4=(h+h+h+h)%2;
m=4*p4+2*p2+p1;
return m;
}
if(n>=9&&n<=15){
//k=4;
p1=(h+h+h+h+h+h+h+h)%2;
p2=(h+h+h+h+h+h+h+h)%2;
p4=(h+h+h+h+h+h+h+h)%2;
p8=(h+h+h+h+h+h+h+h)%2;
m=8*p8+4*p4+2*p2+p1;
return m;
}
else{
cout<<"bla bla"<

cout=""><<<"bla bla"<>n;
cout<<"bla bla"<>h;
m=jiaoyan(h,n);
if(m==0)cout<<"bla bla"<<>coco;
}    ``````