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 <strstream>
#include <math.h>

#ifdef HAVE_VALUES_H
#include <values.h>
#endif

#ifdef HAVE_FLOAT_H
#include <float.h>
#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<float>
* @input_description Input vector
*
* @output_name OUTPUT
* @output_type Vector<float>
* @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<float> &in = object_cast<Vector<float> > (inputValue);
int inputLength = in.size();

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

float s2=0;
float entr=0;
for (int i=0;i<inputLength;i++)
{
s2+=in[i]*in[i];
}
s2 = 1/s2;

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

};

Hamming Coding

#include<iostream.h>
#include<math.h>
void hanming()
{
int i,n,k=2;
int h[20];
for(i=0;i<20;i++)h[i]=0;
cout<<"bla bla"<<endl; cin="">>n;
while(pow(2,k)<n+k+1)k++; cout=""><<"bla bla"<<endl; for(i="1;i<=n+k;i++){" if(i!="1&&i!=2&&i!=4&&i!=8)cin">>h[i];
}
h[1]=(h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;
h[2]=(h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;
h[4]=(h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;
h[8]=(h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;
for(i=1;i<=n+k;i++)cout<<h[i]; jiaoyan(int="" a[],int="" n)="" {="" i,p1,p2,p4,p8,m;="" int="" h[20];="" for(i="0;i<n;i++)h

[i+1]=a[i];" k="2;" p1="(h[1]+h[3])%2;" p2="(h[2]+h[3])%2;" m="2*p2+p1;" return="" m;="" }="" if(n="=3){">=5&&n<=7){
// k=3;
p1=(h[1]+h[3]+h[5]+h[7])%2;
p2=(h[2]+h[3]+h[6]+h[7])%2;
p4=(h[4]+h[5]+h[6]+h[7])%2;
m=4*p4+2*p2+p1;
return m;
}
if(n>=9&&n<=15){
//k=4;
p1=(h[1]+h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;
p2=(h[2]+h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;
p4=(h[4]+h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;
p8=(h[8]+h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;
m=8*p8+4*p4+2*p2+p1;
return m;
}
else{
cout<<"bla bla"<<endl; return="" -1;="" }="" ����="" void="" main()="" {="" hanming();="" coco;="" int="" i,n,m,h[20];=""

cout=""><<endl; cout=""><<"bla bla"<<endl; cin="">>n;
cout<<"bla bla"<<endl; for(i="0;i<n;i++)cin">>h[i];
m=jiaoyan(h,n);
if(m==0)cout<<"bla bla"<<endl; if(m!="0)cout<<"bla bla"<<m;" cout=""><<endl; cin="">>coco;
}
jephthah commented: for attempting to game the help forums with your stolen code. :icon_rolleyes: -2

All 16 Replies

First, read this excellent info and migrate your code to be more standard :)
(Especially read 2.3, and when you've some time left, than it might be a good idea to read the whole guide)

Hey I think that you will be getting a load of errors,

I am still unable to understand what the words ENTROPY and HAMMING CODE mean (to this code) even after reading some Wiki's about it.

inputID = addInput("INPUT");

inputID is declared as an Int, And there is no addInput Function presented in the code.

I really would like to have some more information to work with, Maybe If you can explain what your code has to do , and what is it currently doing

Some Sample Input values etc,

Entropy is just the measure of change/randomness in a system. And I suppose he's trying to check the correctness of the bits in a system. Maybe? idk

i notice your function is called: "hanming" ...but i imagine you would easily figure out a compile time error such as that.

otherwise, i dont really have fooking clue as to what "calculating entropy of a file and coding it using hamming" means. To be honest, I was thinking of the Second Law of Thermodynamics and DSP Hamming Filters, so I was all like WTF??? :P

I did find your other posts here and here, to be of some interest.

.

Why do they use the same words for different things?
I always thought Entropy S:
$$dS = \frac{\delta q}{T}$$
and
$$S = - k\sum_i P_i \ln P_i \!$$

Edit: The second formula is from Statistical Thermodynamics.

commented: O! ALMIGHTY! Like ALBERT EINSTIEN, Make Me Bright, So that I am Able to Kill Dark, And Make This World Full Of Light -4
commented: ehh, okay, here's your points back. but publicly complaining about neg rep is kind of gauche. +11

the first one is classic thermodynamics.

im not sure about the second one, but apparently that's what this guy (OP) is doing.

> I did find your other posts here and here, to be of some interest.
Aww man, you beat me :(
I could only find one other cross-post

commented: Is the OP going mad? :P +9

Can anyone help me or guide me with the code please?

Can anyone help me or guide me with the code please?

What do you think we're trying to do?

You only have to keep one thing in mind: We don't like it when you ask the same question numerous of times on different forums...

> Can anyone help me or guide me with the code please?
Not a chance.
It's quite obvious that you wrote neither one of them, and that you just happened to "find" them as a result of a web search.
For a start, the 2nd one looks a decade older than the first.

Further, since you've spammed so many forums, the chances are high that whatever we say here will be said somewhere else as well. I for one am not going to waste any more time on you, repeating what someone else may have written. I'm certainly not going to check all the cross-forum sites just to make sure I'm not repeating what someone else wrote.

Lastly, constant whining "help me" without you making an effort just puts everyone off.

Try writing your own code, not begging for other people to hack together something you found.

commented: shazam! +11

ahah

here's the OP, from one of his cross-posts:

hey there, do you accept payments to make me the code?

:D

iamthwee@reputaion box of post#7>O! ALMIGHTY! Like ALBERT EINSTIEN, Make Me Bright, So that I am Able to Kill >Dark, And Make This World Full Of Light

So? What was your point? That was the ending verse of a poem I wrote when I was nearly 12. Sure it is the published at writing dot com if you go and search my name on google.
But what are you trying to convey? Just picking up my random posts and giving infractions. Is it not a means of harassing me?
Other day, I was discussing with a DaniWeb member about your behavior and I told him that you've improved, but I guess I was wrong.

If there was an option to give infraction on your comments on the reputation box, I (and perhaps more people around) would love to. Those comments are to be written so that the person you are giving infraction knows what he did wrong, not to quote random thoughts.

commented: The "iamthwee is a douche" supporters club +35

okay.

commented: *chuckles* +21

Hey iamthwee, why always neg-repping siddhant ?
Because you don't understand the formulas he's using ??

@jephthah
Then what should I do? Send a PM to Mr.iamthwee? You think it will work? Don't you there is someone lurking here and spreading his gaucheness around? SoS, am I infected.

@Tux,
LoL, those formula were pretty elementary. Anyone who has taken even a high-school course on Thermodynamics can understand them.

@Salem
LoL X2. You read my mind: I was just thinking to start a thread on the Geeks' Lounge.
I mean seriously, I had nothing personal against him. But everyone has his limit of accepting crap.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.