943,755 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2492
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 19th, 2009
-1

Calculating Entropy of a file and coding it using Hamming

Expand Post »
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

C++ Syntax (Toggle Plain Text)
  1.  
  2. #include "BufferedNode.h"
  3. #include "Buffer.h"
  4. #include "Vector.h"
  5. #include <strstream>
  6. #include <math.h>
  7.  
  8. #ifdef HAVE_VALUES_H
  9. #include <values.h>
  10. #endif
  11.  
  12. #ifdef HAVE_FLOAT_H
  13. #include <float.h>
  14. #endif
  15.  
  16. class Entropy;
  17.  
  18. DECLARE_NODE(Entropy)
  19. /*Node
  20.  *
  21.  * @name Entropy
  22.  * @category DSP:Misc
  23.  * @description Calculates the entropy of a vector
  24.  *
  25.  * @input_name INPUT
  26.  * @input_type Vector<float>
  27.  * @input_description Input vector
  28.  *
  29.  * @output_name OUTPUT
  30.  * @output_type Vector<float>
  31.  * @output_description Entropy value (vector of 1)
  32.  *
  33. END*/
  34.  
  35.  
  36. class Entropy : public BufferedNode {
  37.  
  38. int inputID;
  39. int outputID;
  40.  
  41. public:
  42. Entropy(string nodeName, ParameterSet params)
  43. : BufferedNode(nodeName, params)
  44.  
  45. {
  46. inputID = addInput("INPUT");
  47. outputID = addOutput("OUTPUT");
  48. }
  49.  
  50. void calculate(int output_id, int count, Buffer &out)
  51. {
  52. ObjectRef inputValue = getInput(inputID, count);
  53.  
  54. const Vector<float> &in = object_cast<Vector<float> > (inputValue);
  55. int inputLength = in.size();
  56.  
  57. Vector<float> &output = *Vector<float>::alloc(1);
  58. out[count] = &output;
  59.  
  60. float s2=0;
  61. float entr=0;
  62. for (int i=0;i<inputLength;i++)
  63. {
  64. s2+=in[i]*in[i];
  65. }
  66. s2 = 1/s2;
  67.  
  68. for (int i=0;i<inputLength;i++)
  69. {
  70. if (in[i] != 0)
  71. entr -= s2*in[i]*in[i] * log(s2*in[i]*in[i]);
  72. }
  73. //cout << entr << endl;
  74. output[0] = entr;
  75. }
  76.  
  77. };

Hamming Coding

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2. #include<math.h>
  3. void hanming()
  4. {
  5. int i,n,k=2;
  6. int h[20];
  7. for(i=0;i<20;i++)h[i]=0;
  8. cout<<"bla bla"<<endl; cin="">>n;
  9. 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];
  10. }
  11. h[1]=(h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;
  12. h[2]=(h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;
  13. h[4]=(h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;
  14. h[8]=(h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;
  15. 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
  16.  
  17. [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){
  18. // k=3;
  19. p1=(h[1]+h[3]+h[5]+h[7])%2;
  20. p2=(h[2]+h[3]+h[6]+h[7])%2;
  21. p4=(h[4]+h[5]+h[6]+h[7])%2;
  22. m=4*p4+2*p2+p1;
  23. return m;
  24. }
  25. if(n>=9&&n<=15){
  26. //k=4;
  27. p1=(h[1]+h[3]+h[5]+h[7]+h[9]+h[11]+h[13]+h[15])%2;
  28. p2=(h[2]+h[3]+h[6]+h[7]+h[10]+h[11]+h[14]+h[15])%2;
  29. p4=(h[4]+h[5]+h[6]+h[7]+h[12]+h[13]+h[14]+h[15])%2;
  30. p8=(h[8]+h[9]+h[10]+h[11]+h[12]+h[13]+h[14]+h[15])%2;
  31. m=8*p8+4*p4+2*p2+p1;
  32. return m;
  33. }
  34. else{
  35. cout<<"bla bla"<<endl; return="" -1;="" }="" ����="" void="" main()="" {="" hanming();="" coco;="" int="" i,n,m,h[20];=""
  36.  
  37. cout=""><<endl; cout=""><<"bla bla"<<endl; cin="">>n;
  38. cout<<"bla bla"<<endl; for(i="0;i<n;i++)cin">>h[i];
  39. m=jiaoyan(h,n);
  40. if(m==0)cout<<"bla bla"<<endl; if(m!="0)cout<<"bla bla"<<m;" cout=""><<endl; cin="">>coco;
  41. }
Last edited by Punkis448; Jun 19th, 2009 at 6:05 am.
Similar Threads
Reputation Points: 8
Solved Threads: 0
Light Poster
Punkis448 is offline Offline
31 posts
since May 2008
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

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)
Last edited by tux4life; Jun 19th, 2009 at 6:48 am.
Reputation Points: 2125
Solved Threads: 243
Postaholic
tux4life is offline Offline
2,105 posts
since Feb 2009
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

thanks for your answer but ok...
Reputation Points: 8
Solved Threads: 0
Light Poster
Punkis448 is offline Offline
31 posts
since May 2008
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

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.

C++ Syntax (Toggle Plain Text)
  1. 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,
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

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
Reputation Points: 888
Solved Threads: 114
Nearly a Posting Virtuoso
MosaicFuneral is offline Offline
1,270 posts
since Nov 2008
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

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???

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


.
Last edited by jephthah; Jun 19th, 2009 at 7:14 pm.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

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.
Last edited by siddhant3s; Jun 19th, 2009 at 7:28 pm.
Reputation Points: 1486
Solved Threads: 140
Practically a Posting Shark
siddhant3s is offline Offline
816 posts
since Oct 2007
Jun 19th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

the first one is classic thermodynamics.

im not sure about the second one, but apparently that's what this guy (OP) is doing.
Reputation Points: 2143
Solved Threads: 178
Posting Maven
jephthah is offline Offline
2,567 posts
since Feb 2008
Jun 20th, 2009
1

Re: Calculating Entropy of a file and coding it using Hamming

> 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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 20th, 2009
0

Re: Calculating Entropy of a file and coding it using Hamming

Can anyone help me or guide me with the code please?
Reputation Points: 8
Solved Threads: 0
Light Poster
Punkis448 is offline Offline
31 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: structures
Next Thread in C++ Forum Timeline: Syntax Prob: using string.insert





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC