Calculating Entropy of a file and coding it using Hamming

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 31
Reputation: Punkis448 is an unknown quantity at this point 
Solved Threads: 0
Punkis448 Punkis448 is offline Offline
Light Poster

Calculating Entropy of a file and coding it using Hamming

 
-1
  #1
Jun 19th, 2009
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

  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

  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

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

 
0
  #2
Jun 19th, 2009
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.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 31
Reputation: Punkis448 is an unknown quantity at this point 
Solved Threads: 0
Punkis448 Punkis448 is offline Offline
Light Poster

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

 
0
  #3
Jun 19th, 2009
thanks for your answer but ok...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 672
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 99
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

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

 
0
  #4
Jun 19th, 2009
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.

  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,
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 949
Reputation: MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice MosaicFuneral is just really nice 
Solved Threads: 92
MosaicFuneral's Avatar
MosaicFuneral MosaicFuneral is offline Offline
Posting Shark

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

 
0
  #5
Jun 19th, 2009
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
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,602
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

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

 
0
  #6
Jun 19th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 792
Reputation: siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of siddhant3s has much to be proud of 
Solved Threads: 135
siddhant3s's Avatar
siddhant3s siddhant3s is offline Offline
Master Poster

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

 
0
  #7
Jun 19th, 2009
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.
Siddhant Sanyam
(Not posting much)
Migrate to Standard C++ :When to tell your C++ Code is Non-Standard.
Please Read before posting: How To Ask Questions The Smart Way
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,602
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

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

 
0
  #8
Jun 19th, 2009
the first one is classic thermodynamics.

im not sure about the second one, but apparently that's what this guy (OP) is doing.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

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

 
1
  #9
Jun 20th, 2009
> 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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 31
Reputation: Punkis448 is an unknown quantity at this point 
Solved Threads: 0
Punkis448 Punkis448 is offline Offline
Light Poster

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

 
0
  #10
Jun 20th, 2009
Can anyone help me or guide me with the code please?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC